我如何使用ASP.NET Core 3.1身份从业务逻辑层进行身份验证和注册用户

问题描述 投票:0回答:1

[我的问题可能不是建设性的,但仍在学习中,请提供帮助。

我正在设计一个具有dotnet核心3.1 mvc的3层体系结构,Visual Studio2019。我只想使用一个从数据访问层到数据库的连接,并使用业务逻辑层中的身份对用户进行身份验证。那是:

连接字符串在数据访问层中,我想通过扩展的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;
    }
}

然后在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();
    }

但是如果我启动该应用程序,它将在下面引发此错误:

System.AggregateExceptionHResult = 0x80131500消息=无法构建某些服务(验证服务描述符'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”的服务。)源= Microsoft.Extensions.DependencyInjection堆栈跟踪:在Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable1 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.ServiceFactoryAdapter1.CreateServiceProvider(Object containerBuilder)在Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()在Microsoft.Extensions.Hosting.HostBuilder.Build()在C:\ Users \ verky \ source \ repos \ TestCoreApp \ TestCoreApp.UI \ Program.cs:line 16中的TestCoreApp.UI.Program.Main(String [] args)中]

此异常最初是在此调用堆栈上抛出的:

Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(System.Type,System.Type,Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain,System.Reflection.ParameterInfo [],布尔)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':尝试解析类型'AutoMapper.IMapper'的服务时,无法解析激活“ TestCoreApp.BLL.BusinessLogic.CoursesBL”。

内部例外2:

InvalidOperationException:在尝试激活'TestCoreApp.BLL.BusinessLogic.CoursesBL'时无法解析类型为'AutoMapper.IMapper'的服务。

[我的问题可能不是建设性的,但仍在学习中,请提供帮助。我正在设计一个具有dotnet核心3.1 mvc,Visual Studio 2019的3层体系结构。我只想使用一个连接...

c# .net-core asp.net-identity 3-tier
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.