public static void AddMongoRepositories(this IServiceCollection collection, MongoConifgurations configurations, Action <MongoRepositoryConfigurator> registrator) { var builder = new MongoRepositoryConfigurator(collection, configurations); var mongoUrlObject = new MongoUrl(configurations.MongoUrl); var client = new MongoClient(mongoUrlObject); var database = client.GetDatabase(mongoUrlObject.DatabaseName ?? "admin"); collection.AddSingleton(database); registrator(builder); }
public MongoRepositoryConfigurator(IServiceCollection collection, MongoConifgurations configurations) { this.collection = collection; this.configurations = configurations; }
public MongoRepository(MongoConifgurations conifgurations, IMongoDatabase database) { // TODO: Add guard clauses for mongoUrl and schema (not null or empty) this.database = database; this.collection = this.database.GetCollection <TMongoEntity>(string.Join(".", conifgurations.Schema, typeof(TMongoEntity).Name)); }