Пример #1
0
        public void Run(string[] args, ODataWebHostConfig oDataWebHostConfig)
        {
            if (oDataWebHostConfig == null)
            {
                throw new ArgumentNullException(nameof(oDataWebHostConfig));
            }

            var hostBuilder = CreateHostBuilder(args, oDataWebHostConfig);

            hostBuilder.Build()
            .Run();
        }
Пример #2
0
        private IHostBuilder CreateHostBuilder(string[] args, ODataWebHostConfig oDataWebHostConfig)
        {
            oDataWebHostConfig.ContentRoot = oDataWebHostConfig.ContentRoot ?? Directory.GetCurrentDirectory();

            var hostBuilder = Host.CreateDefaultBuilder(args)
                              .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                              .ConfigureWebHostDefaults(webHostBuilder =>
            {
                if (oDataWebHostConfig.Configuration != null)
                {
                    webHostBuilder.UseConfiguration(oDataWebHostConfig.Configuration);
                }

                if (oDataWebHostConfig.Urls != null && oDataWebHostConfig.Urls.Any())
                {
                    webHostBuilder.UseUrls(oDataWebHostConfig.Urls);
                }

                if (oDataWebHostConfig is KestrelODataWebHostConfig kestrelConfig)
                {
                    kestrelConfig.ConfigureKestrelServer = kestrelConfig.ConfigureKestrelServer ?? (options => { });

                    webHostBuilder
                    .UseKestrel(kestrelConfig.ConfigureKestrelServer);
                }
                else
                {
                    webHostBuilder
                    .UseIISIntegration();
                }

                webHostBuilder
                .UseContentRoot(oDataWebHostConfig.ContentRoot ?? Directory.GetCurrentDirectory())
                .UseStartup <TStartup>()
                .ConfigureServices(oDataWebHostConfig?.ConfigureServices ?? (s => { }));

                OnConfigureWebHostBuilder(webHostBuilder);
            });

            return(hostBuilder);
        }