I hope I understood you correctly.
public class ConcreteService {
public int Val { get; set; }
public ConcreteService(int val) {
Val = val;
}
}
Now set up unity.
var container = new UnityContainer();
container.RegisterType<ConcreteService>();
container.Configure<InjectedMembers>().ConfigureInjectionFor<ConcreteService>(new InjectionConstructor(1));
container.RegisterType<ConcreteService>("for42");
container.Configure<InjectedMembers>().ConfigureInjectionFor<ConcreteService>("for42",
new InjectionConstructor(42));
container.RegisterType<ConcreteService>("for31");
container.Configure<InjectedMembers>().ConfigureInjectionFor<ConcreteService>("for31",
new InjectionConstructor(31));
Debug.WriteLine(container.Resolve<ConcreteService>().Val);
Debug.WriteLine(container.Resolve<ConcreteService>("for42").Val);
Debug.WriteLine(container.Resolve<ConcreteService>("for31").Val);
The equivalent configuration for "for42" is
Unity 1.4
<type type="ConcreteService" name="for42">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement,
Microsoft.Practices.Unity.Configuration">
<constructor>
<param name="val" parameterType="int">
<value value="42"/>
</param>
</constructor>
</typeConfig>
</type>
Unity 2.0
This is the same, but without the redundant type Config node
<type type="ConcreteService" name="for42">
<constructor>
<param name="val" parameterType="int">
<value value="42"/>
</param>
</constructor>
</type>
source
share