我使用microsoft的容器和.net framework 4.7 . 我无法使用.net核心 . 题 . 我想将DI与Microsoft软件容器一起用于DbContext . 我需要传递给facade / service类的那些连接 . 但就目前而言,我无法弄清楚如何做到这一点,这些连接需要注入到Facade / service类 .

这就是我已经拥有的 .

public static void ConfigureServices(IServiceCollection services,ILoggerFactory loggerFactory){

services.AddSingleton(loggerFactory.CreateLogger("Logging"));
        services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));

        services.AddTransient(typeof(IExcelExportFacade), typeof(ExcelExportFacade<CoManagerDbContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IScoreCardFacade), typeof(ScoreCardFacade<ScorecardDBContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IUserFacade), typeof(UserFacade<ScorecardDBContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IApplicabilityQuestionAnswerFacade), typeof(ApplicabilityQuestionAnswerFacade<CoManagerDbContext, EnhesaDbContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IClientFacade), typeof(ClientFacade<EnhesaDbContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(ICountryFacade), typeof(CountryFacade<EnhesaDbContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IFacilityFacade), typeof(FacilityFacade<EnhesaDbContext, CoManagerDbContext, FacilityUpdaterDbContext, ScorecardDBContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IHeadingFacade), typeof(HeadingFacade<EnhesaDbContext, CoManagerDbContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(ILanguageFacade), typeof(LanguageFacade<EnhesaDbContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IRegionFacade), typeof(RegionFacade<EnhesaDbContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IRegulationFacade), typeof(RegulationFacade<EnhesaDbContext, CoManagerDbContext, Microsoft.Extensions.Logging.ILogger>));
        services.AddTransient(typeof(IRequirementFacade), typeof(RequirementFacade<EnhesaDbContext, CoManagerDbContext, Microsoft.Extensions.Logging.ILogger>));            

        services.AddScoped(serviceProvider => new FacilityController(serviceProvider.GetRequiredService<IFacilityFacade>(), serviceProvider.GetRequiredService<IUserFacade>(), serviceProvider.GetRequiredService<Microsoft.Extensions.Logging.ILogger>()));
        services.AddScoped(serviceProvider => new UploadScorecardController(serviceProvider.GetRequiredService<IScoreCardFacade>(), serviceProvider.GetRequiredService<IUserFacade>(), serviceProvider.GetRequiredService<Microsoft.Extensions.Logging.ILogger>()));
        services.AddScoped(serviceProvider => new LoginController(serviceProvider.GetRequiredService<IUserFacade>(), serviceProvider.GetRequiredService<Microsoft.Extensions.Logging.ILogger>()));
        services.AddScoped(serviceProvider => new ComplianceManagerController(serviceProvider.GetRequiredService<Microsoft.Extensions.Logging.ILogger>(), serviceProvider.GetRequiredService<IFacilityFacade>(), serviceProvider.GetRequiredService<IClientFacade>(), serviceProvider.GetRequiredService<IHeadingFacade>(), serviceProvider.GetRequiredService<ICountryFacade>(), serviceProvider.GetRequiredService<IRegionFacade>(), serviceProvider.GetRequiredService<ILanguageFacade>(), serviceProvider.GetRequiredService<IRegulationFacade>(), serviceProvider.GetRequiredService<IRequirementFacade>(), serviceProvider.GetRequiredService<IUserFacade>(), serviceProvider.GetRequiredService<IApplicabilityQuestionAnswerFacade>()));
        services.AddScoped(serviceProvider => new ExcelExporterController(serviceProvider.GetRequiredService<IExcelExportFacade>(), serviceProvider.GetRequiredService<Microsoft.Extensions.Logging.ILogger>()));

}

在那些上下文注入到Facclasses之后,需要将facadeclasses注入到控制器中 .

我怎样才能将这4个上下文注入到我的外观类中,以及使这个工作最好的方法是什么?

错误消息,如果我运行并尝试使用swagger触发服务是在uploadscorecardcontroller上 .

尝试激活'ComplianceManager.Logic.Facade.ScoreCardFacade`2 [ComplianceManager.EntityFramework.DbContexts.ScorecardDBContext,Microsoft.Extensions.Logging.ILogger]时,无法解析类型'ComplianceManager.EntityFramework.DbContexts.ScorecardDBContext'的服务 .

当然,这意味着没有正确注册了ScorecardDBContext .