Disposing Injected Services (or: Using Dependency Injection Scopes)

added by DotNetKicks
8/29/2018 11:09:24 AM

2 Kicks, 1354 Views

The DI container Microsoft.Extensions.DependencyInjection disposes registered services automatically. It's just the question when the dispose takes place. Automatic dispose of transient and scoped services happen at the end of a scope. With ASP.NET Core applications, scopes are created with every HTTP request - after the request, services are disposed.