I have a service which is injected into a controller using the ASP.NET Core's default Dependency Injection Container:
public class FooBarService : IDisposable {
public void Dispose() { ... }
}
services.AddScoped<FooBarService>();
This creates one instance per request. How to ensure that the framework would dispose the FooBarService instance by the end of each request, without relying on destructors and garbage collection?