Files
spectreconsole-examples/examples/Cli/Injection/Program.cs
Frank Ray f113d9fb02 Minor improvements to dependency injection example (#1)
* Update code example to align with snippet in CommandApp/DI documentation

* Renamed TypeRegistrar to MyTypeRegistrar, making it more obvious it is a custom class the user must provide.
2025-04-08 17:00:31 +02:00

25 lines
742 B
C#

using Injection.Commands;
using Injection.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
namespace Injection;
public class Program
{
public static int Main(string[] args)
{
var registrations = new ServiceCollection();
registrations.AddSingleton<IGreeter, HelloWorldGreeter>();
// Create a type registrar and register any dependencies.
// A type registrar is an adapter for a DI framework.
var registrar = new MyTypeRegistrar(registrations);
// Create a new command app with the registrar
// and run it with the provided arguments.
var app = new CommandApp<DefaultCommand>(registrar);
return app.Run(args);
}
}