Skip to content

Commit 3e43c0f

Browse files
authored
Refactor service registration order in ProxyCommandHandler to ensure API controller is disposed last (#1036)
1 parent 24be7a3 commit 3e43c0f

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

dev-proxy/CommandHandlers/ProxyCommandHandler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public async Task<int> InvokeAsync(InvocationContext context)
4040
var builder = WebApplication.CreateBuilder();
4141
builder.Logging.AddFilter("Microsoft.Hosting.*", LogLevel.Error);
4242
builder.Logging.AddFilter("Microsoft.AspNetCore.*", LogLevel.Error);
43+
44+
// API controller is registered first and so is the last service to be disposed of when the app is shutdown
45+
builder.Services.AddControllers();
4346

4447
builder.Services.AddSingleton<IProxyState, ProxyState>();
4548
builder.Services.AddSingleton<IProxyConfiguration, ProxyConfiguration>(sp => ConfigurationFactory.Value);
@@ -48,7 +51,6 @@ public async Task<int> InvokeAsync(InvocationContext context)
4851
builder.Services.AddSingleton(_urlsToWatch);
4952
builder.Services.AddHostedService<ProxyEngine>();
5053

51-
builder.Services.AddControllers();
5254
builder.Services.AddEndpointsApiExplorer();
5355
builder.Services.AddSwaggerGen();
5456

0 commit comments

Comments
 (0)