在哪里可以获得有关政策注入的简单说明?
时间:2020-03-05 18:56:16 来源:igfitidea点击:
我想为消息不灵通的同事简单地解释一下政策注入。哪里有很好的资源呢?我从entlib帮助文件中了解了策略注入,我确信这不是最佳选择。
解决方案
回答
EntLib所谓的策略注入,实际上是面向方面的编程。不久前,我在博客上写了一篇介绍AOP概念的文章,也许会有所帮助。
回答
有关策略注入的MSDN文档有一个非常清晰的解释:
Applications include a mix of business logic and crosscutting concerns, and the two are typically intermingled—which can make the code harder to read and maintain. Each task or feature of an application is referred to as a "concern." Concerns that implement the features of an object within the application, such as the business logic, are core concerns. Crosscutting concerns are the necessary tasks, features, or processes that are common across different objects—for example, logging, authorization, validation, and instrumentation. The purpose of the Policy Injection Application Block is to separate the core concerns and crosscutting concerns.
简而言之,PI块使开发人员可以定义一组策略,这些策略指定系统中对象的行为。因此,核心业务逻辑(例如,一个会计年度中计算每单位利润的代码(一个关注点))与该逻辑执行的日志记录(另一个,但更常用的关注点)是分开的。
同一文档指出PI块不是AOP,因为:
- 它使用拦截功能仅启用预处理程序和后处理程序。
- 它不会将代码插入方法中。
- 它不为类构造函数提供拦截。
因此,尝试从AOP的角度看PI可能会使事情变得有些混乱。