diff --git a/tutorial/01-setup.md b/tutorial/01-setup.md index 615fd684bc4..b046dd8ca1e 100644 --- a/tutorial/01-setup.md +++ b/tutorial/01-setup.md @@ -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(); } @@ -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() {} } ``` diff --git a/tutorial/04-depending-on-interface.md b/tutorial/04-depending-on-interface.md index 5b9cbfb3e9f..d0b2783b676 100644 --- a/tutorial/04-depending-on-interface.md +++ b/tutorial/04-depending-on-interface.md @@ -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`]: diff --git a/tutorial/10-deposit-after-login.md b/tutorial/10-deposit-after-login.md index 516bf317796..30102e0929f 100644 --- a/tutorial/10-deposit-after-login.md +++ b/tutorial/10-deposit-after-login.md @@ -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 @@ -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();