Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-ramotar authored Jun 26, 2024
1 parent 515d4ab commit 4ee182a
Showing 1 changed file with 6 additions and 34 deletions.
40 changes: 6 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

// ...
}
}
Expand Down Expand Up @@ -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<D>` you can specify exactly the dependencies you expect from the parent `Scope`. This allows
Expand Down

0 comments on commit 4ee182a

Please sign in to comment.