0

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 also get an instance of the Foo class through Gin (is that the case anyway for injection to take place)?

Thanks in advance

Tony BenBrahim
  • 7,040
  • 2
  • 36
  • 49

1 Answers1

1

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.

Daniel
  • 10,115
  • 3
  • 44
  • 62
  • Thanks. For me, the Gin tutorial got me started, but if you have never used DI, it is a bit rough on the edges, it seems to assume knowledge of Guice. I am trying to refactor a 600+ classes application, this is not going to be fun... – Tony BenBrahim Sep 27 '11 at 06:54
  • Yeah, I agree. I used Gin before Guice too, and found the same. Good luck with the refactor: your team will love it, even if you don't ;) . – Daniel Sep 27 '11 at 07:08