Genie.Binder binder = new Genie.Binder(autoBinding).to(entry.getValue()); $.T2<Set<Annotation>, String> key = entry.getKey(); Set<Annotation> qualifiers = key._1; String name = key._2; if (!qualifiers.isEmpty()) { binder = binder.withAnnotation(qualifiers.toArray(new Annotation[qualifiers.size()])); binder.named(name); binder.register(injector.genie());
/** * Register this binder to `Genie` * * @param genie * the dependency injector */ public void register(Genie genie) { if (null == provider) { if (null != constructor) { provider = genie.buildConstructor( constructor, BeanSpec.of(constructor.getDeclaringClass(), null, genie), new HashSet<BeanSpec>()); } else if (null != impl) { provider = new LazyProvider<>(impl, genie); } } if (!bound()) { throw new InjectException("Cannot register without binding specified"); } BeanSpec spec = beanSpec(genie); genie.addIntoRegistry(spec, genie.decorate(spec, provider, true), annotations.isEmpty() && S.blank(name)); if (fireEvent || forceFireEvent) { genie.fireProviderRegisteredEvent(type); } }
ensureNoBinding(); try { return to(implement.getConstructor(args)); } catch (NoSuchMethodException e) { throw new InjectException(e,
Genie.Binder binder = new Genie.Binder(autoBinding).to(entry.getValue()); $.T2<Set<Annotation>, String> key = entry.getKey(); Set<Annotation> qualifiers = key._1; String name = key._2; if (!qualifiers.isEmpty()) { binder = binder.withAnnotation(qualifiers.toArray(new Annotation[qualifiers.size()])); binder.named(name); binder.register(injector.genie());
ensureNoBinding(); try { return to(implement.getConstructor(args)); } catch (NoSuchMethodException e) { throw new InjectException(e,
/** * Bind this `Binder` to a specific instance * * If there is another binding already specified then it * will throw out an {@link IllegalStateException} * * @param instance * the instance to which the Binder is bound * @return this binder instance * @throws IllegalStateException * if another binding exists */ public Binder<T> to(final T instance) { ensureNoBinding(); this.provider = new Provider<T>() { @Override public T get() { return instance; } }; return this; }
/** * Register this binder to `Genie` * * @param genie * the dependency injector */ public void register(Genie genie) { if (null == provider) { if (null != constructor) { provider = genie.buildConstructor( constructor, BeanSpec.of(constructor.getDeclaringClass(), null, genie), new HashSet<BeanSpec>()); } else if (null != impl) { provider = new LazyProvider<>(impl, genie); } } if (!bound()) { throw new InjectException("Cannot register without binding specified"); } BeanSpec spec = beanSpec(genie); genie.addIntoRegistry(spec, genie.decorate(spec, provider, true), annotations.isEmpty() && S.blank(name)); if (fireEvent || forceFireEvent) { genie.fireProviderRegisteredEvent(type); } }
/** * Bind this `Binder` to a specific instance * * If there is another binding already specified then it * will throw out an {@link IllegalStateException} * * @param instance * the instance to which the Binder is bound * @return this binder instance * @throws IllegalStateException * if another binding exists */ public Binder<T> to(final T instance) { ensureNoBinding(); this.provider = new Provider<T>() { @Override public T get() { return instance; } }; return this; }
/** * Bind this `Binder` to a provider. * * If there is another binding already specified then it * will throw out an {@link IllegalStateException} * * @param provider * the provider that provides the instance to which this binder is bound * @return this binder instance * @throws IllegalStateException * if another binding exists */ public Binder<T> to(Provider<? extends T> provider) { ensureNoBinding(); this.provider = provider; return this; }
/** * Bind this `Binder` to a specific implementation. * * If there is another binding already specified then it * will throw out an {@link IllegalStateException} * * @param impl * the implementation class * @return this binder instance * @throws IllegalStateException * if another binding exists */ public Binder<T> to(final Class<? extends T> impl) { ensureNoBinding(); this.impl = $.requireNotNull(impl); return this; }
/** * Bind this `Binder` to a specific implementation. * * If there is another binding already specified then it * will throw out an {@link IllegalStateException} * * @param impl * the implementation class * @return this binder instance * @throws IllegalStateException * if another binding exists */ public Binder<T> to(final Class<? extends T> impl) { ensureNoBinding(); this.impl = $.requireNotNull(impl); return this; }
/** * Bind this binder to a constructor * * If there is another binding already specified then it * will throw out an {@link IllegalStateException} * * @param constructor * the constructor that generate the instance to which this binder is bound * @return this binder instance * @throws IllegalStateException * if another binding exists */ public Binder<T> to(final Constructor<? extends T> constructor) { ensureNoBinding(); this.constructor = constructor; return this; }
/** * Bind this binder to a constructor * * If there is another binding already specified then it * will throw out an {@link IllegalStateException} * * @param constructor * the constructor that generate the instance to which this binder is bound * @return this binder instance * @throws IllegalStateException * if another binding exists */ public Binder<T> to(final Constructor<? extends T> constructor) { ensureNoBinding(); this.constructor = constructor; return this; }
/** * Bind this `Binder` to a provider. * * If there is another binding already specified then it * will throw out an {@link IllegalStateException} * * @param provider * the provider that provides the instance to which this binder is bound * @return this binder instance * @throws IllegalStateException * if another binding exists */ public Binder<T> to(Provider<? extends T> provider) { ensureNoBinding(); this.provider = provider; return this; }
final void applyTo(Genie genie) { if (!configured) { configure(); } configured = true; validate(genie); for (Binder<?> binder : binders) { binder.register(genie); } genie.registerQualifiers(qualifiers); for (Map.Entry<Class<?>, GenericTypedBeanLoader<?>> entry : genericTypedBeanLoaders.entrySet()) { genie.registerGenericTypedBeanLoader(entry.getKey(), (GenericTypedBeanLoader) entry.getValue()); } }
private void ensureNoBinding() { E.illegalStateIf(bound(), "binding has already been specified"); }
final void applyTo(Genie genie) { if (!configured) { configure(); } configured = true; validate(genie); for (Binder<?> binder : binders) { binder.register(genie); } genie.registerQualifiers(qualifiers); for (Map.Entry<Class<?>, GenericTypedBeanLoader<?>> entry : genericTypedBeanLoaders.entrySet()) { genie.registerGenericTypedBeanLoader(entry.getKey(), (GenericTypedBeanLoader) entry.getValue()); } }
private void ensureNoBinding() { E.illegalStateIf(bound(), "binding has already been specified"); }
private void validate(Genie genie) { Map<Object, Binder> map = C.newMap(); for (Binder<?> binder : binders) { Object spec = binder.beanSpec(genie); if (map.containsKey(spec)) { throw E.invalidConfiguration("Duplicate bean spec found: ", spec); } map.put(spec, binder); } }