类com.google.inject.binder.ScopedBindingBuilder源码实例Demo

下面列出了怎么用com.google.inject.binder.ScopedBindingBuilder的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: arcusplatform   文件: Binders.java
/**
 * Adds a Binder for Map<String, T> to anything in the context
 * that keyed to a type that implements T.  Note that this has to be a literal class
 * because runtime reflection can't handle generics.
 * @param binder
 * @param type
 * @return
 */
@SuppressWarnings("unchecked")
  public static <T> ScopedBindingBuilder bindMapToInstancesOf(Binder binder, final Class<T> type) {
	return bindMapToInstancesOf(
			binder,
			(TypeLiteral<Map<String, T>>) TypeLiteral.get(new ParameterizedType() {
  				final Type [] args = new Type[] { String.class, type };
				@Override
				public Type getRawType() {
					return Map.class;
				}

				@Override
				public Type getOwnerType() {
					return null;
				}

				@Override
				public Type[] getActualTypeArguments() {
					return args;
				}
			})
		);
}
 
源代码2 项目: arcusplatform   文件: Binders.java
@SuppressWarnings("unchecked")
  public static <T> ScopedBindingBuilder bindListToInstancesOf(Binder binder, final Class<T> type, Comparator<T> comparator) {
	return bindListToInstancesOf(
			binder,
			(TypeLiteral<List<T>>) TypeLiteral.get(new ParameterizedType() {
  				final Type [] args = new Type[] { type };
				@Override
				public Type getRawType() {
					return List.class;
				}

				@Override
				public Type getOwnerType() {
					return null;
				}

				@Override
				public Type[] getActualTypeArguments() {
					return args;
				}
			}),
			comparator
		);
}
 
源代码3 项目: ProjectAres   文件: InjectableMethod.java
public Module bindingModule() {
    return new KeyedManifest.Impl(method) {
        @Override
        public void configure() {
            final Binder binder = binder().withSource(method);
            if(!hasReturnValue()) {
                binder.addError("Cannot bind this method as a provider because it does not return a value");
                return;
            }

            install(InjectableMethod.this);

            final ScopedBindingBuilder builder = binder.bind(providedKey).toProvider(asProvider());
            if(scope != null) builder.in(scope);
        }
    };
}
 
源代码4 项目: seed   文件: SecurityInternalModuleUnitTest.java
@SuppressWarnings({"unchecked", "rawtypes"})
@Before
public void before() {
    PrivateBinder binder = mock(PrivateBinder.class);
    AnnotatedBindingBuilder ab = mock(AnnotatedBindingBuilder.class);
    when(binder.bind(any(Class.class))).thenReturn(ab);
    when(ab.annotatedWith(any(Annotation.class))).thenReturn(ab);
    AnnotatedElementBuilder aeb = mock(AnnotatedElementBuilder.class);
    when(binder.expose(any(Class.class))).thenReturn(aeb);
    ScopedBindingBuilder sb = mock(ScopedBindingBuilder.class);
    when(ab.toProvider(any(Provider.class))).thenReturn(sb);
    when(binder.bind(any(TypeLiteral.class))).thenReturn(ab);
    when(binder.skipSources(any(Class.class), any(Class.class))).thenReturn(binder);
    when(binder.skipSources(any(Class.class))).thenReturn(binder);
    securityConfigurer = mock(SecurityConfigurer.class);
    underTest = new SecurityInternalModule(securityConfigurer, new HashMap<>());
    Whitebox.setInternalState(underTest, "binder", binder);
}
 
源代码5 项目: arcusplatform   文件: Binders.java
public static <T> ScopedBindingBuilder bindMapToInstancesOf(Binder binder, TypeLiteral<Map<String, T>> type) {
  	return bindMapToInstancesOf(binder, type, new Function<T,String>() {
  	   @Override
  	   public String apply(T service) {
  	      return Injectors.getServiceName(service);
  	   }
  	});
}
 
源代码6 项目: jackson-modules-base   文件: ObjectMapperModule.java
@Override
public void configure(Binder binder)
{
  final ScopedBindingBuilder builder = binder.bind(objectMapperKey)
          .toProvider(new ObjectMapperProvider(modulesToInject, modulesToAdd, objectMapper));

  if (scope != null) {
    builder.in(scope);
  }
}
 
源代码7 项目: arcusplatform   文件: Binders.java
public static <K, V> ScopedBindingBuilder bindMapToInstancesOf(Binder binder, TypeLiteral<Map<K, V>> type, Function<V, K> keyFunction) {
  	Class<V> containedType = extractContainedMapType(type);
	return binder
				.bind(type)
				.toProvider(new MapProvider<K, V>(containedType, keyFunction));
}
 
源代码8 项目: arcusplatform   文件: Binders.java
public static <T> ScopedBindingBuilder bindListToInstancesOf(Binder binder, Class<T> type) {
	return bindListToInstancesOf(binder, type, null);
}
 
源代码9 项目: arcusplatform   文件: Binders.java
public static <T> ScopedBindingBuilder bindListToInstancesOf(Binder binder, TypeLiteral<List<T>> type) {
	return bindListToInstancesOf(binder, type, null);
}
 
源代码10 项目: arcusplatform   文件: Binders.java
public static <T> ScopedBindingBuilder bindListToInstancesOf(Binder binder, TypeLiteral<List<T>> type, Comparator<T> comparator) {
  	Class<T> containedType = extractContainedListType(type);
	return binder
				.bind(type)
				.toProvider(new ListProvider<T>(containedType, comparator));
}
 
源代码11 项目: arcusplatform   文件: AbstractIrisModule.java
protected <T> ScopedBindingBuilder bindMapToInstancesOf(Class<T> containedType) {
	return Binders.bindMapToInstancesOf(this.binder(), containedType);
}
 
源代码12 项目: arcusplatform   文件: AbstractIrisModule.java
protected <T> ScopedBindingBuilder bindMapToInstancesOf(TypeLiteral<Map<String, T>> type) {
return Binders.bindMapToInstancesOf(this.binder(), type);
 }
 
源代码13 项目: arcusplatform   文件: AbstractIrisModule.java
protected <K, V> ScopedBindingBuilder bindMapToInstancesOf(TypeLiteral<Map<K, V>> type, Function<V, K> keyFunction) {
return Binders.bindMapToInstancesOf(binder(), type, keyFunction);
 }
 
源代码14 项目: arcusplatform   文件: AbstractIrisModule.java
protected <T> ScopedBindingBuilder bindListToInstancesOf(Class<T> containedType) {
	return Binders.bindListToInstancesOf(this.binder(), containedType);
}
 
源代码15 项目: arcusplatform   文件: AbstractIrisModule.java
protected <T> ScopedBindingBuilder bindListToInstancesOf(Class<T> containedType, Comparator<T> comparator) {
	return Binders.bindListToInstancesOf(this.binder(), containedType, comparator);
}
 
源代码16 项目: arcusplatform   文件: AbstractIrisModule.java
protected <T> ScopedBindingBuilder bindListToInstancesOf(TypeLiteral<List<T>> type) {
return Binders.bindListToInstancesOf(this.binder(), type);
 }
 
源代码17 项目: arcusplatform   文件: AbstractIrisModule.java
protected <T> ScopedBindingBuilder bindListToInstancesOf(TypeLiteral<List<T>> type, Comparator<T> comparator) {
return Binders.bindListToInstancesOf(this.binder(), type, comparator);
 }
 
源代码18 项目: ProjectAres   文件: AbstractBindingBuilder.java
@Override
public ScopedBindingBuilder to(Class<? extends T> implementation) {
    return to(Key.get(implementation));
}
 
源代码19 项目: ProjectAres   文件: AbstractBindingBuilder.java
@Override
public ScopedBindingBuilder to(TypeLiteral<? extends T> implementation) {
    return to(Key.get(implementation));
}
 
源代码20 项目: ProjectAres   文件: AbstractBindingBuilder.java
@Override
public ScopedBindingBuilder toProvider(Provider<? extends T> provider) {
    return toProvider((javax.inject.Provider<? extends T>) provider);
}
 
源代码21 项目: ProjectAres   文件: AbstractBindingBuilder.java
@Override
public ScopedBindingBuilder toProvider(Class<? extends javax.inject.Provider<? extends T>> providerType) {
    return toProvider(Key.get(providerType));
}
 
源代码22 项目: ProjectAres   文件: AbstractBindingBuilder.java
@Override
public ScopedBindingBuilder toProvider(TypeLiteral<? extends javax.inject.Provider<? extends T>> providerType) {
    return toProvider(Key.get(providerType));
}
 
源代码23 项目: ProjectAres   文件: AbstractBindingBuilder.java
@Override
public <S extends T> ScopedBindingBuilder toConstructor(Constructor<S> constructor) {
    return toConstructor(constructor, TypeLiteral.get(constructor.getDeclaringClass()));
}
 
源代码24 项目: dropwizard-guicey   文件: GuiceBindingsModule.java
/**
 * Important moment: request scoped jersey objects must be bound to guice request scope (if guice web used)
 * because otherwise scope delegation to other thread will not work
 * (see {@link com.google.inject.servlet.ServletScopes#transferRequest(java.util.concurrent.Callable)}).
 * <p>
 * WARNING: bean instance must be obtained in current (request) thread in order to be us used later
 * inside transferred thread (simply call {@code provider.get()} (for jersey-managed bean like {@link UriInfo})
 * before {@code ServletScopes.transferRequest()}.
 *
 * @param type   jersey type to bind
 * @param global true for global type binding
 */
private void jerseyToGuiceBinding(final Class<?> type, final boolean global) {
    final ScopedBindingBuilder binding = bindJerseyComponent(binder(), provider, type);
    if (!global && guiceServletSupport) {
        binding.in(RequestScoped.class);
    }
}
 
源代码25 项目: druid-api   文件: PolyBind.java
/**
 * Sets up a "choice" for the injector to resolve at injection time.
 *
 * @param binder the binder for the injector that is being configured
 * @param property the property that will be checked to determine the implementation choice
 * @param interfaceKey the interface that will be injected using this choice
 * @param defaultKey the default instance to be injected if the property doesn't match a choice.  Can be null
 * @param <T> interface type
 * @return A ScopedBindingBuilder so that scopes can be added to the binding, if required.
 */
public static <T> ScopedBindingBuilder createChoice(
    Binder binder,
    String property,
    Key<T> interfaceKey,
    Key<? extends T> defaultKey
)
{
  return createChoiceWithDefault(binder, property, interfaceKey, defaultKey, null);
}
 
源代码26 项目: druid-api   文件: PolyBind.java
/**
 * Sets up a "choice" for the injector to resolve at injection time.
 *
 * @param binder the binder for the injector that is being configured
 * @param property the property that will be checked to determine the implementation choice
 * @param interfaceKey the interface that will be injected using this choice
 * @param defaultKey the default instance to be injected if the property doesn't match a choice.  Can be null
 * @param defaultPropertyValue the default property value to use if the property is not set.
 * @param <T> interface type
 * @return A ScopedBindingBuilder so that scopes can be added to the binding, if required.
 */
public static <T> ScopedBindingBuilder createChoiceWithDefault(
    Binder binder,
    String property,
    Key<T> interfaceKey,
    Key<? extends T> defaultKey,
    String defaultPropertyValue
)
{
  return binder.bind(interfaceKey).toProvider(new ConfiggedProvider<T>(interfaceKey, property, defaultKey, defaultPropertyValue));
}
 
源代码27 项目: dropwizard-guicey   文件: JerseyBinding.java
/**
 * Used to bind jersey beans in guice context (lazily). Guice context is started first, so there is
 * no way to bind instances. Instead "lazy bridge" installed, which will resolve target type on first call.
 * Guice is not completely started and direct injector lookup is impossible here, so lazy injector provider used.
 *
 * @param binder   guice binder
 * @param provider provider for guice injector
 * @param type     jersey type to register
 * @param <T>      type
 * @return scoped binder object to optionally define binding scope.
 * @see ru.vyarus.dropwizard.guice.injector.lookup.InjectorProvider
 */
public static <T> ScopedBindingBuilder bindJerseyComponent(final Binder binder, final Provider<Injector> provider,
                                                           final Class<T> type) {
    return binder.bind(type).toProvider(new JerseyComponentProvider<>(provider, type));
}
 
 类所在包
 类方法
 同包方法