I have MVC 4 project and Ninject 3 all wired up.
Now I want to handle interception on my MVC Controller methods.
If I add this:
kernel.Bind<TT.Controllers.HomeController>().ToSelf().Intercept().With<TT.Interceptors.LoggingInterceptor>();
it kinda works (even though my own methods are not intercepted, but instead I get BeginExecute, EndExecute and Dispose methods intercepted of base Controller class). But let's say that is ok for now.
If I want to intercept specific method on my HomeController like this:
kernel.InterceptAround<TT.Controllers.HomeController>(
c => c.Index(),
invocation => doSomethingOnEnter(invocation),
invocation => doSomethingOnExit(invocation)
);
It simply does not work. Interception is never fired.
On the other hand, if I use the same method interception on some plain service class in my project then it works. Seems like only Controller methods are having problem being intercepted.
kernel.InterceptAround<UrlService>(
c => c.DoSomething(),
invocation => doSomethingOnEnter(invocation),
invocation => doSomethingOnExit(invocation)
);
^This works.
Does anyone have any idea on what should I do?
PS. I am using NinjectWebCommon with WebActivators:
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(TT.NinjectWebCommon), "Start")]
[assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(TT.NinjectWebCommon), "Stop")]