From 3a21465ff148cf3a322de033881bb600968c8d3a Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 14 Oct 2022 14:25:12 -0500 Subject: [PATCH] fix: Fix incorrect version enforcement for Sonarr When using multiple instances of Sonarr at v4 and v3, it was possible to get a VersionException due to stale information carrying over between processing instances. --- CHANGELOG.md | 4 ++++ src/Recyclarr/Command/SonarrCommand.cs | 5 ++++- src/TrashLib/Config/ConfigAutofacModule.cs | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e62dad8..0f7a6829 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Sonarr: Incorrect VersionException occurred when using mixed versions of Sonarr (v4 & v3) + ## [2.6.0] - 2022-10-14 ### Added diff --git a/src/Recyclarr/Command/SonarrCommand.cs b/src/Recyclarr/Command/SonarrCommand.cs index 4477fcfd..62fc7b88 100644 --- a/src/Recyclarr/Command/SonarrCommand.cs +++ b/src/Recyclarr/Command/SonarrCommand.cs @@ -1,3 +1,4 @@ +using Autofac; using CliFx.Attributes; using CliFx.Exceptions; using JetBrains.Annotations; @@ -49,7 +50,6 @@ public class SonarrCommand : ServiceCommand var log = container.Resolve(); var customFormatUpdaterFactory = container.Resolve>(); var guideService = container.Resolve(); - var versionEnforcement = container.Resolve(); if (ListReleaseProfiles) { @@ -88,6 +88,9 @@ public class SonarrCommand : ServiceCommand { log.Information("Processing server {Url}", FlurlLogging.SanitizeUrl(config.BaseUrl)); + var scope = container.Container.BeginLifetimeScope(); + var versionEnforcement = scope.Resolve(); + await versionEnforcement.DoVersionEnforcement(config); if (config.ReleaseProfiles.Count > 0) diff --git a/src/TrashLib/Config/ConfigAutofacModule.cs b/src/TrashLib/Config/ConfigAutofacModule.cs index 3765a107..85780ae4 100644 --- a/src/TrashLib/Config/ConfigAutofacModule.cs +++ b/src/TrashLib/Config/ConfigAutofacModule.cs @@ -15,8 +15,8 @@ public class ConfigAutofacModule : Module .AsClosedTypesOf(typeof(IValidator<>)) .AsImplementedInterfaces(); - builder.RegisterType().As().InstancePerLifetimeScope(); - builder.RegisterType().As().InstancePerLifetimeScope(); + builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); builder.RegisterType().As(); } }