Connection to remote server as global non-persisted state/singleton

Hello, [Mendix newbie here] I am developing a Mendix app that is thin client to a remote server and uses gRPC as the transport layer. For virtually all communication with the server, we need a connection (stub in gRPC-speak). How can I store this connection as a global variable / singleton? I have read about a technique involving the Domain Model within a module to either CreateOrRetrieve something akin to a singleton instance. However, that involves creating an object that is of a unknown type to the Mendix application. Whereas the gRPC connection stub would be an instance of a class that extends io.grpc.stub.AbstractStub<..>. Is there a standardized technique of achieving that? Or am I looking at the problem from a wrong perspective?
2 answers

Yes, thanks.

I was hoping there is some standardized/recommended way of storing global application state – eg: like session info, or a connection to a database.

In the end I resorted to creating a separate jar, added it to userlib in the Mendix app.

This jar contains:

- all protoc-generated java code in a package

- another package containing boilerplate code, which, for now, only creates and  returns the gRPC channel/stub




You probably need to use java to achieve this. Look at the following tutorial –