by WeKnow
Weknow.DI.Extensions:
Weknow.DI.Extensions.Contracts:
You can register your components as:
builder.Services.AddKeyedSingleton<IFunctionality, AFunctionality>("A");
builder.Services.AddKeyedSingleton<IFunctionality, BFunctionality>("B");
And use it as follow:
[ApiController]
[Route("[controller]")]
public class TestController : ControllerBase
{
private readonly IKeyed<IFunctionality> _selector;
public TestController(IKeyed<IFunctionality> selector)
{
_selector = selector;
}
[HttpGet("a")]
public string GetA()
{
return _selector["A"].Id;
}
[HttpGet("b")]
public string GetB()
{
return _selector["B"].Id;
}
}
Looking for other extensions?
Check the following