Skip to content

Commit

Permalink
Only exclude explicit registrations of IHostedService (RicoSuter#4756)
Browse files Browse the repository at this point in the history
This fixes issues when a registered class or interface inherits from IHostedService because they where removed even when it would not run as an IHostedService.
  • Loading branch information
desjoerd authored and lahma committed Jun 13, 2024
1 parent 7d64a6d commit f9f6953
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/NSwag.Commands/HostApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ void ConfigureHostBuilder(object hostBuilder)
// exclude all implementations of IHostedService
// except Microsoft.AspNetCore.Hosting.GenericWebHostService because that one will build/configure
// the WebApplication/Middleware pipeline in the case of the GenericWebHostBuilder.
if (typeof(IHostedService).IsAssignableFrom(services[i].ServiceType)
&& services[i].ImplementationType is not { FullName: "Microsoft.AspNetCore.Hosting.GenericWebHostService" })
var registration = services[i];
if (registration.ServiceType == typeof(IHostedService)
&& registration.ImplementationType is not { FullName: "Microsoft.AspNetCore.Hosting.GenericWebHostService" })
{
services.RemoveAt(i);
}
Expand Down

0 comments on commit f9f6953

Please sign in to comment.