I'm using Entity Framework (code first), Repositories, and the Unit of Work pattern, essentially as described here: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable
I'm also using StructureMap to manage my object instances and I have some code like this wiring up the EF dbcontext and unit of work:
For<DbContext>().HybridHttpOrThreadLocalScoped().Use<MyDbContext>();
For<IUnitOfWork>().HybridHttpOrThreadLocalScoped().Use<UnitOfWork>();
I also have a generic Repository<T>
that currently knows about the MyDbContext
instance. Now I need to be able to support multiple databases, and thus multiple DbContexts. I'm considering trying to adjust my IUnitOfWork
to be instead an IUnitOfWork<T>
, where T is the DbContext
to use. But my repository will also need to know which DbContext
to use, so do I then have to make it doubly generic (e.g. Repository<TEntity,TDbContext>
)?
What's the best, simplest way to support multiple databases using the UnitOfWork pattern I'm using?