Class StrataraIdentityStoreServiceCollectionExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Stratara.EventSourcing.EntityFrameworkCore.dll
Registers StrataraIdentityStore, the identity store several hosts can share, and applies the migrations shipped with it.
public static class StrataraIdentityStoreServiceCollectionExtensions
- Inheritance
-
StrataraIdentityStoreServiceCollectionExtensions
- Inherited Members
Methods
AddStrataraIdentityStore(IServiceCollection)
Registers StrataraIdentityStore on PostgreSQL together with the tenant directory's stores over it — memberships, API keys and settings, each with a context of its own per operation.
public static IServiceCollection AddStrataraIdentityStore(this IServiceCollection services)
Parameters
servicesIServiceCollectionThe service collection to add registrations to.
Returns
- IServiceCollection
The same IServiceCollection for chaining.
Examples
builder.Services.AddStrataraIdentityStore();
builder.AddAspNetIdentityWithSignInManager<IdentityUser, StrataraIdentityStore>();
// after Build():
await app.Services.MigrateStrataraIdentityStoreAsync();
Remarks
The connection is the connection string ConnectionStringName, and where it
is absent the connection string defaultdb. It is read from configuration, never through a tenant-routing
IDbResolver: the identity store is one database for every tenant. Hosts that keep their own databases meet
in the identity store by giving it the same connection.
A host that turns on ProtectPersonalData is refused at start: it would write account columns other hosts sharing the store cannot read or match.
Register the accounts on it with AddAspNetIdentity<IdentityUser, StrataraIdentityStore>() (or the
variant with the sign-in manager), and apply the migrations at start with
MigrateStrataraIdentityStoreAsync(IServiceProvider, CancellationToken). A host that registers the store generates no migrations of its
own for these tables.
Exceptions
- InvalidOperationException
When the store is first used: neither connection string is configured.
MigrateStrataraIdentityStoreAsync(IServiceProvider, CancellationToken)
Creates the identity store's database where it does not exist yet and applies the migrations shipped with StrataraIdentityStore that it has not applied.
public static Task MigrateStrataraIdentityStoreAsync(this IServiceProvider services, CancellationToken cancellationToken = default)
Parameters
servicesIServiceProviderThe host's root service provider.
cancellationTokenCancellationTokenCancels the migration.
Returns
- Task
A task that completes once the store is migrated.
Remarks
Every host that shares the store applies the same migrations, so one a host applied is recognised as applied by every other. Hosts that migrate at the same time take turns: the migration lock of EF Core makes a second host wait for the first, and a database another host created a moment earlier counts as created.