-
-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MS DI AddKeyed... variant registration fails #632
Comments
@detoxhby The keyed services will be supported in the DryIoc v6 version. The support is already added. The version still need the final touches. |
@dadhi thanks! Will you publish pre-release for testing beforehand? Would like to help by checking out in real projects! |
@detoxhby Here it is |
thanks, we've done testing and apart from the change in ConfigureContainer calls (IContainer to DryIocServiceProvider) the only issue is the |
Could you provide the example with the casting? |
for factory based registrations/resolutions we use this for ex.: CurrentContainer.ResolveFactory(Request.Create(CurrentContainer, ServiceInfo.Of<T>(serviceKey: key))).FactoryID CurrentContainer is the |
@detoxhby Got it, will check. Btw, I am still interested why do it with such a "low level" DryIoc stuff, are you integrating with some lib? |
we are mainly using it for factory-based scoped registrations to be able to replace them dynamically during an execution (actually, this solution was discussed with you a few years ago because it was not possible earlier :)) // registration
var factory = ReflectionFactory.Of(typeof(TImplementation), reuse, made, setup);
var id = new FactoryIdentifier<TService>(factory.FactoryID);
container.Register(typeof(TService), factory, ifAlreadyRegistered, serviceKey);
container.RegisterInstance(typeof(FactoryIdentifier<TService>), id, serviceKey: serviceKey);
// usage (context is IResolverContext)
context.CurrentScope.SetOrAdd(context.Resolve<FactoryIdentifier<T>>(), instance) The previous |
Registering keyed services through standard
ServiceCollection
results in error due to forced value in specific overload:at DryIoc.Microsoft.DependencyInjection.DryIocAdapter.RegisterDescriptor(IContainer container, ServiceDescriptor descriptor) in /_/src/DryIoc.Microsoft.DependencyInjection/DryIocAdapter.cs
which has fixed NotKeyed call to main register method
=> container.RegisterDescriptor(descriptor, IfAlreadyRegistered.AppendNotKeyed);
and thus causing the keyed registration to fail.Full stack:
based on main
RegisterDescriptor
code it is fully supported to register keyed services so it should just reuse the appropriate type in mentioned overrideThe text was updated successfully, but these errors were encountered: