Theia: Question about develop singleton service for backend and fronted extension.

Created on 16 Mar 2020  路  7Comments  路  Source: eclipse-theia/theia

I tired to write singleton service for backend and fronted,
so i write it in node endpoint:

** extension-backend-module.ts:

const myConnectionModule = ConnectionContainerModule.create(({ bind, bindBackendService }) => {
bind(MyAddressService).to(MyAddressServiceImpl).inSingletonScope();
bindBackendService(MyAddressServicePath, MyAddressService);
});

export default new ContainerModule(bind => {

bind(ConnectionContainerModule).toConstantValue(myConnectionModule);
});

*** MyAddressService ---> it's DI Symbol end interface
*** MyAddressServiceImpl ---> it's implementation of MyAddressService interface

and in fronted endpoint i write:
** extension-frontend-module.ts:

export default new ContainerModule(bind => {
bind(MyAddressService).toDynamicValue(context => WebSocketConnectionProvider.createProxy(context.container, MyAddressServicePath)).inSingletonScope();

});

And i have exception when i tired to get service from fronted

Uncaught (in promise) Error: Request 'getIpAddress' failed
at Proxy. (proxy-factory.ts:232)

Am I missing something ?
Thanks in Advance

question

All 7 comments

Uncaught (in promise) Error: Request 'getIpAddress' failed
at Proxy. (proxy-factory.ts:232)

Is there a full stack trace? Maybe getIpAddress method failed for some reasons on the backend?

This if full stack trace

Uncaught (in promise) Error: Request 'getIpAddress' failed
at Proxy. (proxy-factory.ts:232)
at MyCustomWidget. (my-custom-widget.tsx:61)
at Generator.next ()
at my-custom-contribution.ts:25
at new Promise ()
at push.../../packages/my-extension/lib/browser/widgets/my-custom/my-custom-widget.js.__awaiter (my-custom-contribution.ts:25)
at MyCustomWidget.testAddService (my-custom-widget.tsx:59)
at MyCustomWidget. (my-custom-widget.tsx:46)
at Generator.next ()
at my-custom-contribution.ts:25
_construct @ construct.js:30
Wrapper @ wrapNativeSuper.js:26
ResponseError @ messages.js:36
handleResponse @ main.js:448
processMessageQueue @ main.js:275
(anonymous) @ main.js:259
run @ setImmediate.js:40
runIfPresent @ setImmediate.js:69
onGlobalMessage @ setImmediate.js:109
Promise.then (async)
step @ my-custom-contribution.ts:25
(anonymous) @ my-custom-contribution.ts:25
push.../../packages/my-extension/lib/browser/widgets/topology/my-custom-widget.js.__awaiter @ my-custom-contribution.ts:25
onClick @ my-custom-widget.tsx:46
callCallback @ react-dom.development.js:100
invokeGuardedCallbackDev @ react-dom.development.js:138
invokeGuardedCallback @ react-dom.development.js:187
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:201
executeDispatch @ react-dom.development.js:461
executeDispatchesInOrder @ react-dom.development.js:483
executeDispatchesAndRelease @ react-dom.development.js:581
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:592
forEachAccumulated @ react-dom.development.js:562
runEventsInBatch @ react-dom.development.js:723
runExtractedEventsInBatch @ react-dom.development.js:732
handleTopLevel @ react-dom.development.js:4477
batchedUpdates$1 @ react-dom.development.js:16660
batchedUpdates @ react-dom.development.js:2131
dispatchEvent @ react-dom.development.js:4556
interactiveUpdates$1 @ react-dom.development.js:16715
interactiveUpdates @ react-dom.development.js:2150
dispatchInteractiveEvent @ react-dom.development.js:4533

@eli88p Is there a was to share reproducible repo on GitHub?

not yet it's still in my local i will pushed and will share with you thanks for help

I found the problem...
the problem was in tsconfig.json after remove es6 it's start to work

{
    "compilerOptions": {
        "skipLibCheck": true,
        "declaration": true,
        "declarationMap": true,
        "noImplicitAny": true,
        "noEmitOnError": false,
        "noImplicitThis": true,
        "noUnusedLocals": true,
        "strictNullChecks": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "downlevelIteration": true,
        "resolveJsonModule": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "target": "es5",
        "jsx": "react",
        "lib": [
            "es6",
            "es5",
            "dom"
        ],
        "sourceMap": true,
        "rootDir": "src",
        "outDir": "lib"
    },
    "include": [
        "src"
    ]
}

Thanks @akosyakov

@akosyakov i have one more question for current topic...
it's possible insert EventEmitters to service like this?

@eli88p No, but you can create a service around a server which installs a client and then dispatch notification as events, for instance like in FileSystemWatcher: https://github.com/eclipse-theia/theia/blob/00c1747c98aefe946d2f2c6b7db5b8e356183abf/packages/filesystem/src/browser/filesystem-watcher.ts#L166-L172

Was this page helpful?
0 / 5 - 0 ratings