Is there a way, using StructureMap (the Dependency Injection container) to inject a specific instance of a type into all types from a given namespace that are requesting that type?
Here is an example set up:
EmployeesDbContext : IAbstractDbContext { ... }
AccountingDbContext : IAbstractDbContext { ... }
MarketingDbContext : IAbstractDbContext { ... }
StructureMap registers all of these types against IAbstractDbContext as expected.
Then:
- HumanResources.Domain which has business logic and entities related to the Employees database, therefore requiring the EmployeesDbContext
- Accounting.Domain which has business logic and entities related to the Accounting database, therefore requiring the AccountingDbContext
- etc...
I then have a WebUI (ASP.NET MVC) project, which can be thought of as the composition root, which is leveraging StructureMap which will compose the dependency trees.
It makes the most sense to leverage the fact that the DbContext requirement is largely driven by the namespace consuming it.
Trouble is, I'm not sure how to tackle this set up, any thoughts much appreciated!