I'm trying to add ninject to the following setup -
public class BaseController : Controller
{
protected ILogger Logger {get;}
public BaseController() { Logger = new MyLogger(); }
}
public class Controller1Controller : BaseController { ... }
public class Controller2Controller : BaseController { ... }
....
public class ControllerNController : BaseController { ... }
With ninject, adding an ILogger parameter to BaseController works great -
public class BaseController : Controller
{
protected ILogger Logger {get;}
public BaseController(ILogger logger) { Logger = logger; }
}
but now it also requires adding a constructor in each of the child controllers because the base class no longer has a parameterless constructor-
public class Controller1Controller : BaseController {
public Controller1Controller(ILogger logger) : base(logger) { }
}
There are over 50 child controllers and going forward it might become a bit of a maintenance problem if we have to add/remove more dependencies. Further, the code being added to each controller is exactly the same.
Is there a way to keep the child controllers as they are (without any constructors) but still make that change to the BaseController?