1

Why does Ninject.Extensions.Interception require all methods and properties be virtual?

I am guessing it overrides the members to provide the AOP functionality but couldn't this be implemented by calling methods before and after the method to intercept? Even in the case of a replace, the original method could be wrapped to do something else or nothing.

Do other containers require members be virtual? Which do and which don't. If any don't? How do they work?

Sam Leach
  • 12,746
  • 9
  • 45
  • 73
  • 1
    This is a restriction of castle.dynamicproxy class proxy. However, you can also do interface proxying, where members don't need to be virtual. Also see http://docs.castleproject.org/Tools.Kinds-of-proxy-objects.ashx – BatteryBackupUnit Oct 21 '13 at 20:59

1 Answers1

4

Dynamic Proxy based interception that is used by IoC containers requires either virtual methods or that you inject interfaces instead of classes so that the proxy can opverride the methods.

If you want to do AOP on none virtual methods you have to use a code weaving AOP approach like PostSharp.

Remo Gloor
  • 32,665
  • 4
  • 68
  • 98
  • Thanks. Can you please link an example of interface injection with interception? – Sam Leach Oct 22 '13 at 22:12
  • 1
    https://github.com/ninject/ninject.extensions.interception/blob/master/src/Ninject.Extensions.Interception.Test/MethodInterceptionContext.cs#L213 – Remo Gloor Oct 22 '13 at 23:14