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 Foo
s 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.
精彩评论