Example of disposing an instance created inside the ConfigureServices method
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 | |
{ | |
public StartUp() | |
{ | |
} | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddSingleton<ISomeDisposable>(new SomeDisposable()); | |
} | |
public void Configure(IApplicationBuilder app, IHostApplicationLifetime applicationLifetime, IEnumerable<ISomeDisposable> someDisposables) | |
{ | |
applicationLifetime.ApplicationStopping.Register(() => | |
{ | |
foreach (var disposable in someDisposables) | |
{ | |
(disposable as IDisposable)?.Dispose(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment