Skip to main content

ServiceRegistry

Namespace: MonineEngine.Core

Manager for engine services. Can also be used to implement custom services.

public static class ServiceRegistry

Inheritance ObjectServiceRegistry
Attributes NullableContextAttribute, NullableAttribute

Methods

Register<T>(T)

Registers a service with the given instance of the service. After a service is registered, the service instance can be retrieved and used anywhere.

public static T Register<T>(T service)

Type Parameters

T
The type of the service.

Parameters

service T
The service to register.

Returns

T
The registered service.

Exceptions

ArgumentNullException
The given service to register was null.

Replace<T>(T)

Replaces an already registered service of the given type with the given service instance. If the service has not been registered, it is instead just simply registered as normal.

public static T Replace<T>(T service)

Type Parameters

T
The type of the service to replace.

Parameters

service T
The service instance to use as a replacement.

Returns

T
The replacement instance.

Remarks:

WARNING - This method is intended for modders to inject custom logic into existing services, and most games will not need to use this themselves. If replacing an existing service, please ensure that overridden methods still do what the original service did with them. This can either be done by calling the base method, or by copying the logic of the overriden method from the source code.

Get<T>()

Retrieves a registered service instance.

public static T Get<T>()

Type Parameters

T
The type of service to retrieve.

Returns

T
If a service of the given type was found, the service; otherwise, null.

Exceptions

KeyNotFoundException
The service that was attempted to be retrieved has not been registered.

TryGet<T>(T&)

Attempts to retrieve a registered service instance.

public static bool TryGet<T>(T& service)

Type Parameters

T
The type of the service to retrieve.

Parameters

service T&
When this method returns, contains the service of the specified type, if found. Otherwise, contains null. This parameter must be passed uninitialized.

Returns

Boolean
If a service of the given type was found, true; otherwise, false.

Has<T>()

Checks if a service is registered.

public static bool Has<T>()

Type Parameters

T
The service to check.

Returns

Boolean
If the service has been registered and can be retrieved, true; otherwise, false.

Update(GameTime)

Updates all currently registered services.

public static void Update(GameTime gameTime)

Parameters

gameTime GameTime
A snapshot of the current time of the game in this update cycle.

Reset()

Disposes all services and clears the list of registered services.

public static void Reset()

Exceptions

TypeLoadException
Thrown if one of the registered services does NOT implement IService. This should be impossible, but is covered nonetheless.

Remarks:

IRendererService will be left alone, as it is required for all Scenes.

Events

ServiceRegistered

An event that gets called whenever a service is registered/replaced.

public static event EventHandler<ServiceRegisteredEventArgs> ServiceRegistered;