I am trying to have ninject use a constructor argument from a parent class and pass it as an argument to the child when it is instantiated. How would I do my bindings to make this happen properly? I have been going through the examples and haven't found a solution.
public class MyModule : NinjectModule
{
public override void Load()
{
Bind<ParentClass>().ToSelf();
Bind<ChildClass>().ToSelf();
}
}
public class ParentClass
{
private string _index;
private ChildClass _childClass;
public ParentClass(string index, ChildClass childClass)
{
_index = index;
_childClass = childClass;
}
}
public class ChildClass
{
private string _index;
public ChildClass(string index)
{
_index = index;
}
public string Index { get; set; }
}
var kernel = new StandardKernel(new MyModule());
kernel.Get<ParentClass>(new ConstructorArgument("index", "MyIndex"));
So when I create my ParentClass instance, I want the ChildClass inside to have the same index value.