### Initialize CommandApp with Dependency Injection Source: https://github.com/wcomab/spectre.console.cli.extensions.dependencyinjection/blob/main/README.md Demonstrates the initial setup in Program.cs to integrate the DependencyInjectionRegistrar with Spectre.Console.Cli. This allows for services registered in the `ServiceCollection` to be injected into your commands. ```csharp 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); ``` -------------------------------- ### Inject Services into CLI Commands Source: https://github.com/wcomab/spectre.console.cli.extensions.dependencyinjection/blob/main/README.md Shows how to register a custom service (e.g., `ICoolService`) with the `ServiceCollection` and how to inject it into a command class constructor. The `DependencyInjectionRegistrar` handles the instantiation and injection automatically. ```csharp // Program.cs var services = new ServiceCollection(); services.AddSingleton(); using registrar = new DependencyInjectionRegistrar(services); var app = new CommandApp(registrar); app.Configure(config => { config.AddCommand("command"); // commands are automatically added to the container }); // in SomeCommand.cs public class SomeCommand : Command { public SomeCommand(ICoolService service) { // the `ICoolService` parameter will be automatically injected with an instance of `MyCoolService` } public override int Execute(SomeCommand.Settings settings, ILookup unmapped) { // command logic here return 0; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.