refactor: Use Autofac composite support for global setup tasks

Utilize built-in composite support in Autofac for `IGlobalSetupTask`
implementations.
pull/311/head
Robert Dailey 3 months ago
parent e745bc32d0
commit 11f7c7ed02

@ -99,7 +99,7 @@ public static class CompositionRoot
{
builder.RegisterType<CommandSetupInterceptor>().As<ICommandInterceptor>();
builder.RegisterType<GlobalSetupTaskExecutor>();
builder.RegisterComposite<CompositeGlobalSetupTask, IGlobalSetupTask>();
builder.RegisterTypes(
typeof(ProgramInformationDisplayTask),
typeof(JanitorCleanupTask))

@ -12,21 +12,22 @@ internal sealed class CommandSetupInterceptor : ICommandInterceptor, IDisposable
private readonly ConsoleAppCancellationTokenSource _ct = new();
private readonly LoggingLevelSwitch _loggingLevelSwitch;
private readonly IAppDataSetup _appDataSetup;
private readonly Lazy<GlobalSetupTaskExecutor> _taskExecutor;
private readonly Lazy<IGlobalSetupTask> _globalTaskSetup;
public CommandSetupInterceptor(
Lazy<ILogger> log,
LoggingLevelSwitch loggingLevelSwitch,
IAppDataSetup appDataSetup,
Lazy<GlobalSetupTaskExecutor> taskExecutor)
Lazy<IGlobalSetupTask> globalTaskSetup)
{
_loggingLevelSwitch = loggingLevelSwitch;
_appDataSetup = appDataSetup;
_taskExecutor = taskExecutor;
_globalTaskSetup = globalTaskSetup;
_ct.CancelPressed.Subscribe(_ => log.Value.Information("Exiting due to signal interrupt"));
}
// Executed on CLI startup
public void Intercept(CommandContext context, CommandSettings settings)
{
switch (settings)
@ -36,12 +37,13 @@ internal sealed class CommandSetupInterceptor : ICommandInterceptor, IDisposable
break;
}
_taskExecutor.Value.OnStart();
_globalTaskSetup.Value.OnStart();
}
// Executed on CLI exit
public void InterceptResult(CommandContext context, CommandSettings settings, ref int result)
{
_taskExecutor.Value.OnFinish();
_globalTaskSetup.Value.OnFinish();
}
private void HandleBaseCommand(BaseCommandSettings cmd)

@ -1,6 +1,9 @@
using JetBrains.Annotations;
namespace Recyclarr.Cli.Console.Setup;
public class GlobalSetupTaskExecutor(IOrderedEnumerable<IGlobalSetupTask> tasks)
[UsedImplicitly]
public class CompositeGlobalSetupTask(IOrderedEnumerable<IGlobalSetupTask> tasks) : IGlobalSetupTask
{
public void OnStart()
{
Loading…
Cancel
Save