当我尝试运行我的应用程序时,我收到错误
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) 我正在尝试将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构建来实现相同的功能?是否可以使用基于约定的绑定?