I'm trying to migrate a Prism WPF application whitch is using Unity IoC container to use DryIoC container.
In a module I have the Unity container injected to register a class specifying the constructor.
unityContainer.RegisterType<IService, Service>(
typeof(Service).FullName,
new ContainerControlledLifetimeManager(),
Invoke.Constructor(
Resolve.Parameter<IDependency1>(),
Resolve.Parameter<IDependency2>()...
));
I wanted to migrate this type of registers to use IContainerRegistry
methods to register. I've seen that IContainerRegistry
interface provides methods to regiser using Factory method whitch I can use to specify constructor, but there is no method with factory method as parameter and named register also.
Does anybody have the same problem? Maybe extending the IContainerRegistry implementation?
You can just skip IContainerRegistry
and call the GetContainer
extension method and use the actual container.
containerRegistry.GetContainer().RegisterDelegate<IDependency1, IDependency2, IService>( (a, b) => new Service(a,b), serviceKey: typeof(Service).FullName, reuse: Reuse.Singleton );
IContainerRegistry
is just a thin wrapper around the container without any defined behavior of its own. For anything but the most trivial registrations, you have to go to the container anyway.