Можно ли использовать новый механизм впрыска зависимостей в ASP.NET Core для ввода IdentityDbContext в мой репозиторий?ASP.NET Core IdentityDbContext с использованием зависимости Инъекция
версия EF:
"EntityFramework.Commands": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
Контекст:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>, IApplicationDbContext
{
public DbSet<Customer> Customers{ get; set; }
protected override void OnModelCreating(ModelBuilder builder) => base.OnModelCreating(builder);
}
Repository:
public class CustomerRepository: ICustomerRepository
{
private readonly IApplicationDbContext _context;
public CustomerRepository(IApplicationDbContext context)
{
_context = context;
}
public List<Customer> GetAll()
{
return _context.Customers.ToList();
}
}
Как настроить Startup.cs?
У меня есть базовая конфигурация
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
это не работает:
services.AddTransient<IApplicationDbContext, ApplicationDbContext>();