@@ -11,14 +11,11 @@ internal class DatabaseInitializer : IHostedService
1111 private readonly ILogger < DatabaseInitializer > _logger ;
1212 private readonly bool _initDatabase ;
1313
14- public DatabaseInitializer ( NpgsqlDataSource db , IOptions < AppSettings > appSettings , IServer server , ILogger < DatabaseInitializer > logger )
14+ public DatabaseInitializer ( NpgsqlDataSource db , IOptions < AppSettings > appSettings , ILogger < DatabaseInitializer > logger )
1515 {
1616 _db = db ;
1717 _logger = logger ;
18- _initDatabase = ! appSettings . Value . SuppressDbInitialization
19- // Only run if this is an actual IServer implementation with addresses to listen on.
20- // Will not be the case for TestServer, NoopServer injected by the OpenAPI doc generator tool, etc.
21- && server . Features . Get < IServerAddressesFeature > ( ) is { Addresses . Count : > 0 } ;
18+ _initDatabase = ! appSettings . Value . SuppressDbInitialization && ! appSettings . Value . GeneratingOpenApiDoc ;
2219 }
2320
2421 public Task StartAsync ( CancellationToken cancellationToken )
@@ -32,14 +29,12 @@ public Task StartAsync(CancellationToken cancellationToken)
3229 {
3330 _logger . LogInformation ( "Database initialization disabled for connection string '{connectionString}'" , _db ? . ConnectionString ) ;
3431 }
35- return Task . CompletedTask ;
36- }
3732
38- public Task StopAsync ( CancellationToken cancellationToken )
39- {
4033 return Task . CompletedTask ;
4134 }
4235
36+ public Task StopAsync ( CancellationToken cancellationToken ) => Task . CompletedTask ;
37+
4338 private async Task Initialize ( CancellationToken cancellationToken = default )
4439 {
4540 // NOTE: Npgsql removes the password from the connection string
0 commit comments