|
| 1 | +/* |
| 2 | + * Copyright (C) 2006 Google Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +/* |
| 18 | + * Adapted from Guice version 4.2.2 as available at |
| 19 | + * https://search.maven.org/classic/remotecontent?filepath=com/google/inject/guice/4.2.2/guice-4.2.2-sources.jar |
| 20 | + * Only relevant stubs of this file have been retained for test purposes. |
| 21 | + */ |
| 22 | + |
| 23 | +package com.google.inject; |
| 24 | + |
| 25 | +/** |
| 26 | + * An object capable of providing instances of type {@code T}. Providers are used in numerous ways |
| 27 | + * by Guice: |
| 28 | + * |
| 29 | + * <ul> |
| 30 | + * <li>When the default means for obtaining instances (an injectable or parameterless constructor) |
| 31 | + * is insufficient for a particular binding, the module can specify a custom {@code Provider} |
| 32 | + * instead, to control exactly how Guice creates or obtains instances for the binding. |
| 33 | + * <li>An implementation class may always choose to have a {@code Provider<T>} instance injected, |
| 34 | + * rather than having a {@code T} injected directly. This may give you access to multiple |
| 35 | + * instances, instances you wish to safely mutate and discard, instances which are out of scope |
| 36 | + * (e.g. using a {@code @RequestScoped} object from within a {@code @SessionScoped} object), or |
| 37 | + * instances that will be initialized lazily. |
| 38 | + * <li>A custom {@link Scope} is implemented as a decorator of {@code Provider<T>}, which decides |
| 39 | + * when to delegate to the backing provider and when to provide the instance some other way. |
| 40 | + * <li>The {@link Injector} offers access to the {@code Provider<T>} it uses to fulfill requests for |
| 41 | + * a given key, via the {@link Injector#getProvider} methods. |
| 42 | + * </ul> |
| 43 | + * |
| 44 | + * @param <T> the type of object this provides |
| 45 | + * @author [email protected] (Bob Lee) |
| 46 | + */ |
| 47 | +public interface Provider<T> { |
| 48 | + |
| 49 | + /** |
| 50 | + * Provides an instance of {@code T}. |
| 51 | + * |
| 52 | + * @throws OutOfScopeException when an attempt is made to access a scoped object while the scope |
| 53 | + * in question is not currently active |
| 54 | + * @throws ProvisionException if an instance cannot be provided. Such exceptions include messages |
| 55 | + * and throwables to describe why provision failed. |
| 56 | + */ |
| 57 | + T get(); |
| 58 | +} |
0 commit comments