Nivot.Aspire.ProjectCommander
1.0.0-beta1
dotnet add package Nivot.Aspire.ProjectCommander --version 1.0.0-beta1
NuGet\Install-Package Nivot.Aspire.ProjectCommander -Version 1.0.0-beta1
<PackageReference Include="Nivot.Aspire.ProjectCommander" Version="1.0.0-beta1" />
paket add Nivot.Aspire.ProjectCommander --version 1.0.0-beta1
#r "nuget: Nivot.Aspire.ProjectCommander, 1.0.0-beta1"
// 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 | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.SignalR.Client (>= 8.0.11)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
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 |