Module class abstract

Represents a DI module—a reusable group of dependency bindings.

Extend Module to declaratively group related Binding definitions, then install your module(s) into a Scope for dependency resolution.

Modules make it easier to organize your DI configuration for features, layers, infrastructure, or integration, and support modular app architecture.

Usage example:

class AppModule extends Module {
  @override
  void builder(Scope currentScope) {
    bind<NetworkService>().toProvide(() => NetworkService());
    bind<AuthService>().toProvide(() => AuthService(currentScope.resolve<NetworkService>()));
    bind<Config>().toInstance(Config.dev());
  }
}

// Installing the module into the root DI scope:
final rootScope = CherryPick.openRootScope();
rootScope.installModules([AppModule()]);

Combine several modules and submodules to implement scalable architectures.

Constructors

Module()

Properties

bindingSet Set<Binding>
Returns the set of all Binding instances registered in this module.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

bind<T>() Binding<T>
Begins the declaration of a new binding within this module.
builder(Scope currentScope) → void
Abstract method where all dependency bindings are registered.
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