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.
public sealed class ServiceRegistryInheritance
Remarks
Read and written on the game’s thread; not thread-safe.
Constructors
ServiceRegistry()
public ServiceRegistry()Properties
Count
The number of registered services.
public int Count { get; }Property Value
Methods
Add<T>(T)
Registers instance as the service of type T.
public void Add<T>(T instance) where T : classParameters
instance T
Type Parameters
T
Exceptions
instance is null.
A service of type T is already registered; use Replace``1 to change it.
Contains<T>()
Whether a service is registered as T.
public bool Contains<T>() where T : classReturns
Type Parameters
T
Get<T>()
The service registered as T.
public T Get<T>() where T : classReturns
T
Type Parameters
T
Exceptions
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.
public bool Remove<T>() where T : classReturns
Type Parameters
T
Replace<T>(T)
Registers instance as the service of type T, in place of the one registered before, if any.
public T? Replace<T>(T instance) where T : classParameters
instance T
Returns
T?
The service it replaced, or null when there was none.
Type Parameters
T
Exceptions
instance is null.
TryGet<T>(out T?)
The service registered as T, if there is one.
public bool TryGet<T>(out T? service) where T : classParameters
service T?
Returns
Type Parameters
T