fix: support passing params when resolving dependency recursively in …
CherryPick Workspace
Welcome to the CherryPick Workspace, a comprehensive suite for dependency management in Flutter applications. It consists of the cherrypick and cherrypick_flutter packages, designed to enhance modularity and testability by providing robust dependency and state management tools.
Overview
cherrypick: A Dart library offering core tools for dependency injection and management through modules and scopes.cherrypick_flutter: A Flutter-specific library facilitating access to the root scope via the context usingCherryPickProvider, simplifying state management within the widget tree.
Repository Structure
- Packages:
cherrypick: Core DI functionalities.cherrypick_flutter: Flutter integration for context-based root scope access.
Quick Start Guide
Installation
To add the packages to your project, include the dependencies in your pubspec.yaml:
dependencies:
cherrypick: any
cherrypick_flutter: any
Run flutter pub get to install the dependencies.
Usage
cherrypick
-
Binding Dependencies: Use
Bindingto set up dependencies.Binding<String>().toInstance("hello world"); Binding<String>().toProvide(() => "hello world").singleton(); -
Creating Modules: Define dependencies within a module.
class AppModule extends Module { @override void builder(Scope currentScope) { bind<ApiClient>().toInstance(ApiClientMock()); } } -
Managing Scopes: Control dependency lifecycles with scopes.
final rootScope = Cherrypick.openRootScope(); rootScope.installModules([AppModule()]); final apiClient = rootScope.resolve<ApiClient>();
cherrypick_flutter
-
CherryPickProvider: Wrap your widget tree to access the root scope via context.
void main() { runApp(CherryPickProvider( rootScope: yourRootScopeInstance, child: MyApp(), )); } -
Accessing Root Scope: Use
CherryPickProvider.of(context).rootScopeto interact with the root scope in your widgets.final rootScope = CherryPickProvider.of(context).rootScope;
Example Project
Check the example directory for a complete demonstration of implementing CherryPick Workspace in a Flutter app.
Features
- Dependency Binding and Resolution
- Custom Module Creation
- Root and Sub-Scopes
- Convenient Root Scope Access in Flutter
Contributing
We welcome contributions from the community. Feel free to open issues or submit pull requests with suggestions and enhancements.
License
This project is licensed under the Apache License 2.0. You may obtain a copy of the License at Apache License 2.0.