网站建设模板源代码,个人怎么开网站,嘉定区 网站建设,北京网站建设策划方案DispatchProxy是微软爸爸编写的一个代理类#xff0c;基于这个#xff0c;我扩展了一个AOP组件 暂时不支持依赖注入构造方法#xff0c;感觉属性注入略显麻烦#xff0c;暂时没打算支持 基于特性的注入流程 [AttributeUsage(AttributeTargets.Method)]internal class TestA… DispatchProxy是微软爸爸编写的一个代理类基于这个我扩展了一个AOP组件 暂时不支持依赖注入构造方法感觉属性注入略显麻烦暂时没打算支持 基于特性的注入流程 [AttributeUsage(AttributeTargets.Method)]internal class TestAttribute:AopAttribute{protected override Task BeforeAsync(MethodInfo targetMethod, object[] args){Console.WriteLine($BeforeAsync {targetMethod.Name});return base.BeforeAsync(targetMethod, args);}protected override Task AfterAsync(MethodInfo targetMethod, object[] args){Console.WriteLine($AfterAsync {targetMethod.Name});return base.AfterAsync(targetMethod, args);}} 编写接口 public interface ITest{[Test]void TestVoid();[Test]int TestInt();[Test]Task TestAsync();[Test]Taskint TestIntAsync();} 整体结构是依赖注入再实现一个实现类就好 特性打在接口的方法上 刚开坑暂时只支持特性对应方法 调用 services.AddNCoreCoderAopITest, Test(ServiceLifetime.Transient); 方法支持同步和异步两种 支持Singleton、Scoped、Transient三种生命周期默认生命周期是Singleton 项目地址 https://github.com/htrlq/NCoreCoder.Framework 转载于:https://www.cnblogs.com/NCoreCoder/p/11492755.html