Why can't I inject value null with Ninjects ConstructorArgument?
Posted
by stiank81
on Stack Overflow
See other posts from Stack Overflow
or by stiank81
Published on 2010-04-19T12:14:47Z
Indexed on
2010/04/19
12:43 UTC
Read the original article
Hit count: 237
When using Ninjects ConstructorArgument you can specify the exact value to inject to specific parameters. Why can't this value be null, or how can I make it work? Maybe it's not something you'd like to do, but I want to use it in my unit tests.. Example:
public class Ninja
{
private readonly IWeapon _weapon;
public Ninja(IWeapon weapon)
{
_weapon = weapon;
}
}
public void SomeFunction()
{
var kernel = new StandardKernel();
var ninja = kernel.Get<Ninja>(new ConstructorArgument("weapon", null));
}
© Stack Overflow or respective owner