From aeef6ebb48d9e3546892123da7bc2f7e2728e8ea Mon Sep 17 00:00:00 2001 From: James White Date: Mon, 19 Aug 2024 15:17:09 -0700 Subject: [PATCH] Another primary constructor update --- .../Commands/HelloCommand.cs | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/Community.Extensions.Spectre.Cli.Hosting.Sample/Commands/HelloCommand.cs b/src/Community.Extensions.Spectre.Cli.Hosting.Sample/Commands/HelloCommand.cs index 5387293..ea496f0 100644 --- a/src/Community.Extensions.Spectre.Cli.Hosting.Sample/Commands/HelloCommand.cs +++ b/src/Community.Extensions.Spectre.Cli.Hosting.Sample/Commands/HelloCommand.cs @@ -8,40 +8,27 @@ namespace Community.Extensions.Spectre.Cli.Hosting.Sample.Commands; /// +/// Creates a HelloCommand with access to services, the console and logging /// -public class HelloCommand : AsyncCommand +/// +/// +public class HelloCommand(IServiceProvider serviceProvider, IAnsiConsole console) : AsyncCommand { - private readonly IAnsiConsole _console; - - private readonly IServiceProvider _serviceProvider; - - /// - /// Creates a HelloCommand with access to services, the console and logging - /// - /// - /// - /// - public HelloCommand(IServiceProvider serviceProvider, IAnsiConsole console, ILogger log) - { - _serviceProvider = serviceProvider; - _console = console; - } - /// Executes the command. /// The command context. /// The command options. /// An integer indicating whether or not the command executed successfully. public override async Task ExecuteAsync(CommandContext context, Options options) { - await using var scope = _serviceProvider.CreateAsyncScope(); + await using var scope = serviceProvider.CreateAsyncScope(); // var coolService = scope.ServiceProvider.GetRequiredService(); - _console.MarkupLineInterpolated($"[darkseagreen2_1] Hello {options.Name}![/]"); + console.MarkupLineInterpolated($"[darkseagreen2_1] Hello {options.Name}![/]"); if (!string.IsNullOrEmpty(options.DogsName)) { - _console.MarkupLineInterpolated($"[darkseagreen2_1] Ooooo who's a good pup? {options.DogsName} thats who! 🐶[/]"); + console.MarkupLineInterpolated($"[darkseagreen2_1] Ooooo who's a good pup? {options.DogsName} thats who! 🐶[/]"); } return 0;