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

Allow Resources to not be started automatically with the AppHost #7043

Open
1 task done
ronbrogan opened this issue Jan 8, 2025 · 1 comment
Open
1 task done

Allow Resources to not be started automatically with the AppHost #7043

ronbrogan opened this issue Jan 8, 2025 · 1 comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Comments

@ronbrogan
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I have various 'accessory' projects in my solution that I would like to start/stop independently of my main API and Frontend services. Currently it seems that if these accessory projects are included in my Aspire AppHost, they're automatically started. I tried setting the initial snapshot state to Waiting, Stopped, Exiting, etc but the project is always started anyhow.

Describe the solution you'd like

It would be great if we could declare that the resource should not be started by default. This could be done via the snapshot state like I was trying, but ideally it should be a bit more straightforward to accomplish. Something that seems decent to me is to have a .WithLifecycle(ResourceLifecycle) extension on the IResourceBuilder that can be used to set how the resource is handled.

public enum ResourceLifecycle
{
    AutoStart,
    DelayStart, // example for other use cases
    ManualStart
}

public static class LifecycleExtensions
{
    public static IResourceBuilder<TResource> WithLifecycle<TResource>(this IResourceBuilder<TResource> builder, ResourceLifecycle lifecycle)
        where TResource: IResource
    {
        return builder.WithAnnotation(new ResourceLifecycleAnnotation(lifecycle));
    }
}

public record class ResourceLifecycleAnnotation(ResourceLifecycle Lifecycle) : IResourceAnnotation { }

// somewhere where the resources are being started
foreach(var exe in allExecutables)
{
    if(exe.TryGetLastAnnotation<ResourceLifecycleAnnotation>(out var lifecycleAnnotation))
    {
        if (lifecycleAnnotation.Lifecycle == ResourceLifecycle.ManualStart)
            continue;

        // etc
    }
}

Additional context

I realize that this can be hacked around with custom commands to run the projects manually, but it seems like a no brainer to me that some things on your dashboard might be optional or scenario dependent - and thus just shouldn't be started automatically.

@KennethHoff
Copy link

Related to #5851

@davidfowl davidfowl added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

No branches or pull requests

3 participants