PostSharp Aop(安装)

本文探讨了在缺少接口的情况下如何实现面向切面编程(AOP),介绍了使用PostSharp进行静态AOP的方法,并提供了详细的配置步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

项目中 Business层,大多数代码都是public static fun(string xx) 这样的代码,没有接口。AOP 对象都是依赖于接口的,对于这种无接口的类有没有办法AOP。
答案有肯定的。可以用PostSharp。

AOP 依赖接口的我称之为动态AOP,编译时(MSIL)称之为静态AOP。

PostSharp,mono.cecil 都是商业版的,都可以静态AOP。

castle,微软企业库,spring.net 都是动态AOP。

引用星爷的一句话:谁说没有枪头就捅不死人(谁说非要接口才能AOP)。


下载
https://www.postsharp.net/purchase
image 


image     image

 

 



所有的Project 必须Add postSharp to Project只引用DLL是无法使用AOP的

image E7)ENZ90UZNVVOXD7K1Y2(Q

 


添加完毕后.csproj文件用文本打开,会有Msbuild信息。


<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\packages\PostSharp.4.0.41\tools\PostSharp.targets" Condition="Exists('..\..\..\packages\PostSharp.4.0.41\tools\PostSharp.targets')" />
<Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
  <Error Condition="!Exists('..\..\..\packages\PostSharp.4.0.41\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://www.postsharp.net/links/nuget-restore." />
  <Error Condition="Exists('..\..\..\packages\PostSharp.4.0.41\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />
</Target>


postsharp 2.0之前没有Msbuild,2.0之后会存在Msbuild信息。

转载于:https://www.cnblogs.com/kfsmqoo/p/4286109.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值