-
Notifications
You must be signed in to change notification settings - Fork 1
Multiple Databases Management
A given IDocumentStore
can give access to one or more databases.
For majority of scenarios, what is needed the most is a IDocumentSession
(or its asynchronous counterpart); so it is very common to take a dependency on such interface and let your IOC container (if used) to provide instances of such interface.
For lower-level operations, dependemcies upon IDatabaseCommands
can also be taken.
Both abstractions operate on a single given database, so the developer faces a small challenge when multiple databases are to be used in the same application as a single interface cannot be used for different databases.
A solution I have used extensively is having an interface for an abstraction per database. E.g. in our system we are using two databases: myDb and yourDb. In such case we would create two interfaces in order to use the "session" abstraction:
public interface IMyDbSession : IDocumentSession { }
public interface IYourDbSession : IDocumentSession { }
For each interface we need a concrete implementation to delegate the execution. In order to create such an implementation there are multiple strategies, each with its pros and cons.
The one that was implementedin rvn-izr is to have a single abstraction implementation, of which each database-specific implementation inherits from. Better explained in code: