docs
Systems
Execution
InitializationSystem
Public API Reference

This reference lists the public and protected members defined in InitializationSystem. Private members are omitted. Members from dependency classes are not documented here.

InitializationManager

Namespace: SaffronLibrary.Prime.Systems.Initialization

Abstract MonoBehaviour that bootstraps the application's initialization sequence. Derived classes implement RegisterSystems and register components through SafeRegister.

RegisterSystems

Abstract hook called from Awake after the service locator is set up. Derived classes use it to register their components.

protected abstract void RegisterSystems()

SafeRegister (synchronous)

Constructs an IInitializable component with the supplied function and registers it with InitializationRegistry. Exceptions thrown during construction are caught and logged. The name is used in the log message and defaults to the type name of T.

protected void SafeRegister<T>(Func<T> constructor, string name = null) where T : IInitializable
ParameterTypeDescription
constructorFunc<T>Function that creates the component.
namestringOptional name for logging. Defaults to the name of T.

SafeRegister (asynchronous)

Constructs an IAsyncInitializable component with the supplied function and registers it. Construction exceptions are caught and logged. The name defaults to IAsyncInitializable.

protected void SafeRegister(Func<IAsyncInitializable> constructor, string name = null)
ParameterTypeDescription
constructorFunc<IAsyncInitializable>Function that creates the component.
namestringOptional name for logging. Defaults to IAsyncInitializable.

InitializationOrchestrator

Namespace: SaffronLibrary.Prime.Systems.Initialization

Plain class that runs the registered components. It is constructed and driven by InitializationManager. It is not a MonoBehaviour.

InitializeSyncSystems

Runs Init on each component in SyncInitializableEventReceivers, then on each component in SyncInitializables, in registration order. Exceptions from Init are not caught.

public void InitializeSyncSystems()

InitializeAsyncSystems

Takes a snapshot of AsyncInitializables and starts InitAsync on each one concurrently. Failures are logged per component. The returned task completes when all components have finished.

public Task InitializeAsyncSystems()

InitializationRegistry

Namespace: SaffronLibrary.Prime.Systems.Initialization

Static class that holds registered components until the orchestrator runs them, then is cleared.

SyncInitializableEventReceivers

Components intended to be initialized first. Populated by Register(IInitializable) when the component is classified as an event receiver.

public static readonly List<IInitializable> SyncInitializableEventReceivers

SyncInitializables

Sync components that are not classified as event receivers. Initialized after SyncInitializableEventReceivers.

public static readonly List<IInitializable> SyncInitializables

AsyncInitializables

Async components run concurrently by the orchestrator.

public static readonly List<IAsyncInitializable> AsyncInitializables

Register (sync)

Adds a sync component to SyncInitializableEventReceivers or SyncInitializables, based on whether it implements IEventReceiver.

public static void Register(IInitializable e)
ParameterTypeDescription
eIInitializableThe component to register. Must not be null.

Because a component implementing both interfaces would match both Register overloads, call RegisterInitializable for such objects instead of Register.

Register (async)

Adds an async component to AsyncInitializables.

public static void Register(IAsyncInitializable e)
ParameterTypeDescription
eIAsyncInitializableThe component to register.

RegisterInitializable

Registers an object with each initialization category it implements. An object implementing both IInitializable and IAsyncInitializable is added to both.

public static void RegisterInitializable(object instance)
ParameterTypeDescription
instanceobjectThe constructed component to register.

Clear

Removes all entries from all three lists. InitializationManager calls this after initialization completes.

public static void Clear()

IInitializable

Namespace: SaffronLibrary.Prime.Systems.Initialization.Interfaces

Contract for components that need synchronous setup during startup.

public interface IInitializable
{
    void Init();
}

Init

Called by the orchestrator during the sync phase.

void Init()

IAsyncInitializable

Namespace: SaffronLibrary.Prime.Systems.Initialization.Interfaces

Contract for components that need asynchronous setup, such as awaiting external resources. Runs after all sync initialization.

public interface IAsyncInitializable
{
    Task InitAsync();
}

InitAsync

Called by the orchestrator during the async phase. The returned task is awaited together with the other async components.

Task InitAsync()