Skip to main content

Class ServiceManager

Namespace: RealityCollective.ServiceFramework.Services

public class ServiceManager

Inheritance​

object ← ServiceManager

Constructors​

ServiceManager(GameObject, ServiceProvidersProfile, Type[])​

Constructor Each Service Manager MUST have a managed GameObject that can route the MonoBehaviours to, if you do not provide a GameObject, then a new GlobalServiceManager will be created for you.

public ServiceManager(GameObject instanceGameObject = null, ServiceProvidersProfile profile = null, Type[] additionalBaseServiceTypes = null)

Parameters​

instanceGameObject GameObject

profile ServiceProvidersProfile

additionalBaseServiceTypes Type[]

Remarks​

It is NOT supported to create a reference to the ServiceManager without a GameObject and then continue to use that reference, as this will actually create two separate ServiceManagers in memory.

Fields​

InitializeOnPlay​

public bool InitializeOnPlay

Field Value​

bool

Properties​

ActivePlatforms​

The list of active platforms detected by the ServiceManager.

public static IReadOnlyList<IPlatform> ActivePlatforms { get; }

Property Value​

IReadOnlyList<IPlatform>

ActiveProfile​

The public property of the Active Profile, ensuring events are raised on the change of the reference

public ServiceProvidersProfile ActiveProfile { get; set; }

Property Value​

ServiceProvidersProfile

ActiveServices​

Current active services registered with the ServiceManager.

public IReadOnlyDictionary<Type, IService> ActiveServices { get; }

Property Value​

IReadOnlyDictionary<Type, IService>

Remarks​

Services can only be registered once by Type and are executed in a specific priority order.

AvailablePlatforms​

The list of active platforms detected by the ServiceManager.

public static IReadOnlyList<IPlatform> AvailablePlatforms { get; }

Property Value​

IReadOnlyList<IPlatform>

HasActiveProfile​

Checks if there is a valid instance of the Service Manager, then checks if there is there a valid Active Profile.

public bool HasActiveProfile { get; }

Property Value​

bool

Instance​

Returns the singleton instance of the ServiceManager.

public static ServiceManager Instance { get; }

Property Value​

ServiceManager

IsActiveAndInitialized​

Gets whether there is an active Instance of the ServiceManager available and it IsInitialized.

public static bool IsActiveAndInitialized { get; }

Property Value​

bool

IsApplicationQuitting​

Flag stating if the application is currently attempting to quit.

public bool IsApplicationQuitting { get; }

Property Value​

bool

IsInitialized​

Returns whether the instance has been initialized or not.

public bool IsInitialized { get; }

Property Value​

bool

ServiceInterfaceTypes​

public static Type[] ServiceInterfaceTypes { get; }

Property Value​

Type[]

ServiceManagerInstanceGuid​

public Guid ServiceManagerInstanceGuid { get; }

Property Value​

Guid

Methods​

AddProcessToUpdate(UpdateMethod, float)​

public void AddProcessToUpdate(UpdateMethod onUpdate, float period)

Parameters​

onUpdate UpdateMethod

period float

AddServiceConfigurationForScene(string, IServiceConfiguration<IService>[])​

Add a IServiceConfiguration%601 for a specific scene.

public void AddServiceConfigurationForScene(string sceneName, IServiceConfiguration<IService>[] serviceConfigurations)

Parameters​

sceneName string

The scene for which to add configuration for.

serviceConfigurations IServiceConfiguration<IService>[]

The IServiceConfiguration%601 for the specific scene.

AssertIsInitialized()​

Expose an assertion whether the Service Manager class is initialized.

public void AssertIsInitialized()

ConfirmInitialized()​

function to determine if the ServiceManager class has been initialized or not.

public bool ConfirmInitialized()

Returns​

bool

DestroyAllServices()​

public void DestroyAllServices()

Dispose()​

Dispose the ServiceManager object.

public void Dispose()

~ServiceManager()​

protected ~ServiceManager()

GetAllServices()​

Gets all IServices by type.

public List<IService> GetAllServices()

Returns​

List<IService>

GetAllServices(ref List<IService>)​

Gets all IServices by type.

public void GetAllServices(ref List<IService> services)

Parameters​

services List<IService>

Memory reference value of the service list to update.

GetService<T>(bool)​

Retrieve a IService from the ActiveServices.

public T GetService<T>(bool showLogs = true) where T : IService

Parameters​

showLogs bool

Should the logs show when services cannot be found?

Returns​

T

The instance of the IService that is registered.

Type Parameters​

T

The interface type for the service to be retrieved.

GetService(Type, bool)​

Retrieve a IService from the ActiveServices by type.

public IService GetService(Type interfaceType, bool showLogs = true)

Parameters​

interfaceType Type

The interface type for the Service to be retrieved.

showLogs bool

Should the logs show when services cannot be found?

Returns​

IService

The instance of the IService that is registered.

GetServiceAsync<T>(int)​

Retrieve a IService from the ActiveServices.

public Task<T> GetServiceAsync<T>(int timeout = 10) where T : IService

Parameters​

timeout int

Optional, time out in seconds to wait before giving up search.

Returns​

Task<T>

The instance of the IService that is registered.

Type Parameters​

T

The interface type for the service to be retrieved.

GetServiceByName<T>(string, bool)​

Retrieve a IService from the ActiveServices.

public IService GetServiceByName<T>(string serviceName, bool showLogs = true) where T : IService

Parameters​

serviceName string

Name of the specific service.

showLogs bool

Should the logs show when services cannot be found?

Returns​

IService

The instance of the IService that is registered.

Type Parameters​

T

GetServiceByName(Type, string, bool)​

Retrieve a IService from the ActiveServices.

public IService GetServiceByName(Type interfaceType, string serviceName, bool showLogs = true)

Parameters​

interfaceType Type

The interface type for the Service to be retrieved.

serviceName string

Name of the specific service.

showLogs bool

Should the logs show when services cannot be found?

Returns​

IService

The instance of the IService that is registered.

GetServiceCached<T>()​

Retrieve a cached reference of an IService from the ActiveServices.

public T GetServiceCached<T>() where T : IService

Returns​

T

The instance of the IService that is registered.

Type Parameters​

T

The interface type for the Service to be retrieved.

Remarks​

Internal function used for high performant services or components, not to be overused.

GetServices<T>()​

Retrieve all services from the active service registry for a given type and an optional name

public List<T> GetServices<T>() where T : IService

Returns​

List<T>

An array of services that meet the search criteria

Type Parameters​

T

The IService interface type for the Service to be retrieved. E.G. IStorageService.

GetServices<T>(Type)​

Retrieve all services from the active service registry for a given type and an optional name

public List<T> GetServices<T>(Type interfaceType) where T : IService

Parameters​

interfaceType Type

The interface type for the Service to be retrieved. E.G. Storage Service.

Returns​

List<T>

An array of services that meet the search criteria

Type Parameters​

T

GetServices<T>(Type, string)​

Retrieve all services from the active service registry for a given type and name

public List<T> GetServices<T>(Type interfaceType, string serviceName) where T : IService

Parameters​

interfaceType Type

The interface type for the Service to be retrieved. Storage Service.

serviceName string

Name of the specific service

Returns​

List<T>

An array of services that meet the search criteria

Type Parameters​

T

GetSystemCachedAsync<T>(int)​

Retrieve a IService from the ActiveSystems.

public Task<T> GetSystemCachedAsync<T>(int timeout = 10) where T : IService

Parameters​

timeout int

Optional, time out in seconds to wait before giving up search.

Returns​

Task<T>

The instance of the IService that is registered.

Type Parameters​

T

The interface type for the Service to be retrieved.

Initialize(GameObject, ServiceProvidersProfile)​

public void Initialize(GameObject instanceGameObject = null, ServiceProvidersProfile profile = null)

Parameters​

instanceGameObject GameObject

profile ServiceProvidersProfile

InitializeServiceManager()​

Initialize the Service Framework configured services.

public void InitializeServiceManager()

IsServiceRegistered<T>()​

Query the ActiveServices for the existence of a IService.

public bool IsServiceRegistered<T>() where T : IService

Returns​

bool

Returns true, if there is a IService registered, otherwise false.

Type Parameters​

T

The interface type for the service to be retrieved.

IsServiceRegistered(object)​

Query the ActiveServices for the existence of a IService.

public bool IsServiceRegistered(object concreteType)

Parameters​

concreteType object

Returns​

bool

Returns true, if there is a IService registered, otherwise false.

LoadServicesForScene(string)​

Load services for a specific scene.

public void LoadServicesForScene(string sceneName)

Parameters​

sceneName string

The scene for which to load the services for.

RemoveProcessFromUpdate(UpdateMethod)​

Safe to call even if onUpdate was not previously Subscribed.

public void RemoveProcessFromUpdate(UpdateMethod onUpdate)

Parameters​

onUpdate UpdateMethod

ResetProfile(ServiceProvidersProfile, GameObject)​

When a profile is replaced with a new one, force all services to reset and read the new values

public void ResetProfile(ServiceProvidersProfile profile, GameObject instance = null)

Parameters​

profile ServiceProvidersProfile

instance GameObject

TryCreateAndRegisterService<T>(IServiceConfiguration<T>, out T)​

Creates a new instance of a service and registers it to the Service Manager service registry for the specified platform.

public bool TryCreateAndRegisterService<T>(IServiceConfiguration<T> configuration, out T service) where T : IService

Parameters​

configuration IServiceConfiguration<T>

The IServiceConfiguration%601 to use to create and register the service.

service T

If successful, then the new IService instance will be passed back out.

Returns​

bool

True, if the service was successfully created and registered.

Type Parameters​

T

The interface type for the IService to be registered.

TryCreateAndRegisterService<T>(Type, out T, params object[])​

Creates a new instance of a service and registers it to the Reality Toolkit service registry for all platforms.

public bool TryCreateAndRegisterService<T>(Type concreteType, out T service, params object[] args) where T : IService

Parameters​

concreteType Type

The concrete class type to instantiate.

service T

If successful, then the new IService instance will be passed back out.

args object[]

Optional arguments used when instantiating the concrete type.

Returns​

bool

True, if the service was successfully created and registered.

Type Parameters​

T

The interface type for the IService to be registered.

TryCreateAndRegisterService<T>(Type, IReadOnlyList<IPlatform>, out T, params object[])​

Creates a new instance of a service and registers it to the Reality Toolkit service registry for the specified platform(s).

public bool TryCreateAndRegisterService<T>(Type concreteType, IReadOnlyList<IPlatform> runtimePlatforms, out T service, params object[] args) where T : IService

Parameters​

concreteType Type

The concrete class type to instantiate.

runtimePlatforms IReadOnlyList<IPlatform>

The runtime IPlatforms to check against when registering.

service T

If successful, then the new IService instance will be passed back out.

args object[]

Optional arguments used when instantiating the concrete type.

Returns​

bool

True, if the service was successfully created and registered.

Type Parameters​

T

The interface type for the IService to be registered.

TryCreateAndRegisterServiceModule<T>(IServiceConfiguration<T>, IService)​

Creates a new instance of a service module and registers it to the Service Manager service registry for the specified platform.

public bool TryCreateAndRegisterServiceModule<T>(IServiceConfiguration<T> configuration, IService serviceParent) where T : IServiceModule

Parameters​

configuration IServiceConfiguration<T>

The IServiceConfiguration%601 to use to create and register the service module.

serviceParent IService

The IService that the IServiceModule will be assigned to.

Returns​

bool

True, if the service was successfully created and registered.

Type Parameters​

T

The interface type for the IService to be registered.

TryGetService<T>(out T)​

Retrieve a IService from the ActiveServices.

public bool TryGetService<T>(out T service) where T : IService

Parameters​

service T

The instance of the service class that is registered.

Returns​

bool

Returns true if the IService was found, otherwise false.

Type Parameters​

T

The interface type for the service to be retrieved.

TryGetService(Type, out IService)​

Retrieve the first IService from the ActiveServices that meets the selected type and name.

public bool TryGetService(Type interfaceType, out IService service)

Parameters​

interfaceType Type

Interface type of the service being requested.

service IService

return parameter of the function.

Returns​

bool

TryGetService(Type, string, out IService)​

Retrieve the first IService from the ActiveServices that meets the selected type and name.

public bool TryGetService(Type interfaceType, string serviceName, out IService serviceInstance)

Parameters​

interfaceType Type

Interface type of the service being requested.

serviceName string

Name of the specific service.

serviceInstance IService

return parameter of the function.

Returns​

bool

TryGetService(IService, out IService)​

public bool TryGetService(IService service, out IService serviceInstance)

Parameters​

service IService

serviceInstance IService

Returns​

bool

TryGetServiceByName<T>(string, out T)​

Retrieve a IService from the ActiveServices by name.

public bool TryGetServiceByName<T>(string serviceName, out T service) where T : IService

Parameters​

serviceName string

Name of the specific service to search for.

service T

The instance of the service class that is registered.

Returns​

bool

Returns true if the IService was found, otherwise false.

Type Parameters​

T

The interface type for the service to be retrieved.

TryGetServiceByName(Type, string, out IService)​

Retrieve the first IService from the ActiveServices that meets the selected type and name.

public bool TryGetServiceByName(Type interfaceType, string serviceName, out IService serviceInstance)

Parameters​

interfaceType Type

Interface type of the service being requested.

serviceName string

Name of the specific service.

serviceInstance IService

return parameter of the function.

Returns​

bool

TryGetServiceCached<T>(out T)​

Retrieve a IService from the ActiveSystems.

public bool TryGetServiceCached<T>(out T service) where T : IService

Parameters​

service T

The instance of the Service class that is registered.

Returns​

bool

Returns true if the IService was found, otherwise false.

Type Parameters​

T

The interface type for the Service to be retrieved.

TryGetServiceProfile<TService, TProfile>(out TProfile, BaseServiceProfile<IService>)​

Try to get the TProfile of the TService

public bool TryGetServiceProfile<TService, TProfile>(out TProfile profile, BaseServiceProfile<IService> rootProfile = null) where TService : IService where TProfile : BaseProfile

Parameters​

profile TProfile

The profile instance.

rootProfile BaseServiceProfile<IService>

Optional root profile reference.

Returns​

bool

True if a TService type is matched and a valid TProfile is found, otherwise false.

Type Parameters​

TService

TProfile

TryGetServices<T>(Type, string, ref List<T>)​

Retrieve all services from the active service registry for a given type and name

public bool TryGetServices<T>(Type interfaceType, string serviceName, ref List<T> services) where T : IService

Parameters​

interfaceType Type

The interface type for the Service to be retrieved. Storage Service.

serviceName string

Name of the specific service

services List<T>

Returns​

bool

An array of services that meet the search criteria

Type Parameters​

T

TryRegisterService<T>(IService)​

Add a service instance to the Service Manager active service registry.

public bool TryRegisterService<T>(IService serviceInstance) where T : IService

Parameters​

serviceInstance IService

Instance of the IService to register.

Returns​

bool

True, if the service was successfully registered.

Type Parameters​

T

The interface type for the IService to be registered.

TryRegisterService(Type, IService)​

Service registration.

public bool TryRegisterService(Type interfaceType, IService serviceInstance)

Parameters​

interfaceType Type

The interface type for the IService to be registered.

serviceInstance IService

Instance of the IService to register.

Returns​

bool

True if registration is successful, false otherwise.

TryRegisterServiceConfigurations<T>(IServiceConfiguration<T>[])​

Registers all the IServices defined in the provided configuration collection.

public bool TryRegisterServiceConfigurations<T>(IServiceConfiguration<T>[] configurations) where T : IService

Parameters​

configurations IServiceConfiguration<T>[]

The list of IServiceConfiguration%601s.

Returns​

bool

True, if all configurations successfully created and registered their services.

Type Parameters​

T

The interface type for the IService to be registered.

TryRegisterServiceModuleConfigurations<T>(IServiceConfiguration<T>[], IService)​

Registers all the IServiceModules defined in the provided configuration collection.

public bool TryRegisterServiceModuleConfigurations<T>(IServiceConfiguration<T>[] configurations, IService serviceParent) where T : IServiceModule

Parameters​

configurations IServiceConfiguration<T>[]

The list of IServiceConfiguration%601s.

serviceParent IService

The IService that the IServiceModule will be assigned to.

Returns​

bool

True, if all configurations successfully created and registered their service modules.

Type Parameters​

T

The interface type for the IServiceModule to be registered.

TryUnRegisterServiceConfigurations<T>(IServiceConfiguration<T>[])​

Removed all the IServices from active the active runtime, defined in the provided configuration collection.

public bool TryUnRegisterServiceConfigurations<T>(IServiceConfiguration<T>[] configurations) where T : IService

Parameters​

configurations IServiceConfiguration<T>[]

The list of IServiceConfiguration%601s.

Returns​

bool

True, if all active instances have been successfully removed.

Type Parameters​

T

The interface type for the IService to be removed.

TryUnregisterService<T>(T)​

Removes a specific service with the provided name.

public bool TryUnregisterService<T>(T serviceInstance) where T : IService

Parameters​

serviceInstance T

The instance of the IService to remove.

Returns​

bool

Type Parameters​

T

TryUnregisterServicesOfType<T>()​

Remove all services from the Service Manager active service registry for a given type

public bool TryUnregisterServicesOfType<T>() where T : IService

Returns​

bool

Type Parameters​

T

UnloadServicesForScene(string)​

Unload services for a specific scene.

public void UnloadServicesForScene(string sceneName)

Parameters​

sceneName string

The scene for which to unload the services for.

WaitUntilInitializedAsync(float, string)​

Waits for the ServiceManager to initialize until timeout seconds have passed or IsActiveAndInitialized.

public static ValueTask WaitUntilInitializedAsync(float timeout = 10, string sceneName = null)

Parameters​

timeout float

Time to wait in seconds for IsActiveAndInitialized to become true.

sceneName string

An optional scene name. If set, will wait for sceneName services to initialize as well.

Returns​

ValueTask

WaitUntilInitializedAsync(float)​

Waits for the ServiceManager to initialize until timeout seconds have passed or IsActiveAndInitialized.

public static ValueTask WaitUntilInitializedAsync(float timeout)

Parameters​

timeout float

Time to wait in seconds for IsActiveAndInitialized to become true.

Returns​

ValueTask

WaitUntilInitializedAsync(string)​

Waits for the ServiceManager to initialize until defaultInitializationTimeout seconds have passed or IsActiveAndInitialized and all services for sceneName are initialized.

public static ValueTask WaitUntilInitializedAsync(string sceneName)

Parameters​

sceneName string

Will wait for sceneName services to initialize.

Returns​

ValueTask

Initialized​

The ServiceManager Instance has finished initialzing.

public static event Action<ServiceManager> Initialized

Event Type​

Action<ServiceManager>