后锐化和关键代码部分
假设应用程序业务规则的关键部分依赖于给定的行为,但显式编码此行为会使您的代码变得混乱,您是否会依赖使用 PostSharp(或与此相关的任何其他方面框架)将其封装在方面中?这是一个“安全”和“明智”的选择,还是显式编码该行为总是更好,无论它如何使代码混乱?这样的解决方案的可维护性怎么样?
Supposing a critical part of an application's business rules are dependent on a given behavior, but that coding this behavior explicitly will clutter your code, would you rely on encapsulating it in an aspect with PostSharp (or with any other aspect framework for that matter)? Is that a "safe" and "wise" option, or is it always better to explicitly code the behavior no matter how it will clutter the code? What about the maintainability of such a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不建议将业务规则或业务逻辑放在方面中。它违背了 AOP 的目的。业务规则/逻辑不是跨领域的关注点。如果您认为部分业务逻辑很混乱,那么您应该使用常见的 OOP 实践来抽象它或将其提取到它自己的方法中。
当然,你可以将其转移到某个方面,但目标是什么?为了减少混乱?这对我来说是不能接受的。使用方面来消除与业务逻辑无关的混乱,以便您的业务逻辑清晰。如果您的业务逻辑混乱,那么您需要重构。
PostSharp 与其他 AOP 框架相比:如果您最终将“关键代码”放入某个方面,那么 PostSharp 将是获得最佳性能的最佳框架。 IoC 等包含的运行时框架进行动态拦截,其执行效果不如静态编译的代码。另外,PostSharp 有如此多的优化,它根据您编写的代码执行,这是其他框架无法比拟的。
It is not recommend putting business rules or business logic in aspects. It defeats the purpose of AOP. Business rules/logic are not cross cutting concerns. If you consider part of your business logic as clutter then you should use common OOP practices to abstract it or extract it into it's own method(s).
You can, of course, move it into an aspect, but what would the goal be? To reduce clutter? That isn't acceptable to me. Use aspects to remove clutter not related to business logic so that your business logic is clear. If your business logic is cluttered then you need to refactor.
PostSharp vs other AOP frameworks: If you do end up putting "critical code" into an aspect, then PostSharp will be the best framework to get the best performance. Runtime frameworks like IoC contains that do dynamic interception will not perform as well as statically compiled code. Plus, PostSharp has so many optimizations that it performs based on the code you write that no other framework can match.