//HomeController.cs public class HomeController : Controller { public interface ITestDI { } public class TestDIClass1: ITestDI { public TestDIClass1() { } } public class TestDIClass2 : ITestDI { public TestDIClass2() { } } ITestDI td; public HomeController(ITestDI _td) { this.td = _td; // how to control which ITestDI implementation will injected with constructor injection? With the configuration below, always get TestDIClass2. } public IActionResult Index() { return View(); } } //Startup.cs services.AddScoped<ITestDI, TestDIClass1>(); services.AddScoped<ITestDI, TestDIClass2>();// it seems like TestDIClass2 has overwrited the TestDIClass1.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)