[Featured] Consider AutoServiceScopes in autocomplete handler executions (#3068)
* Add AutoServiceScopes to autocomplete handlers * Fix disposing behavior * Update AutocompleteHandler.cs --------- Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@ using System;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Discord.Interactions
|
namespace Discord.Interactions
|
||||||
{
|
{
|
||||||
@@ -29,6 +30,9 @@ 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:
|
||||||
|
|||||||
Reference in New Issue
Block a user