#20|20 IdentityServer4.EntityFrameworkCore
###Entity Framework Core persistence layer for IdentityServer v4
The primary key type can be configured for ClientStore and ScopeStore. To facilitate this, subclass the ClientConfigurationContext<TKey>
and ScopeConfigurationContext<TKey>
with the desired key type.
public class ClientConfigurationContext : ClientConfigurationContext<Guid>
{
public ClientConfigurationContext(DbContextOptions options)
: base(options)
{ }
}
public class ScopeConfigurationContext : ScopeConfigurationContext<Guid>
{
public ScopeConfigurationContext(DbContextOptions options)
: base(options)
{ }
}
In the Startup.cs
, register your DbContexts with Entity Framework
public void ConfigureServices(IServiceCollection services)
{
...
services.AddEntityFrameworkSqlServer()
.AddDbContext<ClientConfigurationContext>(o => o
.UseSqlServer(connectionString, b =>
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))
.AddDbContext<ScopeConfigurationContext>(o => o
.UseSqlServer((connectionString, , b =>
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)))
.AddDbContext<OperationalContextEx>(o => o
.UseSqlServer((connectionString, , b =>
b.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name)));
...
}
Register the EFCore Contexts
public void ConfigureServices(IServiceCollection services)
{
...
var builder = services.AddIdentityServer(options =>
{
options.RequireSsl = false;
});
builder.ConfigureEntityFramework()
.RegisterOperationalStores()
.RegisterClientStore<Guid, ClientConfigurationContext>()
.RegisterScopeStore<Guid, ScopeConfigurationContext<>();
...
}
To get started, sign the Contributor License Agreement.