C# 如何使用ASP.NET Core 3.1标识对业务逻辑层的用户进行身份验证和注册

C# 如何使用ASP.NET Core 3.1标识对业务逻辑层的用户进行身份验证和注册,c#,.net-core,asp.net-identity,3-tier,C#,.net Core,Asp.net Identity,3 Tier,请注意,我的问题可能不是建设性的,但我仍在学习,所以请帮助 我正在用dotnet core 3.1 mvc visual studio 2019设计一个三层体系结构。我只想从数据访问层使用一个到数据库的连接,并使用业务逻辑层的标识对用户进行身份验证。即: 连接字符串位于数据访问层,我想通过扩展的IServiceCollectionExtension配置服务 public static class IServiceCollectionExtension { public static IS

请注意,我的问题可能不是建设性的,但我仍在学习,所以请帮助

我正在用dotnet core 3.1 mvc visual studio 2019设计一个三层体系结构。我只想从数据访问层使用一个到数据库的连接,并使用业务逻辑层的标识对用户进行身份验证。即:

连接字符串位于数据访问层,我想通过扩展的IServiceCollectionExtension配置服务

public static class IServiceCollectionExtension
{
    public static IServiceCollection AddDALDependenciesLibraries(this IServiceCollection services)
    {
        services.AddScoped<IUnitOfWork, UnitOfWork>();
        services.AddScoped<ICoursesBL, CoursesBL>();
        services.AddScoped<IStudentsBL, StudentBL>();
        services.AddIdentity<IdentityUser, IdentityRole>).AddEntityFrameworkStores<GooddbContext>();

        return services;
    }
}
公共静态类IServiceCollectionExtension
{
公共静态IServiceCollection AddDALDependenciesLibraries(此IServiceCollection服务)
{
services.addScope();
services.addScope();
services.addScope();
services.additionity).AddEntityFrameworkStores();
返回服务;
}
}
然后在startup.cs中启动它,就像

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContextPool<GooddbContext>(
            options => options.UseSqlServer(Configuration.GetConnectionString("EmployeeDBConnection")));
        services.AddDALDependenciesLibraries();
        services.AddControllersWithViews();
    }
//此方法由运行时调用。使用此方法向容器中添加服务。
public void配置服务(IServiceCollection服务)
{
services.AddDbContextPool(
options=>options.UseSqlServer(Configuration.GetConnectionString(“EmployeeDBConnection”));
services.AddDALDependenciesLibraries();
services.AddControllersWithViews();
}
但如果我启动应用程序,它会抛出以下错误:

System.AggregateException HResult=0x80131500 Message=无法构造某些服务(验证服务描述符“ServiceType:TestCoreApp.BLL.BusinessLogic.Interfaces.ICoursesBL生存期:作用域实现类型:TestCoreApp.BLL.BusinessLogic.CoursesBL”时出错:在尝试激活“TestCoreApp.BLL.BusinessLogic.CoursesBL”时无法解析类型“AutoMapper.IMapper”的服务。)(验证服务描述符“ServiceType:TestCoreApp.BLL.BusinessLogic.Interfaces.IStudentsBL生存期:作用域实现类型:TestCoreApp.BLL.BusinessLogic.StudentBL”时出错:在尝试激活“TestCoreApp.BLL.BusinessLogic.StudentBL”时无法解析类型“AutoMapper.IMapper”的服务。) Source=Microsoft.Extensions.DependencyInjection 堆栈跟踪: 位于Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable
1服务描述符,ServiceProviderOptions)
位于Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection服务,ServiceProviderOptions)
位于Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder)
在Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter上
1.CreateServiceProvider(Object containerBuilder) 在Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()上 在Microsoft.Extensions.Hosting.HostBuilder.Build()上 在C:\Users\verky\source\repos\TestCoreApp\TestCoreApp.UI\Program.Main(字符串[]args)中的TestCoreApp.UI.Program.Main处:第16行

此异常最初是在此调用堆栈中引发的:

Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(System.Type,System.Type,Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain,System.Reflection.ParameterInfo[],bool) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ResultCache,System.Type,System.Type,Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Microsoft.Extensions.DependencyInjection.ServiceDescriptor,System.Type,Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain,int) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Microsoft.Extensions.DependencyInjection.ServiceDescriptor,Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain) Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(Microsoft.Extensions.DependencyInjection.ServiceDescriptor)

内部异常1:

InvalidOperationException:验证服务描述符“ServiceType:TestCoreApp.BLL.BusinessLogic.Interfaces.ICoursesBL生存期:作用域实现类型:TestCoreApp.BLL.BusinessLogic.CoursesBL”时出错:在尝试激活“TestCoreApp.bl.BusinessLogic.CoursesBL”时无法解析类型“AutoMapper.IMapper”的服务

内部例外2:

InvalidOperationException:尝试激活“TestCoreApp.BLL.BusinessLogic.CoursesBL”时,无法解析类型“AutoMapper.IMapper”的服务


//此方法由运行时调用。请使用此方法将服务添加到容器中

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContextPool<GooddbContext>(
        options => options.UseSqlServer(Configuration.GetConnectionString("EmployeeDBConnection")));
    services.AddDALDependenciesLibraries();
    services.AddControllersWithViews();
}
public void配置服务(IServiceCollection服务)
{
services.AddDbContextPool(
options=>options.UseSqlServer(Configuration.GetConnectionString(“EmployeeDBConnection”));
services.AddDALDependenciesLibraries();
services.AddControllersWithViews();
}

您的
automapper
注册在哪里?