.Net Core 3.0 ~ water under test AOP

Yesterday lie down a bit dependent on the injection of 3.0 Lei

Today homeopathy AOP do a bit of adjustment, such as automated injection AOP

 

Default Program method to add a line inside the CreateHostBuilder

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(new JitServiceProviderFactory()) //新增
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

Increase in the Startup method inside

        public void ConfigureContainer(JitAopBuilder builder)
        {
            builder.Add<IMyClass, MyClass>(ServiceLifetime.Singleton);
        }

or

Normal dependency injection

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            //...略略略
            services.AddSingleton<IMyClass, MyClass>();
        }

Modify the default MyClass

    [JitInject]
    public class MyClass: IMyClass
    {
        [JitAop]
        public void Hello()
        {
            Console.WriteLine("Hello");
        }
    }

JitInject characteristic representative of this class need AOP inject JitAop method represents the method of specific AOP interception process, if you want to customize, just like you can inherit JitAopAttribute

 

Support synchronous / asynchronous AOP intercept, process independent of each other


Project links

https://github.com/htrlq/NCoreCoder.Framework

 

Guess you like

Origin www.cnblogs.com/NCoreCoder/p/11586797.html