Nivot.Aspire.ProjectCommander 1.0.0-beta1

This is a prerelease version of Nivot.Aspire.ProjectCommander.
dotnet add package Nivot.Aspire.ProjectCommander --version 1.0.0-beta1                
NuGet\Install-Package Nivot.Aspire.ProjectCommander -Version 1.0.0-beta1                
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.ProjectCommander" Version="1.0.0-beta1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nivot.Aspire.ProjectCommander --version 1.0.0-beta1                
#r "nuget: Nivot.Aspire.ProjectCommander, 1.0.0-beta1"                
#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.
// Install Nivot.Aspire.ProjectCommander as a Cake Addin
#addin nuget:?package=Nivot.Aspire.ProjectCommander&version=1.0.0-beta1&prerelease

// Install Nivot.Aspire.ProjectCommander as a Cake Tool
#tool nuget:?package=Nivot.Aspire.ProjectCommander&version=1.0.0-beta1&prerelease                

<img src="https://github.com/microsoft/fluentui-system-icons/blob/master/assets/Desktop Signal/SVG/ic_fluent_desktop_signal_24_filled.svg?raw=true" width="24" height="24" align="absmiddle"> Aspire Project Commander

Version: 1.0.0-beta1

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

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

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: "start", DisplayName: "Start Generator"), ("stop", "Stop Generator"))
    // wait for commander signalr hub to be ready    
    .WaitFor(commander);

var app = builder.Build();

await app.RunAsync();

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. 
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.0-beta1 40 12/26/2024