private static void RegisterService(IServiceCollection services, IConfiguration configuration) { NativeInjectorBootstrapp.RegisterServices(services); ContextConfig context = new ContextConfig(configuration); context.RegisterContext(services); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); ContextConfig.RegisterContext(Configuration); }
// 重写加载配置 protected override void Load(ContainerBuilder builder) { //base.Load(builder); builder = ContextConfig.RegisterContext(builder); builder.RegisterType <Log>().As <ILog>(); var assembly = this.GetType().GetTypeInfo().Assembly; builder.RegisterType <CachingInterceptor>(); builder.RegisterType <TransactionInterceptor>(); builder.RegisterAssemblyTypes(assembly) .Where(type => typeof(IDependency).IsAssignableFrom(type) && !type.GetTypeInfo().IsAbstract) .AsImplementedInterfaces() .InstancePerLifetimeScope() .EnableInterfaceInterceptors() .InterceptedBy(typeof(TransactionInterceptor)) .InterceptedBy(typeof(CachingInterceptor)); }
public void Configuration(IAppBuilder app) { var config = new HttpConfiguration(); var builder = new ContainerBuilder(); AutofacConfig.RegisterAutofacIoc(app, config, builder); AuthConfig.ConfigureOAuth(app); AutoMapperConfig.RegisterMapping(); ContextConfig.RegisterContext(builder); LogicConfig.RegisterContext(builder); ApiHelperConfig.RegisterContext(builder); Log4NetConfig.RegisterLogger(builder); FluentValidationConfig.RegisterValidation(builder, config); var container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); WebApiConfig.Register(config); XmlConfigurator.Configure(); builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration); app.UseAutofacMiddleware(container); app.UseAutofacWebApi(config); app.UseWebApi(config); //app.UseCors(CorsOptions.AllowAll); }