LightInject icon indicating copy to clipboard operation
LightInject copied to clipboard

registering multiple constructors with parameters

Open reinaldoarrosi opened this issue 8 years ago • 1 comments

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)

reinaldoarrosi avatar Apr 11 '17 14:04 reinaldoarrosi

Bump?

aggiehorns avatar Nov 30 '20 16:11 aggiehorns