[Fix] Interaction Service failing to create scopes with some DI providers (#3031)
This commit is contained in:
@@ -462,9 +462,12 @@ namespace Discord.Interactions.Builders
|
||||
{
|
||||
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
|
||||
{
|
||||
using var scope = services?.CreateScope();
|
||||
IServiceScope scope = null;
|
||||
if (interactionService._autoServiceScopes)
|
||||
{
|
||||
scope = services?.CreateScope();
|
||||
services = scope?.ServiceProvider ?? EmptyServiceProvider.Instance;
|
||||
}
|
||||
|
||||
var instance = ReflectionUtils<IInteractionModuleBase>.CreateObject(TypeInfo, interactionService, services);
|
||||
|
||||
@@ -473,10 +476,13 @@ namespace Discord.Interactions.Builders
|
||||
instance.Construct(this, interactionService);
|
||||
var moduleInfo = new ModuleInfo(this, interactionService, services, parent);
|
||||
instance.OnModuleBuilding(interactionService, moduleInfo);
|
||||
|
||||
scope?.Dispose();
|
||||
return moduleInfo;
|
||||
}
|
||||
finally
|
||||
{
|
||||
scope?.Dispose();
|
||||
(instance as IDisposable)?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,10 +113,12 @@ namespace Discord.Interactions
|
||||
{
|
||||
await CommandService._cmdLogger.DebugAsync($"Executing {GetLogString(context)}").ConfigureAwait(false);
|
||||
|
||||
using var scope = services?.CreateScope();
|
||||
|
||||
IServiceScope scope = null;
|
||||
if (CommandService._autoServiceScopes)
|
||||
{
|
||||
scope = services?.CreateScope();
|
||||
services = scope?.ServiceProvider ?? EmptyServiceProvider.Instance;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@@ -179,11 +181,13 @@ namespace Discord.Interactions
|
||||
ExceptionDispatchInfo.Capture(ex).Throw();
|
||||
}
|
||||
|
||||
scope?.Dispose();
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
await CommandService._cmdLogger.VerboseAsync($"Executed {GetLogString(context)}").ConfigureAwait(false);
|
||||
scope?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user