// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime lifetime) { lifetime.ApplicationStarted.Register(() => CommonFuncs.OutPut("IApplicationLifetime.ApplicationStarted")); lifetime.ApplicationStopping.Register(() => { CommonFuncs.OutPut("ApplicationLifetime - Stopping"); }); lifetime.ApplicationStopped.Register(() => { Thread.Sleep(5 * 1000); CommonFuncs.OutPut("ApplicationLifetime - Stopped"); }); app.Run(async(context) => { await context.Response.WriteAsync("Hello World!"); }); // For trigger stop WebHost var thread = new Thread(new ThreadStart(() => { Thread.Sleep(10 * 1000); CommonFuncs.OutPut("Trigger stop WebHost"); lifetime.StopApplication(); })); thread.Start(); CommonFuncs.OutPut("Startup.Configure - Called"); }
public static void Main(string[] args) { CommonFuncs.OutPut("开始进入Main入口"); var builder = CreateWebHostBuilder(args).Build(); CommonFuncs.OutPut("构建WebHost"); CommonFuncs.OutPut("准备运行WebHost"); builder.Run(); CommonFuncs.OutPut("运行WebHost,你猜会不会执行?"); }
public static IWebHostBuilder CreateWebHostBuilder(string[] args) { CommonFuncs.OutPut("准备构建WebHost"); return(WebHost.CreateDefaultBuilder(args) .UseStartup <Startup>()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { CommonFuncs.OutPut("Configure-Services"); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
public Startup(IConfiguration configuration) { CommonFuncs.OutPut("Call Startup"); Configuration = configuration; }