Example #1
0
        public void ConfigureContainer(ContainerBuilder builder)
        {
            //使用AspectCore
            builder.AddAspectCoreInterceptor(x => x.CacheProviderName = EasyCachingConstValue.DefaultInMemoryName);

            //使用Castle
            //builder.AddCastleInterceptor(x=>x.CacheProviderName= EasyCachingConstValue.DefaultInMemoryName);
        }
Example #2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //AspectCore
            services.AddScoped <IAspectCoreService, AspectCoreService>();

            //Castle
            services.AddScoped <ICastleService, CastleService>();

            //将WebClient接口注入
            services.AddWebApiClientUseHttpClientFactory <IWebApiClientService>();
            //or
            // services.AddWebApiClientUseHttpClientFactory<IWebApiClientService>((httpApiConfig) =>
            // {
            //  httpApiConfig.HttpHost = new Uri("http://www.baidu.com");
            // });
            //or
            // services.AddWebApiClientUseHttpClientFactory<IWebApiClientService>((httpApiConfig, p) =>
            // {
            //  httpApiConfig.HttpHost = new Uri("http://www.baidu.com");
            // });

            services.AddEasyCaching(options =>
            {
                options.UseInMemory();
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);


            var builder = new ContainerBuilder();

            builder.Populate(services);


            //使用AspectCore
            builder.AddAspectCoreInterceptor();

            //使用Castle
            //builder.AddCastleInterceptor();

            return(new AutofacServiceProvider(builder.Build()));
        }