Jes*_*ess 2 duende-identity-server
我有一些集成测试,它们使用针对 ConfigurationDbContext 的真实数据库。升级到 Duende IdentityServer 6.0 时,由于添加了 DbContext 连接池功能,ConfigurationDbContext 的构造函数会中断(仅接受 1 个参数而不是 2 个)。
这段代码破坏了:
public static ConfigurationDbContext GetConfigurationDbContext()
{
var connectionString = Configuration.GetConnectionString("ConfigurationDbContext");
var builder = new DbContextOptionsBuilder<ConfigurationDbContext>();
builder.UseSqlServer(connectionString);
var options = new ConfigurationStoreOptions
{
DefaultSchema = Schema.IdSrv
};
return new ConfigurationDbContext(builder.Options, options);
}
Run Code Online (Sandbox Code Playgroud)
所以我把它改为:
return new ConfigurationDbContext(builder.Options);
Run Code Online (Sandbox Code Playgroud)
现在我可以构建,但我的测试因以下错误而失败:
Unable to resolve service for type 'Duende.IdentityServer.EntityFramework.Options.ConfigurationStoreOptions'
我应该如何传递 ConfigurationStoreOptions ?查看Github上的代码,看起来依赖于依赖注入。(从服务集合中获取选项)。
好吧,我找到了自己的问题,但我不得不到处寻找和啄食。它没有被列为升级文档中的重大更改:
https://docs.duendesoftware.com/identityserver/v6/upgrades/v5.2_to_v6.0/
解决方案是将您的项目升级到6.1
<PackageReference Include="Duende.IdentityServer.EntityFramework.Storage" Version="6.1.5" />
Run Code Online (Sandbox Code Playgroud)
然后您可以使用此代码(StoreOptions 已成为公共设置属性)
public static ConfigurationDbContext GetConfigurationDbContext()
{
var connectionString = Configuration.GetConnectionString("MyIdentity");
var builder = new DbContextOptionsBuilder<ConfigurationDbContext>();
builder.UseSqlServer(connectionString);
var options = new ConfigurationStoreOptions
{
DefaultSchema = Schema.IdSrv
};
var dbContext = new ConfigurationDbContext(builder.Options);
dbContext.StoreOptions = options;
return dbContext;
}
Run Code Online (Sandbox Code Playgroud)
这适用于 ConfigurationDbContext 和 PersistedGrantDbContext。
| 归档时间: |
|
| 查看次数: |
1216 次 |
| 最近记录: |