When you register your ISomeInterface implantation, you can give them a name :
containerBuilder.RegisterType<A>().Named<ISomeInterface>("A"); containerBuilder.RegisterType<B>().Named<ISomeInterface>("B");
You can then register your C to resolve its arguments using specific names:
containerBuilder.Register(c => new C(c.ResolveNamed<ISomeInterface>("A"), c.ResolveNamed<ISomeInterface>("B"))) .As<IC>();
Using the code above, you must specify all the parameters of the C constructor, even if some parameters do not need "named" registrations.
So, if you only want to specify "named" parameters, you can use WithParameter together permission:
containerBuilder.RegisterType<C>().As<IC>() .WithParameter((p, c) => p.Name == "dependency1", (p, c) => c.ResolveNamed<ISomeInterface>("A")) .WithParameter((p, c) => p.Name == "dependency2", (p, c) => c.ResolveNamed<ISomeInterface>("B"));
source share