相关疑难解决方法(0)

无法从根提供程序.Net Core 2解析范围服务

当我尝试运行我的应用程序时,我收到错误

InvalidOperationException: Cannot resolve 'API.Domain.Data.Repositories.IEmailRepository' from root provider because it requires scoped service 'API.Domain.Data.EmailRouterContext'.
Run Code Online (Sandbox Code Playgroud)

奇怪的是,这个EmailRepository和界面设置完全相同,因为我可以告诉所有其他存储库,但没有为它们抛出错误.只有在我尝试使用app.UseEmailingExceptionHandling()时才会出现错误; 线.这是我的一些Startup.cs文件.

public class Startup
{
    public IConfiguration Configuration { get; protected set; }
    private APIEnvironment _environment { get; set; }

    public Startup(IConfiguration configuration, IHostingEnvironment env)
    {
        Configuration = configuration;

        _environment = APIEnvironment.Development;
        if (env.IsProduction()) _environment = APIEnvironment.Production;
        if (env.IsStaging()) _environment = APIEnvironment.Staging;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        var dataConnect = new DataConnect(_environment);

        services.AddDbContext<GeneralInfoContext>(opt => opt.UseSqlServer(dataConnect.GetConnectString(Database.GeneralInfo)));
        services.AddDbContext<EmailRouterContext>(opt => opt.UseSqlServer(dataConnect.GetConnectString(Database.EmailRouter)));

        services.AddWebEncoders();
        services.AddMvc();

        services.AddScoped<IGenInfoNoteRepository, GenInfoNoteRepository>();
        services.AddScoped<IEventLogRepository, EventLogRepository>(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core asp.net-core-2.0

53
推荐指数
5
解决办法
3万
查看次数

Asp.Net核心中的属性注入

我正在尝试将asp.net应用程序移植到asp.net核心.我在我的UnitOfWork实现上有属性注入(使用ninject).

[Inject]
public IOrderRepository OrderRepository { get; set; }
[Inject]
public ICustomerRepository CustomerRepository { get; set; }
Run Code Online (Sandbox Code Playgroud)

有没有办法在.net核心上使用DI构建来实现相同的功能?是否可以使用基于约定的绑定?

dependency-injection asp.net-core

30
推荐指数
3
解决办法
2万
查看次数