I think this is a pretty simple script in Ninject, but it's hard for me to find the right terminology for finding it.
I want to do something like:
public interface IClass
{
IInner Inner { get; }
}
public class ConcreteClass : IClass
{
public ConcreteClass(IInner inner)
{
Inner = inner;
}
public IInner Inner {get; private set;}
}
public class Test
{
private BindingObject _binding {get; set;}
private override BindingTest()
{
Kernel.Bind<IClass>().To<ConcreteClass>();
Kernel.Bind<IInner>().To<ConcreteInner>();
_binding = new BindingObject(1);
IClass class1 = Kernel.Get<IClass>();
_binding = new BindingObject(2);
IClass class2 = Kernel.Get<IClass>();
_binding = new BindingObject(1);
IClass class3 = Kernel.Get<IClass>();
Assert.AreSame(class1.Inner, class3.Inner);
Assert.AreNotSame(class1.Inner, class2.Inner);
}
}
The implementation BindingObjectdoes not matter, as this is just an example of a toy. The idea is that the two BindingObjectswill compare the same values if and only if the intone passed to their constructor is the same. Similarly, implementation IInnerand ConcreteInnerdo not matter.
, , , _binding, , Ninject IInner, , _binding, , . - ? , ( ) ?