It's any possible to using new dependency injection mechanism in ASP.NET Core to inject IdentityDbContext into my repository?
EF version:
"EntityFramework.Commands": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
Context:
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();
}
}
How to configure Startup.cs?
I have basic configuration
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
this does not work:
services.AddTransient<IApplicationDbContext, ApplicationDbContext>();