Lazy dependency access
Fields annotated with@Inject(lazy=true)
will be resolved after the whole dependency tree was resolved. This way, when injecting these fields, each of the required dependencies are already resolved.
Note that, these fields will be null
in the constructor. If you want to use these fields after initialization, check out the Service lifecycles
section in the Advanced usage
category.
@Service
class ServiceA {
@Inject(lazy = true)
ServiceB serviceB;
}
@Service
class ServiceB {
@Inject(lazy = true)
ServiceA serviceA;
}
Last updated