by rcats on December 24, 2010
So a couple of weeks ago I started playing around with Ninject and the extensions for WCF and Interception. I ran into a problem Remo Gloor (who is working on the ninject project) helped me out with and I figured it’s worth dedicating a separate post to.
I was trying to intercept my method calls to log the execution time of these methods without littering my code with log statements. Interception is perfect for this.
Now, there are many syntax variants you can use with Ninject, but all of them broke when trying to intercept anything (except when using attributes). For interception to work, your class needs to be virtual, otherwise it’s not possible for the container to create proxy classes. The problem was that Linfu breaks when trying to intercept non-virtual methods. DynamicProxy2 also works only on virtual methods, but doesn’t break if some of your methods aren’t virtual.
So please keep this in mind when choosing between the two!
Hope this helps,