Skip to content

WithExplicitStart() should block OnBeforeResourceStarted #13070

@afscrome

Description

@afscrome

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

If you have a resource WithExplicitStart() and with OnBeforeResourceStarted(), the event will fire on app start up, even if you haven't explicitly triggered the resource to start.

The event will then fire a second time (and a third time due to #13068) when you actually start the resource.

Expected Behavior

The event should only fire once (not 3 times), and I'd expect the event to not fire until after the resource is explicitly started.

Steps To Reproduce

var builder = DistributedApplication
    .CreateBuilder(args);

var foo = builder.AddContainer("nginx", "nginx")
    .WithExplicitStart()
    .OnBeforeResourceStarted((_, _, _) =>
    {
        Console.WriteLine($"Before Start {DateTime.Now}");
        return Task.CompletedTask;
    });

builder.Build().Run();

Exceptions (if any)

info: Aspire.Hosting.DistributedApplication[0]
      Aspire version: 13.0.0+7512c2944094a58904b6c803aa824c4a4ce42e11
info: Aspire.Hosting.DistributedApplication[0]
      Distributed application starting.
info: Aspire.Hosting.DistributedApplication[0]
      Application host directory is: S:\DotNetConf\DotNetConf.AppHost
Before Start 20/11/2025 14:05:23
info: Aspire.Hosting.DistributedApplication[0]
      Distributed application started. Press Ctrl+C to shut down.
info: Aspire.Hosting.DistributedApplication[0]
      Now listening on: https://localhost:17031
info: Aspire.Hosting.DistributedApplication[0]
      Login to the dashboard at https://localhost:17031/login?t=db417f7470e0d14fdebe82c268787cf5
Before Start 20/11/2025 14:05:32
Before Start 20/11/2025 14:05:32

.NET Version info

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions