From 6b1444c308935ebbd9710e73d141321985e6f749 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Tue, 20 Feb 2018 11:31:44 -0600 Subject: [PATCH] Refactor StopApplication example in Hosting topic (#5485) --- aspnetcore/fundamentals/hosting.md | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/aspnetcore/fundamentals/hosting.md b/aspnetcore/fundamentals/hosting.md index 13f30ec40a..f819ade7bb 100644 --- a/aspnetcore/fundamentals/hosting.md +++ b/aspnetcore/fundamentals/hosting.md @@ -860,28 +860,19 @@ public class Startup } ``` -[StopApplication](/dotnet/api/microsoft.aspnetcore.hosting.iapplicationlifetime.stopapplication) requests termination of the app. The following [Razor Pages](xref:mvc/razor-pages/index) page model class uses `StopApplication` to gracefully shutdown an app. The `OnPostShutdown` method executes after the **Shutdown** button in the UI is selected: - -```cshtml - -``` +[StopApplication](/dotnet/api/microsoft.aspnetcore.hosting.iapplicationlifetime.stopapplication) requests termination of the app. The following class uses `StopApplication` to gracefully shutdown an app when the class's `Shutdown` method is called: ```csharp -public class IndexModel : PageModel +public class MyClass { private readonly IApplicationLifetime _appLifetime; - public IndexModel(IApplicationLifetime appLifetime) + public MyClass(IApplicationLifetime appLifetime) { _appLifetime = appLifetime; } - public void OnGet() - { - ... - } - - public void OnPostShutdown() + public void Shutdown() { _appLifetime.StopApplication(); }