From 515d4ab2dfaf17f457ccdc5a5cb33faa2d2d1a57 Mon Sep 17 00:00:00 2001 From: Matt Ramotar Date: Wed, 26 Jun 2024 16:27:40 -0400 Subject: [PATCH 1/2] Update README.md --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 39d58050..debe74b6 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,37 @@ MainScope mainScope = new MainScopeImpl(); ChildScope childScope = mainScope.child(); ``` +## Dependency Resolution and Exposure + +Motif requires explicit dependency declarations to properly resolve and inject dependencies across scopes. When a parent scope needs to provide a dependency to a child scope, the dependency must be explicitly exposed using the `@Expose` annotation. + +For example: + +```kotlin +@motif.Scope +interface ParentScope { + @motif.Objects + class Objects { + fun provideImpl(): Impl { + return Impl() + } + + @Expose + fun provideApi(impl: Impl): Api { + return impl + } + } +} + +@motif.Scope +interface ChildScope { + @motif.Objects + abstract class Objects { + abstract fun api(): Api + } +} +``` + ## Root Scopes By extending `Creatable` you can specify exactly the dependencies you expect from the parent `Scope`. This allows From 4ee182ac1d0de19a72e3ac852750705425b218f1 Mon Sep 17 00:00:00 2001 From: Matt Ramotar Date: Wed, 26 Jun 2024 17:12:51 -0400 Subject: [PATCH 2/2] Update README.md --- README.md | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index debe74b6..47d754e5 100644 --- a/README.md +++ b/README.md @@ -164,12 +164,15 @@ interface MainScope { @motif.Objects class Objects { + DatabaseImpl databaseImpl() { + return new DatabaseImpl(); + } + // Motif requires explicit dependency declarations to properly resolve and inject dependencies across scopes @Expose - Database database() { - return new Database(); + Database database(DatabaseImpl impl) { + return impl; } - // ... } } @@ -202,37 +205,6 @@ MainScope mainScope = new MainScopeImpl(); ChildScope childScope = mainScope.child(); ``` -## Dependency Resolution and Exposure - -Motif requires explicit dependency declarations to properly resolve and inject dependencies across scopes. When a parent scope needs to provide a dependency to a child scope, the dependency must be explicitly exposed using the `@Expose` annotation. - -For example: - -```kotlin -@motif.Scope -interface ParentScope { - @motif.Objects - class Objects { - fun provideImpl(): Impl { - return Impl() - } - - @Expose - fun provideApi(impl: Impl): Api { - return impl - } - } -} - -@motif.Scope -interface ChildScope { - @motif.Objects - abstract class Objects { - abstract fun api(): Api - } -} -``` - ## Root Scopes By extending `Creatable` you can specify exactly the dependencies you expect from the parent `Scope`. This allows