Reputation: 412
I'm embarking upon a new application framework which will ultimately support many different applications and for each of those applications they will all share a set of common domain entities e.g. Accounts, Contacts, Addresses etc.
For the purposes of this question lets say I have 2 applications Forms and Complaints and both of these applications will have a common shared domain entity called Accounts. Each application will have its own database context and corresponding physical database. I can create a common domain project that defines and configures the Account domain entity and then each application database context can use that so that the common entity is shared between both databases, excellent!
The problems start when I try to implement IAccountRepository this will need access to the database context however, because these domain entities are shared across all databases I can't use ComplaintsDbContext or FormsDbContext directly. I could use the DbContext abstraction but I how can I register this within the dependency injection container allowing some form of dynamic switching between the 2 database contexts ComplaintsDbContext or FormsDbContext.
I feel like there is going to be some pattern I'm not aware of that will help with this?
My repositories will be implemented using .Set() so I have no concerns about having access to set properties on the db context itself as we do not implement any. Hence why I feel that I can inject a DbContext and my repositories will work fine but, how do I get the appropriate database context injected?
Thanks in advance!
Upvotes: 0
Views: 30