我有这个错误
AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: BulkyBook.DataAccess.Repository.IRepository.IUnitOfWork Lifetime: Scoped ImplementationType: BulkyBook.DataAccess.Repository.UnitOfWork': Unable to resolve service for type 'BulkyBook.DataAccess.ApplicationDbContext' while attempting to activate 'BulkyBook.DataAccess.Repository.UnitOfWork'.)
使用身份scafolding后,我只是改变DbContext到IdentityDBContext,我尝试了一切,我有同样的错误,我没有改变任何东西,只是我的DbContext与包
这是我的program.cs
using BulkyBook.DataAccess;
using BulkyBook.DataAccess.Repository;
using BulkyBook.DataAccess.Repository.IRepository;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.AspNetCore.Identity;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();;
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{area=Customer}/{controller=Home}/{action=Index}/{id?}");
app.Run();
这是ApplicationDbContext
using BulkyBook.Models;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace BulkyBook.DataAccess
{
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; }
}
}
我只是想修复此错误以再次运行我的应用程序
1条答案
按热度按时间zpgglvta1#
我建议创建一个新的项目,并选择个人帐户进行身份验证
,这样做它将自行配置dbcontext,在项目创建脚手架后,您想要处理和自定义的身份页面。