cancel
Showing results for 
Search instead for 
Did you mean: 

CAP Node.JS: Replace implementation of existing service

gregorw
Active Contributor

Hello CAP Community, Hi daniel.hutzel,

thanks to the answer from martin.stenzig3 at SAP CAP Dynamic Service Definition I was able to implement a functionality that loads a service definition plus it's JavaScript implementation from the database persistence. Check out srv/init.js where I fill the persistency and srv/server.js#L162 where the dynamic service is instantiated. With the REST Client script tests/app/dynamic.http#L20 I can execute the test to the hello-world function "hello" without problems.

But now I try to use that to replace the handler for an existing service (minimal.MinimalService). Unfortunately calling:

      services[serviceDefinition.ServiceName] = await cds
        .serve(serviceDefinition.ServiceName)
        .from(csn)
        .to("odata")
        .at(serviceDefinition.ServicePath)
        .with(eval(serviceDefinition.Implementation))
        .in(cds.app);

has no effect and the response is:

 Service \"minimal.MinimalService\" has no handler for \"hello\"

The usecase for this functionality is the following:

We already implemented a CAP Multitenant application using @sap/cds-mtxs that currently deploys new entities into an existing service using the functionality provided by cds.xt.ExtensibilityService. This gives us the benefit that all the deployment to the tenant specific HDI container is handled by cds-mtxs. That way also the generic handler implementations are triggered. But with a growing number of entities the metadata of the service gets hander to consume by the client applications. As the Entities belong already to a so called Environment we would like to create one service by Environment. cds.xt.ExtensibilityService does already support this. But until now we haven't found a way to set also our generic handlers for this new services.

Looking forward for your input.

Best Regards
Gregor

martinstenzig
Contributor
0 Kudos

I have noticed that as well. Creating an new one is working well, but there does not seem to be any way to change/destroy one at runtime that I have found.

Accepted Solutions (0)

Answers (0)