无法从单例'ProjName范围内定义服务'ProjName.Contexts.ProductContext'。 Persistence.IProductRepository'
这是我的代码:
Public void ConfigurationService (IServiceCollection service )
{
service. AddDbContext <ProductContext>(options =>UserSqlServer (Configuration. GetConnectionString ("Prdcn")));
Services. AddSingleton <IPRODUCTREPOSITORY, ProductRepository >();
}
答案 0 :(得分:0)
没有太多信息可以继续,所以我只向您展示如何为DI注册上下文和存储库。
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<MyAppDbContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString("LocalMachine"));
});
services.AddScoped<DbContext, MyAppDbContext>();
services.AddScoped<IUnitOfWork, UnitOfWork>();
//my repository is generic
services.AddScoped<IRepository<IBaseEntity>, Repository>();
...
}