-
- All Implemented Interfaces:
-
javax.inject.Provider
public final class CacheableProvider<T extends Object> implements Provider<T>
We quite often need to inject not a dependency object itself but a wrapper around it in order to break circular dependency like
A -> B,B -> C,C -> A.Many popular dependency injection frameworks like Spring do full context resolve when an actual object needs to be retrieved. The benefit is that is something new is added to context later on, that is properly reflected. The problem is that that is usually such process is slow.
When we know that a provider is used as a singleton just to solve circular dependency, it's worth to cache the target decorated object on the first request and reuse it for all subsequent calls. This class facilitates that.
-
-
Constructor Summary
Constructors Constructor Description CacheableProvider(Function0<T> delegate)
-