Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/davidfowl/waitfordependenciesaspire
https://github.com/davidfowl/waitfordependenciesaspire
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/davidfowl/waitfordependenciesaspire
- Owner: davidfowl
- License: mit
- Created: 2024-04-24T07:24:03.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-08-08T02:17:43.000Z (5 months ago)
- Last Synced: 2024-12-08T05:30:16.476Z (14 days ago)
- Language: C#
- Size: 64.5 KB
- Stars: 98
- Watchers: 6
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Waiting for dependencies
This examples shows how to extend the .NET Aspire application model to enable waiting for dependencies to be available before starting the application. It uses ASP.NET Core's [health checks API](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-8.0) to determine if specific resources are available after they are considered running.
```C#
var builder = DistributedApplication.CreateBuilder(args);var db = builder.AddSqlServer("sql")
.WithHealthCheck()
.AddDatabase("db");var rabbit = builder.AddRabbitMQ("rabbit")
.WithHealthCheck();var console = builder.AddProject("console");
builder.AddProject("api")
.WithExternalHttpEndpoints()
.WithReference(db)
.WithReference(rabbit)
// Wait for the database and rabbitmq to be healthy before starting the api
.WaitFor(db)
.WaitFor(rabbit)
// Wait for the console application to run to completion
.WaitForCompletion(console);builder.Build().Run();
```The above example shows the usage. `WaitFor` is an extension method that stores a
reference to the dependency and waits for it to be healthy before starting a specific resource. In the above case,
the `api` project will wait for the `db` and `rabbit` dependencies to be healthy before starting.