[英]Several questions trying out n-tier with ASP.NET 5/EF7 using Dependency Injection
[英]Dependency injection asp.net n-tier c#
我正在使用 asp.net 核心 3.1 开发 N 层应用程序
在 application.domain 我将不得不接口和一个存储库
IIntentRepository
, IntentRepository
IPredictionRepository
PredictionRepository
在我的数据层中,我将有 1 个接口
IIntentDataRepository
, IntentDataRepository
然后在我的 startup.cs 文件中,我将调用每个依赖注入,如下所示。
services.AddTransient<IIntentRepository,IntentRepository>();
services.AddTransient<IPredictionRepository,PredictionRepository>();
services.AddTransient<IIntentDataRepository,IntentDataRepository>();
然后我通常将接口放在构造函数中,例如
private readonly IIntentDataRepository intentDataRepsoitory;
public IntentRepository(IIntentDataRepository _intentDataRepsoitory)
{
intentDataRepsoitory = _intentDataRepsoitory;
}
问题出在我的PredictionRepository
中,我想在域层中调用IntentRepository
。 我不知道该怎么做,这就是我在域层中调用它的方式
public class PredictionRepository : IPredictionRepository
{
private readonly IIntentRepository intentRepository;
PredictionRepository(IIntentRepository _intentRepository)
{
intentRepository = _intentRepository;
}
...}
但我不断收到PredictionRepository
'无法找到。 确保类型是具体的,并且为公共构造函数的所有参数注册了服务。)'
异常消息看起来很准确:
...确保类型是具体的,并且为公共构造函数的所有参数注册了服务。
您粘贴的代码显示PredictionRepository
构造函数未标记为公共,这就是 DI 机制无法使用它的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.