Multiple session

From architectural point of view, the way you are initializing connection within base repository class using static class Utils is not the best option, maybe even wrong.

In case of multiple repositories, it will result in multiple independent sessions to MongoDB open on the client side. In general, taking into consideration that it is MongoDB repository, it will work fine having session per repository as you did, however it
is much better to share one session over all repository instances.

So I'd suggest rethink the way you are managing sessions in your code.

Whatever you'll decide, it is good work and great initiative to start a project like this one.

MongoDB driver handles the connection pooling for you. It doesn't matter how many connections or Repositories you create. MongoDB driver will get the same object from pool and returns you. And the default pool size is 5 which is more or less enough.

MongoDB driver handles the connection pooling for you. It doesn't matter how many connections or Repositories you create. MongoDB driver will get the same object from pool and returns you. And the default pool size is 5 which is more or less enough.

That is true, however:

AlexeyNayda wrote:

From architectural point of view

...and that makes sense in a way. Even if it were only for a "transaction", it would make sense to "group" repositories onto the same connection when possible. Even when the actual connection would be pooled into/onto different underlying
(actual) TCP connections to MongoDB, from an architectural POV using the same "virtual" connection would make sense.

However, this is low on my "nice to haves" list and not really a dealbreaker to me.