- private static readonly instances: Map<string, OCPPResponseService> = new Map<
- string,
- OCPPResponseService
- >();
- protected readonly chargingStation: ChargingStation;
-
- protected constructor(chargingStation: ChargingStation) {
- this.chargingStation = chargingStation;
+ private static instance: OCPPResponseService | null = null;
+ private readonly ajv: Ajv;
+
+ protected constructor() {
+ this.ajv = new Ajv();
+ ajvFormats(this.ajv);
+ this.responseHandler.bind(this);
+ this.validateResponsePayload.bind(this);
+ }
+
+ public static getInstance<T extends OCPPResponseService>(this: new () => T): T {
+ if (OCPPResponseService.instance === null) {
+ OCPPResponseService.instance = new this();
+ }
+ return OCPPResponseService.instance as T;