I've a BaseController
but when I call the functions from the child Controllers the Context is always null
:
public class BaseController : Controller
{
private readonly TheContext _tContext;
public BaseController(TheContext tContext)
{
_tContext= tContext;
}
public BaseController() { }
public void test()
{
var foo = _tContext.BAR;
}
}
I've been dealing with this by passing the Context to the BaseControler
function from the child controller.
However, I now need to use OnActionExecuting()
as there is code I need to run on load for each controller which uses the BaseController
, which means I can't pass it the initialized context from the child controller.