private static IWebHost HostInitialization(HttpApplication application) { var kernelBuilder = new KernelBuilder(); kernelBuilder.UseCaching(c => c.UseMemoryCache()); kernelBuilder.UseLogging(c => c.UseNLog()); kernelBuilder.UseWeb(c => c.EnableMvc().EnableSecurity()); kernelBuilder.UseData(c => { c.UseEntityFramework(); c.EnableMvcFilterTransaction(); c.EnableDataMigrators(); }); //开启基础设置层。 kernelBuilder.UseInfrastructures(); var container = kernelBuilder.Build(); var host = container.Resolve <IWebHost>(); host.Initialize(); host.BeginRequest(); host.EndRequest(); return(host); }
private static IWebHost HostInitialization(HttpApplication application) { var kernelBuilder = new KernelBuilder(); kernelBuilder.UseCaching(c => c.UseMemoryCache()); kernelBuilder.UseLogging(c => c.UseNLog()); kernelBuilder.UseWeb(c => c.EnableMvc().EnableSecurity()); kernelBuilder.UseData(c => { c.UseEntityFramework(); c.EnableMvcFilterTransaction(); //如果开启了EntityFramework的自动迁移则不启动数据迁移。 var automaticMigrationsEnabled = ConfigurationManager.AppSettings["Data.EntityFramework.AutomaticMigrationsEnabled"]; if (!string.Equals(automaticMigrationsEnabled, "true", StringComparison.OrdinalIgnoreCase)) { c.EnableDataMigrators(); } }); kernelBuilder.UseResources(); var container = kernelBuilder.Build(); var host = container.Resolve <IWebHost>(); host.Initialize(); host.BeginRequest(); host.EndRequest(); return(host); }
protected TestBase() { var kernelBuilder = new KernelBuilder(); kernelBuilder.OnStarting(Register); kernelBuilder.UseCaching(c => c.UseMemoryCache()); kernelBuilder.UseLogging(c => c.UseNLog()); var container = Container = kernelBuilder.Build(); var type = GetType(); var properties = type.GetProperties(); foreach (var property in properties) { var propertyType = property.PropertyType; if (!container.IsRegistered(propertyType)) continue; property.SetValue(this, container.Resolve(propertyType), null); } }
protected TestBase() { var kernelBuilder = new KernelBuilder(); kernelBuilder.OnStarting(Register); kernelBuilder.UseCaching(c => c.UseMemoryCache()); kernelBuilder.UseLogging(c => c.UseNLog()); var container = Container = kernelBuilder.Build(); var type = GetType(); var properties = type.GetProperties(); foreach (var property in properties) { var propertyType = property.PropertyType; if (!container.IsRegistered(propertyType)) { continue; } property.SetValue(this, container.Resolve(propertyType), null); } }