I have a single application that talks to separate databases through two individual UnitOfWork
classes. I am using StructureMap
to build my classes. Individually, each one builds and runs correctly.
However, once I consume both container registries within my "Web Application", I get conflicts. Both registries reference the same DbContext
(base) class from their common framework. However, each registry has its own concrete DbContext
class (that inherits from DbContext
).
The problem is...
- The moment I consume both registries, last in "wins"...and the wrong
CONCRETE
Dbcontext
class is applied (into the first registry). - Multiple instances of
DbContext
are applied to the Repository references.
Q: How do I ensure the right CONCRETE DbContext is applied across my registry?
Q: How do I ensure a SINGLE INSTANCE of the DbContext across my registry?
I have tried various methods without success...thanks for the help.
For Example...
REGISTERY 'ONE' CONTAINS:
For<DbContext>().Use<BBLDataContext>();
For<IUnitOfWork>().Use<BBLUnitOfWork>();
For(typeof(ICompositeRepository<>)).Use(typeof(DbRepository<>)).Ctor<DbContext>().Is<BBLDataContext>();
For(typeof(IRepository<>)).Use(typeof(DbRepository<>)).Ctor<DbContext>().Is<BBLDataContext>();
REGISTERY 'TWO' CONTAINS:
For<DbContext>().Use<WsDataContext>();
For<IUnitOfWork>().Use<WsUnitOfWork>();
For(typeof(ICompositeRepository<>)).Use(typeof(DbRepository<>)).Ctor<DbContext>().Is<WsDataContext>();
For(typeof(IRepository<>)).Use(typeof(DbRepository<>)).Ctor<DbContext>().Is<WsDataContext>();