
Services that can automatically be delivered to clients by Init(args) can be split into two groups based on their availability: global and local services.
A global service is a service that is available to all clients, regardless of their location in the scene hierarchies.
Registering Global Services
The main way to register global services is using [Service] attribute.
It’s also technically possible to create global services using any of the following methods:
- Attach the Service Tag to a component in the first scene and set Availability to Everywhere.
- Drag an Object into a Services component in the first scene and set For Clients to Everywhere.
- Manually register an object as a service by calling Service.Set during the initialization of the application.
Registering Plain C# Objects
Plain C# objects can be registered as global services using any the following methods:
- By adding the [Service] attribute directly to its class.
- By adding the [Service] attribute to a value provider class.
- By attaching the Service Tag to a Wrapper that wraps the plain C# object and setting Availability to Everywhere.
- By dragging a value provider that returns the plain C# object into a Services component and setting For Clients to Everywhere.
- By manually registering it as a service by calling Service.Set
Best Practices
Global services should typically exists for the entire lifetime of the application after being initialized. You always want to avoid situations where a client could live longer than one of the services that it depends on. Since all clients can receive global services, destroying or disposing global service after they have already been delivered to some clients is risky.