Nivot.Aspire.Hosting.ProjectCommander 1.0.2

dotnet add package Nivot.Aspire.Hosting.ProjectCommander --version 1.0.2
                    
NuGet\Install-Package Nivot.Aspire.Hosting.ProjectCommander -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nivot.Aspire.Hosting.ProjectCommander" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nivot.Aspire.Hosting.ProjectCommander" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Nivot.Aspire.Hosting.ProjectCommander" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nivot.Aspire.Hosting.ProjectCommander --version 1.0.2
                    
#r "nuget: Nivot.Aspire.Hosting.ProjectCommander, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Nivot.Aspire.Hosting.ProjectCommander&version=1.0.2
                    
Install Nivot.Aspire.Hosting.ProjectCommander as a Cake Addin
#tool nuget:?package=Nivot.Aspire.Hosting.ProjectCommander&version=1.0.2
                    
Install Nivot.Aspire.Hosting.ProjectCommander as a Cake Tool

publish

Aspire Project Commander

icon

Aspire Project commander is a set of packages that lets you send simple string commands from the dashboard directly to projects.

NuGet Packages

Type Name Status
Integration Nivot.Aspire.ProjectCommander NuGet pre version
Hosting Nivot.Aspire.Hosting.ProjectCommander NuGet pre version

Custom Resource Commands

Aspire allows adding custom commands to any project in the dashboard but these commands are scoped to and handled in the AppHost itself. These are useful to send commands to APIs on running containers, such as performing a FLUSHALL on a Redis container to reset state. Ultimately, the WithCommand resource extension method requires you to interface with each target resource (e.g. Executable, Container, Project) independently, using code you write yourself.

Custom Project Commands (New!)

This project and its associated NuGet packages allow you to send simple commands directly to Project type resources, that is to say, regular dotnet projects you're writing yourself. Register some simple string commands in the Aspire Dashboard -- for example "start-messages", "stop-messages" -- using the hosting package Nivot.Aspire.Hosting.ProjectCommander, and then use the integration package Nivot.Aspire.ProjectCommander to receive commands in your message generating project that you're using to dump data into an Azure Event Hubs emulator.

Example

See the Sample folder for an Aspire example that allows you to signal a data generator project that is writing messages into an emulator instance of Azure Event Hubs.

AppHost Hosting

var builder = DistributedApplication.CreateBuilder(args);

var commander = builder.AddAspireProjectCommander();

builder.AddProject<Projects.DataGenerator>("eventhub-datagenerator")
    // provides commander signalr hub connectionstring to integration 
    .WithReference(commander)
    // array of simple tuples with the command string and a display value for the dashbaord 
    .WithProjectCommands((Name: "slow", DisplayName: "Go Slow"), ("fast", "Go Fast"))
    // wait for commander signalr hub to be ready    
    .WaitFor(commander);

var app = builder.Build();

await app.RunAsync();

image

Project Integration

var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();

// add client to connect to apphost
builder.Services.AddAspireProjectCommanderClient();

// add background service to handle commands
builder.Services.AddHostedService<MyProjectCommands>();

// background service with DI IAspireProjectCommanderClient interface that allows registering an async handler
public sealed class MyProjectCommands(IAspireProjectCommanderClient commander, ILogger<MyProjectCommands> logger) : BackgroundService
{    
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        await Task.Run(async () =>
        {
            // add a handler that will receive commands
            commander.CommandReceived += (string command, IServiceProvider sp) =>
            {
                // grab a service, call a method, set an option, signal a cancellation token etc...
                logger.LogInformation("Received command: {CommandName}", command);

                return Task.CompletedTask;
            };

            await Task.Delay(Timeout.Infinite, stoppingToken);

        }, stoppingToken);
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 132 5/6/2025
1.0.0-beta1 85 12/26/2024