[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))
|
if (TypeInfo is not null && ModuleClassBuilder.IsValidModuleDefinition(TypeInfo))
|
||||||
{
|
{
|
||||||
using var scope = services?.CreateScope();
|
IServiceScope scope = null;
|
||||||
if (interactionService._autoServiceScopes)
|
if (interactionService._autoServiceScopes)
|
||||||
|
{
|
||||||
|
scope = services?.CreateScope();
|
||||||
services = scope?.ServiceProvider ?? EmptyServiceProvider.Instance;
|
services = scope?.ServiceProvider ?? EmptyServiceProvider.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
var instance = ReflectionUtils<IInteractionModuleBase>.CreateObject(TypeInfo, interactionService, services);
|
var instance = ReflectionUtils<IInteractionModuleBase>.CreateObject(TypeInfo, interactionService, services);
|
||||||
|
|
||||||
@@ -473,10 +476,13 @@ namespace Discord.Interactions.Builders
|
|||||||
instance.Construct(this, interactionService);
|
instance.Construct(this, interactionService);
|
||||||
var moduleInfo = new ModuleInfo(this, interactionService, services, parent);
|
var moduleInfo = new ModuleInfo(this, interactionService, services, parent);
|
||||||
instance.OnModuleBuilding(interactionService, moduleInfo);
|
instance.OnModuleBuilding(interactionService, moduleInfo);
|
||||||
|
|
||||||
|
scope?.Dispose();
|
||||||
return moduleInfo;
|
return moduleInfo;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
scope?.Dispose();
|
||||||
(instance as IDisposable)?.Dispose();
|
(instance as IDisposable)?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,10 +113,12 @@ namespace Discord.Interactions
|
|||||||
{
|
{
|
||||||
await CommandService._cmdLogger.DebugAsync($"Executing {GetLogString(context)}").ConfigureAwait(false);
|
await CommandService._cmdLogger.DebugAsync($"Executing {GetLogString(context)}").ConfigureAwait(false);
|
||||||
|
|
||||||
using var scope = services?.CreateScope();
|
IServiceScope scope = null;
|
||||||
|
|
||||||
if (CommandService._autoServiceScopes)
|
if (CommandService._autoServiceScopes)
|
||||||
|
{
|
||||||
|
scope = services?.CreateScope();
|
||||||
services = scope?.ServiceProvider ?? EmptyServiceProvider.Instance;
|
services = scope?.ServiceProvider ?? EmptyServiceProvider.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -179,11 +181,13 @@ namespace Discord.Interactions
|
|||||||
ExceptionDispatchInfo.Capture(ex).Throw();
|
ExceptionDispatchInfo.Capture(ex).Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope?.Dispose();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
await CommandService._cmdLogger.VerboseAsync($"Executed {GetLogString(context)}").ConfigureAwait(false);
|
await CommandService._cmdLogger.VerboseAsync($"Executed {GetLogString(context)}").ConfigureAwait(false);
|
||||||
|
scope?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user