From e75f853e6a187aab5906e13bdbf20d46b8a308b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Mon, 19 Dec 2022 18:56:39 +0100 Subject: [PATCH] Use IServiceProvider in Help command --- src/Alma.App/Application.cs | 4 ++-- src/Alma.App/Command/Help/HelpCommand.cs | 4 ++-- src/Alma/Program.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Alma.App/Application.cs b/src/Alma.App/Application.cs index 6f91ff3..58c54c5 100644 --- a/src/Alma.App/Application.cs +++ b/src/Alma.App/Application.cs @@ -9,9 +9,9 @@ public class Application private readonly IList _commands; private readonly ILogger _logger; - public Application(IEnumerable commands, ILogger logger, ILogger helpCommandLogger) + public Application(IEnumerable commands, ILogger logger) { - _commands = commands.Append(new HelpCommand(() => _commands!, helpCommandLogger)).ToList(); + _commands = commands.ToList(); _logger = logger; } diff --git a/src/Alma.App/Command/Help/HelpCommand.cs b/src/Alma.App/Command/Help/HelpCommand.cs index e03e990..fd87431 100644 --- a/src/Alma.App/Command/Help/HelpCommand.cs +++ b/src/Alma.App/Command/Help/HelpCommand.cs @@ -10,11 +10,11 @@ public class HelpCommand : ICommand public string CommandString => "help"; public HelpCommand( - Func> commandsProvider, + IServiceProvider serviceProvider, ILogger logger ) { - _commandsProvider = commandsProvider; + _commandsProvider = () => (IEnumerable?)serviceProvider.GetService(typeof(IEnumerable)) ?? throw new ApplicationException(); _logger = logger; } diff --git a/src/Alma/Program.cs b/src/Alma/Program.cs index ab984f4..cda5553 100644 --- a/src/Alma/Program.cs +++ b/src/Alma/Program.cs @@ -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))]