You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Seems there is a behavior difference between how Unity handles the IServiceProvider.GetServices extension vs how Microsoft.Extensions.DependencyInjection does it.
This code using Microsoft.Extensions.DependencyInjection does NOT throw:
varmseServices=newServiceCollection();usingvarmseServiceProvider=ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(mseServices);varmseFoundServices=mseServiceProvider.GetServices<SomeService>();if(mseFoundServices.Any()){thrownewNotSupportedException("Found SomeService registrations in MSE");// Not thrown when executed}
This code using Unity.Microsoft.DependencyInjection does throw:
varmseServices=newServiceCollection();varunityServiceProvider=ServiceProviderExtensions.BuildServiceProvider(mseServices);varunityFoundServices=unityServiceProvider.GetServices<SomeService>();if(unityFoundServices.Any()){thrownewNotSupportedException("Found SomeService registrations in Unity");// Thrown with executed}
If I swap SomeService to an interface (eg ISomeService) then the behavior is consistent. But shouldn't it be consistent for both cases? From Unity's perspective, users should be able to swap in Unity over Microsoft.Extensions.DependencyInjection and not have to worry about subtle behavioral differences like this causing issues in random libraries, no?
The text was updated successfully, but these errors were encountered:
Greetings!
This issue has been raised in a project I work on: open-telemetry/opentelemetry-dotnet#5537
Seems there is a behavior difference between how Unity handles the
IServiceProvider.GetServices
extension vs how Microsoft.Extensions.DependencyInjection does it.This code using Microsoft.Extensions.DependencyInjection does NOT throw:
This code using Unity.Microsoft.DependencyInjection does throw:
If I swap
SomeService
to an interface (egISomeService
) then the behavior is consistent. But shouldn't it be consistent for both cases? From Unity's perspective, users should be able to swap in Unity over Microsoft.Extensions.DependencyInjection and not have to worry about subtle behavioral differences like this causing issues in random libraries, no?The text was updated successfully, but these errors were encountered: