Skip to content

Instantly share code, notes, and snippets.

@stevetalkscode
Last active November 14, 2020 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevetalkscode/ea202bb970d4a325fda099c0cde3e8b2 to your computer and use it in GitHub Desktop.
Save stevetalkscode/ea202bb970d4a325fda099c0cde3e8b2 to your computer and use it in GitHub Desktop.
Example of Disposing a Class Level object in StartUp using IHostApplicationLifetime
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