Unitycontainer.Resolve() 'issue'

Oct 22, 2009 at 4:31 PM


I'm quite new to all this Unity stuff, so maybe my question might be stupid :)


I have a class with two constructors, one of which takes a Class that doesn't have a public constructor:


class A
	public A(){}
	public A(ClassWithoutPublicConstructor) {}

Now, when i do UnityContainer.Resolve<A>(), I get an error saying that something like 'there is no accessible constructor for .

I was expecting it to take the A() constructor if it couldn't use the other one. Can i somehow force this?


Dec 18, 2009 at 1:43 AM

Yes. Through the API, you can do:

container.RegisterType<A>(new InjectionConstructor());

or you can use the [InjectionConstructor] attribute on the constructor you want to call, OR you can specify it in configuration.