public static IdentityBuilder AddSqliteIdentityStore <TKey, TUser, TRole, TTenant>( this IdentityBuilder identityBuilder, string connectionString, ConnectionScope scope = ConnectionScope.ByRequest, Action <SqliteOptions> configureDatabase = null) where TKey : IEquatable <TKey> where TUser : IdentityUserExtended <TKey> where TRole : IdentityRoleExtended <TKey> where TTenant : IdentityTenant <TKey> { identityBuilder.Services.AddSingleton <ITypeRegistry, TypeRegistry>(); var dialect = new SqliteDialect(); var builder = new SqliteConnectionStringBuilder(connectionString); void ConfigureDatabase(SqliteOptions o) { configureDatabase?.Invoke(o); } identityBuilder.Services.Configure <SqliteOptions>(ConfigureDatabase); var serviceProvider = identityBuilder.Services.BuildServiceProvider(); var options = serviceProvider.GetService <IOptions <SqliteOptions> >()?.Value ?? new SqliteOptions(); configureDatabase?.Invoke(options); identityBuilder.AddSqlStores <SqliteConnectionFactory, TKey, TUser, TRole, TTenant>(connectionString, scope, OnCommand <TKey>(), OnConnection); identityBuilder.Services.AddSingleton(dialect); SqlBuilder.Dialect = dialect; SimpleDataDescriptor.TableNameConvention = s => { switch (s) { case nameof(IdentityRoleExtended): return("AspNetRoles"); case nameof(IdentityUserExtended): return("AspNetUsers"); case nameof(IdentityTenant): return("AspNetTenants"); default: return(s); } }; DescriptorColumnMapper.AddTypeMap <TUser>(StringComparer.Ordinal); DescriptorColumnMapper.AddTypeMap <TRole>(StringComparer.Ordinal); DescriptorColumnMapper.AddTypeMap <TTenant>(StringComparer.Ordinal); identityBuilder.Services.AddMetrics(); identityBuilder.Services.AddSingleton(dialect); identityBuilder.Services.AddSingleton <IQueryableProvider <TUser>, NoQueryableProvider <TUser> >(); identityBuilder.Services.AddSingleton <IQueryableProvider <TRole>, NoQueryableProvider <TRole> >(); identityBuilder.Services.AddSingleton <IQueryableProvider <TTenant>, NoQueryableProvider <TTenant> >(); var identityOptions = serviceProvider.GetRequiredService <IOptions <IdentityOptionsExtended> >().Value; MigrateToLatest <TKey>(connectionString, identityOptions, options); return(identityBuilder); }
public static IdentityBuilder AddDocumentDbIdentityStore <TKey, TUser, TRole, TTenant>( this IdentityBuilder identityBuilder, string connectionString, ConnectionScope scope = ConnectionScope.ByRequest, Action <DocumentDbOptions> configureDocumentDb = null) where TKey : IEquatable <TKey> where TUser : IdentityUserExtended <TKey> where TRole : IdentityRoleExtended <TKey> where TTenant : IdentityTenant <TKey> { var services = identityBuilder.Services; services.AddSingleton <ITypeRegistry, TypeRegistry>(); var serviceProvider = services.BuildServiceProvider(); var builder = new DocumentDbConnectionStringBuilder(connectionString); void ConfigureAction(DocumentDbOptions o) { configureDocumentDb?.Invoke(o); o.DatabaseId = o.DatabaseId ?? builder.Database; o.CollectionId = o.CollectionId ?? builder.DefaultCollection ?? Constants.Identity.DefaultCollection; } identityBuilder.Services.Configure <DocumentDbOptions>(ConfigureAction); var dialect = new DocumentDbDialect(); identityBuilder.AddSqlStores <DocumentDbConnectionFactory, TKey, TUser, TRole, TTenant>(connectionString, scope, OnCommand <TKey>(), OnConnection); SqlBuilder.Dialect = dialect; SimpleDataDescriptor.TableNameConvention = s => { switch (s) { case nameof(IdentityRoleExtended): return(nameof(IdentityRole)); case nameof(IdentityUserExtended): return(nameof(IdentityUser)); default: return(s); } }; DescriptorColumnMapper.AddTypeMap <TUser>(StringComparer.Ordinal); DescriptorColumnMapper.AddTypeMap <TRole>(StringComparer.Ordinal); DescriptorColumnMapper.AddTypeMap <TTenant>(StringComparer.Ordinal); services.AddMetrics(); services.AddSingleton(dialect); services.AddSingleton <IQueryableProvider <TUser>, DocumentDbQueryableProvider <TUser> >(); services.AddSingleton <IQueryableProvider <TRole>, DocumentDbQueryableProvider <TRole> >(); services.AddSingleton <IQueryableProvider <TTenant>, DocumentDbQueryableProvider <TTenant> >(); var options = new DocumentDbOptions(); ConfigureAction(options); var identityOptions = serviceProvider.GetRequiredService <IOptions <IdentityOptionsExtended> >().Value; MigrateToLatest <TKey>(connectionString, identityOptions, options); return(identityBuilder); }