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| Parameter | Type | Description |
|---|---|---|
constructor | Func<T> | Function that creates the component. |
name | string | Optional 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)| Parameter | Type | Description |
|---|---|---|
constructor | Func<IAsyncInitializable> | Function that creates the component. |
name | string | Optional 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> SyncInitializableEventReceiversSyncInitializables
Sync components that are not classified as event receivers. Initialized after SyncInitializableEventReceivers.
public static readonly List<IInitializable> SyncInitializablesAsyncInitializables
Async components run concurrently by the orchestrator.
public static readonly List<IAsyncInitializable> AsyncInitializablesRegister (sync)
Adds a sync component to SyncInitializableEventReceivers or SyncInitializables, based on whether it implements IEventReceiver.
public static void Register(IInitializable e)| Parameter | Type | Description |
|---|---|---|
e | IInitializable | The 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)| Parameter | Type | Description |
|---|---|---|
e | IAsyncInitializable | The 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)| Parameter | Type | Description |
|---|---|---|
instance | object | The 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()