Skip to main content
Table of Contents

Class IdentityDirectoryDbContext<TContext>

Namespace
Stratara.Identity.EntityFrameworkCore
Assembly
Stratara.Identity.EntityFrameworkCore.dll

Standalone EF Core context hosting the Stratara identity-directory tables (tenant_membership, active_tenant, setting_entry, api_key) for hosts that do not fold them into an existing context. Consumers derive a concrete context and own its migrations, mirroring the pattern of the ASP.NET Identity store base: class MyDirectoryDbContext(DbContextOptions<MyDirectoryDbContext> options) : IdentityDirectoryDbContext<MyDirectoryDbContext>(options).

public class IdentityDirectoryDbContext<TContext> : DbContext, IInfrastructure<IServiceProvider>, IDbContextDependencies, IDbSetCache, IDbContextPoolable, IResettableService, IDisposable, IAsyncDisposable where TContext : DbContext

Type Parameters

TContext

The concrete derived DbContext type (used for DbContextOptions<TContext> binding).

Inheritance
IdentityDirectoryDbContext<TContext>
Implements
Inherited Members
Extension Methods

Remarks

The model is applied via explicit ApplyConfiguration calls (ApplyIdentityDirectoryModel(ModelBuilder)), not an assembly scan, so co-hosting this context next to other contexts can never leak foreign entity configurations into its model. To add the directory tables to an existing context instead (single migration lineage), skip this base class and call ApplyIdentityDirectoryModel(ModelBuilder) from that context's OnModelCreating.

Constructors

IdentityDirectoryDbContext(DbContextOptions<TContext>)

Standalone EF Core context hosting the Stratara identity-directory tables (tenant_membership, active_tenant, setting_entry, api_key) for hosts that do not fold them into an existing context. Consumers derive a concrete context and own its migrations, mirroring the pattern of the ASP.NET Identity store base: class MyDirectoryDbContext(DbContextOptions<MyDirectoryDbContext> options) : IdentityDirectoryDbContext<MyDirectoryDbContext>(options).

public IdentityDirectoryDbContext(DbContextOptions<TContext> options)

Parameters

options DbContextOptions<TContext>

Options bound by the host's DbContext registration.

Remarks

The model is applied via explicit ApplyConfiguration calls (ApplyIdentityDirectoryModel(ModelBuilder)), not an assembly scan, so co-hosting this context next to other contexts can never leak foreign entity configurations into its model. To add the directory tables to an existing context instead (single migration lineage), skip this base class and call ApplyIdentityDirectoryModel(ModelBuilder) from that context's OnModelCreating.

Properties

ActiveTenants

The per-user active-tenant selections.

public DbSet<ActiveTenantEntry> ActiveTenants { get; }

Property Value

DbSet<ActiveTenantEntry>

ApiKeys

The issued API keys (hashed).

public DbSet<ApiKeyEntry> ApiKeys { get; }

Property Value

DbSet<ApiKeyEntry>

Settings

The scoped setting values.

public DbSet<SettingEntry> Settings { get; }

Property Value

DbSet<SettingEntry>

TenantMemberships

The user↔tenant membership rows.

public DbSet<TenantMembershipEntry> TenantMemberships { get; }

Property Value

DbSet<TenantMembershipEntry>

Methods

OnModelCreating(ModelBuilder)

Override this method to further configure the model that was discovered by convention from the entity types exposed in DbSet<TEntity> properties on your derived context. The resulting model may be cached and re-used for subsequent instances of your derived context.

protected override void OnModelCreating(ModelBuilder modelBuilder)

Parameters

modelBuilder ModelBuilder

The builder being used to construct the model for this context. Databases (and other extensions) typically define extension methods on this object that allow you to configure aspects of the model that are specific to a given database.

Remarks

If a model is explicitly set on the options for this context (via UseModel(IModel)) then this method will not be run. However, it will still run when creating a compiled model.

See Modeling entity types and relationships for more information and examples.