private static RuntimeBuilder AddDocumentDbRuntimeStores(this RuntimeBuilder builder, string connectionString, ConnectionScope scope, Action <DocumentDbOptions> configureDatabase) { var slot = Constants.ConnectionSlots.Runtime; if (configureDatabase != null) { builder.Services.Configure(slot, configureDatabase); } var serviceProvider = builder.Services.BuildServiceProvider(); var dbOptions = serviceProvider.GetService <IOptions <DocumentDbOptions> >()?.Value ?? new DocumentDbOptions(); configureDatabase?.Invoke(dbOptions); var dialect = new DocumentDbDialect(); SqlBuilder.Dialect = dialect; builder.AddSqlRuntimeStores <DocumentDbConnectionFactory>(connectionString, scope, OnCommand(), OnConnection); builder.Services.AddMetrics(); builder.Services.TryAddSingleton <ISqlDialect>(dialect); builder.Services.TryAddSingleton(dialect); builder.Services .TryAddSingleton <IDataBatchOperation <DocumentDbBatchOptions>, DocumentDbBatchDataOperation>(); var runtimeOptions = serviceProvider.GetRequiredService <IOptions <RuntimeOptions> >().Value; MigrateToLatest(runtimeOptions, dbOptions); return(builder); }
public static IdentityBuilder AddDocumentDbIdentityStore <TKey, TUser, TRole, TTenant, TApplication>( this IdentityBuilder identityBuilder, Action <DocumentDbOptions> configureAction = null, ConnectionScope scope = ConnectionScope.ByRequest) where TKey : IEquatable <TKey> where TUser : IdentityUserExtended <TKey> where TRole : IdentityRoleExtended <TKey> where TTenant : IdentityTenant <TKey> where TApplication : IdentityApplication <TKey> { var services = identityBuilder.Services; const string slot = Constants.ConnectionSlots.Identity; if (configureAction != null) { services.Configure(slot, configureAction); } var options = new DocumentDbOptions(); configureAction?.Invoke(options); identityBuilder .AddIdentityStores <TKey, TUser, TRole, TTenant, TApplication>(); var dialect = new DocumentDbDialect(); SqlBuilder.Dialect = dialect; SimpleDataDescriptor.TableNameConvention = s => { return(s switch { nameof(IdentityRoleExtended) => nameof(IdentityRole), nameof(IdentityUserExtended) => nameof(IdentityUser), _ => s }); };
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); }