Skip to main content
net8.0net9.0net10.0.NETStandard2.0

Package Description

Published
Apr 13, 2026
6mo ago
Total Downloads
937.6K
937,589

Install

dotnet add package Spectre.Console.Cli.Extensions.DependencyInjection --version 0.24.1-preview.0.1
ProductVersions
.NET
net10.0net8.0net9.0
.NET Standard
netstandard2.0

README

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.

Changes from Previous Version

No structural changes between v0.24.0 and v0.24.1-preview.0.1.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 4 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.