Skip to content

Commit

Permalink
Merge pull request #213 from ChrisDoernen/patch-1
Browse files Browse the repository at this point in the history
Defer calling AddServices
  • Loading branch information
Arash-Sabet authored Dec 21, 2023
2 parents 1727b22 + b607402 commit f7ed359
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Abstracts/TestBedFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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();
}
Expand Down

0 comments on commit f7ed359

Please sign in to comment.