<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sergey Penkovsky on Medium]]></title>
        <description><![CDATA[Stories by Sergey Penkovsky on Medium]]></description>
        <link>https://medium.com/@sergey.penkovsky?source=rss-f7b514155429------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7rhZ_yqDQsku2kpd.jpg</url>
            <title>Stories by Sergey Penkovsky on Medium</title>
            <link>https://medium.com/@sergey.penkovsky?source=rss-f7b514155429------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:37:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sergey.penkovsky/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ Release: CherryPick 3.x]]></title>
            <link>https://medium.com/@sergey.penkovsky/release-cherrypick-3-x-db6d4e4bbd8f?source=rss-f7b514155429------2</link>
            <guid isPermaLink="false">https://medium.com/p/db6d4e4bbd8f</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <dc:creator><![CDATA[Sergey Penkovsky]]></dc:creator>
            <pubDate>Wed, 10 Sep 2025 07:31:18 GMT</pubDate>
            <atom:updated>2025-09-10T07:31:18.434Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>CherryPick</strong> is a lightweight and modular DI framework for Dart and Flutter that handles dependency injection through strong typing, code generation, and dependency control.</p><p>Version <strong>3.x</strong> is out, bringing significant improvements for performance, safety, and developer experience.</p><p>—</p><p><strong>✨ What’s New in 3.x</strong></p><ul><li>⚡ <strong>O(1) Dependency Resolution</strong></li></ul><p>Thanks to Map indexing of bindings, resolving dependencies no longer depends on the scope size. Large projects will see a noticeable speed boost.</p><ul><li>🔄 <strong>Protection Against Circular Dependencies</strong></li></ul><p>Detect cycles automatically — within a single scope or across the entire hierarchy. When a cycle is found, an informative exception with the dependency chain is thrown.</p><ul><li>📝 <strong>Integration with Talker</strong></li></ul><p>Log all DI events (registration, creation, deletion, errors) in the console or UI for easy debugging and diagnostics.</p><ul><li>🧹 <strong>Automatic Resource Cleanup</strong></li></ul><p>Objects implementing `Disposable` are automatically disposed when a scope is closed.</p><ul><li>✅ <strong>Stabilized Declarative Approach</strong></li></ul><p>Annotation-based DI and code generation are now more reliable, making declarative DI simpler to adopt in projects.</p><p>—</p><p><strong>Resource Cleanup Example</strong></p><pre>class MyServiceWithSocket implements Disposable {<br>  @override<br>  Future&lt;void&gt; dispose() async {<br>    await socket.close();<br>    print(&#39;Socket closed!&#39;);<br>  }<br>}<br><br>class AppModule extends Module {<br>  @override<br>  void builder(Scope currentScope) {<br>    bind&lt;MyServiceWithSocket&gt;()<br>      .toProvide(() =&gt; MyServiceWithSocket())<br>      .singleton();<br>  }<br>}<br><br>scope.installModules([AppModule()]);<br><br>await CherryPick.closeRootScope(); // waits for async dispose to completedar</pre><p><strong>🔄 Circular Dependency Checking</strong></p><p>CherryPick 3.x introduces <strong>built-in cycle detection</strong> to catch circular dependencies early.</p><p><strong>Enable checking within a single scope:</strong></p><pre>final scope = CherryPick.openRootScope();<br>scope.enableCycleDetection();</pre><p><strong>Enable global checking across all scopes:</strong></p><pre>CherryPick.enableGlobalCycleDetection();<br>CherryPick.enableGlobalCrossScopeCycleDetection();<br>final rootScope = CherryPick.openRootScope();</pre><p><strong>Example of a circular dependency:</strong></p><pre>class UserService {<br>  final OrderService orderService;<br>  UserService(this.orderService);<br>}<br><br>class OrderService {<br>  final UserService userService;<br>  OrderService(this.userService);<br>}</pre><p>Registering them programmatically:</p><pre>class AppModule extends Module {<br>  @override<br>  void builder(Scope currentScope) {<br>    bind&lt;UserService&gt;().toProvide(() =&gt; UserService(scope.resolve()));<br>    bind&lt;OrderService&gt;().toProvide(() =&gt; OrderService(scope.resolve()));<br>  }<br>}<br><br>final scope = CherryPick.openRootScope()<br>  ..enableCycleDetection()<br>  ..installModules([AppModule()]);<br><br>scope.resolve&lt;UserService&gt;();</pre><p><strong>Result:</strong></p><pre>❌ Circular dependency detected for UserService<br>Dependency chain: UserService -&gt; OrderService -&gt; UserService</pre><p>Errors are detected immediately, avoiding runtime surprises.</p><p>—</p><p><strong>🖥 Integration with Talker</strong></p><p>CherryPick 3.x allows logging all DI events via [Talker](https://pub.dev/packages/talker): registration, object creation, deletion, and errors. Perfect for debugging or inspecting your dependency graph.</p><p><strong>Setup example:</strong></p><pre>final talker = Talker();<br>final observer = TalkerCherryPickObserver(talker);<br>CherryPick.setGlobalObserver(observer);</pre><p>Logs appear in console or UI:</p><pre>┌───────────────────────────────<br>│ [info] 9:41:33 | [scope opened][CherryPick] scope_1757054493089_7072<br>└───────────────────────────────<br>┌───────────────────────────────<br>│ [verbose] 9:41:33 | [diagnostic][CherryPick] Scope created: scope_1757054493089_7072<br>└───────────────────────────────</pre><p>—</p><p><strong>🏷 Declarative Approach with Annotations</strong></p><p>CherryPick supports <strong>declarative DI via annotations</strong>, reducing boilerplate and automatically generating modules and mixins.</p><p><strong>Declarative module example:</strong></p><pre>@module()<br>abstract class AppModule extends Module {<br>  @provide()<br>  @singleton()<br>  Api api() =&gt; Api();<br><br>  @provide()<br>  Repo repo(Api api) =&gt; Repo(api);<br>}</pre><p>Inject dependencies into widgets or services automatically:</p><pre>@injectable()<br>class MyScreen extends StatelessWidget with _$MyScreen {<br>  @inject()<br>  late final Repo repo;<br><br>  MyScreen() {<br>    _inject(this);<br>  }<br>}</pre><p>Choose your preferred style: <strong>programmatic (imperative) with explicit registration</strong> or <strong>declarative using annotations</strong>.</p><p>—</p><p><strong>👥 Who Will Benefit</strong></p><ul><li>Projects needing <strong>cycle-free dependency graphs</strong></li><li>Teams wanting to <strong>minimize manual DI code</strong> with declarative annotations</li><li>Applications requiring <strong>automatic resource cleanup</strong> (sockets, controllers, streams)</li></ul><p>—</p><p><strong>🔗 Useful Links</strong></p><ul><li>📦 Package: <a href="https://pub.dev/packages/cherrypick">https://pub.dev/packages/cherrypick</a></li><li>💻 Source Code: <a href="https://github.com/pese-git/cherrypick">https://github.com/pese-git/cherrypick</a></li><li>📖 Documentation: <a href="https://cherrypick-di.netlify.app/">https://cherrypick-di.netlify.app</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db6d4e4bbd8f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Complete Review of CherryPick DI for Dart and Flutter]]></title>
            <link>https://medium.com/@sergey.penkovsky/complete-review-of-cherrypick-di-for-dart-and-flutter-749f8223cbeb?source=rss-f7b514155429------2</link>
            <guid isPermaLink="false">https://medium.com/p/749f8223cbeb</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[cherrypick]]></category>
            <category><![CDATA[id]]></category>
            <category><![CDATA[dart]]></category>
            <category><![CDATA[flutter]]></category>
            <dc:creator><![CDATA[Sergey Penkovsky]]></dc:creator>
            <pubDate>Mon, 28 Jul 2025 10:52:47 GMT</pubDate>
            <atom:updated>2025-07-29T05:11:45.434Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wm-B_DtQju0f55HEwZx-lQ.jpeg" /></figure><h3>Dependency Injection with Annotations and Automatic Code Generation</h3><p><strong>CherryPick</strong> is a modern and powerful dependency injection (DI) solution for Dart and Flutter projects. It supports annotation-based configuration, code generation, async providers, named and parameterized bindings, and field injection.</p><blockquote><em>🛠️ Tools:</em></blockquote><ul><li><a href="https://pub.dev/packages/cherrypick">cherrypick</a> — runtime DI core</li><li><a href="https://pub.dev/packages/cherrypick_annotations">cherrypick_annotations</a> — DI annotations</li><li><a href="https://pub.dev/packages/cherrypick_generator">cherrypick_generator</a> — code generator</li></ul><h3>💡 Why CherryPick over other DI solutions?</h3><ul><li>📦 Simple declarative API for registering and resolving dependencies</li><li>⚡️ Full support for both sync and async providers</li><li>🧩 DI via annotations + code generation</li><li>🏷️ Named bindings for multiple implementations</li><li>🏭 Parameterized bindings for runtime factories</li><li>🌲 Flexible scope system for hierarchical dependency isolation</li><li>🕹️ Optional resolution with tryResolve()</li><li>🐞 Clean compile-time errors for misconfigurations</li></ul><h3>🔧 Core Concepts of CherryPick</h3><h3>Dependency Registration</h3><pre>bind&lt;MyService&gt;().toProvide(() =&gt; MyServiceImpl());<br>bind&lt;MyRepository&gt;().toProvideAsync(() async =&gt; await initRepo());<br>bind&lt;UserService&gt;().toProvideWithParams((id) =&gt; UserService(id));</pre><ul><li>toProvide: sync factory</li><li>toProvideAsync: async factory</li><li>toProvideWithParams: factory with runtime parameters</li><li>toInstance: use existing object</li><li>toInstanceAsync: use already-started async dependency</li></ul><h3>Singleton Scope</h3><pre>bind&lt;MyApi&gt;().toProvide(() =&gt; MyApi()).singleton();</pre><p>By default, dependencies are not singletons unless .singleton() is used.</p><h3>🏷️ Named Bindings</h3><p>Register different implementations under specific names:</p><pre>bind&lt;ApiClient&gt;().toProvide(() =&gt; ApiClientProd()).withName(&#39;prod&#39;);<br>bind&lt;ApiClient&gt;().toProvide(() =&gt; ApiClientMock()).withName(&#39;mock&#39;);</pre><pre>final api = scope.resolve&lt;ApiClient&gt;(named: &#39;mock&#39;);</pre><h3>🏭 Parameterized Bindings</h3><pre>bind&lt;UserService&gt;().toProvideWithParams((userId) =&gt; UserService(userId));<br>final userService = scope.resolve&lt;UserService&gt;(params: &#39;123&#39;);</pre><h3>🌐 Scope Management</h3><p>CherryPick supports scope hierarchy for better modularization.</p><pre>final rootScope = CherryPick.openRootScope();<br>final profileScope = rootScope.openSubScope(&#39;profile&#39;);</pre><p>Open scopes by name:</p><pre>final scope = CherryPick.openScope(scopeName: &#39;profile.settings&#39;);</pre><p>Use custom separators:</p><pre>final scope = CherryPick.openScope(<br>  scopeName: &#39;project&gt;&gt;dev&gt;&gt;api&#39;,<br>  separator: &#39;&gt;&gt;&#39;,<br>);</pre><p>Close scopes:</p><pre>CherryPick.closeScope(scopeName: &#39;profile.settings&#39;);</pre><h3>🛡️ Safe Dependency Resolution</h3><p>Use tryResolve() or tryResolveAsync() to avoid exceptions when resolving optional services:</p><pre>final service = scope.tryResolve&lt;OptionalService&gt;();</pre><h3>✨ Dependency Injection via Annotations</h3><p>CherryPick supports annotations for clean and declarative DI setup.</p><p>Annotations List:</p><ol><li><strong>@module</strong><br> ▸ Purpose: DI module<br> ▸ Where to use: Classes</li><li><strong>@singleton</strong><br> ▸ Purpose: Singleton<br> ▸ Where to use: Module methods</li><li><strong>@instance</strong><br> ▸ Purpose: New object<br> ▸ Where to use: Module methods</li><li><strong>@provide</strong><br> ▸ Purpose: Provider<br> ▸ Where to use: Methods (with DI params)</li><li><strong>@named</strong><br> ▸ Purpose: Named binding<br> ▸ Where to use: Method argument / Class fields</li><li><strong>@params</strong><br> ▸ Purpose: Parameter passing<br> ▸ Where to use: Provider argument</li><li><strong>@injectable</strong><br> ▸ Purpose: Field injection support<br> ▸ Where to use: Classes</li><li><strong>@inject</strong><br> ▸ Purpose: Auto-injection<br> ▸ Where to use: Class fields</li><li><strong>@scope</strong><br> ▸ Purpose: Scope / realm<br> ▸ Where to use: Class fields</li></ol><h3>Module Example</h3><pre>@module()<br>abstract class AppModule extends Module {<br>  @singleton()<br>  @provide()<br>  ApiClient apiClient() =&gt; ApiClient();<br><br>  @provide()<br>  UserService userService(ApiClient api) =&gt; UserService(api);<br><br>  @singleton()<br>  @provide()<br>  @named(&#39;mock&#39;)<br>  ApiClient mockApiClient() =&gt; ApiClientMock();<br>}</pre><p>Generated code:</p><pre>class $AppModule extends AppModule {<br>  @override<br>  void builder(Scope currentScope) {<br>    bind&lt;ApiClient&gt;().toProvide(() =&gt; apiClient()).singleton();<br>    bind&lt;UserService&gt;().toProvide(() =&gt; userService(currentScope.resolve&lt;ApiClient&gt;()));<br>    bind&lt;ApiClient&gt;().toProvide(() =&gt; mockApiClient()).withName(&#39;mock&#39;).singleton();<br>  }<br>}</pre><h3>Field Injection Example</h3><pre>@injectable()<br>class ProfileBloc with _$ProfileBloc {<br>  @inject()<br>  late final AuthService auth;<br><br>  @inject()<br>  @named(&#39;admin&#39;)<br>  late final UserService adminUser;<br>  ProfileBloc() {<br>    _inject(this); // auto-injected<br>  }<br>}</pre><p>Generated mixin:</p><pre>mixin $ProfileBloc {<br>  @override<br>  void _inject(ProfileBloc instance) {<br>    instance.auth = CherryPick.openRootScope().resolve&lt;AuthService&gt;();<br>    instance.adminUser = CherryPick.openRootScope().resolve&lt;UserService&gt;(named: &#39;admin&#39;);<br>  }<br>}</pre><h3>🧵 Async Dependencies</h3><pre>bind&lt;RemoteConfig&gt;().toProvideAsync(() async =&gt; await RemoteConfig.load());<br><br>final config = await scope.resolveAsync&lt;RemoteConfig&gt;();</pre><h3>🧪 Validation &amp; Diagnostics</h3><ul><li>Compile-time errors for invalid annotations</li><li>Codegen helps avoid runtime surprises</li><li>Improves confidence and developer experience</li></ul><h3>🧩 Flutter Integration: cherrypick_flutter</h3><p>Use CherryPickProvider widget to access DI scopes inside the widget tree.</p><pre>void main() {<br>  runApp(<br>    CherryPickProvider(<br>      child: MyApp(),<br>    ),<br>  );<br>}<br><br>class MyApp extends StatelessWidget {<br>  @override<br>  Widget build(BuildContext context) {<br>    final rootScope = CherryPickProvider.of(context).openRootScope();<br>    return MaterialApp(<br>      home: Scaffold(<br>        body: Center(<br>          child: Text(<br>            rootScope.resolve&lt;AppService&gt;().getStatus(),<br>          ),<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><h3>🖥️ Not Just for Flutter!</h3><p>CherryPick works in CLI apps, servers, and microservices — no Flutter required.</p><h3>🚀 Quick Start</h3><p>Add dependencies to pubspec.yaml:</p><pre>environment:<br>  sdk: ^3.5.2<br><br>dependencies:<br>  cherrypick: ^2.2.0<br>  cherrypick_annotations: ^1.1.0<br><br>dev_dependencies:<br>  build_runner: 2.4.15<br>  cherrypick_generator: ^1.1.0</pre><p>Annotate your modules</p><p>Run codegen:</p><pre>dart run build_runner build --delete-conflicting-outputs</pre><p>Enjoy zero-boilerplate DI!!!</p><h3>✅ Conclusion</h3><p><strong>CherryPick</strong> offers a clean, scalable, and modern approach to DI in Dart and Flutter. With annotation-based modules, async and named bindings, scopes, and field injection, it’s a powerful tool for both small and enterprise-grade apps.</p><h3>🔗 Useful Links</h3><ul><li><a href="https://pub.dev/packages/cherrypick">cherrypick</a></li><li><a href="https://pub.dev/packages/cherrypick_annotations">cherrypick_annotations</a></li><li><a href="https://pub.dev/packages/cherrypick_generator">cherrypick_generator</a></li><li><a href="https://github.com/pese-git/cherrypick">GitHub repository</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=749f8223cbeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>