Я хочу зарегистрировать OrderContext в Autofac, но OrderContext использует IDesignTimeDbContextFactory, и Autofac завершается с ошибкой при выполнении.Ошибка следующая:
Не удалось разрешить параметр 'Microsoft.EntityFrameworkCore.DbContextOptions 1[...OrderContext]
options' of constructor 'Void
.ctor(Microsoft.EntityFrameworkCore.DbContextOptions
1 [... OrderContext])'.в Autofac.Core.Activators.Reflection.ReflectionActivator.GetValidConstructorBindings (контекст IComponentContext, параметры IEnumerable 1 parameters) at
Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext
context, IEnumerable
1) в Autofac.Core.Resolving.InstanceLookup.Activate (параметры IEnumerable`1)
1007
100:
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<OrderContext>()
.InstancePerDependency();
}
OrderContext следующий:
public class OrderContext : DbContext
{
public DbSet<Order> Orders { get; }
public OrderContext(DbContextOptions<OrderContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new OrderEntityTypeConfiguration());
}
}
public class OrderContextDesignFactory : IDesignTimeDbContextFactory<OrderContext>
{
public OrderContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<OrderContext>()
.UseSqlServer(
"...");
return new OrderContext(optionsBuilder.Options);
}
}