Tutorials/howto lookup services

Firebase provides a number of Services available to game developer. In addition to these Services it is possible, and highly recommend, to develop and deploy your own Services.

A Service can be seen as an isolated, decoupled module for business logic. Typically Services wraps remote services or other logical parts that benefits from encapsulation.

Service Registry
Services are fetched from the ServiceRegistry. The ServiceRegistry is typically accessed from the Context class that is provided to the different API interfaces.

Example, when implement the Game interface you get an init method with a GameContext in it. This context can be used to get the ServiceRegistry. public void init(GameContext con) { ServiceRegistry serviceRegistry = con.getServices; }

Both the ServiceRegistry and Service lookups are singletons and it is safe to pass around the reference. The Service Registry and all Services provided by Firebase should be considered thread-safe. If you provide your own Services you need to ensure thread-safety yourself.

Service Look Up
A look up for a Service is done by querying the Service Registry. You can provided the class or the service id. Below is an example for getting the Public Client Registry.

PublicSystemStateService systemState = serviceRegistry.getServiceInstance(PublicClientRegistryService.class);

The same pattern applies to all public services and your own deployed services.

Guice Integration
If you use the Guice Support module for your game then you can use the inject support. Below is an example of using Guice to inject the wallet service into a class. Note that the class itself has to be initialized by Guice. @Service WalletServiceContract walletService;