Domanda

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

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top