Skip to content

Commit d71fcb1

Browse files
authored
AutoServiceScopes strikes again (#3072)
1 parent 6fb2a29 commit d71fcb1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Discord.Net.Interactions/AutocompleteHandlers/AutocompleteHandler.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ protected virtual string GetLogString(IInteractionContext context)
3030
public Task<IResult> ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter,
3131
IServiceProvider services)
3232
{
33-
using IServiceScope scope = InteractionService._autoServiceScopes ? services?.CreateScope() : null;
34-
services = InteractionService._autoServiceScopes ? scope?.ServiceProvider ?? EmptyServiceProvider.Instance : services;
35-
3633
switch (InteractionService._runMode)
3734
{
3835
case RunMode.Sync:
@@ -57,6 +54,14 @@ private async Task<IResult> ExecuteInternalAsync(IInteractionContext context, IA
5754
{
5855
try
5956
{
57+
await using var scope = InteractionService._autoServiceScopes
58+
? services?.CreateAsyncScope()
59+
: null;
60+
61+
services = (InteractionService._autoServiceScopes
62+
? scope?.ServiceProvider
63+
: services) ?? EmptyServiceProvider.Instance;
64+
6065
var result = await GenerateSuggestionsAsync(context, autocompleteInteraction, parameter, services).ConfigureAwait(false);
6166

6267
if (result.IsSuccess)

0 commit comments

Comments
 (0)