How to avoid having injector.createInstance() all over the place when using guice?

前端 未结 3 2026
故里飘歌
故里飘歌 2020-12-30 05:28

There\'s something I just don\'t get about guice: According to what I\'ve read so far, I\'m supposed to use the Injector only in my bootstrapping class (in a standalone appl

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 05:38

    In the abstract, I think the general idea is that if responding to user events is part of the capabilities of your application, then, well...

    BillingService billingService = injector.getInstance(BillingService.class);
    billingService.respondToUserEvent( event );
    

    I guess that might be a little abstract, but the basic idea is that you get from Guice your top-level application class. Judging from your question, I guess that maybe BillingService isn't your top-level class?

提交回复
热议问题