Named service constructor injection #665
-
Let's assume I have
Afaik i have to register the services like this to enable named service constructor injection
Is there any other way to achieve this? I would like to avoid hardcoded parameter names.
Thank you in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@lucacivale If you are using MS.DI and DryIoc.Microsoft.DependencyInjection, then you may utilize internal class OtherService
{
public OtherService(
[FromKeyedServices("service1")] IService service1,
[FromKeyedServices("service2")] IService service2)
{
Service1 = service1;
Service2 = service2;
}
public IService Service1 { get; }
public IService Service2 { get; }
} For this, you need https://www.nuget.org/packages/DryIoc.Microsoft.DependencyInjection/8.0.0-preview-03 and DryIoc.dll v6.0.0-preview-08 Or you may use DryIoc.MefAttributedModel.dll and use a usual MEF Export, Import attributes. |
Beta Was this translation helpful? Give feedback.
-
@dadhi thanks for the quick response. I'm using the Prism library including the Prism.Container.DryIoc package wich references DryIoc.dll. Do you know if this should also work or do I have to work with Microsoft.DependencyInjection |
Beta Was this translation helpful? Give feedback.
-
@dadhi thank you, works like a charm |
Beta Was this translation helpful? Give feedback.
@lucacivale I am not sure about Prism. I would've asked the maintainer if and where I can add
.WithMefAttributedModel()
to the container configuration.I think adding package dependency of DryIoc.MefAttributedModel.dll should not be an issue.