public async Task RunAsync(string[] args, WebHostConfig oDataWebHostConfig, CancellationToken cancellationToken = default(CancellationToken)) { if (oDataWebHostConfig == null) { throw new ArgumentNullException(nameof(oDataWebHostConfig)); } var hostBuilder = CreateHostBuilder(args, oDataWebHostConfig); await hostBuilder.Build() .OnBuilt(OnHostBuilt) .RunAsync(cancellationToken); }
public void Run(string[] args, WebHostConfig oDataWebHostConfig) { if (oDataWebHostConfig == null) { throw new ArgumentNullException(nameof(oDataWebHostConfig)); } var hostBuilder = CreateHostBuilder(args, oDataWebHostConfig); hostBuilder.Build() .OnBuilt(OnHostBuilt) .Run(); }
private IHostBuilder CreateHostBuilder(string[] args, WebHostConfig 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); }