Skip to content

Commit b607402

Browse files
committed
Preventing the initialization of the service collection
1 parent 3beb4da commit b607402

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Abstracts/TestBedFixture.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ public abstract class TestBedFixture : IDisposable, IAsyncDisposable
66
private IServiceProvider? _serviceProvider;
77
private bool _disposedValue;
88
private bool _disposedAsync;
9+
private bool _servicesAdded;
910

1011
protected TestBedFixture()
1112
{
1213
_services = new ServiceCollection();
1314
ConfigurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory());
1415
Configuration = GetConfigurationRoot();
16+
_servicesAdded = false;
1517
}
1618

1719
public IConfigurationRoot? Configuration { get; private set; }
@@ -23,9 +25,11 @@ public IServiceProvider GetServiceProvider(ITestOutputHelper testOutputHelper)
2325
{
2426
return _serviceProvider;
2527
}
26-
27-
AddServices(_services, Configuration);
28-
28+
if(!_servicesAdded)
29+
{
30+
AddServices(_services, Configuration);
31+
_servicesAdded = true;
32+
}
2933
_services.AddLogging(loggingBuilder => AddLoggingProvider(loggingBuilder, new OutputLoggerProvider(testOutputHelper)));
3034
return _serviceProvider = _services.BuildServiceProvider();
3135
}

0 commit comments

Comments
 (0)