I have a backend service called SchedulerService
that is bound as shown below
bind(SchedulerServiceSymbol).to(SchedulerService).inSingletonScope();
bind(ConnectionHandler).toDynamicValue(
({ container }) =>
// Scheduler service doesn't have a watcher, so little simpler binding
new JsonRpcConnectionHandler(SERVICE_URL.SCHEDULER, (): SchedulerService => {
return container.get(SchedulerServiceSymbol);
})
);
I am injecting this into a frontend class PropertyStore
as shown below
@injectable()
export class PropertyStore {
constructor(
@inject(PropertyStoreInitArgs.objUid)
readonly objUid: string,
@inject(PropertyStoreInitArgs.propName)
propNames: string[],
@inject(SchedulerService)
readonly schedulerService: ISchedulerService
) { }
}
The PropertyStore
is created via an async factory a.k.a provider as follows
bind(PropertyStoreProvider).toProvider<IPropertyStore>(
({ container }) =>
async (uid: string, propName: string[]): Promise<IPropertyStore> => {
const child = new Container();
child.parent = container;
child.bind(PropertyStoreInitArgs.objUid).toConstantValue(uid);
child.bind(PropertyStoreInitArgs.propName).toConstantValue(propName);
child.bind(PropertyStore).toSelf();
const propStore = child.get(PropertyStore);
// HERE --- Below function calls the SchedulerService in the backend
await propStore.<xyz>()
return propStore;
}
);
However, for some reason the calls to functions in the ScheduleService
are never received by the backend.
When I introspected using the browser dev tools, I noticed that the connectionPromise
is pending.
Comparing this with a case where I am able to call the ScheduleService
APIs, I have a feeling this promise is not supposed to be “pending” for the JSON-RPC to work.
Would the experts here have any thoughts on things I could try to get past this?
PS - I wouldn’t call myself an Inversify expert. If this is an anti-pattern and I should do things a different way, please let me know.