Guice assisted injection deeper down the dependency hierarchy

前端 未结 2 2022
南旧
南旧 2020-11-30 12:40

I want to conduct a chain of processing elements and wire them together via Guice. Let\'s assume the following path:

  • interface A implemented by
2条回答
  •  天涯浪人
    2020-11-30 13:21

    I see three options. They depend on how often you change the input for A .

    1) Bind input as a constant in your module. This works only, if you know that value before you create the Injector and never want to change the value. See bindConstant

    2) Use a private submodule which binds either A or the value for input inside that module. Basically you can have two or three instance graphs with different value. See newPrivateBinder.

    3) Use a Scope ala RequestScope, SessionScope, ... This way you can change the input often but you must enter/leave the scope at some point to be defined. See Custom Scopes for an example.

提交回复
热议问题