aspnet / DependencyInjection

[Archived] Contains common DI abstractions that ASP.NET Core and Entity Framework Core use. Project moved to https://github.com/aspnet/Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BuildServiceProvider should return IServiceProvider instead of ServiceProvider

cknaap opened this issue · comments

Method Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider returns a ServiceProvider instead of the associated interface IServiceProvider.

The latter allows for better mocking in unit tests.

Plus, the documentation on the method also says it returns IServiceProvider.

No, it shouldn't. How can you mock an extension method? This method is about building a concrete implementation of an IServiceProvider.

Plus, the documentation on the method also says it returns IServiceProvider.

It was changed in 2.0 and needs to be updated /cc @Rick-Anderson

This issue was moved to dotnet/aspnetcore#2329