Skip to content

KernelAPI reference

Class ServiceRegistry

Namespace: MicroEngine.Kernel
Assembly: MicroEngine.Kernel.dll
Guide: Modules and the frame schedule

The engine’s services, one instance per type, registered by modules and read by whoever needs them. Typed and explicit: a service is found by the exact type it was registered as (no base classes, no interfaces it also implements), nothing is created on demand and nothing is discovered by reflection, so the registry works the same under trimming, NativeAOT and WebAssembly.

C#
public sealed class ServiceRegistry

Inheritance

object ← ServiceRegistry

Remarks

Read and written on the game’s thread; not thread-safe.

Constructors

ServiceRegistry()

C#
public ServiceRegistry()

Properties

Count

The number of registered services.

C#
public int Count { get; }

Property Value

int

Methods

Add<T>(T)

Registers instance as the service of type T.

C#
public void Add<T>(T instance) where T : class

Parameters

instance T

Type Parameters

T

Exceptions

ArgumentNullException

instance is null.

InvalidOperationException

A service of type T is already registered; use Replace``1 to change it.

Contains<T>()

Whether a service is registered as T.

C#
public bool Contains<T>() where T : class

Returns

bool

Type Parameters

T

Get<T>()

The service registered as T.

C#
public T Get<T>() where T : class

Returns

T

Type Parameters

T

Exceptions

InvalidOperationException

No service of type T is registered; the message names the type.

Remove<T>()

Removes the service registered as T; false when there was none.

C#
public bool Remove<T>() where T : class

Returns

bool

Type Parameters

T

Replace<T>(T)

Registers instance as the service of type T, in place of the one registered before, if any.

C#
public T? Replace<T>(T instance) where T : class

Parameters

instance T

Returns

T?

The service it replaced, or null when there was none.

Type Parameters

T

Exceptions

ArgumentNullException

instance is null.

TryGet<T>(out T?)

The service registered as T, if there is one.

C#
public bool TryGet<T>(out T? service) where T : class

Parameters

service T?

Returns

bool

Type Parameters

T