【问题标题】:How to use PersistedGrantDbContext to select PersistedGrant如何使用 PersistedGrantDbContext 选择 PersistedGrant
【发布时间】:2020-05-20 04:11:11
【问题描述】:

我想得到这样的数据:

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

这是我的配置:

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

但我有一个错误:

处理请求时发生未处理的异常。 InvalidOperationException:无法解析类型的服务 'IdentityServer4.EntityFramework.Options.OperationalStoreOptions' 在尝试激活时 'IdentityServer4.EntityFramework.DbContexts.PersistedGrantDbContext'。

我应该怎么解决?

【问题讨论】:

    标签: c# asp.net .net asp.net-core identityserver4


    【解决方案1】:

    无需直接调用数据库,直接使用提供的store即可。

    在这种情况下,您可以使用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);
        }
    
    }
    

    【讨论】:

    • 是的,我已经解决了我的问题。我错过了services.AddIdentityServer().AddOperationalStore。我必须使用PersistedGrantDbContext 来获取PersistedGrants 表中的所有数据。谢谢
    【解决方案2】:

    是的,我已经解决了我的问题。我错过了services.AddIdentityServer().AddOperationalStore

    【讨论】:

      猜你喜欢
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      • 2016-02-19
      • 1970-01-01
      • 2017-08-01
      • 2020-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多