Since IServiceProvider doesn't implement IDisposable, and ServiceProvider (which does implement it) is internal, how are you supposed to dispose a "top-level service provider", i.e. the result of calling IServiceCollection.BuildServiceProvider()?
I could of course do a (provider as IDisposable)?.Dispose(), but it would be nicer if the interface implemented IDisposable. That way it would work better with generic constraints etc.
I understand that there's little to do with the interface itself, since it's an old interface that's been reused, but would it be possible to add a separate one?
Something along the lines of
namespace Microsoft.Extensions.DependencyInjection
{
public interface IServiceProvider : System.IServiceProvider, IDisposable { }
}
I think I've gotten around the problem by immediately creating a scope, which is disposable, and use its provider, but I don't think it's a good solution.
What was the reasoning for using the existing interface? And why is everything internal? 😝