예제 #1
0
파일: ODataHost.cs 프로젝트: mtikoian/Joker
        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
파일: ODataHost.cs 프로젝트: mtikoian/Joker
        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);
        }