ModuleController class

Manages the full lifecycle of a single Module: dependency resolution, initialization, hot reload, and disposal.

The controller orchestrates the following sequence during initialize:

  1. Resolves and initializes all imported modules via GraphResolver.
  2. Validates Module.expects against available scopes.
  3. Calls Module.binds (private scope) and Module.exports (public scope).
  4. Applies any overrides to the binder.
  5. Calls Module.onInit for async setup.
final controller = ModuleController(AppModule());
await controller.initialize({});

// Access dependencies:
final service = controller.binder.get<MyService>();

// Dispose when done:
await controller.dispose();

See also:

  • Module for the lifecycle hooks.
  • GraphResolver for the import resolution algorithm.
  • ModuleOverrideScope for hierarchical dependency overrides.

Constructors

ModuleController(Module module, {Binder? binder, BinderFactory? binderFactory, void overrides(Binder)?, ModuleOverrideScope? overrideScopeTree, List<ModuleInterceptor> interceptors = const []})
Creates a controller for module with optional DI configuration.

Properties

binder Binder
The Binder that holds all dependency registrations for module.
final
currentStatus ModuleStatus
Return the most recent ModuleStatus of this controller.
no setter
hashCode int
The hash code for this object.
no setterinherited
importedControllers List<ModuleController>
References to the controllers of imported modules.
no setter
interceptors List<ModuleInterceptor>
Ordered list of ModuleInterceptors notified at each lifecycle event.
final
lastError Object?
Return the error captured during the last failed initialize call, or null if no error occurred.
no setter
module Module
The Module whose lifecycle this controller manages.
final
overrides → void Function(Binder)?
Optional callback applied to the Binder after binds/exports to override registrations (e.g. for testing or feature flags).
final
overrideScope ModuleOverrideScope?
Hierarchical override scope propagated to imported modules.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
status Stream<ModuleStatus>
Broadcast stream of ModuleStatus transitions.
no setter

Methods

configure(dynamic args) → void
Passes args to the module's Configurable.configure method.
dispose() Future<void>
Disposes the module, its Binder, and closes the status stream.
hotReload() → void
Re-runs Module.binds and Module.exports under RegistrationStrategy.preserveExisting to refresh factory closures without losing singleton state.
initialize(Map<ModuleRegistryKey, ModuleController> globalModuleRegistry, {Set<Type>? resolutionStack, Set<ModuleGraphNodeKey>? graphResolutionStack}) Future<void>
Runs the full initialization lifecycle for this module.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited