Skip to content

Commit

Permalink
Preventing the initialization of the service collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Arash-Sabet committed Dec 21, 2023
1 parent 3beb4da commit b607402
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Abstracts/TestBedFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +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();
_servicesAdded = false;
}

public IConfigurationRoot? Configuration { get; private set; }
Expand All @@ -23,9 +25,11 @@ public IServiceProvider GetServiceProvider(ITestOutputHelper testOutputHelper)
{
return _serviceProvider;
}

AddServices(_services, Configuration);

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 b607402

Please sign in to comment.