Hi, does anyone know how the @BindsOptionalOf anno...
# dagger
r
Hi, does anyone know how the @BindsOptionalOf annotation is supposed to work? Because in the dagger.dev ATM tutorial, at the last step it uses this annotation to bind an object that is part of the Subcomponent into an object that is part of the root component.
Copy code
@Module
public interface LoginCommandModule { // part of the root component
  ...

  @BindsOptionalOf
  Account optionalAccount();

}
Copy code
@Subcomponent(modules = ...)
@PerSession
public interface UserCommandsRouter {

    CommandRouter router();

    @Subcomponent.Factory
    interface Factory {
        UserCommandsRouter create(@BindsInstance Database.Account account);
    }

    @Module(subcomponents = UserCommandsRouter.class)
    interface InstallationModule { // Included in the RootComponent
    }

}
What would be the usages of the @BindsOptionalOf annotation besides checking if the subcomponent has already been initialized? And, if there are multiple subcomponents, which Account from which subcomponent would be selected in order to be used by the root component?