[Hosting] Move to GenericHost (#24297)
This commit is contained in:
parent
97ced4e7c9
commit
747957bb40
|
|
@ -1,9 +1,11 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
||||
|
||||
|
|
@ -27,20 +29,25 @@ namespace SampleStartups
|
|||
}
|
||||
|
||||
// Entry point for the application.
|
||||
public static void Main(string[] args)
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
|
||||
|
||||
var host = new WebHostBuilder()
|
||||
.UseConfiguration(config)
|
||||
.UseKestrel()
|
||||
.UseStartup<StartupBlockingOnStart>()
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseConfiguration(config)
|
||||
.UseKestrel()
|
||||
.UseStartup<StartupBlockingOnStart>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
using (host)
|
||||
{
|
||||
host.Start();
|
||||
await host.StartAsync();
|
||||
Console.ReadLine();
|
||||
await host.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
||||
|
||||
|
|
@ -19,18 +21,22 @@ namespace SampleStartups
|
|||
}
|
||||
|
||||
// Entry point for the application.
|
||||
public static void Main(string[] args)
|
||||
public static Task Main(string[] args)
|
||||
{
|
||||
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
|
||||
|
||||
var host = new WebHostBuilder()
|
||||
.UseConfiguration(config)
|
||||
.UseKestrel()
|
||||
.UseStartup<StartupConfigureAddresses>()
|
||||
.UseUrls("http://localhost:5000", "http://localhost:5001")
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseConfiguration(config)
|
||||
.UseKestrel()
|
||||
.UseStartup<StartupConfigureAddresses>()
|
||||
.UseUrls("http://localhost:5000", "http://localhost:5001");
|
||||
})
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
return host.RunAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
||||
|
||||
|
|
@ -11,7 +12,7 @@ namespace SampleStartups
|
|||
{
|
||||
public class StartupExternallyControlled : StartupBase
|
||||
{
|
||||
private IWebHost _host;
|
||||
private IHost _host;
|
||||
private readonly List<string> _urls = new List<string>();
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
|
@ -29,10 +30,15 @@ namespace SampleStartups
|
|||
|
||||
public void Start()
|
||||
{
|
||||
_host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseStartup<StartupExternallyControlled>()
|
||||
.Start(_urls.ToArray());
|
||||
_host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseStartup<StartupExternallyControlled>()
|
||||
.UseUrls(_urls.ToArray());
|
||||
})
|
||||
.Start();
|
||||
}
|
||||
|
||||
public async Task StopAsync()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
|
@ -13,7 +14,7 @@ namespace SampleStartups
|
|||
{
|
||||
public class StartupFullControl
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
public static Task Main(string[] args)
|
||||
{
|
||||
var config = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables(prefix: "ASPNETCORE_")
|
||||
|
|
@ -21,30 +22,34 @@ namespace SampleStartups
|
|||
.AddCommandLine(args)
|
||||
.Build();
|
||||
|
||||
var host = new WebHostBuilder()
|
||||
.UseConfiguration(config) // Default set of configurations to use, may be subsequently overridden
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory()) // Override the content root with the current directory
|
||||
.UseUrls("http://*:1000", "https://*:902")
|
||||
.UseEnvironment(Environments.Development)
|
||||
.UseWebRoot("public")
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseConfiguration(config) // Default set of configurations to use, may be subsequently overridden
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory()) // Override the content root with the current directory
|
||||
.UseUrls("http://*:1000", "https://*:902")
|
||||
.UseEnvironment(Environments.Development)
|
||||
.UseWebRoot("public")
|
||||
.Configure(app =>
|
||||
{
|
||||
// Write the application inline, this won't call any startup class in the assembly
|
||||
|
||||
app.Use(next => context =>
|
||||
{
|
||||
return next(context);
|
||||
});
|
||||
});
|
||||
})
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
// Configure services that the application can see
|
||||
services.AddSingleton<IMyCustomService, MyCustomService>();
|
||||
})
|
||||
.Configure(app =>
|
||||
{
|
||||
// Write the application inline, this won't call any startup class in the assembly
|
||||
|
||||
app.Use(next => context =>
|
||||
{
|
||||
return next(context);
|
||||
});
|
||||
})
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
return host.RunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
// Note that this sample will not run. It is only here to illustrate usage patterns.
|
||||
|
||||
|
|
@ -18,14 +20,18 @@ namespace SampleStartups
|
|||
}
|
||||
|
||||
// Entry point for the application.
|
||||
public static void Main(string[] args)
|
||||
public static Task Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseStartup<StartupHelloWorld>()
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
.UseStartup<StartupHelloWorld>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
return host.RunAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
// HostingStartup's in the primary assembly are run automatically.
|
||||
[assembly: HostingStartup(typeof(SampleStartups.StartupInjection))]
|
||||
|
|
@ -17,18 +19,22 @@ namespace SampleStartups
|
|||
}
|
||||
|
||||
// Entry point for the application.
|
||||
public static void Main(string[] args)
|
||||
public static Task Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseKestrel()
|
||||
// Each of these three sets ApplicationName to the current assembly, which is needed in order to
|
||||
// scan the assembly for HostingStartupAttributes.
|
||||
// .UseSetting(WebHostDefaults.ApplicationKey, "SampleStartups")
|
||||
// .Configure(_ => { })
|
||||
.UseStartup<NormalStartup>()
|
||||
var host = new HostBuilder()
|
||||
.ConfigureWebHost(webHostBuilder =>
|
||||
{
|
||||
webHostBuilder
|
||||
.UseKestrel()
|
||||
// Each of these three sets ApplicationName to the current assembly, which is needed in order to
|
||||
// scan the assembly for HostingStartupAttributes.
|
||||
// .UseSetting(WebHostDefaults.ApplicationKey, "SampleStartups")
|
||||
// .Configure(_ => { })
|
||||
.UseStartup<NormalStartup>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
return host.RunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue