Cannot instantiate implementation type '*****Repository`1[TEntity]' for service type '****.IRepository`1[TEntity]'
如上报错是在依赖注入时出错的
上代码
点击查看代码
Assembly asmCore = Assembly.Load("DealerPlatform.Core");
Type resitoryType = asmCore.GetTypes().FirstOrDefault(m => m.Name == "Repository`1");
Type interFaceType = resitoryType?.GetInterface("IRepository`1");
return services.AddTransient(interFaceType, resitoryType);
点击查看代码
var asmCore = Assembly.Load("DealerPlatform.Core");
var test = asmCore.GetTypes();
var interFaceTypes = asmCore.GetTypes().Where(m => m.IsAssignableTo(typeof(IRepository))
&& !m.IsInterface
&& !m.IsAbstract);
foreach (var interFaceType in interFaceTypes)
{
services.AddTransient(typeof(IRepository<>), interFaceType);
}
return services;
越是无知的人越是觉得自己无所不知(之前的自己)
越是学习的人越是觉得自己会的太少了(现在的自己)
共勉