Month: June 2022

Implementing constructor injection – Dependency Injection

At this point, you should be familiar with constructor injection. Nonetheless, next is the controller’s code after migrating the Service Locator pattern to constructor injection: namespace ServiceLocator;public class ConstructorInjectionController : ControllerBase{    private readonly IMyService _myService;    public ConstructorInjectionController(IMyService myService)    {        _myService = myService ??throw new ArgumentNullException(nameof(myService));    }    [Route(“/constructor-injection”)]    public IActionResult GetUsingConstructorInjection()    {        _myService.Execute();        return Ok(“Success!”);    }} […]



         


          Terms of Use | Accessibility Privacy