-
-
Save stevetalkscode/ea202bb970d4a325fda099c0cde3e8b2 to your computer and use it in GitHub Desktop.
Example of Disposing a Class Level object in StartUp using IHostApplicationLifetime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StartUp | |
{ | |
private readonly SomeDisposable _someDisposable; | |
public StartUp() | |
{ | |
_someDisposable = new SomeDisposable(); | |
} | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddSingleton<ISomeDisposable>(_someDisposable); | |
} | |
public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicationLifetime) | |
{ | |
applicationLifetime.ApplicationStopping.Register(() => { _someDisposable.Dispose(); }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment