c# - BaseController 中的 EF Core 上下文始终为空
问题描述
我有一个BaseController
但是当我从子控制器调用函数时,上下文总是null
:
public class BaseController : Controller
{
private readonly TheContext _tContext;
public BaseController(TheContext tContext)
{
_tContext= tContext;
}
public BaseController() { }
public void test()
{
var foo = _tContext.BAR;
}
}
我一直在通过将上下文BaseControler
从子控制器传递给函数来处理这个问题。
但是,我现在需要使用OnActionExecuting()
,因为我需要为每个使用BaseController
.
解决方案
推荐阅读
- laravel - hasManyThrough 带有逻辑运算符的 laravel
- node.js - 在 Telegraf (node.js) 中无需输入即可制作输入键盘
- javascript - e.touches[0].pageY 返回未定义
- reactjs - 如何在使用 graphql useQuery 返回错误时关闭 shopify 北极星横幅?
- python-3.x - Django - 将字符串字段保存到 Postgres 中的日期字段中
- iis - Clasic ASP webapp 在新服务器中获取 HTTP 错误 404.17
- matlab - 保存的图例框不显示其中一条线
- google-sheets - 在 Google 表格中加入表格
- javascript - 顶部的传单标签
- java - Open JDK JVM not support this platform then Unsupported major.minor version 52.0