[英]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.