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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top