@@ -27,7 +27,7 @@ public class FeatureFlagIntegrationTest
2727 public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync ( string userId , bool expectedResult , ServiceLifetime serviceLifetime )
2828 {
2929 // Arrange
30- using var server = await CreateServerAsync ( services =>
30+ using var server = await CreateServerAsync ( serviceLifetime , services =>
3131 {
3232 switch ( serviceLifetime )
3333 {
@@ -59,7 +59,7 @@ public async Task VerifyFeatureFlagBehaviorAcrossServiceLifetimesAsync(string us
5959 Assert . Equal ( expectedResult , responseContent . FeatureValue ) ;
6060 }
6161
62- private static async Task < TestServer > CreateServerAsync ( Action < IServiceCollection > ? configureServices = null )
62+ private static async Task < TestServer > CreateServerAsync ( ServiceLifetime serviceLifetime , Action < IServiceCollection > ? configureServices = null )
6363 {
6464 var builder = WebApplication . CreateBuilder ( ) ;
6565 builder . WebHost . UseTestServer ( ) ;
@@ -82,8 +82,17 @@ private static async Task<TestServer> CreateServerAsync(Action<IServiceCollectio
8282 } ) ;
8383 cfg . AddInMemoryProvider ( provider =>
8484 {
85- var flagService = provider . GetRequiredService < IFeatureFlagConfigurationService > ( ) ;
86- return flagService . GetFlags ( ) ;
85+ if ( serviceLifetime == ServiceLifetime . Scoped )
86+ {
87+ using var scoped = provider . CreateScope ( ) ;
88+ var flagService = scoped . ServiceProvider . GetRequiredService < IFeatureFlagConfigurationService > ( ) ;
89+ return flagService . GetFlags ( ) ;
90+ }
91+ else
92+ {
93+ var flagService = provider . GetRequiredService < IFeatureFlagConfigurationService > ( ) ;
94+ return flagService . GetFlags ( ) ;
95+ }
8796 } ) ;
8897 } ) ;
8998
0 commit comments