Binding Instances问题的Dagger官方示例

Dagger official example for Binding Instances problem

我是 dagger 新手。我一直在关注 https://dagger.dev/dev-guide/ 上的文档,当涉及到绑定实例部分时,这里提供了示例:

@Component(modules = AppModule.class)
interface AppComponent {
  App app();

  @Component.Builder
  interface Builder {
    @BindsInstance Builder userName(@UserName String userName);
    AppComponent build();
  }
}

我的问题是这个 @UserName 来自哪里? 导致此代码块的解释是

Perhaps your app takes a single argument representing the user’s name that you’d like to inject as @UserName String. You can add a method annotated @BindsInstance to the component builder to allow that instance to be injected in the component.

我无法推理。任何人都可以解释一下吗?

谢谢

本例中的

@Username限定符。如果你要 use/inject 一个普通的 String 它会把事情搞得一团糟(因为 String 是一种有点常见的类型),但与限定符 @Username String 结合使用成为唯一键。

@Named("foo") 是一个基本的限定符,您可以使用它,或者您可以创建自己的限定符——例如@Username