DependencyProvider<AppState, AppAction, AppEnvironment> class
A type-based service locator for dependency injection.
Register dependencies by type and resolve them later. Optionally
configure an environmentBuilder and storeBuilder to wire up
the full application graph.
final provider = DependencyProvider()
..register<ApiClient>(ApiClient())
..register<Database>(Database());
final api = provider.resolve<ApiClient>();
Constructors
-
DependencyProvider({Map<
Type, dynamic> dependencies = const {}, AppEnvironment environmentBuilder(DependencyProvider<AppState, AppAction, AppEnvironment> provider)?, Store<AppState, AppAction> storeBuilder(AppEnvironment env)?}) - Creates a dependency provider.
Properties
-
dependencies
→ Map<
Type, dynamic> -
The registered dependency instances, keyed by type.
final
- environment → AppEnvironment
-
The application environment, built from
environmentBuilder.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
-
store
↔ Store<
AppState, AppAction> -
The application store, built from
storeBuilderif provided.latefinal
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
register<
T> (T dependency) → void -
Registers a
dependencyinstance under typeT. -
resolve<
T> () → T -
Resolves a dependency by type
T. -
resolveOrNull<
T> () → T? -
Resolves a dependency by type
T, returningnullif not found. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited