Interface Provider<T>

All Known Subinterfaces:
Instance<T>, SeContainer
All Known Implementing Classes:
CDI

public interface Provider<T>
Provides instances of T. Typically implemented by an injector. For any type T that can be injected, you can also inject Provider<T>. Compared to injecting T directly, injecting Provider<T> enables:
  • retrieving multiple instances.
  • lazy or optional retrieval of an instance.
  • breaking circular dependencies.
  • abstracting scope so you can look up an instance in a smaller scope from an instance in a containing scope.

For example:

   class Car {
     @Inject Car(Provider<Seat> seatProvider) {
       Seat driver = seatProvider.get();
       Seat passenger = seatProvider.get();
       ...
     }
   }