IdentityServer4 with a customise ConfigurationDBContext

dbcontext entity-framework-core identityserver4

Question

Is it Okay if I customise the ConfigurationDBContext? I have already created one, the code is below

public class MyConfigurationDbContext : ConfigurationDbContext
{    
        public MyConfigurationDbContext(DbContextOptions<ConfigurationDbContext> options, 
                ConfigurationStoreOptions storeOptions)
                : base(options, storeOptions)
        {                
        }
}

I noticed that ConfigurationDBContext requires special DbContextOptions

DbContextOptions<ConfigurationDbContext>

I am bit confused now. Before i go any further just want to check has anybody done this before? Or if anyone can point out to project or tutorial regarding this.

1
2
3/3/2017 10:22:15 AM

Accepted Answer

The definition of IConfigurationDbContext from IdentityServer4.EntityFramework

public interface IConfigurationDbContext : IDisposable
{
    DbSet<Client> Clients { get; set; }
    DbSet<IdentityResource> IdentityResources { get; set; }
    DbSet<ApiResource> ApiResources { get; set; }

    int SaveChanges();
    Task<int> SaveChangesAsync();
}

This interface is there to allow developers to customize the context. If you donot want to inherit from ConfigurationDbContext(bind to Ef.Core.DbContext), you can build your own implementation of IConfigurationDbContext just need to add IDbContextFactory<MyConfigurationDbContext>

public class IdentityConfigurationDbContextFactory : IDbContextFactory<MyConfigurationDbContext>
{
    public MyConfigurationDbContext Create(DbContextFactoryOptions options)
    {
        //....
    }
}
0
10/5/2017 11:21:48 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow