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

查看:83
本文介绍了您是否在生产软件中使用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 中的"before/after"属性(一个开源项目I运行)是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天全站免登陆