castle-dynamicproxy

How to access custom method attributes from ProxyGenerationHook in Castle.DynamicProxy

◇◆丶佛笑我妖孽 提交于 2021-01-07 05:14:34
问题 I'm implementing Interceptor mechanism in .NET with Castle.DynamicProxy (Castle.Core 4.4.0). I'm following this tutorial for selecting which method to intercept: https://kozmic.net/2009/01/17/castle-dynamic-proxy-tutorial-part-iii-selecting-which-methods-to/ It was given an example in this article about "selecting which methods to intercept": public class FreezableProxyGenerationHook:IProxyGenerationHook { public bool ShouldInterceptMethod(Type type, MethodInfo memberInfo) { return

How to access custom method attributes from ProxyGenerationHook in Castle.DynamicProxy

自闭症网瘾萝莉.ら 提交于 2021-01-07 05:05:23
问题 I'm implementing Interceptor mechanism in .NET with Castle.DynamicProxy (Castle.Core 4.4.0). I'm following this tutorial for selecting which method to intercept: https://kozmic.net/2009/01/17/castle-dynamic-proxy-tutorial-part-iii-selecting-which-methods-to/ It was given an example in this article about "selecting which methods to intercept": public class FreezableProxyGenerationHook:IProxyGenerationHook { public bool ShouldInterceptMethod(Type type, MethodInfo memberInfo) { return

Autofac method level interception with Castle DynamicProxy in .NET Core 2

房东的猫 提交于 2020-12-12 05:11:32
问题 I currently wrote an Interceptor which code is below public class TransactionalInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { using (var transaction = ...) { try { invocation.Proceed(); transaction.Commit(); } catch { transaction.Rollback(); } finally { transaction.Dispose(); } } } } but when register this interceptor it will apply to all methods. I have a service class with a repository injected having CRUD methods. I don't want a transaction to be opened for

Autofac method level interception with Castle DynamicProxy in .NET Core 2

只谈情不闲聊 提交于 2020-12-12 05:09:24
问题 I currently wrote an Interceptor which code is below public class TransactionalInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { using (var transaction = ...) { try { invocation.Proceed(); transaction.Commit(); } catch { transaction.Rollback(); } finally { transaction.Dispose(); } } } } but when register this interceptor it will apply to all methods. I have a service class with a repository injected having CRUD methods. I don't want a transaction to be opened for

System.Collections.Generic.KeyNotFoundException with Mono, but not Microsoft's .NET

[亡魂溺海] 提交于 2020-01-16 00:57:45
问题 I found a really strange problem while creating unit tests that only occurs with the Mono runtime (Xamarin on Mac included), but runs fine within Visual Studio. I isolated it as far as I could, and I reached a point that I can't tell if it is a bug with Mono, Moq or Castle DinamicProxy, although it only crashes when using the Mono runtime. This is the code: using System; using System.Collections.Generic; using Moq; namespace ConsoleApplication1 { public interface ISomething<T> { List<T>

Cannot retrieve CustomAttributes in Interceptor using DynamicProxy

旧巷老猫 提交于 2020-01-03 02:52:16
问题 I'm currently implementing Interceptors using Castle DynamicProxy. I require the interceptor to pick up some custom attributes on my service layer method, but invocation.Method.GetCustomAttributes returns nothing. Anything I could be doing wrong? Intercepted Method: [Transaction()] [SecurityRole(AuthenticationRequired = false, Role = SystemRole.Unauthorised)] public virtual void LoginUser(out SystemUser userToLogin, string username) { ... } Interceptor: // Checks that a security attribute has

Why won't DynamicProxy's interceptor get called for *each* virtual method call?

人盡茶涼 提交于 2019-12-31 22:37:31
问题 An example explains it best : public interface IA { void foo(); void bar(); } public class A : IA { public virtual void foo(){ Console.Write("foo"); bar(); //call virtual method } public virtual void bar(){ Console.Write("bar"); } } public class Interceptor : IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Intercepted: " + invocation.Method.Name); invocation.Proceed(); } } Main(){ IA a = new A(); //proxy-ing an interface, given an implementation IA proxy =

Castle Windsor intercept method call from within the class

社会主义新天地 提交于 2019-12-29 06:31:52
问题 We have components registrations in Castle Windsor container like so void RegisterComponent<TInterface, TImplementation>() { var component = Component.For<TInterface>().ImplementedBy<TImplementation>(); component.Interceptors<SomeInterceptor>(); container.Register(component); } However we got to the problem that when we do a method call from within the class it does not get intercepted. For example we have component like ServiceA : IService { public void MethodA1() { // do some stuff } public

NuGet: NHibernate, Castle.Core 3.0 and where is ProxyFactoryFactory?

柔情痞子 提交于 2019-12-28 13:57:20
问题 I installed with NuGet the packages NHibernate and Castle.Core 3.0 for a new project. Usually we copied around the dlls manually; it is the first time I do that with NuGet. Now I can't find out how to configure the ProxyFactoryFactory, or let's say, I can't find it. I referenced NHibernate and Castle.Core (the only dll I could find in the Castle.Core - package) within the project, and configured the following: <property name="proxyfactory.factory_class"> NHibernate.ByteCode.Castle

NuGet: NHibernate, Castle.Core 3.0 and where is ProxyFactoryFactory?

无人久伴 提交于 2019-12-28 13:56:39
问题 I installed with NuGet the packages NHibernate and Castle.Core 3.0 for a new project. Usually we copied around the dlls manually; it is the first time I do that with NuGet. Now I can't find out how to configure the ProxyFactoryFactory, or let's say, I can't find it. I referenced NHibernate and Castle.Core (the only dll I could find in the Castle.Core - package) within the project, and configured the following: <property name="proxyfactory.factory_class"> NHibernate.ByteCode.Castle