interception icon indicating copy to clipboard operation
interception copied to clipboard

ICallHandler did not intercept class with HandlerAttribute after upgrading from Unity 4 to Unity 5

Open raytangRT opened this issue 6 years ago • 7 comments

Hi,

I am trying to update the Unity from 4.0 to 5.10, and my logging interceptor did not work, can somebody give me some idea? Thanks.

My Container setup/

container.Register<ICallHandler, LogCallHandler>(nameof(LogCallHandler));
container.AddNewExtension<Interception>();

and all my interface-implementaion registrations are going through the following helper function.

 if (typeof(Service).IsInterface)
{
        injectionMembers.Add(new InterceptionBehavior<PolicyInjectionBehavior>());
        injectionMembers.Add(new Interceptor<InterfaceInterceptor>());
 }
        var lifetimeManager = registerAsSingleton ? new ContainerControlledLifetimeManager() : null;

         container.RegisterType<Service, Implementation>(name, lifetimeManager, injectionMembers.ToArray());

and my targetted class are annotated with a HandlerAttribute

raytangRT avatar Mar 25 '19 09:03 raytangRT

Could you provide a unit test that works in 4 and fails in 5?

ENikS avatar Mar 25 '19 12:03 ENikS

Hi @ENikS, I have create a repo here. You may build it and run either Unity4 or Unity5 version.

You can see that in Unity5 Version, the CallHandler did not get invoked.

edit... I found something interesting, In Unity5 project, If I put the CallHandler and AddNewExtension before Services Registration, everything works fine... wired... Unity 4 Unity 5

raytangRT avatar Mar 25 '19 13:03 raytangRT

@raytangRT I need a Unity Test that I could add to other regression tests. Something like this

ENikS avatar Mar 25 '19 13:03 ENikS

@ENikS I will make one once I get home tonite.

raytangRT avatar Mar 26 '19 01:03 raytangRT

@ENikS Please find the attached the test case, thanks

Issue27CallHandlerNotBeingInvoke.zip

raytangRT avatar Mar 26 '19 12:03 raytangRT

I am surprised this was not fixed after so much time. The problem is that people migration to 5.x may inadvertently run into this issue. There is no much point into supporting quite an old syntax if it does not behaves as expected.

FWIW, I got a similar case working and I described the changes here

gerardog avatar Jun 19 '20 19:06 gerardog

Would you like to contribute the fix? I am sure people will appreciate it.

ENikS avatar Jun 19 '20 19:06 ENikS