Skip to content

Extend IWithDbContextBuilder API to allow registration of DbContext with interface #379

@achobanov

Description

@achobanov

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:

  1. Instance of MyDbContext, registed as MyDbContext and used to arrange the test data.
  2. 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.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions