castle-dynamicproxy

Castle DynamicProxy Interceptor having problems with different assemblies

落花浮王杯 提交于 2019-12-06 03:29:09
问题 I have a scenario like this: I'm using interceptor to catch calls to a class that is inside assembly (let's call it Feature) that is referenced by main project. Assembly Feature is installed by NuGet (it's not public but our internal one) and has reference to another assembly (let's call it Core). Main project is referencing assembly Core as well. Core contains class definition that is used as an argument type of one of the intercepted methods. It all works fine as long as Main project and

Dynamic cast to generic type

限于喜欢 提交于 2019-12-05 10:23:09
Just a quickie before the weekend rolls in... I have a Method with the following signature, that I need to invoke: public interface IObjectProvider<T> { T Get(Predicate<T> condition); } This will provide me with a T from whatever kind of source, that meets the predicate criteria. Now, this has to be called from a context where all I have is the following: //the actual predicate that's going to be evaluated var predicate = predicateProperty.GetValue(invocation.InvocationTarget, null); //The type that should go into the call as type param Type relationTargetType = relationDefinition.RelatedType;

System.InvalidProgramException when executing unit tests in MSTest after Microsoft Security update MS13-004

穿精又带淫゛_ 提交于 2019-12-05 08:03:43
After applying the Microsoft Security update on the 8th of January 2013 http://technet.microsoft.com/en-us/security/bulletin/ms13-004 we have started to experience failures in our CI builds on our build servers and locally when running tests on our development boxes. We get a System.InvalidProgramException: Common Language Runtime detected an invalid program . This only happens when running tests using MSTest that make use of Castle Windsor DynamicProxy although I am not convinced DynamicProxy is at fault here. An example piece of code that would generate the exception is below. [TestMethod]

Intercept only interface methods with DynamicProxy

一笑奈何 提交于 2019-12-04 19:13:20
I got an interface like this public interface IService { void InterceptedMethod(); } A class that implements that interface and also has another method public class Service : IService { public virtual void InterceptedMethod() { Console.WriteLine("InterceptedMethod"); } public virtual void SomeMethod() { Console.WriteLine("SomeMethod"); } } And an Interceptor public class MyInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Intercepting"); invocation.Proceed(); } } I want to intercept only the methods on Service that exists on IService (i.e I want to

Interception with Ninject. Fails to load IProxyRequestFactory

大憨熊 提交于 2019-12-04 08:00:58
I'm learning to use Ninject and Interceptor pattern. I have the following interceptor. public class MyInterceptor:IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Pre Execute: " + invocation.Request.Method.Name); foreach (var param in invocation.Request.Arguments) { Console.WriteLine("param : " + param); } invocation.Proceed(); Console.WriteLine("Post Execute: " + invocation.Request.Method.Name); Console.WriteLine("Returned: " + invocation.ReturnValue); } } And have a class named MyClass which got nothing but 2 simple methods, virtual to allow the interceptors

castle dynamic proxy creation

拈花ヽ惹草 提交于 2019-12-03 08:01:31
I am implementing a design where my layer would sit between client and server, and whatever objects i get from server, i would wrap it in a transparent proxy and give to the client, that way i can keep a track of what changed in the object, so when saving it back, i would only send changed information. I looked at castle dynamic proxy, linfu, although they can generate a proxy type, but they cant take existing objects and wrap them instead. Wondering if its possible to do with these frameworks, or if there any other frameworks that enable this... Castle Dynamic Proxy 3.x or later can do that,

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

*爱你&永不变心* 提交于 2019-12-03 03:25:37
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 = new Castle.DynamicProxy.ProxyGenerator() .CreateInterfaceProxyWithTarget(a, new Interceptor()); proxy.foo

Windsor MixIn is a Singleton?

隐身守侯 提交于 2019-12-02 09:43:41
I have a MixIn that requires some state to operate. I am registering it as so.. container.Register(Component.For(Of ICat) _ .ImplementedBy(Of Cat) _ .LifeStyle.Transient _ .Proxy.MixIns(New MyMixin())) When I call container.Resolve(of ICat), I get back a proxy for ICat, which also implements IMixin. However, if I call container.Resolve(of ICat) again, I get a new proxy for ICat, but MyMixin is the SAME instance. (Which makes sense because I didn't tell the container any way to create IMixin) So, IMixin is a Singleton, even though the Component's lifestyle is Transient. How can I tell Windsor,

Getting underlying type of a proxy object

ぐ巨炮叔叔 提交于 2019-11-30 22:29:44
问题 I'm using Castle DynamicProxy and my ViewModels are a proxy, something like this: namespace MyApplication.ViewModels { public class MyViewModel : BaseViewModel, IMyViewModel { } } a proxy of my viewmodel looks like this though: {Name = "IRootViewModelProxyffecb133f590422098ca7c0ac13b8f98" FullName = "IRootViewModelProxyffecb133f590422098ca7c0ac13b8f98"} I want to get the actual type or namespace of the actual type that is being proxied. Is there any way to do this? I want something that