From b25181395557060107269719788df562189baf54 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 13 Jul 2019 21:53:42 -0500 Subject: [PATCH] defer resolving of IMediator --- src/FilterLists.Agent/CommandLineOptions.cs | 5 +++++ src/FilterLists.Agent/Program.cs | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/FilterLists.Agent/CommandLineOptions.cs b/src/FilterLists.Agent/CommandLineOptions.cs index 7a5c38293..8e2c3aee6 100644 --- a/src/FilterLists.Agent/CommandLineOptions.cs +++ b/src/FilterLists.Agent/CommandLineOptions.cs @@ -15,5 +15,10 @@ public CommandLineOptions(bool archiveLists, bool validateUrls) [Option('v', "validate", Required = false, HelpText = "Validate all URLs in the FilterLists database.")] public bool ValidateUrls { get; } + + public bool Any() + { + return ArchiveLists || ValidateUrls; + } } } \ No newline at end of file diff --git a/src/FilterLists.Agent/Program.cs b/src/FilterLists.Agent/Program.cs index 0644fdde5..3742ae124 100644 --- a/src/FilterLists.Agent/Program.cs +++ b/src/FilterLists.Agent/Program.cs @@ -17,13 +17,16 @@ public static async Task Main(string[] args) { _serviceProvider = ServiceProviderBuilder.Build(); var parser = _serviceProvider.GetService(); - var mediator = _serviceProvider.GetService(); await parser.ParseArguments(args).MapResult(async o => { - if (o.ArchiveLists) - await mediator.Send(new ArchiveLists.Command()); - if (o.ValidateUrls) - await mediator.Send(new ValidateAllUrls.Command()); + if (o.Any()) + { + var mediator = _serviceProvider.GetService(); + if (o.ArchiveLists) + await mediator.Send(new ArchiveLists.Command()); + if (o.ValidateUrls) + await mediator.Send(new ValidateAllUrls.Command()); + } }, e => Task.FromResult(0) );