summaryrefslogtreecommitdiff
path: root/src/javax/inject/Provider.java
blob: ba1df61f487d7516443a04af9c23ca5499e2abac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package javax.inject;

/**
 * Provides instances of {@code T}. For any type {@code T} that can be
 * injected, you can also inject {@code Provider<T>}. Compared to injecting
 * {@code T} directly, injecting {@code Provider<T>} enables:
 *
 * <ul>
 *   <li>retrieving multiple instances.</li>
 *   <li>lazy or optional retrieval of an instance.</li>
 *   <li>breaking circular dependencies.</li>
 *   <li>abstracting scope so you can look up an instance in a smaller scope
 *      from an instance in a containing scope.</li>
 * </ul>
 *
 * <p>For example:
 *
 * <pre>
 *   class Car {
 *     &#064;Inject Car(Provider&lt;Seat> seatProvider) {
 *       Seat driver = seatProvider.get();
 *       Seat passenger = seatProvider.get();
 *       ...
 *     }
 *   }</pre>
 */
public interface Provider<T> {

    // TODO: Specify OutOfScopeException (or IllegalStateException) and
    //  ProvisionException?

    /**
     * Provides an instance of {@code T}.
     */
    T get();
}