This is more of a design problem.
In any case, the controller should not create child classes. This is not a problem that the dispatcher must deal with SRP (single responsibility principle).
My question is what should I pass to child classes called from my controller
If you prefer to separate registrars, then there really is no other choice but to have child (dependent) classes with their own registrars.
Ask the lesson children to enter their own logger.
public class TodoRepository : ITodoRepository { private readonly ILogger logger; public TodoRepository(ILogger<TodoRepository> logger) { this.logger = logger; }
and then enter the child class in the controller.
public class TodoController : Controller { private readonly ILogger logger; private readonly ITodoRepository todoRepository; public TodoController(ILogger<TodoController> logger, ITodoRepository todoRepository) { this.logger = logger; this.todoRepository = todoRepository; }
Thus, child registrars will be eliminated when child classes are enabled and entered into the controller.
Nkosi
source share