@Override public Object getInstance(final InjectionManager injectionManager) { return Injections.getOrCreate(injectionManager, handlerClass); }
/** * Create a new Jersey server-side application handler configured by an instance * of a {@link ResourceConfig}, custom {@link Binder} and a parent used by {@link InjectionManager}. * * @param application an instance of a JAX-RS {@code Application} (sub-)class that * will be used to configure the new Jersey application handler. * @param customBinder additional custom bindings used during {@link InjectionManager} creation. * @param parentManager parent used in {@link InjectionManager} for a specific DI provider. */ public ApplicationHandler(final Application application, final Binder customBinder, final Object parentManager) { initialize(new ApplicationConfigurator(application), Injections.createInjectionManager(parentManager), customBinder); }
/** * Creates an unnamed, parented {@link InjectionManager}. In case the {@code parent} injection manager is not specified, the * locator will not be parented. * * @param parent The parent of this injection manager. Services can be found in the parent (and all grand-parents). May be * {@code null}. An underlying DI provider checks whether the parent is in a proper type. * @return an injection manager with all the bindings. */ public static InjectionManager createInjectionManager(Object parent) { return lookupInjectionManagerFactory().create(parent); }
@SuppressWarnings("unchecked") private <T> void bindInstance(final T instance, final DynamicConfiguration dc) { for (final Class contract : Providers.getProviderContracts(instance.getClass())) { Injections.addBinding(Injections.newBinder(instance).to(contract).qualifiedBy(CustomAnnotationLiteral.INSTANCE), dc); } }
private void bindWaeRestoringExceptionMapper() { final DynamicConfiguration dc = Injections.getConfiguration(locator); final ServiceBindingBuilder bindingBuilder = Injections.newFactoryBinder(new CdiFactory(TransactionalExceptionMapper.class, locator, beanManager, true)); bindingBuilder.to(ExceptionMapper.class); Injections.addBinding(bindingBuilder, dc); dc.commit(); }
private void registerManagedObjectsFinalizer(ServiceLocator locator) { DynamicConfiguration dc = Injections.getConfiguration(locator); ScopedBindingBuilder<ManagedObjectsFinalizer> binder = Injections.newBinder(ManagedObjectsFinalizer.class) .to(ManagedObjectsFinalizer.class) .in(Singleton.class); Injections.addBinding(binder, dc); dc.commit(); }
@Override public void bind(DynamicConfiguration config) { Injections.addBinding( Injections.newFactoryBinder(this).to(type).in(Singleton.class), config); Injections.addBinding( Injections.newBinder(this).to(ValueFactoryProvider.class), config); } }
/** * Register/bind custom provider instances. Registered providers will be handled * always as Singletons. * * @param instances custom provider instances. */ public void bindInstances(final Iterable<Object> instances) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Object instance : instances) { bindInstance(instance, dc); } dc.commit(); }
runtimeCfgState.markAsShared(); final ServiceLocator locator = Injections.createLocator(new ClientBinder(runtimeCfgState.getProperties())); locator.setDefaultClassAnalyzerName(JerseyClassAnalyzer.NAME); final DynamicConfiguration dc = Injections.getConfiguration(locator); configBinder.bind(dc); dc.commit();
/** * Create an unnamed {@link ServiceLocator}. * * @param binders custom the HK2 {@link Binder binders}. * @return a service locator with all the bindings. */ public static ServiceLocator createLocator(final Binder... binders) { return _createLocator(null, null, binders); }
public RuntimeDelegateImpl() { // TODO add more binders as necessary super(Injections.createLocator("jersey-server-rd-locator", new MessagingBinders.HeaderDelegateProviders())); }
private static ServiceLocator _createLocator(final String name, final ServiceLocator parent, final Binder... binders) { // Passing null as service locator generator would force HK2 to find appropriate one. final ServiceLocator result = factory.create(name, parent, null, ServiceLocatorFactory.CreatePolicy.DESTROY); result.setNeutralContextClassLoader(false); ServiceLocatorUtilities.enablePerThreadScope(result); // HK2 Immediate Scope is commented out due to JERSEY-2979 and other issues // ServiceLocatorUtilities.enableImmediateScope(result); for (final Binder binder : binders) { bind(result, binder); } return result; }
@SuppressWarnings("unchecked") private <T> void bindInstance(final T instance, final DynamicConfiguration dc) { for (final Class contract : Providers.getProviderContracts(instance.getClass())) { Injections.addBinding(Injections.newBinder(instance).to(contract).qualifiedBy(CustomAnnotationLiteral.INSTANCE), dc); } }
final DynamicConfiguration dc = Injections.getConfiguration(locator); .newFactoryBinder(new ExecutorServiceFactory(executorProvider)) .to(ExecutorService.class) .in(Singleton.class); Injections.addBinding(bindingBuilder.named(((Named) qualifier).value()), dc); } else { Injections.addBinding(bindingBuilder.qualifiedBy(qualifier), dc); Injections.newFactoryBinder(new ScheduledExecutorServiceFactory(executorProvider)) .in(Singleton.class) .to(ScheduledExecutorService.class); Injections.addBinding(bindingBuilder.named(((Named) qualifier).value()), dc); } else { Injections.addBinding(bindingBuilder.qualifiedBy(qualifier), dc);
private void registerManagedObjectsFinalizer(ServiceLocator locator) { DynamicConfiguration dc = Injections.getConfiguration(locator); ScopedBindingBuilder<ManagedObjectsFinalizer> binder = Injections.newBinder(ManagedObjectsFinalizer.class) .to(ManagedObjectsFinalizer.class) .in(Singleton.class); Injections.addBinding(binder, dc); dc.commit(); }
/** * Register/bind custom provider instances. Registered providers will be handled * always as Singletons. * * @param instances custom provider instances. */ public void bindInstances(final Iterable<Object> instances) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Object instance : instances) { bindInstance(instance, dc); } dc.commit(); }
runtimeCfgState.markAsShared(); final ServiceLocator locator = Injections.createLocator(new ClientBinder(runtimeCfgState.getProperties())); locator.setDefaultClassAnalyzerName(JerseyClassAnalyzer.NAME); final DynamicConfiguration dc = Injections.getConfiguration(locator); configBinder.bind(dc); dc.commit();
/** * Create a {@link ServiceLocator}. In case the {@code name} is not specified, the locator * will be unnamed. * * @param name The name of this service locator. Passing a {@code null} * name will result in a newly created service locator with a * generated name. * @param binders custom the HK2 {@link Binder binders}. * @return a service locator with all the bindings. */ public static ServiceLocator createLocator(final String name, final Binder... binders) { return _createLocator(name, null, binders); }
public RuntimeDelegateImpl() { // TODO add more binders as necessary super(Injections.createLocator("jersey-server-rd-locator", new MessagingBinders.HeaderDelegateProviders())); }
private static ServiceLocator _createLocator(final String name, final ServiceLocator parent, final Binder... binders) { // Passing null as service locator generator would force HK2 to find appropriate one. final ServiceLocator result = factory.create(name, parent, null, ServiceLocatorFactory.CreatePolicy.DESTROY); result.setNeutralContextClassLoader(false); ServiceLocatorUtilities.enablePerThreadScope(result); // HK2 Immediate Scope is commented out due to JERSEY-2979 and other issues // ServiceLocatorUtilities.enableImmediateScope(result); for (final Binder binder : binders) { bind(result, binder); } return result; }