dotnet / dotnet/aspnetcore

`DbContextCheck` should work together with `IDbContextFactory`

Open
#33,344 4 comments 8 reactions 0 assignees View on GitHub
area-healthchecks enhancement
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is your feature request related to a problem? Please describe.

We use the `services.AddDbContextCheck()` method to monitor the connection to the database in our apps. Due to performance reasons we switched to using `IDbContextFactory` to access instances of EF Core DbContext:

```csharp
services.AddPooledDbContextFactory(dbContextOptions)
```

When we did so, we noticed that the `DbContextHealthCheck` does not support the factory and, thus, we had to register the DbContext directly to keep the HealthCheck working:

```csharp
// This is just required for the HealthCheck, since it does not (yet?) work with the Factory.
services.AddDbContextPool(dbContextOptions);
```

### Describe the solution you'd like

The `DbContextHealthCheck` should support `IDbContextFactory` without any additional service registrations.

### Additional context

We are willing to invest some time to implement this and submit a pull request. But we need some support on how we should implement this and how the API should look like.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.