I would expect second constructor to be used in injectedB, but first is being used with new ClassA created and classB just dropped.
class ClassA
{ }
class ClassB
{ }
class InjectedClass
{
public ClassA ClassA;
public ClassB ClassB;
public InjectedClass(ClassA classA)
{
ClassA = classA;
}
public InjectedClass(ClassB classB)
{
ClassB = classB;
}
}
public class ConstructorSelection
{
[Fact]
public void Test()
{
var container = new DependencyInjectionContainer();
container.Configure(c => c.Export<ClassA>().As<ClassA>());
container.Configure(c => c.Export<ClassB>().As<ClassB>());
container.Configure(c => c.Export<InjectedClass>().As<InjectedClass>());
var funcA = container.Locate<Func<ClassA, InjectedClass>>();
var classA = container.Locate<ClassA>();
var injectedA = funcA(classA);
var funcB = container.Locate<Func<ClassB, InjectedClass>>();
var classB = container.Locate<ClassB>();
var injectedB = funcB(classB);
Assert.Equal(classA,injectedA.ClassA);
Assert.Equal(classB,injectedB.ClassB);
}
}
I would expect second constructor to be used in injectedB, but first is being used with new ClassA created and classB just dropped.