-
Notifications
You must be signed in to change notification settings - Fork 474
Closed
Labels
Description
As part of .NET 6, we will want to move the ServiceCollection
type to Microsoft.Extensions.DependencyInjection.Abstractions dotnet/runtime#52284. This broke OData since it uses private reflection to make this work 1.0 and 2.0 work without having to re-compile.
WebApi/src/Microsoft.AspNet.OData.Shared/DefaultContainerBuilder.cs
Lines 80 to 92 in 757631f
public virtual IServiceProvider BuildContainer() | |
{ | |
/* "services.BuildServiceProvider()" returns IServiceProvider in Microsoft.Extensions.DependencyInjection 1.0 and ServiceProvider in Microsoft.Extensions.DependencyInjection 2.0 | |
* (This is a breaking change)[https://github.com/aspnet/DependencyInjection/issues/550]. | |
* To support both versions with the same code base in OData/WebAPI we decided to call that extension method using reflection. | |
* More info at https://github.com/OData/WebApi/pull/1082 | |
*/ | |
Assembly microsoftExtensionsDependencyInjectionAssembly = services.GetType().GetTypeInfo().Assembly; | |
TypeInfo serviceCollectionContainerBuilderExtensionsType = microsoftExtensionsDependencyInjectionAssembly.GetType(typeof(ServiceCollectionContainerBuilderExtensions).GetTypeInfo().FullName).GetTypeInfo(); | |
MethodInfo buildServiceProviderMethod = serviceCollectionContainerBuilderExtensionsType.GetMethod("BuildServiceProvider", new[] { typeof(IServiceCollection) }); | |
return (IServiceProvider)buildServiceProviderMethod.Invoke(null, new object[] { services }); |
It might be time to drop Microsoft.Extensions.DependencyInjection 1.0 support. That would clean this code up nicely.