System.AggregateException: "Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: BulkyBook.DataAccess.Repository.IRepository.IUnitOfWork Lifetime: Singleton ImplementationType: BulkyBook.DataAccess.Repository.UnitOfWork': Unable to resolve service for type 'BulkyBook.DataAccess.ApplicationDbContext' while attempting to activate 'BulkyBook.DataAccess.Repository.UnitOfWork'.)"
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnections")
));
builder.Services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
var app = builder.Build();
System.AggregateException: "Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: BulkyBook.DataAccess.Repository.IRepository.IUnitOfWork Lifetime: Singleton ImplementationType: BulkyBook.DataAccess.Repository.UnitOfWork': Unable to resolve service for type 'BulkyBook.DataAccess.ApplicationDbContext' while attempting to activate 'BulkyBook.DataAccess.Repository.UnitOfWork'.)"
public class UnitOfWork : IUnitOfWork
{
private ApplicationDbContext _db;
public ICategoryRepository Category { get; private set; }
public ICoverTypeRepository CoverType { get; private set; }
public IProductRepository Product { get; private set; }
public UnitOfWork(ApplicationDbContext db)
{
_db = db;
Category = new CategoryRepository(_db);
CoverType= new CoverTypeRepository(_db);
Product = new ProductRepository(_db);
}
public void Save()
{
_db.SaveChanges();
}
}
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public DbSet<Category> Categories { get; set; }
public DbSet<CoverType> CoverTypes { get; set; }
public DbSet<Product> Products { get; set; }
}
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public DbSet<Category> Categories { get; set; }
public DbSet<CoverType> CoverTypes { get; set; }
public DbSet<Product> Products { get; set; }
}
public interface IUnitOfWork
{
ICategoryRepository Category { get; }
ICoverTypeRepository CoverType { get; }
IProductRepository Product { get; }
void Save();
}
D:\1\aspMVC-identity\BulkyBookWeb\Areas\Identity\Data\ApplicationDbContext.cs(9,50): warning CS0436: Тип "ApplicationDbContext" в "D:\1\aspMVC-identity\BulkyBookWeb\Areas\Identity\Data\ApplicationDbContext.cs"
конфликтует с импортированным типом "ApplicationDbContext" в "BulkyBook.DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null". Используется тип, определенный в "D:\1\aspMVC-identity\BulkyBookWeb\Ar
eas\Identity\Data\ApplicationDbContext.cs". [D:\1\aspMVC-identity\BulkyBookWeb\BulkyBookWeb.csproj]
D:\1\aspMVC-identity\BulkyBookWeb\Program.cs(12,31): warning CS0436: Тип "ApplicationDbContext" в "D:\1\aspMVC-identity\BulkyBookWeb\Areas\Identity\Data\ApplicationDbContext.cs" конфликтует с импортированным ти
пом "ApplicationDbContext" в "BulkyBook.DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null". Используется тип, определенный в "D:\1\aspMVC-identity\BulkyBookWeb\Areas\Identity\Data\ApplicationDbC
ontext.cs". [D:\1\aspMVC-identity\BulkyBookWeb\BulkyBookWeb.csproj]
D:\1\aspMVC-identity\BulkyBookWeb\Program.cs(17,31): warning CS0436: Тип "ApplicationDbContext" в "D:\1\aspMVC-identity\BulkyBookWeb\Areas\Identity\Data\ApplicationDbContext.cs" конфликтует с импортированным ти
пом "ApplicationDbContext" в "BulkyBook.DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null". Используется тип, определенный в "D:\1\aspMVC-identity\BulkyBookWeb\Areas\Identity\Data\ApplicationDbC
ontext.cs". [D:\1\aspMVC-identity\BulkyBookWeb\BulkyBookWeb.csproj]