I'm playing around with the Ninject Interception extension. Ian Davis's blog post about it indicates that interception is always based on the actual service type, rather than the interface. For example, the following code will have no effect because IFoo is an interface:
Kernel.InterceptBefore<IFoo>(f => f.DoSomething(),
i => Console.WriteLine("before"));
And of course, the next code piece will only work if Foo.DoSomething is virtual:
Kernel.InterceptBefore<Foo>(f => f.DoSomething(),
i => Console.WriteLine("before"));
This seems like a pretty glaring hole when it comes to Aspect-Oriented programming. I've been pretty conscientious about programming to interfaces so that we could use mocking frameworks to mock our various services, but the vast majority of my actual method implementations are not virtual. If a mocking framework can produce an IFoo with a method that does what I ask for, it seems like Ninject ought to be able to.
So I guess my question is two-fold:
- Is there any reason Ninject Interception doesn't allow you to bind to interface methods?
- Is there an easy way to make Ninject bind to dynamic "wrapper" classes that can let me perform certain interception actions on all the interface methods, and then pass the call through to the real implementation?