From dcfbccae2f4ce33b1257465908d5a419efb79686 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sun, 23 Oct 2022 13:25:17 -0500 Subject: [PATCH] refactor: Use IServiceLocatorProxy instead of ILifetimeScope In IntegrationFixture --- src/Recyclarr.TestLibrary/IntegrationFixture.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Recyclarr.TestLibrary/IntegrationFixture.cs b/src/Recyclarr.TestLibrary/IntegrationFixture.cs index 758a5848..005e3bf4 100644 --- a/src/Recyclarr.TestLibrary/IntegrationFixture.cs +++ b/src/Recyclarr.TestLibrary/IntegrationFixture.cs @@ -20,12 +20,10 @@ namespace Recyclarr.TestLibrary; [FixtureLifeCycle(LifeCycle.InstancePerTestCase)] public abstract class IntegrationFixture : IDisposable { - private readonly ILifetimeScope _container; - protected IntegrationFixture() { var compRoot = new CompositionRoot(); - _container = compRoot.Setup(builder => + ServiceLocator = compRoot.Setup(builder => { builder.RegisterInstance(Fs).As(); builder.RegisterInstance(new AppPaths(Fs.CurrentDirectory())).As(); @@ -38,7 +36,7 @@ public abstract class IntegrationFixture : IDisposable RegisterMockFor(builder); builder.RegisterSource(); - }).Container; + }); SetupMetadataJson(); } @@ -60,6 +58,7 @@ public abstract class IntegrationFixture : IDisposable protected MockFileSystem Fs { get; } = new(); protected FakeInMemoryConsole Console { get; } = new(); + protected IServiceLocatorProxy ServiceLocator { get; } private static void RegisterMockFor(ContainerBuilder builder) where T : class { @@ -68,13 +67,13 @@ public abstract class IntegrationFixture : IDisposable protected T Resolve(Action customRegistrations) where T : notnull { - var childScope = _container.BeginLifetimeScope(customRegistrations); + var childScope = ServiceLocator.Container.BeginLifetimeScope(customRegistrations); return childScope.Resolve(); } protected T Resolve() where T : notnull { - return _container.Resolve(); + return ServiceLocator.Resolve(); } protected virtual void Dispose(bool disposing) @@ -84,7 +83,7 @@ public abstract class IntegrationFixture : IDisposable return; } - _container.Dispose(); + ServiceLocator.Dispose(); Console.Dispose(); }