1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
using Microsoft.AspNetCore.Hosting; //IWebHostBuilder using Microsoft.AspNetCore.Builder; //IApplicationBuilder using Microsoft.AspNetCore.Http; //WriteAsync using Microsoft.AspNetCore; //webHost using Microsoft.Extensions.Logging;//ILoggerFactory using Microsoft.Extensions.DependencyInjection; // IServiceCollection namespace WebApplication1 { public class Startup1 { public Startup1(IHostingEnvironment env, ILoggerFactory logger) { //These are two services available at constructor } public void ConfigureServices(IServiceCollection services) { //This is the only service available at ConfigureServices } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger) { app.Run(context => { return context.Response.WriteAsync("Hello from multi start1"); }); } } public class Startup2 { public Startup2(IHostingEnvironment env, ILoggerFactory logger) { //These are two services available at constructor } public void ConfigureServices(IServiceCollection services) { //This is the only service available at ConfigureServices } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger) { //These are the three default services available at Configure app.Run(context => { return context.Response.WriteAsync("Hello world Startup2"); }); } } public class Program { public static void Main(string[] args) { CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) { var hostBuilder = WebHost.CreateDefaultBuilder(args).UseEnvironment("Development"); //This is a dumb way of doing it. You can use command line argument, etc to switch your startup const int startupNumber = 2; //CHANGE THIS to 2 if you want to use Startup2 if (startupNumber == 1) hostBuilder.UseStartup<Startup1>(); else if (startupNumber == 2) hostBuilder.UseStartup<Startup2>(); return hostBuilder; } } } |
결과 : Hello from multi start1