`AfterResourcesCreatedEvent` is inconsistently fired
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
I'm finding the logic for when the `AfterResourcesCreatedEvent` is fired to be very confusing. Take the following code for example:
```cs
var builder = DistributedApplication.CreateBuilder(args);
builder.Services.AddHealthChecks().AddCheck("alwaysUnhealthy", () => HealthCheckResult.Unhealthy());
var one = builder.AddContainer("one", "nginx").WithHealthCheck("alwaysUnhealthy");
var two = builder.AddContainer("two", "nginx");
//two.WaitFor(one);
builder.Eventing.Subscribe((evt, ct) =>
{
Console.WriteLine("AfterResourcesCreatedEvent");
Console.Beep();
return Task.CompletedTask;
});
builder.Build().Run();
```
Run this whilst **docker is stopped**, no resoruces are stated but the `AfterResourcesCreatedEvent` does get fired.

However if you comment out the `//two.WaitFor(one);` line above and run the app (whilst **docker is still not running**), then the `AfterResourcesCreatedEvent` does not get fired.
The issue here seems to be that when `WaitFor` is used, the `AfterResourcesCreatedEvent` is blocked until all health checks become healthy. However the runtime availability is handled by a different flow which does not block `AfterResourcesCreatedEvent`.
From my point of view, both the above are essentially the same in both cases the containers are waiting on something else before they can start, and so I'd expect either both cases to raise `AfterResourcesCreatedEvent` or I'd neither to raise the event.

Contributor guide
Assessment
This issue has not been assessed yet.