Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Healthchecks support #17

Closed
Inlustris opened this issue Jun 25, 2019 · 1 comment
Closed

Healthchecks support #17

Inlustris opened this issue Jun 25, 2019 · 1 comment

Comments

@Inlustris
Copy link

Hello vany0114,

We use the dbcontextfactory and would like to start using the EF 2.2 health checks. After starting with the health checks i encountered a problem. The healthcheck delivered in AspNet makes use of DbContext. And not the DbContextFactory we use.

Is it possible to create or implement the healthcheck of 2.2 in this package?

King regards Inlustris,

@vany0114 vany0114 changed the title Dot net dore 2.2 Healthchecks support Jun 26, 2019
@vany0114
Copy link
Owner

Hi @Inlustris

You're right, the HealthChecks.EntityFrameworkCore implementation expects a DbContext instance itself rather than a factory of a DbContext (Func<DbContext>) that's why you have that issue.

So, as I see this scenario, you could handle that using a custom healthcheck or even using the built-in healthcheck provided by Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore package.

I made a simple example in order to show you both approaches, I think both are correct, so you can create your custom healthcheck which receives a DbContext factory or you can use the built-in one, injecting a DbContext as an instance just for the health check purpose. At the end of the day, that instance only will be injected when the health check is executed and it's only for reading purposes, so you shouldn't have concurrency issues.

So, let me know if that helps.

PD: The idea to implement a healthcheck using DbContextFactory out of the box is great, let's see if more people request it, then we can package it!

@vany0114 vany0114 closed this as completed Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants