Please or Register to create posts and topics.

Installing IdentityServer4

Hi All,

It is my first time installing IdentitySever on my QuickApp and I am using this link from Eben has a guide. However I am getting a error related with DbContext.

"InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext."

This exception was generated at:
QuickApp.IdentityServerDbInitializer.SeedAsync() in IdentityServerDBInitializer.cs

I'm probably missing something from this part of the post:

"Note that we use the override keyword for our SeedAsync() method. That means we have to add the virtual keyword to our base implementation in the file DatabaseInitializer.cs ( i.e. virtual public async Task SeedAsync()).
Also we now have additional DbContexts in our solution (i.e. IdentityServer’s PersistedGrantDbContext and ConfigurationDbContext), so we need to modify the constructor of our own ApplicationDbContext class and restrict the parameter it can accept to the type DbContextOptions<ApplicationDbContext>, else dependency injection will pass in the wrong DbContextOptions that belongs to one of the other DbContext.
We do this by changing the line public ApplicationDbContext(DbContextOptions options) : base(options) to public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)"

What I did was:

In DatabaseInitializer.cs 

Change: public async Task SeedAsync()     

to:  virtual public async Task SeedAsync() 


In ApplicationDbContext.cs

Changed: public ApplicationDbContext(DbContextOptions options) : base(options)

To: public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)


Finally and not shore if this has any impact:

  1. I've placed the file IdentityServerDBInitializer.cs under the QuickApp folder at the same level as the startup.cs file is. Is this correct or should this be under the DAL project at the same level has DatabaseInitializer.cs?

Would appreciate any help on this. 

Many thank in advance



I would first try to bring the database up to date.
With add-migration Versx

If you do not use the template then note that the DBContext should look like this:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>

It must be derived from IdentityDbContext.

If you are using a current version, please note this link https://github.com/emonney/QuickApp/issues/160

Hi Ingo,

Many thanks for you help. It seems I was also missing the libraries System.Reflection at startup.cs

and didn't have the connection string properly done.

Many thanks