diff --git a/cherrypick/README.md b/cherrypick/README.md index ca4503d..8f5f3c3 100644 --- a/cherrypick/README.md +++ b/cherrypick/README.md @@ -223,50 +223,6 @@ await CherryPick.closeRootScope(); // awaits async disposal --- -### Automatic resource management (`Disposable`, `dispose`) - -CherryPick automatically manages the lifecycle of any object registered via DI that implements the `Disposable` interface. - -**Best practice:** -Always finish your work with `await CherryPick.closeRootScope()` (for the root scope) or `await scope.closeSubScope('key')` (for subscopes). -These methods will automatically await `dispose()` on all resolved objects (e.g., singletons) that implement `Disposable`, ensuring proper and complete resource cleanup—sync or async. - -Manual `await scope.dispose()` may be useful if you manually manage custom scopes. - -#### Example - -```dart -class MyService implements Disposable { - @override - FutureOr dispose() async { - // release resources, close streams, perform async shutdown, etc. - print('MyService disposed!'); - } -} - -final scope = openRootScope(); -scope.installModules([ - ModuleImpl(), -]); - -final service = scope.resolve(); - -// ... use service - -// Recommended completion: -await CherryPick.closeRootScope(); // will print: MyService disposed! - -// Or, to close and clean up a subscope and its resources: -await scope.closeSubScope('feature'); - -class ModuleImpl extends Module { - @override - void builder(Scope scope) { - bind().toProvide(() => MyService()).singleton(); - } -} -``` - #### Working with Subscopes ```dart