Spectre.Console.Cli.Extensions.DependencyInjection
0.4.1-preview.0.5
See the version list below for details.
dotnet add package Spectre.Console.Cli.Extensions.DependencyInjection --version 0.4.1-preview.0.5
NuGet\Install-Package Spectre.Console.Cli.Extensions.DependencyInjection -Version 0.4.1-preview.0.5
<PackageReference Include="Spectre.Console.Cli.Extensions.DependencyInjection" Version="0.4.1-preview.0.5" />
paket add Spectre.Console.Cli.Extensions.DependencyInjection --version 0.4.1-preview.0.5
#r "nuget: Spectre.Console.Cli.Extensions.DependencyInjection, 0.4.1-preview.0.5"
// Install Spectre.Console.Cli.Extensions.DependencyInjection as a Cake Addin #addin nuget:?package=Spectre.Console.Cli.Extensions.DependencyInjection&version=0.4.1-preview.0.5&prerelease // Install Spectre.Console.Cli.Extensions.DependencyInjection as a Cake Tool #tool nuget:?package=Spectre.Console.Cli.Extensions.DependencyInjection&version=0.4.1-preview.0.5&prerelease
Spectre.Console.Cli.Extensions.DependencyInjection
A type provider for the CLI component of Spectre.Console
using the Microsoft.Extensions.DependencyInjection
container.
This is a fork of agc93/spectre.cli.extensions.dependencyinjection to support newer versions of Spectre.Console.Cli
Getting started
Once you've installed both Spectre.Console.Cli
and this package, just change the call to new CommandApp()
in your Program.cs
to match the below:
var services = new ServiceCollection();
// add extra services to the container here
using var registrar = new DependencyInjectionRegistrar(services);
var app = new CommandApp(registrar);
app.Configure(config =>
{
// configure your commands as per usual
// commands are automatically added to the container
}
return app.Run(args);
Using the container
Once you've changed your Program.cs
as above, you can inject anything you need into your commands:
// Program.cs
var services = new ServiceCollection();
services.AddSingleton<ICoolService, MyCoolService>();
using registrar = new DependencyInjectionRegistrar(services);
var app = new CommandApp(registrar);
app.Configure(config =>
{
config.AddCommand<SomeCommand>("command");
// commands are automatically added to the container
}
// in SomeCommand.cs
public class SomeCommand : Command<SomeCommand.Settings>
{
public ProfileCreateCommand(ICoolService service)
{
// the `ICoolService` parameter will be automatically injected with an instance of `MyCoolService`
}
public override int Execute(SomeCommand.Settings settings, ILookup<string, string> unmapped)
{
// command logic here
}
}
For a more complex example, check out devlead/dpi.
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 is compatible. 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. |
.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
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Spectre.Console.Cli (>= 0.49.1)
-
net8.0
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Spectre.Console.Cli (>= 0.49.1)
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.2)
- Spectre.Console.Cli (>= 0.49.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Spectre.Console.Cli.Extensions.DependencyInjection:
Package | Downloads |
---|---|
Microsoft.ComponentDetection.Orchestrator
Package Description |
|
Microsoft.ComponentDetection
Package Description |
|
Devlead.Console
An opinionated .NET source package simplifying bootstrapping console applications with IoC, command-line parsing, logging, and more. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Spectre.Console.Cli.Extensions.DependencyInjection:
Repository | Stars |
---|---|
microsoft/component-detection
Scans your project to determine what components you use
|
Version | Downloads | Last updated |
---|---|---|
0.5.0 | 499 | 2/25/2025 |
0.4.1-preview.0.5 | 52 | 2/25/2025 |
0.4.1-preview.0.4 | 41 | 2/25/2025 |
0.4.1-preview.0.3 | 69 | 2/12/2025 |
0.4.1-preview.0.2 | 63 | 2/12/2025 |
0.4.1-preview.0.1 | 48 | 2/6/2025 |
0.4.0 | 4,471 | 1/22/2025 |
0.3.1-preview.0.7 | 44 | 1/22/2025 |
0.3.0 | 7,758 | 12/17/2024 |
0.2.1-preview.0.3 | 58 | 12/17/2024 |
0.2.1-preview.0.2 | 57 | 12/17/2024 |
0.2.0 | 181,169 | 10/30/2023 |
0.1.0 | 56,532 | 10/28/2022 |