Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 6 additions & 4 deletions tutorial/01-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ final class CommandRouter {

private Result invalidCommand(String input) {
System.out.println(
String.format("couldn't understand \"%s\". please
try again.", input));
String.format("couldn't understand \"%s\". please try again.",
input));
return Result.invalid();
}

Expand All @@ -105,15 +105,17 @@ final class CommandRouter {
Finally, we'll create a main method:

```java
class CommandLineAtm {
final class CommandLineAtm {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Scanner scanner = new Scanner(System.in, UTF_8);
CommandRouter commandRouter = new CommandRouter();

while (scanner.hasNextLine()) {
Result unused = commandRouter.route(scanner.nextLine());
}
}

private CommandLineAtm() {}
}
```

Expand Down
16 changes: 15 additions & 1 deletion tutorial/04-depending-on-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ CommandRouter(Command command) {
```

But now Dagger doesn't know how to get an instance of `Command`. If you try to
compile, Dagger reports an error. Since `Command` is an _interface_ and can't
compile, Dagger reports an error:

```
interface CommandRouterFactory {
^

[Dagger/MissingBinding] Command cannot be provided without an @Provides-annotated method.

Command is injected at
[CommandRouterFactory] CommandRouter(command)
CommandRouter is requested at
[CommandRouterFactory] CommandRouterFactory.router()
```

Since `Command` is an _interface_ and can't
have an [`@Inject`] constructor, we need to give Dagger more information.

To do that, we can write a method annotated with [`@Binds`]:
Expand Down
20 changes: 16 additions & 4 deletions tutorial/10-deposit-after-login.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ interface Command {
`CommandProcessor` is marked with [`@Singleton`] to ensure that only one
`CommandRouter` stack is created.

We can rename our [`@Component`] to `CommandProcessorFactory`.
Since we're changing from only creating a single `CommandRouter` at the root to
creating a `CommandProcessor`, we'll rename the component to match.
We can rename our root [`@Component`] from `CommandRouterFactory` to
`CommandProcessorFactory`, and have it provide our new `CommandProcessor`.

Now it looks like this:

```java
Expand Down Expand Up @@ -172,15 +176,23 @@ There are a few things that are happening here. Let's break it down:
_another component_ will make the [`@Subcomponent.Factory`] available there.
That's our bridge between the two components.

We need to include `UserCommandsRouter.InstallationModule` in our [`@Component`]
annotation:
Now that we've moved `UserCommandsModule` to the `UserCommandsRouter`
subcomponent, we need to remove it from the root `CommandProcessorFactory` and
install `UserCommandsRouter.InstallationModule` instead.

We do this because those commands should only be available after login. If they
were in the root component, they'd be available immediately. This also shows up
as a technical dependency: `DepositCommand` needs an `Account`, which is only
available in the subcomponent (which is itself created after login).

```java
@Singleton
@Component(
modules = {
...
LoginCommandModule.class,
HelloWorldModule.class,
UserCommandsRouter.InstallationModule.class,
SystemOutModule.class
})
interface CommandProcessorFactory {
CommandProcessor commandProcessor();
Expand Down
Loading