Table of Contents

Class ModuleHost

Namespace
Shard.Server.Modules
Assembly
Shard.Server.dll

Orchestrates the module lifecycle: resolves the dependency-ordered load order, runs setup across all modules, waits for their dependency-aware preloads, starts them, and shuts them down in reverse order. Failures are isolated to the affected modules and their dependents. Each module receives its own event-scoped Shard.Server.Modules.ModuleContext.

public sealed class ModuleHost
Inheritance
ModuleHost
Inherited Members

Constructors

ModuleHost(EventBus, IServiceRegistry)

Orchestrates the module lifecycle: resolves the dependency-ordered load order, runs setup across all modules, waits for their dependency-aware preloads, starts them, and shuts them down in reverse order. Failures are isolated to the affected modules and their dependents. Each module receives its own event-scoped Shard.Server.Modules.ModuleContext.

public ModuleHost(EventBus events, IServiceRegistry services)

Parameters

events EventBus
services IServiceRegistry

Properties

Events

Gets the server event bus shared with module-scoped contexts.

public IEventBus Events { get; }

Property Value

IEventBus

Services

Gets the service registry shared by loaded modules.

public IServiceRegistry Services { get; }

Property Value

IServiceRegistry

Methods

Load(ModuleLoadPlan, CancellationToken)

Runs one previously resolved module load plan. Ownership transfers only after this host accepts the plan, and a plan cannot be accepted by a second host. The caller must dispose a plan that this host rejects; disposal is a no-op after a successful ownership claim.

public IReadOnlyList<IModule> Load(ModuleLoadPlan plan, CancellationToken cancellationToken = default)

Parameters

plan ModuleLoadPlan
cancellationToken CancellationToken

Returns

IReadOnlyList<IModule>

Load(IReadOnlyList<IModule>, CancellationToken)

Resolves the module load order and runs setup, preload, and start across all modules. Modules that fail a lifecycle phase are logged and excluded from subsequent phases. Modules whose dependencies fail are skipped. Ownership transfers when this host reserves the load attempt; a resolution failure therefore disposes the supplied modules. If reservation is rejected, ownership remains with the caller.

public IReadOnlyList<IModule> Load(IReadOnlyList<IModule> modules, CancellationToken cancellationToken = default)

Parameters

modules IReadOnlyList<IModule>
cancellationToken CancellationToken

Returns

IReadOnlyList<IModule>

Exceptions

ModuleLoadException

The filtered module set cannot be dependency-ordered.

OperationCanceledException

cancellationToken is canceled during preload.

ShutdownAsync()

Stops every module, waits for accepted work, then shuts modules down in reverse load order. Every caller receives the same completion after shutdown starts.

public Task ShutdownAsync()

Returns

Task