If the existing injection token for this provider is available, I want to use it. Otherwise, I will use the specified provider.
Below is the code snippet:
providers: [
{
provide: DesignerRecoveryComponentStore,
useFactory: (injector: Injector) => {
return injector.get(
DesignerRecoveryComponentStore,
new DesignerRecoveryComponentStore(
injector.get(Store),
injector.get(Actions),
injector.get(NgZone),
injector.get(DesignerActionDispatcher),
injector.get(PresentationRecoveryService),
injector.get(Router),
injector.get(PadsDialogService)
)
);
},
deps: [Injector]
}
]
This code snippet checks the availability of a provider for DesignerRecoveryComponentStore (a subclass). If it exists, it is returned. If not, a new instance of the main class is created.
The log shows circular dependency errors.
What is the correct way to address this issue?
I attempted to use an interface instead of the class I am searching for, but it resulted in compilation errors.