您是否在生产软件中使用 AOP(面向方面​​的编程)? [英] Do you use AOP (Aspect Oriented Programming) in production software?

查看:28
本文介绍了您是否在生产软件中使用 AOP(面向方面​​的编程)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AOP 在我看来是一种有趣的编程范式.但是,stackoverflow 上还没有关于它的讨论(至少我找不到它们).你对它有什么看法?你在你的项目中使用 AOP 吗?或者你认为它是一种不会存在很长时间或不会成为主流的小众技术(就像 OOP 那样,至少在理论上;))?

AOP is an interesting programming paradigm in my opinion. However, there haven't been discussions about it yet here on stackoverflow (at least I couldn't find them). What do you think about it in general? Do you use AOP in your projects? Or do you think it's rather a niche technology that won't be around for a long time or won't make it into the mainstream (like OOP did, at least in theory ;))?

如果您确实使用 AOP,请告诉我们您还使用了哪些工具.谢谢!

If you do use AOP then please let us know which tools you use as well. Thanks!

推荐答案

是.

正交问题,如安全性,最好使用 AOP 风格的拦截来完成.是自动完成(通过依赖注入容器之类的东西)还是手动完成对最终目标来说并不重要.

Orthogonal concerns, like security, are best done with AOP-style interception. Whether that is done automatically (through something like a dependency injection container) or manually is unimportant to the end goal.

一个例子:xUnit.net(一个开源项目我run) 是一种 AOP 风格的方法拦截形式.你用这些属性装饰你的测试方法,在测试方法运行之前和之后,你的代码被调用.它可用于设置数据库和回滚结果、更改测试运行的安全上下文等.

One example: the "before/after" attributes in xUnit.net (an open source project I run) are a form of AOP-style method interception. You decorate your test methods with these attributes, and just before and after that test method runs, your code is called. It can be used for things like setting up a database and rolling back the results, changing the security context in which the test runs, etc.

另一个例子:ASP.NET MVC 中的过滤器属性也充当专门的 AOP 风格的方法拦截器.例如,一个允许您说明未处理的错误应该如何处理,如果它们发生在您的操作方法中.

Another example: the filter attributes in ASP.NET MVC also act like specialized AOP-style method interceptors. One, for instance, allows you to say how unhandled errors should be treated, if they happen in your action method.

许多依赖注入容器,包括 Castle Windsor 和 Unity,都支持这种行为,要么在盒子里",要么通过使用扩展.

Many dependency injection containers, including Castle Windsor and Unity, support this behavior either "in the box" or through the use of extensions.

这篇关于您是否在生产软件中使用 AOP(面向方面​​的编程)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆