Class CacheableProvider

  • All Implemented Interfaces:
    jakarta.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.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      CacheableProvider(Function0<T> delegate)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      T get()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CacheableProvider

        CacheableProvider(Function0<T> delegate)