AOP 和 .NET:上下文是一个过时的概念吗?
最近我开始学习 .NET 中的上下文(上下文绑定、上下文敏捷、消息接收器等)。几个警钟开始敲响:
- 所有上下文绑定类都派生自 ContextBoundObject,而 ContextBoundObject 又派生自 MarshalByRefObject。 MarshalByRefObject 是 .NET Remoting 架构的一部分。 .NET Remoting 架构被认为已经过时。
- 大多数与 .NET 相关的书籍很少甚至根本不关注上下文的概念。
- MSDN 几乎没有提供有关上下文的任何信息:对类进行了解释,但没有提供卫星文章(例如“如何”、“概述”、“教程”等)。
- 大多数讨论上下文的文章和论坛帖子都有几年历史了。
- 除了同步上下文之外,.NET 框架似乎很少甚至没有使用上下文架构。
因此,我的问题是:.NET 中的上下文概念是否已经过时并且在新的开发中应该避免?如果它已过时,建议使用哪些替代方案?
Recently I've started learning about Contexts in .NET (context-bound, context-agile, message sinks, etc.). Several alarm bells started ringing:
- All context-bound classes are derived from ContextBoundObject, which in turn is derieved from MarshalByRefObject. MarshalByRefObject is a part of the .NET Remoting architecture. The .NET Remoting architecture is considered obsolete.
- Most .NET-related books pay little to no attention to the concept of Contexts.
- MSDN barely provides any information on Contexts: classes are explained, but sattelite-articles (such as "How To"s, "Overview"s, "Tutorials" etc.) are not provided.
- Most articles and forums threads discussing Contexts are a few years old.
- Aside from the Synchronization context, it seems that the .NET framework makes little-to-no use of the Contexts architecture.
Thus, my question is: Is the concept of Contexts in .NET obsolete and should be avoided in new developments? If it is obsolete, what alternatives are recommended?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,避免在 AOP 中使用 MarshalByRefObject 和 ContextBoundObject。
大约四年前,我使用上下文绑定的 MarshalByRefObject 方法推出了一个自定义 AOP 解决方案。我当时就知道自己正陷入困境,但还是这么做了,因为 .NET 的许多 AOP 框架还很年轻。
.NET 通过 MarshalByRefObject 支持 AOP 的事实是一个令人高兴的意外。 MBO 从来就不是为了这个目的,并且将 MBO 用于 AOP 是对 .NET 远程处理和 MBO 初衷的劫持。
这并不意味着 .NET 不能支持 AOP,只是应该以一种不那么“hacky”的方式来完成,使用支持 AOP 的框架,如 Spring.NET、PostSharp 等。
这里是一篇关于 .网。
Yes, avoid MarshalByRefObject and ContextBoundObject for AOP.
I rolled a custom AOP solution about four years ago using the context-bound MarshalByRefObject method. I knew at the time I was going down a rabbit hole but did it anyway because many of the AOP frameworks for .NET were still very young.
The fact that .NET supports AOP with MarshalByRefObject is a happy accident. MBO was never intended for that purpose, and using MBO for AOP is a hijacking of the original intent of .NET remoting and MBO.
None of this means that .NET can't support AOP, just that it should be done in a less "hacky" way, using a framework that supports AOP, like Spring.NET, PostSharp, and others.
Here is a good, if a little dated, article on AOP frameworks for .NET.
我需要纠正,但如果您仅限于使用“供应商”(re:Microsoft)代码,我相信 Unity 和/或 MS 企业库策略块中存在一定程度的 AoP。
I stand to be corrected but if you are restricted to using "Vendor" (re:Microsoft) code, I believe there is a degree of AoP in Unity and/or the MS Enterprise Library Policy block.