Use IServiceProvider in Help command
This commit is contained in:
@@ -9,9 +9,9 @@ public class Application
|
||||
private readonly IList<ICommand> _commands;
|
||||
private readonly ILogger<Application> _logger;
|
||||
|
||||
public Application(IEnumerable<ICommand> commands, ILogger<Application> logger, ILogger<HelpCommand> helpCommandLogger)
|
||||
public Application(IEnumerable<ICommand> commands, ILogger<Application> logger)
|
||||
{
|
||||
_commands = commands.Append(new HelpCommand(() => _commands!, helpCommandLogger)).ToList();
|
||||
_commands = commands.ToList();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ public class HelpCommand : ICommand
|
||||
public string CommandString => "help";
|
||||
|
||||
public HelpCommand(
|
||||
Func<IEnumerable<ICommand>> commandsProvider,
|
||||
IServiceProvider serviceProvider,
|
||||
ILogger<HelpCommand> logger
|
||||
)
|
||||
{
|
||||
_commandsProvider = commandsProvider;
|
||||
_commandsProvider = () => (IEnumerable<ICommand>?)serviceProvider.GetService(typeof(IEnumerable<ICommand>)) ?? throw new ApplicationException();
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Alma.Command;
|
||||
using Alma.Command.Help;
|
||||
using Alma.Command.Info;
|
||||
using Alma.Command.Install;
|
||||
using Alma.Command.Link;
|
||||
@@ -45,8 +46,7 @@ public static class Program
|
||||
[Singleton(typeof(ICommand), typeof(InfoCommand))]
|
||||
[Singleton(typeof(ICommand), typeof(ListCommand))]
|
||||
[Singleton(typeof(ICommand), typeof(InstallCommand))]
|
||||
//Dependency cycle
|
||||
//[Singleton(typeof(ICommand), typeof(HelpCommand))]
|
||||
[Singleton(typeof(ICommand), typeof(HelpCommand))]
|
||||
[Singleton(typeof(IModuleConfigurationResolver), typeof(ModuleConfigurationResolver))]
|
||||
[Singleton(typeof(IMetadataHandler), typeof(MetadataHandler))]
|
||||
[Singleton(typeof(IShellService), typeof(ShellService))]
|
||||
|
||||
Reference in New Issue
Block a user