public static void AddMongoRepository <T>(this IServiceCollection services, string collection, Action <BsonClassMap <T> > mapSetup = null, Action <IMongoIndexManager <T> > indexSetup = null) where T : IIdentifiable { DataAccessClassMap.RegisterClass(mapSetup); services.AddSingleton <IRepository <T> >(sp => CreateMongoRepository(sp, collection, indexSetup)); }
public static IServiceCollection AddDataAccess(this IServiceCollection services, IConfiguration configuration) { var options = configuration.GetOptions <DataAccessOptions>(); string jobDatabaseName = options.JobDatabaseName ?? options.Prefix + "_jobs"; services.AddHangfire(x => x.UseMongoStorage($"{options.ConnectionString}/{jobDatabaseName}", new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions { Strategy = MongoMigrationStrategy.Migrate } })); DataAccessClassMap.RegisterConventions("SIL.XForge", new CamelCaseElementNameConvention(), new EnumRepresentationConvention(BsonType.String), new IgnoreIfNullConvention(true)); DataAccessClassMap.RegisterClass <Json0Snapshot>(cm => cm.MapIdProperty(e => e.Id)); DataAccessClassMap.RegisterClass <ProjectSecret>(cm => cm.MapIdProperty(e => e.Id)); services.AddSingleton <IMongoClient>(sp => new MongoClient(options.ConnectionString)); services.AddSingleton(sp => sp.GetService <IMongoClient>().GetDatabase(options.MongoDatabaseName)); services.AddMongoRepository <UserSecret>("user_secrets", cm => cm.MapIdProperty(us => us.Id)); services.AddMongoRepository <BetaMigration>("users_beta_migration"); return(services); }
public static void AddMongoRepository <T>(this IServiceCollection services, string collectionName, Action <BsonClassMap <T> > mapSetup = null, Action <IMongoIndexManager <T> > indexSetup = null) where T : Entity { DataAccessClassMap.RegisterClass(mapSetup); services.AddSingleton <IRepository <T> >(sp => new MongoRepository <T>( sp.GetService <IMongoDatabase>().GetCollection <T>(collectionName), c => indexSetup?.Invoke(c.Indexes))); }
public static IServiceCollection AddTranscriberDataAccess(this IServiceCollection services, IConfiguration configuration) { services.AddDataAccess(configuration); DataAccessClassMap.RegisterConcreteClass <ProjectUserEntity, TranscriberProjectUserEntity>(); services.AddMongoRepository <TranscriberTaskEntity>("tasks"); return(services); }
public static IServiceCollection AddSFDataAccess(this IServiceCollection services, IConfiguration configuration) { services.AddDataAccess(configuration); DataAccessClassMap.RegisterClass <SyncUser>(cm => cm.SetIdMember(null)); services.AddMongoRepository <TranslateMetrics>("translate_metrics", cm => cm.MapIdProperty(tm => tm.Id)); services.AddMongoRepository <SFProjectSecret>("sf_project_secrets"); return(services); }
public static IServiceCollection AddDataAccess(this IServiceCollection services, IConfiguration configuration) { var options = configuration.GetOptions <DataAccessOptions>(); services.AddHangfire(x => x.UseMongoStorage(options.ConnectionString, options.JobDatabase, new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions { Strategy = MongoMigrationStrategy.Migrate } })); DataAccessClassMap.RegisterConventions("SIL.XForge", new CamelCaseElementNameConvention(), new ObjectRefConvention(), new EnumRepresentationConvention(BsonType.String), new IgnoreIfNullConvention(true)); DataAccessClassMap.RegisterClass <Entity>(cm => { cm.MapIdProperty(e => e.Id) .SetIdGenerator(StringObjectIdGenerator.Instance) .SetSerializer(new StringSerializer(BsonType.ObjectId)); }); DataAccessClassMap.RegisterClass <ProjectUserEntity>(cm => { cm.SetIdMember(null); cm.MapProperty(u => u.Id).SetSerializer(new StringSerializer(BsonType.ObjectId)); cm.UnmapProperty(u => u.ProjectRef); }); services.AddSingleton <IMongoClient>(sp => new MongoClient(options.ConnectionString)); services.AddSingleton <IMongoDatabase>( sp => sp.GetService <IMongoClient>().GetDatabase(options.MongoDatabaseName)); services.AddMongoRepository <UserEntity>("users", mapSetup: cm => { var customSitesSerializer = new DictionaryInterfaceImplementerSerializer <Dictionary <string, Site> >( DictionaryRepresentation.Document, new StringSerializer(), BsonSerializer.SerializerRegistry.GetSerializer <Site>()); cm.GetMemberMap(u => u.Sites).SetSerializer(customSitesSerializer); }); return(services); }
public static IServiceCollection AddSFDataAccess(this IServiceCollection services, IConfiguration configuration) { services.AddDataAccess(configuration); DataAccessClassMap.RegisterConcreteClass <ProjectUserEntity, SFProjectUserEntity>(); services.AddMongoRepository <SFProjectEntity>(SFDataAccessConstants.ProjectsCollectionName, indexSetup: indexes => { IndexKeysDefinitionBuilder <SFProjectEntity> builder = Builders <SFProjectEntity> .IndexKeys; indexes.CreateOrUpdate(new CreateIndexModel <SFProjectEntity>(builder.Ascending("Users.Id"), new CreateIndexOptions { Unique = true })); indexes.CreateOrUpdate(new CreateIndexModel <SFProjectEntity>(builder.Ascending("Users.UserRef"))); }); services.AddMongoRepository <SyncJobEntity>("sync_jobs"); services.AddMongoRepository <TextEntity>(SFDataAccessConstants.TextsCollectionName); services.AddMongoRepository <TranslateMetrics>("translate_metrics", cm => cm.MapProperty(m => m.SessionId).SetSerializer(new StringSerializer(BsonType.ObjectId))); return(services); }