defer resolving of IMediator

This commit is contained in:
Collin M. Barrett 2019-07-13 21:53:42 -05:00
parent 1a3e7b8dc0
commit b251813955
2 changed files with 13 additions and 5 deletions

View file

@ -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;
}
}
}

View file

@ -17,13 +17,16 @@ public static async Task Main(string[] args)
{
_serviceProvider = ServiceProviderBuilder.Build();
var parser = _serviceProvider.GetService<Parser>();
var mediator = _serviceProvider.GetService<IMediator>();
await parser.ParseArguments<CommandLineOptions>(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<IMediator>();
if (o.ArchiveLists)
await mediator.Send(new ArchiveLists.Command());
if (o.ValidateUrls)
await mediator.Send(new ValidateAllUrls.Command());
}
},
e => Task.FromResult(0)
);