Skip to content

How to Use (The Builder Approach)

Iuga Alexandru edited this page May 19, 2023 · 2 revisions

Commando offers support for three dependency injection frameworks:

Step 1 - Include the nuget package

Reference the nuget package corresponding to the dependency injection framework that you want to use.

  • ConsoleTools.Commando.Setup.Autofac
  • ConsoleTools.Commando.Setup.Ninject
  • ConsoleTools.Commando.Setup.Microsoft

Step 2 - Build and run the Application.

In the Main method, use an ApplicationBuilder:

Application application = ApplicationBuilder.Create()
    .RegisterCommandsFrom(typeof(DummyCommand).Assembly) // Provide here the assembly containing your commands.
    .Build();

await application.RunAsync(args);

Step 3 - Create your commands.

[NamedCommand("read", Description = "Display the content of a text file.")]
internal class ReadCommand : ICommand
{
    [NamedParameter("file", ShortName = 'f', Description = "The full path of the file.")]
    public string FilePath { get; set; }
    
	public Task Execute()
	{
		...
	}
}
Clone this wiki locally