cherrypick
4.0.0, released 3 weeks ago by an unverified publisher
Flexible and lightweight dependency injection library for Dart and Flutter.
What it does
Cherrypick provides a system for registering, scoping, and resolving dependencies using modular bindings and hierarchical scopes. It supports singletons, lazy providers, asynchronous factories, and automatic resource cleanup for disposable dependencies.
AI-written summary of version 4.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You want hierarchical scopes and modular composition in your dependency injection setup.
- You need automatic resource cleanup via the Disposable interface.
- You want support for both manual configuration and annotation-based code generation.
Skip it when
- You prefer a heavily runtime-reflected DI container without module definitions.
- Your project uses an entirely different state management or service locator solution like get_it and you don't want to migrate.
Strengths
- Supports hierarchical subscopes and named instances.
- Automatic resource cleanup for Disposable dependencies.
- Both manual bindings and annotation-based code generation are supported.
Weaknesses
- Potential misuse of bindings inside modules (e.g., resolving types via toInstance during registration can cause errors).
- Requires careful lifecycle management of scopes and singletons.
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 1
Requires adding cherrypick to pubspec.yaml, and optionally cherrypick_annotations and cherrypick_generator with build_runner if using code generation.
import 'package:cherrypick/cherrypick.dart';
class AppModule extends Module {
@override
void builder(Scope currentScope) {
bind<ApiClient>().toInstance(ApiClientMock());
bind<String>().toProvide(() => "Hello, CherryPick!");
}
}
final rootScope = CherryPick.openRootScope();
rootScope.installModules([AppModule()]);
final greeting = rootScope.resolve<String>();
print(greeting);
await CherryPick.closeRootScope();Alternatives
Packages that do the same job and could replace cherrypick.
- get_it
A widely adopted, straightforward service locator for Dart and Flutter that doesn't require modules or code generation.
89Compare - injectable
Provides extensive annotation-based code generation built on top of get_it for automatic dependency injection wiring.
78Compare