Example #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);
        }
Example #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);
        }
Example #3
0
        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);
            }
        }
Example #4
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var kernelBuilder = new KernelBuilder();

            kernelBuilder.OnStarting(builder => builder.RegisterType <MainForm>().AsSelf().As <IUserInterfaceController>().InstancePerLifetimeScope());
            kernelBuilder.UseCaching(c => c.UseMemoryCache());

            var hostContainer = kernelBuilder.Build();
            var host          = hostContainer.Resolve <IHost>();

            host.Initialize();

            var work = host.CreateStandaloneEnvironment(new ShellSettings {
                Name = "Default"
            });
            var form = work.Resolve <MainForm>();

            Application.Run(form);
        }
Example #5
0
        protected TestBase()
        {
            var kernelBuilder = new KernelBuilder();

            kernelBuilder.OnStarting(Register);
            kernelBuilder.UseCaching(c => c.UseMemoryCache());
            //.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);
            }
        }