I have the following code:
namespace Test.Ninject.ConstructorArgumentBug
{
public class ClassA
{
private readonly IDependecy _dependecy;
public ClassA(IDependecy dependecy)
{
_dependecy = dependecy;
}
}
public interface IDependecy
{
}
public class ConcreteDependency : IDependecy
{
private readonly string _arg;
public ConcreteDependency(string arg)
{
_arg = arg;
}
}
public class Tests
{
[Test]
public void Test1()
{
var kernel = new StandardKernel();
kernel.Bind<IDependecy>()
.To<ConcreteDependency>()
.WhenInjectedInto<ClassA>()
.WithConstructorArgument(new ConstructorArgument("arg", "test"));
var classA = kernel.Get<ClassA>();
Assert.IsNotNull(classA);
}
[Test]
public void Test2()
{
var kernel = new StandardKernel();
kernel.Bind<IDependecy>()
.To<ConcreteDependency>()
.WhenInjectedInto<ClassA>()
.WithConstructorArgument("arg", "test");
var classA = kernel.Get<ClassA>();
Assert.IsNotNull(classA);
}
}
}
The Test1 doesn't work, but the Test2 does, and I believe they should behave the same. It looks like a bug to me. For some reason the first test cannot resolve dependency with the following error:
Ninject.ActivationException : Error activating string No matching bindings are available, and the type is not self-bindable. Activation path: 3) Injection of dependency string into parameter arg of constructor of type ConcreteDependency 2) Injection of dependency IDependecy into parameter dependecy of constructor of type ClassA 1) Request for ClassA
I guess if the first test fails the second should fail too. Am I doing something wrong?
Thanks!