kirov-opensource / NAutowired

ASP.NET CORE Field Injection Implement
MIT License
77 stars 16 forks source link

使用NAutowired依赖注入,是否可以InterceptedBy进行AOP拦截 #35

Closed km93522719 closed 2 years ago

km93522719 commented 2 years ago
        Assembly servicesDllFile = Assembly.Load("LinCms.Application");

        bool Predicate(Type a) => !a.IsDefined(typeof(DisableConventionalRegistrationAttribute), true) && a.Name.EndsWith("Service") && !a.IsAbstract && !a.IsInterface && a.IsPublic;

        builder.RegisterAssemblyTypes(servicesDllFile)
            .Where(Predicate)
            .AsImplementedInterfaces()
            .InstancePerLifetimeScope()
            .PropertiesAutowired()// 属性注入
            .InterceptedBy(interceptorServiceTypes.ToArray())
            .EnableInterfaceInterceptors();
FatTigerWang commented 2 years ago

请提供更详细的示例, 最好是有个能重现的Repo

km93522719 commented 2 years ago

比如:服务类BlogService的方法CreateBlog,这个方法使用特性TransactionalAttribute,然后InterceptedBy对BlogService进行拦截,只要有使用特性TransactionalAttribute,就会使用事务。类似于Java的@Transaction的使用

InterceptedBy这个方法是Autofac进行依赖注入时,对相关的注入的对象进行拦截,从而可以使用AOP进行业务逻辑处理

FatTigerWang commented 2 years ago

目前只支持原生的DI容器,无法支持第三方的例如Autofac DI 容器,因此是不支持的。

km93522719 commented 2 years ago

目前只支持原生的DI容器,无法支持第三方的例如Autofac DI 容器,因此是不支持的。

好的,谢谢你的回复