How to use PersistedGrantDbContext to select PersistedGrant

I want to get data like this:

var persistedGrants = await _PersistedGrantDbContext.PersistedGrants.ToListAsync();

This is my config:

services.AddDbContext<AccountDbContext>(options =>
                        options.UseSqlServer(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly)))
                    .AddDbContext<PersistedGrantDbContext>(options =>
                        options.UseSqlServer(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly)));

But I have a mistake:

An unhandled exception occurred while processing the request. InvalidOperationException: Unable to resolve service for type 'IdentityServer4.EntityFramework.Options.OperationalStoreOptions' while attempting to activate 'IdentityServer4.EntityFramework.DbContexts.PersistedGrantDbContext'.

What should I go to fix it?

Upvotes: 0

Views: 524

Answers (2)

Yeah I have resolved my problem. I was missed services.AddIdentityServer().AddOperationalStore

Upvotes: 0

user4864425
user4864425

Reputation:

There is no need to call the database directly, use the provided stores instead.

In this case you can use IPersistedGrantStore:

public class MyClass
{
    private readonly IPersistedGrantStore _store;

    public MyClass(IPersistedGrantStore store)
    {
        _store = store;
    }

    public async Task Something(string sub)
    {
        var persistedGrants = await _store.GetAllAsync(sub);
    }

}

Upvotes: 1

Related Questions