【发布时间】:2021-05-07 07:36:12
【问题描述】:
使用以下行正在使用部分视图(否则工作完全正常;当不使用 DI 时):
<partial
name="Partials/SelectLoc"
model="new Partials.SelectLocModel(new HttpClient(), (<this is the part with DI>))" />
LocationList 的 ctor 采用 LocationDbContext 类的对象,该对象基本上是 DbContext 的子对象。
但是,事实证明,我无法在对部分的调用中实例化 LocationDbContext。
我该如何纠正这个问题?
【问题讨论】:
-
另外,与this的部分原因相同吗?
-
是的,我在回复中也提到了这个话题,但是很抱歉,我无法举报。
-
完成,如中,标记为重复
标签: asp.net-core dependency-injection inversion-of-control partial-views asp.net-core-razor-pages