Example #1
0
        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);
        }
Example #2
0
 public MongoRepositoryConfigurator(IServiceCollection collection, MongoConifgurations configurations)
 {
     this.collection     = collection;
     this.configurations = configurations;
 }
Example #3
0
 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));
 }