Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }