asp.net core mvc in the application of the start, end and other events

We used to using asp.net mvc or when webform, often with the use Application in the events start, end and so on. We also have a similar approach in the .net core inside.

In the Startup class, Configure method was to add a parameter IApplicationLifetime applicationLeftTime it. Specific wording as follows:

  public void Configure(IApplicationBuilder app, IHostingEnvironment env,IApplicationLifetime applicationLeftTime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            applicationLeftTime.ApplicationStarted.Register(() =>
            { 
                // which can write another logic 

                Console.Write ( " ApplicationStarted " ); 
            }); 

            applicationLeftTime.ApplicationStopped.Register (() => {
                 // which can write another logic 
                Console.Write ( " ApplicationStopped " ); 
            }); 

            applicationLeftTime.ApplicationStopping.Register (() => {
                 // which can write another logic 
                Console.Write ( " ApplicationStopping " ); 
            });



            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }

 

Guess you like

Origin www.cnblogs.com/puzi0315/p/11318539.html