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
We are currently using Unity in some of our projects and want to use it with asp.net core. To enable this feature we use the "Unity.Microsoft.DependencyInjection - 2.1.1". We also register some types in the default ServiceCollection provided here that then resolves types from the Unity registrations. There seems to be an issue how unity resolves object by using lambda functions. Since all the DI tests runs successfully using the Unity bridge perhaps the "Microsoft.Extensions.DependencyInjection.Specification.Tests" needs to address this.
The issue is related to scoped containers.
Create and register a transient type that takes a scoped type as parameter.
Create service provider
Create scoped provider
Make sure that the scoped type comes from the child container when getting the transient type.
This works in Unity if you register the type with
serviceCollection.AddTransient<ITransientService, TransientService>()
but not if you register it with
serviceCollection.AddTransient<ITransientService>(sp=>new TransientService(sp.GetRequiredService<IScopedService>()))
The lamda function receives the root container when resolving types in the scoped container.
Attaching test case. Not XUnit :(
I can rewrite the test in XUnit and perhaps reuse some of the existing test structures if this is an issue that you feel should be addressed.
We are currently using Unity in some of our projects and want to use it with asp.net core. To enable this feature we use the "Unity.Microsoft.DependencyInjection - 2.1.1". We also register some types in the default ServiceCollection provided here that then resolves types from the Unity registrations. There seems to be an issue how unity resolves object by using lambda functions. Since all the DI tests runs successfully using the Unity bridge perhaps the "Microsoft.Extensions.DependencyInjection.Specification.Tests" needs to address this.
The issue is related to scoped containers.
Create and register a transient type that takes a scoped type as parameter.
Create service provider
Create scoped provider
Make sure that the scoped type comes from the child container when getting the transient type.
This works in Unity if you register the type with
serviceCollection.AddTransient<ITransientService, TransientService>()
but not if you register it with
serviceCollection.AddTransient<ITransientService>(sp=>new TransientService(sp.GetRequiredService<IScopedService>()))
The lamda function receives the root container when resolving types in the scoped container.
Attaching test case. Not XUnit :(
I can rewrite the test in XUnit and perhaps reuse some of the existing test structures if this is an issue that you feel should be addressed.
See dotnet/runtime#50029
The text was updated successfully, but these errors were encountered: