在 Spring.Net 中向递归方法注入建议?
我正在尝试使用 Spring.NET 对 AOP 的支持来进行依赖注入/控制反转/面向方面的编程(抱歉有大量的流行语 - 也许我会发布一个单独的问题要求某人澄清差异:)) 。
具体来说,我想要拦截递归方法调用,以便每次调用该方法时,都会调用 AOP 建议/拦截器。
Spring.Net 似乎不会拦截除第一个方法调用之外的任何内容。 我认为 Spring.Net 为每个实例维护了 1 个拦截器链,并且在第一个方法调用完成之前不再调用任何拦截器。
有没有人有关于让拦截器(建议)为每个方法调用(包括递归调用)触发的信息?
如果有帮助的话,我可以提供代码/示例输出。 谢谢!
I'm trying to use Spring.NET's support for AOP to do dependency injection/inversion of control/aspect-oriented programming (sorry for the slew of buzzwords - maybe I'll post a separate question asking someone to clarify the difference :) ).
Specifically, I want to have intercept a recursive method call, so that every time that the method is invoked, the AOP advice/interceptor will be called.
Spring.Net doesn't appear to intercept anything other than the very first method call. I think that Spring.Net is maintaining exactly 1 chain of interceptors per instance, and not call any more interceptors until that first method invocation has finished.
Does anybody have any info about getting the interceptor (the advice) to be triggered for EVERY method invocation, including recursive calls?
I can provide code/example output, if that's helpful.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我知道这本身不是 Spring.NET,但请查看 PostSharp。 它为您提供了不依赖动态代理的编译时编织,并且可以处理递归方法调用。 不过配置略有不同...
I know this isn't Spring.NET per se, but have a look at PostSharp. It gives you compile time weaving that doesn't rely on dynamic proxies, and would handle the recursive method call. The configuration is slightly different though...
如果您使用基于代理的 AOP,那么这不适用于递归方法调用。 针对目标的第一次调用将被代理拦截,并且您的建议将运行。 然后,目标上的方法将被调用,后续调用将保留在目标类中,而不考虑代理。 实现此目的的唯一方法是实际修改字节码,以便类本身包含该行为。
实际上,我没有使用过 Spring.NET(仅使用过 Java 的 Spring),因此不幸的是,我不知道 .NET 世界中存在哪些类型的字节码编织选项。
If you are using proxy-based AOP then this will not work for recursive method calls. The first call against the target will be intercepted by the proxy and your advice will run. Then the method on the target will be invoked, and subsequent calls will stay within the target class, ignorant of the proxy. The only way to make this work is to actually modify your bytecode so that class itself contains the behavior.
I actually haven't worked with Spring.NET (only Spring with Java) so I'm unfortunately ignorant about what kinds of bytecode weaving options exist in the .NET universe.
请参阅http://forum.springframework.net/showthread.php?t=5331
See http://forum.springframework.net/showthread.php?t=5331