// Copyright © 2022-2026 Partium, Inc. DBA Partium import { BaseService, BaseServiceClass } from './base.service'; /** * Manages and provides all services as singletons. * If a certain Service is needed somewhere it can be requested here if it is already existing, * the instance is returned, or if not a new instance is generated. * * This Service operates in two stages: * 1) In the first stage useService can be called, in order to choose which service to use for certain interfaces (eg: HttpsService) * 2) In the second phase services can be retrieved or created, but not via useService() anymore * This is required, because services cross-reference each other and this can cause to inconsistencies, especially with services * that are instantiated via useService, such as HttpsService. */ export declare class ServiceProvider { private services; private useServicePhaseEnded; /** * Get the singleton instance of a certain service class * * @param serviceClass the Service-class to get an instance of * @returns Promise that resoles with singleton instance of the requested service */ getService(serviceClass: BaseServiceClass): S; /** * Allow to select one specific service out of alternative options. * eg: HttpsService: There are multiple alternative Https-service, * which the user of the api can choose from. This function allows * to choose one and use it over the whole plugin with the unified * name of it's ancestor. * * eg: serviceProvider.useService( HttpsServiceApiKey, HttpsService ) * -> later this can be referred to via serviceProvider.getService( HttpsService ) * * @param serviceClass the Service-class to use * @param useFor the super-class to "replace" with */ useService(serviceClass: BaseServiceClass, useFor: BaseServiceClass, ...initArgs: any[]): void; /** * Allows to set an instance for a specified service class * This can be for example used for setting mocked services in the context of tests * * eg: serviceProvider.setService( { ..mocked object }, HttpsService ) * * @param serviceInstance the service instance to use * @param useFor the super-class to "replace" with the service instance */ setService(serviceInstance: S, useFor: BaseServiceClass): void; /** * Call this function when all useService-calls are done to close the 1st stage and allow to use the * getService method. */ serviceSelectionFinished(): void; /** * Reset the state of the provider to the initial state. * (Mainly used for tests) */ reset(): void; }