IBinder mixin
Mixin for declaring dependency injection bindings of a module.
A IBinder defines what services or dependencies a module provides and what other modules it depends on. This separates the concern of dependency injection from routing, ensuring a clear division of responsibilities inside a Module.
Responsibilities
- Declares the bindings (services, controllers, repositories, etc.) that this module contributes to the global dependency injection container.
- Specifies imported modules, enabling modular composition where one module can depend on and reuse the bindings of others.
- Ensures that imports are processed recursively before the current module’s own bindings are registered, avoiding missing dependencies.
Behavior
- By default, binds is a no-op and imports returns an empty list, meaning the module has no dependencies and provides no bindings.
- Subclasses/modules override binds to register their dependencies
using the GetIt instance (accessible via
GetIt.instanceor through theigetter in Module). - The Modugo framework ensures that each module’s binds is executed at most once per module type, even if imported by multiple modules.
Example
final class AuthModule with IBinder {
@override
void binds() {
final i = GetIt.instance;
i.registerLazySingleton<AuthRepository>(
() => AuthRepositoryImpl(i.get<ApiClient>()),
);
}
@override
List<IBinder> imports() => [CoreModule()];
}
In this example, the AuthModule provides an AuthRepository binding
and declares a dependency on CoreModule to reuse its bindings.
See also:
- Mixin applications
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
binds(
) → void - Registers all dependency injection bindings for this module.
-
imports(
) → List< IBinder> - List of imported modules that this module depends on.
-
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