Ryan Bergman
unread,Nov 13, 2010, 5:02:03 PM11/13/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ninject
Greetings,
Accoding to the documentation on the github wiki ctor injection
should choose based on:
If a constructor has an [Inject] attribute, it is used.
If no constructors have an [Inject] attribute, Ninject will select the
one with the most parameters that Ninject understands how to resolve.
If no constructors are defined, Ninject will select the default
parameterless constructor.
However I found that this unit test fails. Is this a bug? I found a
similar thread from last spring but there was no resolution.
[Test]
public void NoParamCtorShouldBeUsed(){
var dojo = new StandardKernel();
Assert.That(dojo.Get< Foo>().NoParamCtorUsed, Is.True);
}
public class Foo
{
public bool NoParamCtorUsed;
public bool AmNothingWasUsed;
public Foo(IAmNothing nothing)
{
AmNothingWasUsed = true;
}
public Foo()
{
NoParamCtorUsed = true;
}
}
public interface IAmNothing {}
If I reverse the physical order of the ctors in the class then the
test passes.