Skip to content
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

[Featured] Consider AutoServiceScopes in autocomplete handler executions #3068

Merged
merged 3 commits into from
Mar 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;

namespace Discord.Interactions
{
Expand All @@ -29,6 +30,9 @@ protected virtual string GetLogString(IInteractionContext context)
public Task<IResult> ExecuteAsync(IInteractionContext context, IAutocompleteInteraction autocompleteInteraction, IParameterInfo parameter,
IServiceProvider services)
{
using IServiceScope scope = InteractionService._autoServiceScopes ? services?.CreateScope() : null;
services = InteractionService._autoServiceScopes ? scope?.ServiceProvider ?? EmptyServiceProvider.Instance : services;

switch (InteractionService._runMode)
{
case RunMode.Sync:
Expand All @@ -44,7 +48,7 @@ public Task<IResult> ExecuteAsync(IInteractionContext context, IAutocompleteInte
default:
throw new InvalidOperationException($"RunMode {InteractionService._runMode} is not supported.");
}

return Task.FromResult((IResult)ExecuteResult.FromSuccess());
}

Expand Down