I play with the Ninject Interception extension. an Ian Davis blog post about this indicates that the interception is always based on the actual type of service, not the interface. For example, the following code will have no effect since IFoo is an interface:
Kernel.InterceptBefore<IFoo>(f => f.DoSomething(), i => Console.WriteLine("before"));
And, of course, the following code snippet will work only if Foo.DoSomething is virtual :
Kernel.InterceptBefore<Foo>(f => f.DoSomething(), i => Console.WriteLine("before"));
It looks like a pretty bright hole when it comes to Aspect-oriented programming. I was pretty conscientious in programming interfaces so that we could use mocking frameworks to mock our various services, but the vast majority of my real-world implementations are not virtual. If the mocking framework can create IFoo using a method that does what I ask, it seems like Ninject should be able to.
So, I think my question is double:
- Is there any reason Ninject Interception doesn't allow you to bind to interface methods?
- Is there an easy way to bind Ninject to dynamic wrapper classes that can allow me to perform certain interception operations in all interface methods and then pass the call to the actual implementation?
source share