Class InjectionManagerProvider
- Direct Known Subclasses:
InjectionManagerClientProvider
injection manager
from various JAX-RS components. This class can be used when no injection is possible by
Context
or Inject
annotation due to character of
provider but there is a need to get any service from InjectionManager
.
Injections are not possible for example when a provider is registered as an instance on the client. In this case the runtime will not inject the instance as this instance might be used in other client runtimes too.
Example. This is the class using a standard injection:
public static class MyWriterInterceptor implements WriterInterceptor { @Inject MyInjectedService service; @Override public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { Something something = service.getSomething(); ... } }
If this injection is not possible then this construct can be used:
public static class MyWriterInterceptor implements WriterInterceptor { @Override public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException { InjectionManager injectionManager = InjectionManagerProvider.getInjectionManager(context); MyInjectedService service = injectionManager.getInstance(MyInjectedService.class); Something something = service.getSomething(); ... } }
Note, that this injection support is intended mostly for injection of custom user types. JAX-RS types are usually available without need for injections in method parameters. However, when injection of custom type is needed it is preferred to use standard injections if it is possible rather than injection support provided by this class.
User returned InjectionManager
only for purpose of getting services (do not change the state of the injection manager).
- Since:
- 2.6
- Author:
- Miroslav Fuksa
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic org.glassfish.jersey.internal.inject.InjectionManager
getInjectionManager
(FeatureContext featureContext) Extract and return injection manager fromfeatureContext
.static org.glassfish.jersey.internal.inject.InjectionManager
getInjectionManager
(ReaderInterceptorContext readerInterceptorContext) Extract and return injection manager fromreaderInterceptorContext
.static org.glassfish.jersey.internal.inject.InjectionManager
getInjectionManager
(WriterInterceptorContext writerInterceptorContext) Extract and return injection manager fromwriterInterceptorContext
.
-
Constructor Details
-
InjectionManagerProvider
public InjectionManagerProvider()
-
-
Method Details
-
getInjectionManager
public static org.glassfish.jersey.internal.inject.InjectionManager getInjectionManager(WriterInterceptorContext writerInterceptorContext) Extract and return injection manager fromwriterInterceptorContext
. The method can be used to inject custom types into aWriterInterceptor
.- Parameters:
writerInterceptorContext
- Writer interceptor context.- Returns:
- injection manager.
- Throws:
IllegalArgumentException
- whenwriterInterceptorContext
is not a default Jersey implementation provided by Jersey as argument in theWriterInterceptor.aroundWriteTo(jakarta.ws.rs.ext.WriterInterceptorContext)
method.
-
getInjectionManager
public static org.glassfish.jersey.internal.inject.InjectionManager getInjectionManager(ReaderInterceptorContext readerInterceptorContext) Extract and return injection manager fromreaderInterceptorContext
. The method can be used to inject custom types into aReaderInterceptor
.- Parameters:
readerInterceptorContext
- Reader interceptor context.- Returns:
- injection manager.
- Throws:
IllegalArgumentException
- whenreaderInterceptorContext
is not a default Jersey implementation provided by Jersey as argument in theReaderInterceptor.aroundReadFrom(jakarta.ws.rs.ext.ReaderInterceptorContext)
method.
-
getInjectionManager
public static org.glassfish.jersey.internal.inject.InjectionManager getInjectionManager(FeatureContext featureContext) Extract and return injection manager fromfeatureContext
. The method can be used to inject custom types into aFeature
.Note that features are utilized during initialization phase when not all providers are registered yet. It is undefined which injections are already available in this phase.
- Parameters:
featureContext
- Feature context.- Returns:
- injection manager.
- Throws:
IllegalArgumentException
- whenwriterInterceptorContext
is not a default Jersey instance provided by Jersey inFeature.configure(jakarta.ws.rs.core.FeatureContext)
method.
-