AutoServiceScopes strikes again (#3072)

This commit is contained in:
Mihail Gribkov
2025-03-02 00:55:59 +03:00
committed by GitHub
parent 6fb2a29351
commit d71fcb1a42

View File

@@ -30,9 +30,6 @@ namespace Discord.Interactions
public Task<IResult> ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter, public Task<IResult> ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter,
IServiceProvider services) IServiceProvider services)
{ {
using IServiceScope scope = InteractionService._autoServiceScopes ? services?.CreateScope() : null;
services = InteractionService._autoServiceScopes ? scope?.ServiceProvider ?? EmptyServiceProvider.Instance : services;
switch (InteractionService._runMode) switch (InteractionService._runMode)
{ {
case RunMode.Sync: case RunMode.Sync:
@@ -57,6 +54,14 @@ namespace Discord.Interactions
{ {
try try
{ {
await using var scope = InteractionService._autoServiceScopes
? services?.CreateAsyncScope()
: null;
services = (InteractionService._autoServiceScopes
? scope?.ServiceProvider
: services) ?? EmptyServiceProvider.Instance;
var result = await GenerateSuggestionsAsync(context, autocompleteInteraction, parameter, services).ConfigureAwait(false); var result = await GenerateSuggestionsAsync(context, autocompleteInteraction, parameter, services).ConfigureAwait(false);
if (result.IsSuccess) if (result.IsSuccess)