خرید بک لینک

Vote count: 0

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()
    {
        retu _context.Customers.ToList();
    }
}

How to configure Startup.cs?

I have basic configuration

        services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration["Data:DefaultCoection:CoectionString"]));

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>()
            .AddDefaultTokenProviders();

this does not work:

        services.AddTransient<IApplicationDbContext, ApplicationDbContext>();

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 10 خرداد 1395 ساعت: 0:44

صفحه بندی