Commands.NET
2.0.0-alpha.21
dotnet add package Commands.NET --version 2.0.0-alpha.21
NuGet\Install-Package Commands.NET -Version 2.0.0-alpha.21
<PackageReference Include="Commands.NET" Version="2.0.0-alpha.21" />
<PackageVersion Include="Commands.NET" Version="2.0.0-alpha.21" />
<PackageReference Include="Commands.NET" />
paket add Commands.NET --version 2.0.0-alpha.21
#r "nuget: Commands.NET, 2.0.0-alpha.21"
#addin nuget:?package=Commands.NET&version=2.0.0-alpha.21&prerelease
#tool nuget:?package=Commands.NET&version=2.0.0-alpha.21&prerelease
Commands.NET
Consider leaving a ⭐
Do more, with less. With speed, compatibility and fluent integration in mind.
Commands.NET aims to improve your experience integrating input from different sources* into the same, concurrent pool and treating them as triggered actions, called commands. It provides a modular and intuitive API for registering and executing commands.
*Sources can range from command-line, console, HTTP, chatboxes, to social platforms like Discord, Slack, Messenger & much, much more.
Documentation
Browse the wiki for a full overview of the library.
Installation
Commands.NET is available on NuGet. You can install it using the package manager, or the following command:
dotnet add package Commands.NET
Alternatively, adding it to your .csproj
file:
<PackageReference Include="Commands.NET" Version="x.x.x" />
Commands.NET.Hosting
and Commands.NET.Http
are available as extension packages for respective features,
allowing you to host commands in the .NET Generic Host and expose them as HTTP endpoints.
Usage
Running a Command
A command is a method executed when a specific query is provided. By creating a manager to contain said command, you can run it with the provided arguments.
var provider = new ComponentProvider();
provider.Components.Add(new Command(() => "Hello world!", "greet"));
await provider.Execute(new ConsoleContext(args));
// dotnet run greet -> Hello world!
Creating Command Groups
Command groups are named collections of commands or other command groups. Groups allow for subcommand creation, where the group name is a category for its children.
var mathGroup = new ComponentGroup("math")
{
new Command((double number, int sumBy) => number + sumBy,
"sum", "add"),
new Command((double number, int subtractBy) => number - subtractBy,
"subtract", "sub"),
new Command((double number, int multiplyBy) => number * multiplyBy,
"multiply", "mul"),
new Command((double number, int divideBy) => number / divideBy,
"divide", "div")
};
var provider = new ComponentProvider();
provider.Components.Add(mathGroup);
await collection.Execute(new ConsoleContext(args));
// dotnet run math sum 5 3 -> 8
Creating Command Modules
Command modules are classes that can contain commands or nested command modules, which themselves can also contain (sub)commands.
public class PingModule : CommandModule
{
[Name("ping")]
public string Ping() => "Pong!";
[Name("pong")]
public string Pong() => "Ping!";
}
...
var provider = new ComponentProvider();
provider.Components.Add<HelpModule>();
provider.Components.Add(mathGroup);
await provider.Execute(new ConsoleContext(args));
// dotnet run help -> Commands: math sum <...> math subtract <...> math ...
Dependency Injection
Commands.NET is designed to be compatible with dependency injection out of the box, propagating IServiceProvider
throughout the execution flow.
var services = new ServiceCollection()
.AddSingleton<MyService>()
.AddSingleton<ComponentProvider>();
.BuildServiceProvider();
var provider = services.GetRequiredService<ComponentProvider>();
provider.Components.Add<HelpModule>();
provider.Components.Add(mathGroup);
await provider.Execute(new ConsoleContext(args), new ExecutionOptions() { Services = services });
Modules can be injected directly from the provider. They themselves are considered transient service consumers, being created and disposed of per command execution.
public class ServicedModule(MyService service) : CommandModule
{
}
.NET Generic Host
Alongside dependency injection support in the base package, Commands.NET provides an extension package for the .NET Generic Host, allowing you to integrate Commands.NET into your application with ease.
var host = Host.CreateDefaultBuilder(args)
.ConfigureComponents(configure => ...)
.Build();
The extension package supports factory-based command execution alongside scope management, allowing you to manage the lifetime of your commands and modules.
Samples
This repository includes a set of samples with documented code to help you get started with Commands.NET.
- Manage, create and execute commands in a basic console application.
- Fluent API's, complex execution flow and workflow expansion.
- Use Commands.NET in F# projects.
- Integrating Commands.NET into the .NET Generic Host infrastructure.
- Exposing commands as lightweight HTTP endpoints without the heavy lifting.
- Building Native-AOT apps with Commands.NET.
Benchmarks
Benchmark results are found here.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.6.0)
- System.Threading.Tasks.Extensions (>= 4.6.0)
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Commands.NET:
Package | Downloads |
---|---|
Commands.NET.Hosting
A package containing tooling for integrating Commands.NET with Microsoft.Extensions.*. |
|
Commands.NET.Console
An extension for Commands.NET that specifically aims to support the console and CLI, implementing Spectre.Console for beautification. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0-alpha.21 | 0 | 6/21/2025 |
2.0.0-alpha.20 | 2 | 6/21/2025 |
2.0.0-alpha.19 | 111 | 5/27/2025 |
2.0.0-alpha.18 | 110 | 5/26/2025 |
2.0.0-alpha.17 | 45 | 5/23/2025 |
2.0.0-alpha.16 | 106 | 5/22/2025 |
2.0.0-alpha.15 | 68 | 4/25/2025 |
2.0.0-alpha.14 | 96 | 4/25/2025 |
2.0.0-alpha.13 | 132 | 4/22/2025 |
2.0.0-alpha.12 | 127 | 4/22/2025 |
2.0.0-alpha.11 | 72 | 2/5/2025 |
2.0.0-alpha.10 | 65 | 1/30/2025 |
2.0.0-alpha.9 | 55 | 1/27/2025 |
2.0.0-alpha.8 | 61 | 1/27/2025 |
2.0.0-alpha.7 | 53 | 1/22/2025 |
2.0.0-alpha.6 | 54 | 1/16/2025 |
2.0.0-alpha.5 | 55 | 1/11/2025 |
2.0.0-alpha.4 | 55 | 1/9/2025 |
2.0.0-alpha.3 | 44 | 1/9/2025 |
2.0.0-alpha.2 | 68 | 1/7/2025 |
2.0.0-alpha.1 | 56 | 1/7/2025 |
1.0.0 | 158 | 12/2/2024 |
1.0.0-rc6 | 119 | 11/21/2024 |
1.0.0-rc5 | 108 | 11/19/2024 |
1.0.0-rc4 | 112 | 11/16/2024 |
1.0.0-rc3 | 107 | 11/16/2024 |
1.0.0-rc2 | 111 | 11/15/2024 |
1.0.0-rc1 | 111 | 11/15/2024 |
1.0.0-alpha9 | 109 | 11/2/2024 |
1.0.0-alpha8 | 105 | 10/21/2024 |
1.0.0-alpha7 | 292 | 10/16/2024 |
1.0.0-alpha6 | 131 | 5/22/2024 |
1.0.0-alpha5 | 130 | 4/14/2024 |
1.0.0-alpha4 | 109 | 2/15/2024 |
1.0.0-alpha3 | 103 | 2/14/2024 |
1.0.0-alpha2 | 109 | 2/10/2024 |
1.0.0-alpha1 | 107 | 2/8/2024 |
1.0.0-alpha | 115 | 2/6/2024 |