Fix GetService getting stuck in Task

This commit is contained in:
Haselnussbomber 2025-10-20 10:45:02 +02:00
parent 9001c96986
commit 9ea417c9ef
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
2 changed files with 17 additions and 6 deletions

View file

@ -18,7 +18,7 @@ namespace Dalamud.IoC.Internal;
/// Dalamud services are constructed via Service{T}.ConstructObject at the moment.
/// </summary>
[ServiceManager.ProvidedService]
internal class ServiceContainer : IServiceProvider, IServiceType
internal class ServiceContainer : IServiceType
{
private static readonly ModuleLog Log = new("SERVICECONTAINER");
@ -160,10 +160,21 @@ internal class ServiceContainer : IServiceProvider, IServiceType
/// <returns>An implementation of a service scope.</returns>
public IServiceScope GetScope() => new ServiceScopeImpl(this);
/// <inheritdoc/>
public object? GetService(Type serviceType) => this.GetSingletonService(serviceType).Result;
private async Task<object> GetService(Type serviceType, ServiceScopeImpl? scope, object[] scopedObjects)
/// <summary>
/// Resolves and returns an instance of the specified service type, using either singleton or scoped lifetime as
/// appropriate.
/// </summary>
/// <param name="serviceType">The type of the service to resolve. This must be a concrete or interface type registered with the service
/// manager.</param>
/// <param name="scope">The scope within which to create scoped services. Required if the requested service type is registered as
/// scoped; otherwise, can be null.</param>
/// <param name="scopedObjects">An array of objects available for scoped resolution. Used to locate or create scoped service instances when
/// applicable.</param>
/// <returns>An instance of the requested service type. Returns a singleton instance if available, a scoped instance if
/// required, or an object from the provided scoped objects if it matches the service type.</returns>
/// <exception cref="InvalidOperationException">Thrown if a scoped service is requested but no scope is provided, or if the requested service type cannot be
/// resolved from the scoped objects.</exception>
public async Task<object> GetService(Type serviceType, ServiceScopeImpl? scope, object[] scopedObjects)
{
if (this.interfaceToTypeMap.TryGetValue(serviceType, out var implementingType))
serviceType = implementingType;

View file

@ -60,7 +60,7 @@ internal class ServiceScopeImpl : IServiceScope
/// <inheritdoc/>
public object? GetService(Type serviceType)
{
return this.container.GetService(serviceType);
return this.container.GetService(serviceType, this, []).ConfigureAwait(false).GetAwaiter().GetResult();
}
/// <inheritdoc/>