Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Pass in DbContextOptions to /Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext #418

Closed
diffused opened this issue Mar 23, 2015 · 5 comments
Assignees

Comments

@diffused
Copy link

Would like to externally override DbContextOptions when instantiating a context that uses IdentityDbContext like so:

public class AppDbContext : IdentityDbContext<ApplicationUser>
{
    public AppDbContext() { }

    public AppDbContext(DbContextOptions options)
        : base(options)
    {
    }
}

Perhaps adding something like this to IdentityDbContext.cs?

public class IdentityDbContext<TUser> : IdentityDbContext<TUser, IdentityRole, string> where TUser : IdentityUser
{
    public IdentityDbContext() { }
    public IdentityDbContext(DbContextOptions options)
        : base(options)
    {
    }
}
@rustd
Copy link

rustd commented Mar 30, 2015

@divega can you please comment on this?

@divega
Copy link

divega commented Mar 30, 2015

@diffused could you elaborate a bit on why you would want this? To be clear currently if you use the AddDbContext<T>(options => { ... }) method on ConfigureServices() you will get an instance of DbContextOptions accessible to the DbContext without having to have a parameter constructor. On the other hand, the case can be made for copying all the non-default constructors from DbContext into the IdentityDbContext, we are just not sure about the priority of doing so.

@diffused
Copy link
Author

I'd like to be able to do something like this:

public class Startup
{

    public void ConfigureServices(IServiceCollection services)
    { 
        var connectionString = Configuration.Get("Data:DefaultConnection:ConnectionString");

        // Add EF services to the services container.
        services.AddEntityFramework(Configuration)
            .AddSqlServer()
            .AddDbContext<AppDbContext>(option => {
                option.UseSqlServer(connectionString);
            }); 
    }

}

I've been using "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta3"
(it's what comes up in in intellisense when adding to the project.json)

@rustd
Copy link

rustd commented Apr 6, 2015

This should work. Can you tell us what does not work?

@rustd
Copy link

rustd commented May 11, 2015

Closing as we think this should work with Beta4. Please reopen if it does not.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants