2025-05-21 12:45:52 +03:00
2025-05-18 16:41:48 +03:00
2025-05-19 16:11:41 +03:00
2025-05-02 11:41:18 +03:00
2025-05-19 16:11:41 +03:00
2025-05-19 10:12:32 +03:00
2025-05-16 16:43:23 +03:00
2020-06-27 06:05:03 +03:00
2025-05-19 16:11:41 +03:00
2025-05-19 16:11:41 +03:00
2025-05-19 16:11:41 +03:00
2025-05-19 16:12:45 +03:00

CherryPick Workspace

CherryPick Workspace is a modular ecosystem for declarative, type-safe dependency injection in Dart and Flutter applications. It brings together core dependency management, advanced code generation, annotation-driven DI, and seamless Flutter integration for stateful, testable, and scalable app architectures.


Overview

CherryPick Workspace includes the following packages:

  • cherrypick Core dependency injection engine for Dart: bindings, modules, scopes, and runtime resolution.
  • cherrypick_annotations Lightweight annotation library (@module, @singleton, @named) for injectable code and code generation.
  • cherrypick_generator Code generator that produces DI module boilerplate from annotated Dart classes, using cherrypick_annotations.
  • cherrypick_flutter Flutter integration providing scope-aware dependency resolution via CherryPickProvider in the widget tree.

Repository Structure

  • cherrypick/ Core DI library (bindings, modules, scopes, runtime resolution)
  • cherrypick_annotations/ DI annotations for use with generators
  • cherrypick_generator/ Source-gen implementation for codegen of modules and bindings
  • cherrypick_flutter/ Flutter tools to provide DI in widget subtree via CherryPickProvider
  • examples/ Sample Flutter projects demonstrating patterns

Quick Start Guide

Installation

Add the desired packages to your pubspec.yaml (pick what you need):

dependencies:
  cherrypick: ^latest
  cherrypick_annotations: ^latest
  cherrypick_flutter: ^latest

dev_dependencies:
  cherrypick_generator: ^latest
  build_runner: ^latest

Run flutter pub get or dart pub get to fetch dependencies.


Usage

Core DI (cherrypick)

  • Bind dependencies:

    Binding<String>().toInstance("hello world");
    Binding<ApiClient>().toProvide(() => ApiClientImpl()).singleton();
    
  • Module definition:

    class AppModule extends Module {
      @override
      void builder(Scope currentScope) {
        bind<ApiClient>().toInstance(ApiClientMock());
      }
    }
    
  • Scope management:

    final rootScope = CherryPick.openRootScope();
    rootScope.installModules([AppModule()]);
    final client = rootScope.resolve<ApiClient>();
    

    You can create sub-scopes for feature isolation as needed:

    final featureScope = rootScope.openSubScope("feature");
    featureScope.installModules([FeatureModule()]);
    

Annotation & Code Generation (cherrypick_annotations, cherrypick_generator)

  • Annotate your DI modules:

    import 'package:cherrypick_annotations/cherrypick_annotations.dart';
    import 'package:cherrypick/cherrypick.dart';
    
    part 'app_module.cherrypick.g.dart';
    
    @module()
    abstract class AppModule extends Module {
      @singleton()
      ApiClient client() => ApiClientImpl();
    
      @named('apiBaseUrl')
      String baseUrl() => 'https://api.example.com';
    }
    
  • Generate code:

    Run:

    dart run build_runner build
    

    This will generate efficient registration code for your modules.

Flutter Integration (cherrypick_flutter)

  • Setup CherryPickProvider in your widget tree:

    void main() {
      runApp(
        CherryPickProvider(
          child: MyApp(),
        ),
      );
    }
    
  • Access DI scopes anywhere in Flutter:

    class MyWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        final cherryPick = CherryPickProvider.of(context);
        final rootScope = cherryPick.openRootScope();
    
        final repo = rootScope.resolve<MyRepository>();
        // use repo as needed...
    
        return Text('Dependency resolved!');
      }
    }
    

Features

  • Module-based configuration & composition
  • Flexible scopes (main/root/subscopes)
  • Named and singleton bindings
  • Async binding and parameter injection
  • Annotations (@module, @singleton, @named) for concise setup
  • Code generation for efficient, boilerplate-free DI modules
  • Seamless integration with Flutter via InheritedWidget (CherryPickProvider)

Example Projects

See the examples/ directory for real-world usage patterns, including synchronous, asynchronous, and named injection in Flutter apps.


Contributing

Community feedback, bug reports, and PRs are welcome! Please file issues and suggestions on the GitHub issues page.


License

CherryPick Workspace is licensed under the Apache License 2.0.


Description
CherryPick is a modular, open-source dependency injection ecosystem for Dart and Flutter
Readme Apache-2.0 2 MiB
Languages
Dart 96.2%
TypeScript 2.1%
Python 1.3%
CSS 0.4%