目錄調試
System.InvalidOperationException: Unable to resolve service for type 'IBMS.Infrastruct.UoW.UnitOfWork' while attempting to activate 'IBMS.WEBAPI.Controllers.ValueController'.
出錯圖片以下:
code
System.InvalidOperationException: Unable to resolve service for type 'IBMS.Infrastruct.Context.IPBoxContext' while attempting to activate 'IBMS.Infrastruct.UoW.UnitOfWork'.
出錯圖片以下:
blog
在startup.cs中的ConfigureServices方法中進行依賴注入圖片
services.AddDbContext<IIPBoxContext, IPBoxContext>(options => options.UseMySql(Configuration.GetConnectionString("MySqlConnection"))); services.AddScoped<IIPBoxRepository, IPBoxRepository>(); services.AddScoped(typeof(UnitOfWork));//注入工做單元 services.AddScoped(typeof(IPBoxContext));
注意:IPBoxContext進行AddDbContext注入數據上下文以後,仍須要注入services.AddScoped(typeof(IPBoxContext))。
ip