|
1 | | -using System.IO; |
| 1 | +using System.Threading.Tasks; |
| 2 | +using IdentityServer4.EntityFramework.Entities; |
| 3 | +using IdentityServer4.EntityFramework.Extensions; |
| 4 | +using IdentityServer4.EntityFramework.Interfaces; |
| 5 | +using IdentityServer4.EntityFramework.Mappers; |
| 6 | +using IdentityServer4.EntityFramework.Options; |
2 | 7 | using Microsoft.EntityFrameworkCore; |
3 | | -using Microsoft.Extensions.Configuration; |
4 | 8 |
|
5 | 9 | namespace Jp.Infra.Data.Context |
6 | 10 | { |
7 | 11 | public class JpContext : DbContext |
| 12 | + , IConfigurationDbContext |
| 13 | + , IPersistedGrantDbContext |
8 | 14 | { |
9 | | - public JpContext(DbContextOptions<JpContext> options |
10 | | - ) : base(options) |
| 15 | + private readonly ConfigurationStoreOptions _storeOptions; |
| 16 | + private readonly OperationalStoreOptions _operationalOptions; |
| 17 | + |
| 18 | + public JpContext(DbContextOptions<JpContext> options, |
| 19 | + ConfigurationStoreOptions storeOptions, |
| 20 | + OperationalStoreOptions operationalOptions |
| 21 | + ) : base(options) |
11 | 22 | { |
| 23 | + _storeOptions = storeOptions; |
| 24 | + _operationalOptions = operationalOptions; |
12 | 25 | } |
13 | | - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) |
| 26 | + |
| 27 | + |
| 28 | + public DbSet<ApiResource> ApiResources { get; set; } |
| 29 | + |
| 30 | + public DbSet<IdentityResource> IdentityResources { get; set; } |
| 31 | + |
| 32 | + public DbSet<ApiSecret> ApiSecrets { get; set; } |
| 33 | + |
| 34 | + public DbSet<ApiScope> ApiScopes { get; set; } |
| 35 | + |
| 36 | + public DbSet<ApiScopeClaim> ApiScopeClaims { get; set; } |
| 37 | + |
| 38 | + public DbSet<IdentityClaim> IdentityClaims { get; set; } |
| 39 | + |
| 40 | + public DbSet<ApiResourceClaim> ApiResourceClaims { get; set; } |
| 41 | + |
| 42 | + public DbSet<Client> Clients { get; set; } |
| 43 | + |
| 44 | + public DbSet<ClientGrantType> ClientGrantTypes { get; set; } |
| 45 | + |
| 46 | + public DbSet<ClientScope> ClientScopes { get; set; } |
| 47 | + |
| 48 | + public DbSet<ClientSecret> ClientSecrets { get; set; } |
| 49 | + |
| 50 | + public DbSet<ClientPostLogoutRedirectUri> ClientPostLogoutRedirectUris { get; set; } |
| 51 | + |
| 52 | + public DbSet<ClientCorsOrigin> ClientCorsOrigins { get; set; } |
| 53 | + |
| 54 | + public DbSet<ClientIdPRestriction> ClientIdPRestrictions { get; set; } |
| 55 | + |
| 56 | + public DbSet<ClientRedirectUri> ClientRedirectUris { get; set; } |
| 57 | + |
| 58 | + public DbSet<ClientClaim> ClientClaims { get; set; } |
| 59 | + |
| 60 | + public DbSet<ClientProperty> ClientProperties { get; set; } |
| 61 | + |
| 62 | + public DbSet<PersistedGrant> PersistedGrants { get; set; } |
| 63 | + |
| 64 | + protected override void OnModelCreating(ModelBuilder modelBuilder) |
14 | 65 | { |
15 | | - |
| 66 | + base.OnModelCreating(modelBuilder); |
| 67 | + modelBuilder.ConfigureClientContext(_storeOptions); |
| 68 | + modelBuilder.ConfigureResourcesContext(_storeOptions); |
| 69 | + modelBuilder.ConfigurePersistedGrantContext(_operationalOptions); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + public Task<int> SaveChangesAsync() |
| 75 | + { |
| 76 | + return base.SaveChangesAsync(); |
16 | 77 | } |
17 | 78 | } |
18 | | - |
| 79 | + |
19 | 80 | } |
0 commit comments