I have an existing code implementing singleton pattern by having private constructor and returning object instance returning the object -
export class SingletonFactory {
private static factoryInstance = new SingletonFactory();
private constructor() {
}
public static getInstance() {
return SingletonFactory.factoryInstance;
}
}
I need to inject a dependency into this factory. And I changed my code to the following -
@Inject('MyService')
export class SingletonFactory {
private static factoryInstance = new SingletonFactory();
private constructor(private myService : MyService) {
}
public static getInstance() {
return SingletonFactory.factoryInstance;
}
}
Please suggest, how I can inject the dependency at object creation in the constructor?
Inject into your component.