.net core 如何使用.NET内核注入通用接口

.net core 如何使用.NET内核注入通用接口,.net-core,dependency-injection,interface,.net Core,Dependency Injection,Interface,我有下一个错误: System.ArgumentException:'无法实例化实现类型 要注入的接口: 公共接口iContext{} 如何使用这个界面 公共类用户存储:iUsersRepository { 只读iContext数据库; 公共用户存储库(iContext db) { 这个.db=db; } } 如何加载项启动: //services.AddScoped(typeof(iContext)、typeof(UserEntities)); AddScoped(typeof(iCont

我有下一个错误:

System.ArgumentException:'无法实例化实现类型

要注入的接口:

公共接口iContext{}
如何使用这个界面

公共类用户存储:iUsersRepository
{
只读iContext数据库;
公共用户存储库(iContext db)
{
这个.db=db;
}
}
如何加载项启动:

//services.AddScoped(typeof(iContext)、typeof(UserEntities));
AddScoped(typeof(iContext));
//services.AddTransient();
//services.AddSingleton();
编辑:

System.ArgumentException: Cannot instantiate implementation type 'Infrastructure._01_DataAccess.iContext`1[T]' for service type 'Infrastructure._01_DataAccess.iContext`1[T]'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.Populate()
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory..ctor(IEnumerable`1 descriptors)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngineCallback callback)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CompiledServiceProviderEngine..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngineCallback callback)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable`1 serviceDescriptors, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder)
   at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter`1.CreateServiceProvider(Object containerBuilder)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at WebApi.Program.Main(String[] args) in C:\Users\Daviel.SPAIN-HOLIDAY\Source\Repos\dhmaker-user\WebApi\Program.cs:line 16

您需要注册一个实现
iContext
的具体类,如下所示:

services.AddScoped(typeof(iContext)、typeof(Context))


其中
Context
是一个实现
iContext

的类,很难重现该问题,因为您没有显示完整的异常消息,没有添加完整的堆栈跟踪,也没有显示
UserEntities
实现。请提供一个带有错误的“i edit with Error”作为建议,接口的命名约定,“i”必须为大写。“iUsersRepository”变为“iUsersRepository”。嗨。我尝试了此操作,但收到了相同的错误您是否能够解析
UserEntities
IContext
实现的任何/所有其他依赖项?