Specify constructor for the Unity IoC container to use?

Register it like this instead: container. RegisterType(new InjectionConstructor()) You can add the LifetimeManager as well using an overload of the RegisterType method That said, when modeling for DI, your life will be much easier if you have unambiguous contructors (i.e. No overloaded constructors).

Register it like this instead: container. RegisterType(new InjectionConstructor()); You can add the LifetimeManager as well using an overload of the RegisterType method. That said, when modeling for DI, your life will be much easier if you have unambiguous contructors (i.e.No overloaded constructors).

1 Thx. I've been using the IoC container for a while, and this is the first time I've seen the need of overloaded constructors, so I'm all with you there.. (btw; out of votes today, so +1 tomorrow! ) – stiank81 Jan 29 '10 at 13:21.

By default, Unity chooses a constructor with maximum number of arguments. To override this, decorate required constructor with InjectionConstructorAttribute.

Multiple-Constructor Injection Using an Attribute When a target class contains more than one constructor with the same number of parameters, you must apply the InjectionConstructor attribute to the constructor that the Unity container will use to indicate which constructor the container should use. As with automatic constructor injection, you can specify the constructor parameters as a concrete type, or you can specify an interface or base class for which the Unity container contains a registered mapping.

I really have to point out the way you're using dependency injection in this instance is just wrong. The container should be able to inject SomeValueObject on the construction. What you most likely should do is register a default object of SomeValueObject that the .

Name property returns string. Empty instead.

Maybe my simple example is a bit off, but imo there is a need of two different constructors in the actual code.. Thanks for mentioning anyway. – stiank81 Jan 29 '10 at 18:17.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions