Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top