匕首子组件构建器可以设置数据(模块除外)吗?

Can dagger subcomponent builder set data (other than module)?

参考Dagger 2 Subcomponent Documentation,示例代码表明

@Singleton
class RequestRouter {
  @Inject RequestRouter(
      Provider<RequestComponent.Builder> requestComponentProvider) {}

  void dataReceived(Data data) {
    RequestComponent requestComponent =
        requestComponentProvider.get()
            .data(data)  // Data could be set here?
            .build();
    requestComponent.requestHandler()
        .writeResponse(200, "hello, world");
  }
}

据我了解,Subcomponent.Builder 只能根据 https://dagger.dev/api/2.10/dagger/Component.Builder.html

设置模块和构建

只是想知道我们如何将 Data 传递给构建器?

请务必阅读 latest JavaDoc2.10 相当(2017 年 3 月 20 日)。我相信 @BindsInstance 是在 Dagger 2.12 中引入的:

  • [...]
  • There may be setter methods annotated with @BindsInstance. These methods bind the instance passed to them within the component. See @BindsInstance for more information.
  • [...]

您可以向您的组件添加各种绑定,例如

@BindsInstance
Builder foo(Foo foo); // allow binding of some `Foo`