From 5b9edbfdf5444a55beae55313667d396a553f115 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sat, 24 Aug 2024 11:06:17 -0500 Subject: [PATCH] refactor: Move CF log logic to a reusable instance object This replaces the static extension method. --- .../Pipelines/CustomFormat/CustomFormatAutofacModule.cs | 1 + ...ipelineExtensions.cs => CustomFormatTransactionLogger.cs} | 4 ++-- .../CustomFormat/PipelinePhases/CustomFormatLogPhase.cs | 5 +++-- .../CustomFormat/PipelinePhases/CustomFormatPreviewPhase.cs | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) rename src/Recyclarr.Cli/Pipelines/CustomFormat/{CustomFormatPipelineExtensions.cs => CustomFormatTransactionLogger.cs} (94%) diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatAutofacModule.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatAutofacModule.cs index 04f93f63..6e7a0319 100644 --- a/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatAutofacModule.cs +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatAutofacModule.cs @@ -17,6 +17,7 @@ public class CustomFormatAutofacModule : Module builder.RegisterType(); builder.RegisterType().As>(); + builder.RegisterType(); builder.RegisterTypes( typeof(CustomFormatConfigPhase), diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatPipelineExtensions.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatTransactionLogger.cs similarity index 94% rename from src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatPipelineExtensions.cs rename to src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatTransactionLogger.cs index 5110cfd3..013e6d3b 100644 --- a/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatPipelineExtensions.cs +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/CustomFormatTransactionLogger.cs @@ -1,8 +1,8 @@ namespace Recyclarr.Cli.Pipelines.CustomFormat; -internal static class CustomFormatPipelineExtensions +internal class CustomFormatTransactionLogger(ILogger log) { - public static void LogTransactions(this CustomFormatPipelineContext context, ILogger log) + public void LogTransactions(CustomFormatPipelineContext context) { var transactions = context.TransactionOutput; diff --git a/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatLogPhase.cs b/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatLogPhase.cs index cf92bc74..b1c94a72 100644 --- a/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatLogPhase.cs +++ b/src/Recyclarr.Cli/Pipelines/CustomFormat/PipelinePhases/CustomFormatLogPhase.cs @@ -2,7 +2,8 @@ using Recyclarr.Cli.Pipelines.Generic; namespace Recyclarr.Cli.Pipelines.CustomFormat.PipelinePhases; -public class CustomFormatLogPhase(ILogger log) : ILogPipelinePhase +internal class CustomFormatLogPhase(CustomFormatTransactionLogger cfLogger, ILogger log) + : ILogPipelinePhase { // Returning 'true' means to exit. 'false' means to proceed. public bool LogConfigPhaseAndExitIfNeeded(CustomFormatPipelineContext context) @@ -23,6 +24,6 @@ public class CustomFormatLogPhase(ILogger log) : ILogPipelinePhase +internal class CustomFormatPreviewPhase(CustomFormatTransactionLogger logger) + : IPreviewPipelinePhase { public void Execute(CustomFormatPipelineContext context) { - context.LogTransactions(log); + logger.LogTransactions(context); } }