问题描述
我已经使用了横切关注点,如安全性,日志记录,验证,等我的解决方案已经envolved周围的并DynamicProxy。我已经走了这条路,因为我可以使用基于DSL嘘适用的一切,让我的代码清洁的属性的。我在上周末告诉看看,因为它应该是一个更好的解决方案。我有一个快速浏览一下PostSharp,但我一直在使用属性推迟。
I've been using some basic AOP style solutions for cross-cutting concerns like security, logging, validation, etc. My solution has envolved around Castle Windsor and DynamicProxy. I've gone down this route because I can apply everything using a Boo based DSL and keep my code clean of Attributes. I was told at the weekend to have a look at PostSharp as it's supposed to be a "better" solution. I've had a quick look at PostSharp, but I've been put off by the Attribute usage.
有没有人尝试这两种解决方案,并会照顾分享他们的经验?
Has anyone tried both solutions and would care to share their experiences?
推荐答案
我只能看着城堡温莎很短的时间(还),所以我不能对此发表意见,但我没有使用postsharp。
I only looked at castle-windsor for a short time (yet) so I can't comment on that but I did use postsharp.
Postsharp的工作原理是在编译时织。它的广告编译后步骤来构建它会修改你的代码。因为如果你只是编程的横切关注到你的代码的代码被编译。这是一个有点比运行时编织更高性能和因为使用属性的Postsharp是非常容易使用。我想使用AOP的属性不如用它来作为DI问题。但是,这只是我个人的口味。
Postsharp works by weaving at compile time. It ads a post-compile step to your build where it modifies your code. The code is compiled as if you just programmed the cross cutting concerns into you code. This is a bit more performant than runtime weaving and because of the use of attributes Postsharp is very easy to use. I think using attributes for AOP isn't as problematic as using it for DI. But that's just my personal taste.
不过......
如果您已经使用城堡依赖注入我没有看到一个很好的理由,为什么你不应该还用它进行AOP的东西。我认为,虽然在运行时AOP是不是在编译时有点慢,它也更强大。 AOP和DI是在我看来,相关的概念,所以我认为这是使用一个框架,这两个是个好主意。所以我可能会看在城堡的东西再下一个项目,我需要AOP。
If you already use castle for dependency injection I don't see a good reason why you shouldn't also use it for AOP stuff. I think though the AOP at runtime is a bit slower than at compile time it's also more powerful. AOP and DI are in my opinion related concepts so I think it's a good idea to use one framework for both. So I'll probably look at the castle stuff again next project I need AOP.
这篇关于AOP应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!