LightInject
LightInject copied to clipboard
registering multiple constructors with parameters
Given the following class:
public class Test
{
public Test(IDependency dep) { ... }
public Test(string someParameter, IDependency dep) { ... }
}
I'm trying to register both constructors, like this:
container.Register<Test>();
container.Register<string, Test>((sf, s1) => new Test(s1, sf.GetInstance<IDependency>()))
But the second call to register overrides the first one, causing this to work:
var t = container.GetInstance(typeof(Test), new object[] { "test" }) as Test;
But not this
var t = container.GetInstance(typeof(Test)) as Test;
Is there a way to register multiple constructors for the same class, so that the constructor resolution will select the most resolvable one while considering runtime arguments? (this already happens when there are multiple constructors and all parameters are services that will be injected)
Bump?