public interface ContextSensitiveProvider<T>
Provider
, but with knowledge of the target InjectionPoint
.
This interface, along with ContextSensitiveBinder
, is useful for injecting custom logger types, among other
things. However, context-sensitive injections can make maintenance and debugging more difficult.
Modifier and Type | Method and Description |
---|---|
T |
getInContext(InjectionPoint injectionPoint)
Provide an instance of
T for the given context. |
T |
getInUnknownContext()
Provide an instance of
T for an unknown context. |
T getInContext(InjectionPoint injectionPoint)
T
for the given context.injectionPoint
- The InjectionPoint
for this provision.T
.T getInUnknownContext()
T
for an unknown context.
The InjectionPoint
may not be known in all cases, for example if a Provider<T>
is used instead
of
a bare T
. This method will be called in those cases.
One reasonable implementation is to return a generically applicable instance, such as an anonymous logger.
Another valid implementation is to throw an unchecked exception; in that case, Provider<T>
injections
will fail.
T
RuntimeException
- If injection without a context is not supported.Copyright © 2014–2015. All rights reserved.