目录调试
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