ModuleOverrideScope class
Hierarchical tree of BinderOverrides that mirrors the module import graph.
Each node in the tree holds an optional selfOverrides callback for the owning module and a children map keyed by module Type for imported modules. This allows targeted overrides at any depth in the graph without modifying module code.
final scope = ModuleOverrideScope(
selfOverrides: (binder) {
binder.registerSingleton<ApiClient>(MockApiClient());
},
children: {
AuthModule: ModuleOverrideScope(
selfOverrides: (binder) {
binder.registerSingleton<AuthService>(FakeAuth());
},
),
},
);
final controller = ModuleController(
AppModule(),
overrideScopeTree: scope,
);
See also:
- BinderOverride for the callback signature.
ModuleControllerfor how the scope is applied during initialization.
Constructors
-
ModuleOverrideScope({BinderOverride? selfOverrides, Map<
Type, ModuleOverrideScope> children = const {}}) -
Creates a scope with optional
selfOverridesandchildrenmap.const
Properties
-
children
→ Map<
Type, ModuleOverrideScope> -
Per-module-type override scopes for imported (child) modules.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selfOverrides → BinderOverride?
-
Override callback applied to the owning module's Binder, or
nullif no overrides are needed at this level.final
Methods
-
childFor(
Type type) → ModuleOverrideScope? -
Returns the override scope for the imported module of the given
type, ornullif no overrides exist for that module. -
merge(
ModuleOverrideScope? other) → ModuleOverrideScope -
Deeply merges this scope with
other. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
withAdditionalOverride(
BinderOverride? override) → ModuleOverrideScope -
Returns a new scope whose selfOverrides is the composition of the
current callback followed by
override.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited