MVP with CDI; avoiding circular dependency

后端 未结 4 1689
别那么骄傲
别那么骄傲 2021-01-12 02:03

I try to build a Webapp with the MVP paradigm. Because I want the API to be clean and make everything easy testable I try to inject everything possible via Contructor Inject

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-12 02:12

    Try to move injection points from constructor to properties. So annotate properties with @Injection, not constructor. I think this way weld first creates instances of classes and only then injects dependencies. And replace your constructor with default.
    If you annotate constructor weld needs to have instance of View when on creating Presenter, but to create View he needs Presenter. With default constructor and annotated properties it can create both View and Presenter and only then inject them to each other.

提交回复
热议问题