C# 中的内置 AOP - 正在开发中吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/833729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Built-in AOP in C# - is it on the way?
提问by Sam Saffron
In large apps I find myself really wishing I had built-in AOP facilities. As it stands in C# the best you can do is factories and RealProxys, PostSharp, ICorDebug, ICorProfiler or injection frameworks. There is no clean built-in way of doing AOP.
在大型应用程序中,我发现自己真的希望我有内置的 AOP 工具。就 C# 而言,你能做的最好的是工厂和 RealProxys、PostSharp、ICorDebug、ICorProfiler 或注入框架。没有干净的内置 AOP 方式。
Is there any indication anywhere (blog post / internal discussion) that indicates that AOP is on the way?
是否有任何迹象(博客文章/内部讨论)表明 AOP 正在进行中?
采纳答案by Jb Evain
Romain's answer covers (almost :) perfectly the current solutions. As for the future support, Anders Hejlsberghas previously statedthat they'were in wait & see mode about AOP.
Romain 的回答(几乎 :)完美地涵盖了当前的解决方案。至于未来的支持,安德斯·海尔斯伯格已如前所述是they'were在等待和看到AOP模式。
We can only hope that with the managed rewrite of csc, and a ?Compiler as a Service?, one could plug into the compiler, and inject aspects there.
我们只能希望通过 csc 的托管重写和“编译器即服务”,可以插入编译器,并在那里注入方面。
回答by Romain Verdier
I haven't heard of a "clean built-in way of doing AOP". But as you stated, there are already plenty "clean ways of doing AOP", using mature and powerful frameworks like PostSharpor Castle DynamicProxy.
我还没有听说过“干净的内置 AOP 方式”。但是正如你所说,已经有很多“干净的 AOP 方法”,使用成熟和强大的框架,如PostSharp或Castle DynamicProxy。
Using the BCL, one obvious way to do AOP, with pretty strong limitations thought, is to use transparent and real proxys, from .NET Remoting stack.
使用 BCL 是执行 AOP 的一种明显方法,但具有很强的局限性,它是使用来自 .NET Remoting 堆栈的透明和真实代理。
Another way is to rely on System.Reflection.Emit to dynamically generate proxies, like, hum, DynamicProxy from Castle.
另一种方法是依靠 System.Reflection.Emit 动态生成代理,例如 hum、来自 Castle 的 DynamicProxy。
Finally, there is also another official Microsoft flagged solution, that came with the Enterprise Library. I'm talking about the Policy Injection Application Block. Unityalso offers some interception capabilities that leverage PIAB.
最后,还有另一个官方标记为 Microsoft 的解决方案,它随Enterprise Library 一起提供。我说的是策略注入应用程序块。Unity还提供了一些利用 PIAB 的拦截功能。
回答by Mosh
The May release of Delphi Prism has AOP support at the language level.
Delphi Prism 的 5 月版本在语言级别具有 AOP 支持。
You can find out more about it here
您可以在此处了解更多信息
http://prismwiki.codegear.com/en/Cirrus
http://prismwiki.codegear.com/en/Cirrus
There is also an open source library of aspects from this location
还有一个来自这个位置的方面的开源库
回答by Matt H
Spring.NET provides AOP as well. It takes a lot of configuration but once it's set up it works well.
Spring.NET 也提供 AOP。它需要大量配置,但一旦设置好,它就可以很好地工作。