diff --git a/src/Abstracts/TestBedFixture.cs b/src/Abstracts/TestBedFixture.cs index 4677c86..44102d9 100644 --- a/src/Abstracts/TestBedFixture.cs +++ b/src/Abstracts/TestBedFixture.cs @@ -6,13 +6,14 @@ public abstract class TestBedFixture : IDisposable, IAsyncDisposable private IServiceProvider? _serviceProvider; private bool _disposedValue; private bool _disposedAsync; + private bool _servicesAdded; protected TestBedFixture() { _services = new ServiceCollection(); ConfigurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()); Configuration = GetConfigurationRoot(); - AddServices(_services, Configuration); + _servicesAdded = false; } public IConfigurationRoot? Configuration { get; private set; } @@ -24,7 +25,11 @@ public IServiceProvider GetServiceProvider(ITestOutputHelper testOutputHelper) { return _serviceProvider; } - + if(!_servicesAdded) + { + AddServices(_services, Configuration); + _servicesAdded = true; + } _services.AddLogging(loggingBuilder => AddLoggingProvider(loggingBuilder, new OutputLoggerProvider(testOutputHelper))); return _serviceProvider = _services.BuildServiceProvider(); }