[Fix] Create a new scope when building interaction service modules if AutoServiceScopes = true (#3028)

* Update ModuleBuilder.cs

* oh right the `using`
This commit is contained in:
Mihail Gribkov
2024-11-16 20:37:18 +03:00
committed by GitHub
parent f644e6831a
commit a1e50c4bbf

View File

@@ -1,3 +1,4 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Reflection;
@@ -461,6 +462,10 @@ namespace Discord.Interactions.Builders
{
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
{
using var scope = services?.CreateScope();
if (interactionService._autoServiceScopes)
services = scope?.ServiceProvider ?? EmptyServiceProvider.Instance;
var instance = ReflectionUtils<IInteractionModuleBase>.CreateObject(TypeInfo, interactionService, services);
try