You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Manually create an instance of that class and register it using RegisterInstance method.
Set transparent proxy interceptor for the interface.
Resolve an object by the interface.
Current: container returns original instance, all method calls go directly to that instance.
Expected: container returns a proxy wrapper, method calls can be handled by the interceptor.
Broken versions: 5.x (tried 5.9.0 and latest stable 5.11.1).
Working versions: 4.0.1 and older.
There is no problem with RegisterType method, unity returns a proxy wrapper as expected in a such scenario. The issue affects only RegisterInstance-way. Both default and named instances are being returned unwrapped.
Below is a unit test to demonstrate the issue, it works well with Unity versions up to 4.0.1 and fails with 5.x:
[TestFixture]publicclassInterceptionTests{[Test]publicvoidRegisteredInstanceIntercepting_ReturnsProxy(){varcontainer=new UnityContainer();
container.AddNewExtension<Interception>();varinstance=new SomeService();
container
.RegisterInstance<ISomeService>(instance).Configure<Interception>().SetInterceptorFor<ISomeService>(new TransparentProxyInterceptor()).AddPolicy("SomePolicy").AddMatchingRule(new TypeMatchingRule(typeof(ISomeService))).AddCallHandler(new SomeCallHandler());varwrapper= container.Resolve<ISomeService>();
Assert.IsTrue(RemotingServices.IsTransparentProxy(wrapper),"Wrapper is not a proxy");
Assert.AreNotSame(instance, wrapper);}privateinterfaceISomeService{voidFoo();}privatesealedclassSomeService:ISomeService{publicvoidFoo()=>thrownew NotImplementedException();}privatesealedclassSomeCallHandler:ICallHandler{public IMethodReturn Invoke(IMethodInvocationinput,GetNextHandlerDelegategetNext)=>thrownew NotImplementedException();publicintOrder{get;set;}}}
Is it enough for you or should I attach a zip with the whole project?
Am I missing some breaking change with interceptors between 4.x and 5.x?
Is there some workaround?
The text was updated successfully, but these errors were encountered:
RegisterInstance
method.Current: container returns original instance, all method calls go directly to that instance.
Expected: container returns a proxy wrapper, method calls can be handled by the interceptor.
Broken versions: 5.x (tried 5.9.0 and latest stable 5.11.1).
Working versions: 4.0.1 and older.
There is no problem with
RegisterType
method, unity returns a proxy wrapper as expected in a such scenario. The issue affects onlyRegisterInstance
-way. Both default and named instances are being returned unwrapped.Below is a unit test to demonstrate the issue, it works well with Unity versions up to 4.0.1 and fails with 5.x:
Is it enough for you or should I attach a zip with the whole project?
Am I missing some breaking change with interceptors between 4.x and 5.x?
Is there some workaround?
The text was updated successfully, but these errors were encountered: