在业务逻辑中使用 AOP 风格的类 MVC 授权的最佳免费方式 [英] Best free way to use AOP style MVC-like authorization in business logic

查看:22
本文介绍了在业务逻辑中使用 AOP 风格的类 MVC 授权的最佳免费方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢 ASP.NET MVC 中的授权属性.与其说是属性本身,不如说是您应用它的方式.

I like the authorization attribute in ASP.NET MVC. Not so much the attribute itself, but the way you apply it.

我想在我的非 ASP MVC 服务层中使用它,最好在我的普通 C# 业务逻辑库中使用它,或者至少在我的 WCF 服务端点的端点上使用它,但不太好.PostSharp 是我唯一的答案还是有类似的免费解决方案?

I want to use it in my non-ASP MVC services layer preferably in my plain C# business logic library or at least but less preferably at the endpoints of my WCF service endpoints. Is PostSharp my only answer or is there a free similar solution?

推荐答案

我遇到了类似的情况,最近研究了很多选项.

I am in a similar situation and have recently researched quite a few options.

有一些使用 .NET 的 AOP 开源项目,但大多数似乎已被放弃或不太活跃.PostSharp 是迄今为止最成熟的.有一个免费的社区版,可用于商业开发.

There are a few open source projects for AOP with .NET but most seems to be abandoned or not very active. PostSharp is by far the most mature of them. There is a community edition which is free and can be used for commercial development.

其他静态编织器(例如 PostSharp):

Other static weavers (such as PostSharp):

  • AspectDNG(已放弃)
  • Gripper-LOOM(自 2008 年起未更新)
  • AOP.NET(似乎被放弃了)

另一种选择是使用动态代理.有一些库使用了这种技术,但除了 Spring.NET 之外,它们似乎也或多或少地死了.

The other option would be to used Dynamic Proxies instead. There are a few libraries which uses this technique but with the exception of Spring.NET they seem to be more or less dead as well.

我相信 Spring.NET AOP 可以在没有 Spring.NET 堆栈的其余部分的情况下使用,但我不完全确定.

I believe Spring.NET AOP can be used without the rest of the Spring.NET stack but I'm not entirely sure.

如果您不介意在较低级别上工作,总有 Mono.Cecil 允许您像 PostSharp 一样重写程序集,但我不推荐它.这将是一项艰巨的工作,而且很难做到正确.

If you don't mind to work on a lower level there are always Mono.Cecil which allows you to rewrite assemblies just like PostSharp does but I wouldn't recommend it. It will be a lot of work and hard to get right.

使用例如 Castle.DynamicProxy 或 LinFu 生成动态代理可能是一个更好的方法,但它仍然需要很多管道才能使一切正常工作.此外,除非您已经在使用 IoC 容器,否则您可能需要考虑这一点,因为它可以更轻松地在需要的地方注入代理.与使用 PostSharp 的 OnMethodInvocationAspect 或类似方法相比,它需要做更多的工作.

Generating dynamic proxies with for example Castle.DynamicProxy or LinFu is probably a better approach then but it will still be quite a lot of plumbing to make everything to work. Also, unless you are already using an IoC-container you might want to consider that as it will make it much easier to inject the proxies where needed. Compared to using an OnMethodInvocationAspect or similar from PostSharp it will be a lot more work.

我目前倾向于使用 PostSharp(社区版),因为它可以满足我的所有需求并且非常易于使用.Spring.NET 看起来有些有趣,但是基于动态代理的解决方案不会像 PostSharp 那样优雅或易于使用.

I currently leaning towards using PostSharp (Community Edition) since it does everything I need and is very easy to use. Spring.NET seems somewhat interesting but a dynamic proxy based solution won't be quite as elegant or easy to use as PostSharp.

这篇关于在业务逻辑中使用 AOP 风格的类 MVC 授权的最佳免费方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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