-
-
Notifications
You must be signed in to change notification settings - Fork 0
How to Use (The Dependency Injection Approach)
Iuga Alexandru edited this page May 19, 2023
·
2 revisions
Commando offers support for three dependency injection frameworks:
Regardless of the one you choose, the approach is similar. Read ahead.
-
Include
ConsoleTools.Commando.Setup.Autofacnuget package.It will automatically include the packages:
ConsoleTools.CommandoAutofac
-
Register
Commandointo Autofac's container.Assembly presentationAssembly = typeof(SomeCommand).Assembly; // The assembly containing your commands. containerBuilder.RegisterCommando(presentationAssembly);
-
Instantiate and run the
Application.Application application = container.Resolve<Application>(); await application.Run(args);
-
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() { ... } }
-
Include
ConsoleTools.Commando.Setup.Ninjectnuget package.It will automatically include the packages:
ConsoleTools.CommandoAutofac
-
Register
Commandointo Ninject's conatiner.Assembly presentationAssembly = typeof(SomeCommand).Assembly; // The assembly containing your commands. kernel.RegisterCommando(presentationAssembly);
-
Instantiate the
Application.Application application = container.Get<Application>(); await application.Run(args);
-
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() { ... } }
-
Include
ConsoleTools.Commando.Setup.Microsoftnuget package.It will automatically include the packages:
ConsoleTools.CommandoAutofac
-
Register
Commandointo Microsoft's dependency container.Assembly presentationAssembly = typeof(SomeCommand).Assembly; // The assembly containing your commands. kernel.AddCommando(presentationAssembly);
-
Instantiate the
Application.Application application = serviceProvider.GetService<Application>(); await application.Run(args);
-
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() { ... } }