MongoDB - register each collection instead of repositories registration


#1

Hi. I noticed that in Distributed.NetShop you register each MongoDbRepository like:

  builder.AddMongoDBRepository<Cart>("Carts");
  builder.AddMongoDBRepository<Customer>("Customers");

The MongoDbRepository ctor expects IMongoDatabase and collection name as System.String.

My question is: Are there any pros from registering each collection instead of each repository ? Then the constructor will look like:

public MongoRepository(IMongoCollection<TEntity> collection)
{
       Collection = collection;
}

Is it a good move at all ?

Thanks for reply.
Greetings:)


#2

Hi,
Yes, we want to pass a string here and inject the IMongoDatabase, simply due to the proper lifecycle management via IoC container.