开发者

GWT/Gin creating class with @Inject annotation in constructor

Let's say I have a class

public class Foo{
   @Inject
   public Foo(MessageBus messageBus, SomeServiceAsync service){
      ...
   }
...

I have some doubt on how I would construct such a class, given that the constructor parameters are to be injected. Or must I somehow als开发者_StackOverflowo get an instance of the Foo class through Gin (is that the case anyway for injection to take place)?

Thanks in advance


Your assumption is correct. You must get all Foos from Gin if you want them to have their constuctors injected. To get a Foo from Gin, you need to either have it injected into something else, or use a Ginjector. Usually you'll get only one class' instances (or a small number of classes' instances) from a Ginjector, and rely on Gin to inject all of their dependencies, and their dependencies' dependencies, and so on. The Gin Tutorial is a great place to start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜