diff --git a/Dalamud/IoC/Internal/ServiceContainer.cs b/Dalamud/IoC/Internal/ServiceContainer.cs index 6083f5a73..6383b6b11 100644 --- a/Dalamud/IoC/Internal/ServiceContainer.cs +++ b/Dalamud/IoC/Internal/ServiceContainer.cs @@ -18,7 +18,7 @@ namespace Dalamud.IoC.Internal; /// Dalamud services are constructed via Service{T}.ConstructObject at the moment. /// [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 /// An implementation of a service scope. public IServiceScope GetScope() => new ServiceScopeImpl(this); - /// - public object? GetService(Type serviceType) => this.GetSingletonService(serviceType).Result; - - private async Task GetService(Type serviceType, ServiceScopeImpl? scope, object[] scopedObjects) + /// + /// Resolves and returns an instance of the specified service type, using either singleton or scoped lifetime as + /// appropriate. + /// + /// The type of the service to resolve. This must be a concrete or interface type registered with the service + /// manager. + /// The scope within which to create scoped services. Required if the requested service type is registered as + /// scoped; otherwise, can be null. + /// An array of objects available for scoped resolution. Used to locate or create scoped service instances when + /// applicable. + /// 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. + /// 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. + public async Task GetService(Type serviceType, ServiceScopeImpl? scope, object[] scopedObjects) { if (this.interfaceToTypeMap.TryGetValue(serviceType, out var implementingType)) serviceType = implementingType; diff --git a/Dalamud/IoC/Internal/ServiceScope.cs b/Dalamud/IoC/Internal/ServiceScope.cs index 70d409b58..c0c4e0b08 100644 --- a/Dalamud/IoC/Internal/ServiceScope.cs +++ b/Dalamud/IoC/Internal/ServiceScope.cs @@ -60,7 +60,7 @@ internal class ServiceScopeImpl : IServiceScope /// public object? GetService(Type serviceType) { - return this.container.GetService(serviceType); + return this.container.GetService(serviceType, this, []).ConfigureAwait(false).GetAwaiter().GetResult(); } ///