Problem overivew
I have registered my db context with custom interface:
services.AddDatabase<IPersistence, MyDbContext>(...)
The current IWithDbContextBuilder exposes WithEntities<TDbContext which is used to provide the db context implementation and TDbContext is constrained to be of type DbContext.
In my case this results two separate instances of MyDbContext:
- Instance of
MyDbContext, registed as MyDbContext and used to arrange the test data.
- Instance of
MyDbContext, registed as IPersistence , requested by my application logic.
This obviously leads to wrong test results.
Solution
An overload of WithEntities that allows a DbContext to be provided using specific interface, in my case IPersistence.
I have created a snapshot branch which you could checkout and test locally.
Problem overivew
I have registered my db context with custom interface:
The current
IWithDbContextBuilderexposesWithEntities<TDbContextwhich is used to provide the db context implementation andTDbContextis constrained to be of typeDbContext.In my case this results two separate instances of
MyDbContext:MyDbContext, registed asMyDbContextand used to arrange the test data.MyDbContext, registed asIPersistence, requested by my application logic.This obviously leads to wrong test results.
Solution
An overload of
WithEntitiesthat allows a DbContext to be provided using specific interface, in my caseIPersistence.I have created a snapshot branch which you could checkout and test locally.