/** * Bind contract provider model to a provider class using the supplied injection manager. * * @param providerClass provider class. * @param model contract provider model. */ public static void bindProvider(Class<?> providerClass, ContractProvider model, InjectionManager injectionManager) { injectionManager.register(CompositeBinder.wrap(createProviderBinders(providerClass, model))); }
@Override public ForeignDescriptor apply(Class<?> key) { // below we make sure HK2 behaves as if injection happens into a request scoped type // this is to avoid having proxies injected (see JERSEY-2386) // before touching the following statement, check BeanParamMemoryLeakTest first! return injectionManager .createForeignDescriptor(Bindings.serviceAsContract(key).in(RequestScoped.class)); } });
@Override protected void configure() { bindFactory(ReferencingFactory.<MonitoringStatistics>referenceFactory()) .to(new GenericType<Ref<MonitoringStatistics>>() { }) .in(Singleton.class); bindFactory(StatisticsInjectionFactory.class).to(MonitoringStatistics.class); bind(StatisticsListener.class).to(MonitoringStatisticsListener.class).in(Singleton.class); } });
@Override protected void configure() { ClassBinding<T> builder = bind(clazz).in(scope).qualifiedBy(CustomAnnotationLiteral.INSTANCE); Providers.getProviderContracts(clazz).forEach(contract -> builder.to((Class<? super T>) contract)); } };
/** * Creates a {@link InjectionManager} with initial binder that is immediately registered. * * @param binder custom the {@link Binder binder}. * @return a injection manager with all the bindings. */ public static InjectionManager createInjectionManager(Binder binder) { InjectionManagerFactory injectionManagerFactory = lookupInjectionManagerFactory(); InjectionManager injectionManager = injectionManagerFactory.create(); injectionManager.register(binder); return injectionManager; }
@Override public void register(Binder binder) { for (Binding binding : Bindings.getBindings(this, binder)) { bindings.bind(binding); } }
/** * Creates a {@link InjectionManager} without parent and initial binder. * * @return a injection manager with all the bindings. */ public static InjectionManager createInjectionManager() { return lookupInjectionManagerFactory().create(); }
@Override public void initialize(final InjectionManager injectionManager) { this.injectionManager = injectionManager; InstanceBinding<EjbComponentProvider> descriptor = Bindings.service(EjbComponentProvider.this) .to(ResourceMethodInvocationHandlerProvider.class); this.injectionManager.register(descriptor); }
@Override protected void configure() { ClassBinding<T> builder = bind(clazz).in(scope).qualifiedBy(CustomAnnotationLiteral.INSTANCE); Providers.getProviderContracts(clazz).forEach(contract -> builder.to((Class<? super T>) contract)); } };
@Override public ForeignDescriptor apply(Class<?> key) { // below we make sure HK2 behaves as if injection happens into a request scoped type // this is to avoid having proxies injected (see JERSEY-2386) // before touching the following statement, check BeanParamMemoryLeakTest first! return injectionManager .createForeignDescriptor(Bindings.serviceAsContract(key).in(RequestScoped.class)); } });
/** * Bind contract provider model to a provider instance using the supplied injection manager. * <p> * Scope value specified in the {@link ContractProvider contract provider model} * is ignored as instances can only be bound as "singletons". * * @param providerInstance provider instance. * @param model contract provider model. */ public static void bindProvider(Object providerInstance, ContractProvider model, InjectionManager injectionManager) { injectionManager.register(CompositeBinder.wrap(createProviderBinders(providerInstance, model))); }
/** * Creates a {@link InjectionManager} with initial binder that is immediately registered. * * @param binder custom the {@link Binder binder}. * @return a injection manager with all the bindings. */ public static InjectionManager createInjectionManager(Binder binder) { InjectionManagerFactory injectionManagerFactory = lookupInjectionManagerFactory(); InjectionManager injectionManager = injectionManagerFactory.create(); injectionManager.register(binder); return injectionManager; }
/** * 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); }
/** * Bind contract provider model to a provider instance using the supplied injection manager. * <p> * Scope value specified in the {@link ContractProvider contract provider model} * is ignored as instances can only be bound as "singletons". * * @param providerInstance provider instance. * @param model contract provider model. */ public static void bindProvider(Object providerInstance, ContractProvider model, InjectionManager injectionManager) { injectionManager.register(CompositeBinder.wrap(createProviderBinders(providerInstance, model))); }
/** * Creates a {@link InjectionManager} without parent and initial binder. * * @return a injection manager with all the bindings. */ public static InjectionManager createInjectionManager() { return lookupInjectionManagerFactory().create(); }
/** * Bind contract provider model to a provider class using the supplied injection manager. * * @param providerClass provider class. * @param model contract provider model. */ public static void bindProvider(Class<?> providerClass, ContractProvider model, InjectionManager injectionManager) { injectionManager.register(CompositeBinder.wrap(createProviderBinders(providerClass, model))); }