/** * Bind all providers contained in {@code providerBag} (classes and instances) using injection manager. Configuration is * also committed. * * @param componentBag bag of provider classes and instances. * @param injectionManager injection manager the binder will use to bind the providers into. */ public static void bindProviders(final ComponentBag componentBag, final InjectionManager injectionManager) { bindProviders(componentBag, null, Collections.emptySet(), injectionManager); }
/** * Register/bind custom provider classes. Registered providers will be handled * always as Singletons unless annotated by {@link PerLookup}. * * @param classes custom provider classes. */ public void bindClasses(final Collection<Class<?>> classes) { bindClasses(classes, false); }
ProviderBinder.bindProvider(componentClass, model, injectionManager); ProviderBinder.bindProvider(component, model, injectionManager);
@SuppressWarnings("unchecked") private <T> Binder createClassBinders(Class<T> clazz, boolean isResource) { final Class<? extends Annotation> scope = getProviderScope(clazz); if (isResource) { return new AbstractBinder() { @Override protected void configure() { ClassBinding<T> descriptor = bindAsContract(clazz).in(scope); for (Class contract : Providers.getProviderContracts(clazz)) { descriptor.addAlias(contract) .in(scope.getName()) .qualifiedBy(CustomAnnotationLiteral.INSTANCE); } } }; } else { return new AbstractBinder() { @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)); } }; } }
/** * 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))); }
/** * Register/bind custom provider classes. Registered providers will be handled * always as Singletons unless annotated by {@link PerLookup}. * * @param classes custom provider classes. */ public void bindClasses(final Class<?>... classes) { if (classes != null && classes.length > 0) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Class<?> clazz : classes) { bindClass(clazz, locator, dc, false); } 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) { List<Object> instancesList = new ArrayList<>(); instances.forEach(instancesList::add); bindInstances(instancesList); }
/** * Register/bind custom provider classes that may also be resources. Registered * providers/resources will be handled always as Singletons unless annotated by * {@link PerLookup}. * <p> * <p> * If {@code bindAsResources} is set to {@code true}, the providers will also be bound * as resources. * </p> * * @param classes custom provider classes. * @param bindResources if {@code true}, the provider classes will also be bound as * resources. */ public void bindClasses(Collection<Class<?>> classes, boolean bindResources) { List<Binder> binders = classes.stream() .map(clazz -> createClassBinders(clazz, bindResources)) .collect(Collectors.toList()); injectionManager.register(CompositeBinder.wrap(binders)); }
/** * 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(); }
@SuppressWarnings("unchecked") private <T> Binder createClassBinders(Class<T> clazz, boolean isResource) { final Class<? extends Annotation> scope = getProviderScope(clazz); if (isResource) { return new AbstractBinder() { @Override protected void configure() { ClassBinding<T> descriptor = bindAsContract(clazz).in(scope); for (Class contract : Providers.getProviderContracts(clazz)) { descriptor.addAlias(contract) .in(scope.getName()) .qualifiedBy(CustomAnnotationLiteral.INSTANCE); } } }; } else { return new AbstractBinder() { @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)); } }; } }
/** * 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))); }
/** * Register/bind custom provider classes. Registered providers will be handled * always as Singletons unless annotated by {@link PerLookup}. * * @param classes custom provider classes. */ public void bindClasses(final Class<?>... classes) { if (classes != null && classes.length > 0) { final DynamicConfiguration dc = Injections.getConfiguration(locator); for (final Class<?> clazz : classes) { bindClass(clazz, locator, dc, false); } 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) { List<Object> instancesList = new ArrayList<>(); instances.forEach(instancesList::add); bindInstances(instancesList); }
/** * Register/bind custom provider classes that may also be resources. Registered * providers/resources will be handled always as Singletons unless annotated by * {@link PerLookup}. * <p> * <p> * If {@code bindAsResources} is set to {@code true}, the providers will also be bound * as resources. * </p> * * @param classes custom provider classes. * @param bindResources if {@code true}, the provider classes will also be bound as * resources. */ public void bindClasses(Collection<Class<?>> classes, boolean bindResources) { List<Binder> binders = classes.stream() .map(clazz -> createClassBinders(clazz, bindResources)) .collect(Collectors.toList()); injectionManager.register(CompositeBinder.wrap(binders)); }
/** * 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(); }
/** * Bind all providers contained in {@code providerBag} (classes and instances) using injection manager. Configuration is * also committed. * * @param componentBag bag of provider classes and instances. * @param injectionManager injection manager the binder will use to bind the providers into. */ public static void bindProviders(final ComponentBag componentBag, final InjectionManager injectionManager) { bindProviders(componentBag, null, Collections.emptySet(), injectionManager); }
/** * Register/bind custom provider classes. Registered providers will be handled * always as Singletons unless annotated by {@link PerLookup}. * * @param classes custom provider classes. */ public void bindClasses(final Collection<Class<?>> classes) { bindClasses(classes, false); }
ProviderBinder.bindProvider(componentClass, model, injectionManager); ProviderBinder.bindProvider(component, model, injectionManager);
@SuppressWarnings("unchecked") private <T> Binder createClassBinders(Class<T> clazz, boolean isResource) { final Class<? extends Annotation> scope = getProviderScope(clazz); if (isResource) { return new AbstractBinder() { @Override protected void configure() { ClassBinding<T> descriptor = bindAsContract(clazz).in(scope); for (Class contract : Providers.getProviderContracts(clazz)) { descriptor.addAlias(contract) .in(scope.getName()) .qualifiedBy(CustomAnnotationLiteral.INSTANCE); } } }; } else { return new AbstractBinder() { @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)); } }; } }
/** * 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))); }