Merge remote-tracking branch 'origin/main' into 18169-cancel-button-not-working
[arvados-workbench2.git] / src / common / service-provider.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 class ServicesProvider {
6
7     private static instance: ServicesProvider;
8
9     private services;
10
11     private constructor() {}
12
13     public static getInstance(): ServicesProvider {
14         if (!ServicesProvider.instance) {
15             ServicesProvider.instance = new ServicesProvider();
16         }
17
18         return ServicesProvider.instance;
19     }
20
21     public setServices(newServices): void {
22         if (!this.services) {
23             this.services = newServices;
24         }
25     }
26
27     public getServices() {
28         if (!this.services) {
29             throw "Please check if services have been set in the index.ts before the app is initiated"; // eslint-disable-line no-throw-literal
30         }
31         return this.services;
32     }
33 }
34
35 export default ServicesProvider.getInstance();