-
-
Notifications
You must be signed in to change notification settings - Fork 29
Add AutoStartStop option to gateway services #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Introduced an `AutoStartStop` option in `GatewayClientOptions` and `ShardedGatewayClientOptions` to control automatic start and stop behavior of gateway clients. Updated `StartAsync` and `StopAsync` methods in `GatewayClientHostedService` and `ShardedGatewayClientHostedService` to respect this option.
|
The documentation preview is available at https://preview.netcord.dev/207. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds an AutoStartStop configuration option to control whether the Gateway client automatically starts and stops with the hosted service lifecycle. When set to false, the gateway client will not automatically start when the application starts or close when the application stops.
- Adds
AutoStartStopnullable boolean property to bothGatewayClientOptionsandShardedGatewayClientOptions - Implements early returns in both hosted services'
StartAsyncandStopAsyncmethods whenAutoStartStopis set tofalse - Updates test code to demonstrate usage of the new configuration option
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/NetCord.Test.Hosting/Program.cs | Demonstrates setting AutoStartStop = true in gateway configuration |
| Hosting/NetCord.Hosting/Gateway/GatewayClientOptions.cs | Adds AutoStartStop nullable boolean property |
| Hosting/NetCord.Hosting/Gateway/ShardedGatewayClientOptions.cs | Adds AutoStartStop nullable boolean property |
| Hosting/NetCord.Hosting/Gateway/GatewayClientHostedService.cs | Implements conditional start/stop logic based on AutoStartStop option |
| Hosting/NetCord.Hosting/Gateway/ShardedGatewayClientHostedService.cs | Implements conditional start/stop logic based on AutoStartStop option |
Comments suppressed due to low confidence (2)
Hosting/NetCord.Hosting/Gateway/GatewayClientHostedService.cs:26
- When
AutoStartStopis false, the client and handlers are retrieved and registered unnecessarily before the early return. Move theGetRequiredServiceand handler registration logic after theAutoStartStopcheck to avoid unnecessary service resolution and handler registration when the client won't be started.
var client = services.GetRequiredService<GatewayClient>();
foreach (var handler in services.GetServices<IGatewayHandler>())
{
if (handler is IDelegateGatewayHandlerBase delegateHandler)
RegisterDelegateHandler(client, delegateHandler);
else
RegisterClassHandler(client, handler);
}
Hosting/NetCord.Hosting/Gateway/ShardedGatewayClientHostedService.cs:26
- When
AutoStartStopis false, the client and handlers are retrieved and registered unnecessarily before the early return. Move theGetRequiredServiceand handler registration logic after theAutoStartStopcheck to avoid unnecessary service resolution and handler registration when the client won't be started.
var client = services.GetRequiredService<ShardedGatewayClient>();
foreach (var handler in services.GetServices<IShardedGatewayHandler>())
{
if (handler is IDelegateShardedGatewayHandlerBase delegateHandler)
RegisterDelegateShardedHandler(client, delegateHandler);
else
RegisterClassShardedHandler(client, handler);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
Hosting/NetCord.Hosting/Gateway/ShardedGatewayClientHostedService.cs:1
- The options are retrieved twice from the service provider (once in StartAsync and once in StopAsync). Consider caching the options value in a field during StartAsync or retrieving it once in the constructor to avoid repeated service resolution.
using Microsoft.Extensions.DependencyInjection;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Introduced an
AutoStartStopoption inGatewayClientOptionsandShardedGatewayClientOptionsto control automatic start and stop behavior of gateway clients. UpdatedStartAsyncandStopAsyncmethods inGatewayClientHostedServiceandShardedGatewayClientHostedServiceto respect this option.