From the course: Complete Guide to Dapr for .NET and Azure Developers: Building and Managing Microservices

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Implementing app health checks

Implementing app health checks

- [Instructor] ASP. NET Core includes health checks that automatically detect when an application becomes unresponsive. We can use these health endpoints in Dapr to immediately short-circuit incoming service invocation requests, unregister from pub/sub subscriptions, and stop all input bindings. Let's implement a health check for the DbContext in the Pet microservice. The service will be reported as unhealthy if database connectivity is unavailable. So let's go ahead, and here in the Pet.Api project, we can see that we have those package references and we need the Microsoft.Extensions.Diagnostics HealthChecks.EntityFrameworkCore package, since I want to use the DbContext for identifying when there's connection to the database. So let's go here and expand the project, and let's open Program, and then let's add builder.Services, and then AddHealthChecks, and let's use AddDbContextCheck. Let's see the name of the DbContext. This is PetDbContext, so PetDbContext, and that's it. Now we…

Contents