Package org.elasticsearch.common.inject
Interface Provider<T>
- Type Parameters:
T
- the type of object this provides
- All Known Subinterfaces:
AnalyzerProvider<T>
,ProviderWithDependencies<T>
- All Known Implementing Classes:
AbstractIndexAnalyzerProvider
,CustomAnalyzerProvider
,CustomNormalizerProvider
,FactoryProvider
,KeywordAnalyzerProvider
,LowercaseNormalizerProvider
,MapBinder.RealMapBinder.MapBinderProviderWithDependencies
,Multibinder.RealMultibinder
,PreBuiltAnalyzerProvider
,ProviderLookup.ProviderImpl
,ProviderMethod
,SimpleAnalyzerProvider
,StandardAnalyzerProvider
,StopAnalyzerProvider
,WhitespaceAnalyzerProvider
public interface Provider<T>
An object capable of providing instances of type
T
. Providers are used in numerous ways
by Guice:
- When the default means for obtaining instances (an injectable or parameterless constructor)
is insufficient for a particular binding, the module can specify a custom
Provider
instead, to control exactly how Guice creates or obtains instances for the binding. - An implementation class may always choose to have a
Provider<T>
instance injected, rather than having aT
injected directly. This may give you access to multiple instances, instances you wish to safely mutate and discard, instances which are out of scope (e.g. using a@RequestScoped
object from within a@SessionScoped
object), or instances that will be initialized lazily. - A custom
Scope
is implemented as a decorator ofProvider<T>
, which decides when to delegate to the backing provider and when to provide the instance some other way. - The
Injector
offers access to theProvider<T>
it uses to fulfill requests for a given key, via theInjector.getProvider(org.elasticsearch.common.inject.Key<T>)
methods.
-
Method Summary
-
Method Details
-
get
T get()Provides an instance ofT
. Must never returnnull
.- Throws:
OutOfScopeException
- when an attempt is made to access a scoped object while the scope in question is not currently activeProvisionException
- if an instance cannot be provided. Such exceptions include messages and throwables to describe why provision failed.
-