Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update API.md #385

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class LoggedInComponent: Component {
var gameComponent: GameComponent {
return GameComponent(parent: self)
}

func scoreSheetComponent(filter: ScoreFilter? = nil) {
return ScoreSheetComponent(parent: self, filter: filter)
}
}
```
Once this tree structure has been declared in code, the needle command-line tool uses it to decide where the dependencies for a particular Scope come from. The algorithm is simple, for each item that this scope requires, we walk up the chain of parents. The **nearest parent** that is able to provide an item (we match both the name and the type of the variable declared in the dependency protocol), is the one we fetch that property from.
Expand All @@ -125,11 +129,11 @@ Since the root of a DI tree does not have a parent component, we bootstrap the r
```swift
let rootComponent = RootComponent()

class RootComponent: NeedleFoundation.RootComponent {
class RootComponent: BootstrapComponent {
/// Root component code...
}
```
Notice the `RootComponent` does not need to specify any dependency protocol by inheriting from `NeedleFoundation.RootComponent`. Root of a DI graph has no parent to acquire dependencies from anyways.
Notice the `RootComponent` does not need to specify any dependency protocol by inheriting from `BootstrapComponent`. Root of a DI graph has no parent to acquire dependencies from anyways.

Since we know `root` does not have any parents, in application code, we can simply invoke `RootComponent()` to instantiate the root scope.

Expand Down