Refine search
@Override public void configure(Binder binder) { Multibinder<Procedure> procedures = newSetBinder(binder, Procedure.class); procedures.addBinding().toProvider(CreateEmptyPartitionProcedure.class).in(Scopes.SINGLETON); } }
@Override public void configure(Binder binder) { JsonConfigProvider.bind(binder, "druid.client.https", SSLClientConfig.class); binder.bind(SSLContext.class).toProvider(SSLContextProvider.class); binder.bind(SSLContext.class).annotatedWith(Global.class).toProvider(SSLContextProvider.class); binder.bind(SSLContext.class).annotatedWith(Client.class).toProvider(SSLContextProvider.class); binder.bind(SSLContext.class).annotatedWith(Router.class).toProvider(SSLContextProvider.class); binder.bind(SSLContext.class).annotatedWith(EscalatedGlobal.class).toProvider(SSLContextProvider.class); binder.bind(SSLContext.class).annotatedWith(EscalatedClient.class).toProvider(SSLContextProvider.class); } }
public static <T> void bind( Binder binder, String propertyBase, Class<T> clazz, Class<? extends T> defaultClass, Key<T> instanceKey, Key<Supplier<T>> supplierKey ) { binder.bind(supplierKey).toProvider(of(propertyBase, clazz, defaultClass)).in(LazySingleton.class); binder.bind(instanceKey).toProvider(new SupplierProvider<>(supplierKey)); }
@Override public void configure(Binder binder) { binder.bind(HostAndPort.class).annotatedWith(named(HTTP_HOST_AND_PORT)).toProvider(SingularityHostAndPortProvider.class).in(Scopes.SINGLETON); binder.bind(LeaderLatch.class).to(SingularityLeaderLatch.class).in(Scopes.SINGLETON); binder.bind(CuratorFramework.class).toProvider(SingularityCuratorProvider.class).in(Scopes.SINGLETON); binder.bind(SingularityManagedScheduledExecutorServiceFactory.class).in(Scopes.SINGLETON); binder.bind(ScheduledExecutorService.class).annotatedWith(HEALTHCHECK_THREADPOOL_NAMED).toProvider(new SingularityManagedScheduledExecutorServiceProvider(configuration.getHealthcheckStartThreads(), configuration.getThreadpoolShutdownDelayInSeconds(), "healthcheck")).in(Scopes.SINGLETON); binder.bind(ScheduledExecutorService.class).annotatedWith(NEW_TASK_THREADPOOL_NAMED).toProvider(new SingularityManagedScheduledExecutorServiceProvider(configuration.getCheckNewTasksScheduledThreads(), configuration.getThreadpoolShutdownDelayInSeconds(), "check-new-task")).in(Scopes.SINGLETON);
@Override protected void setup(Binder binder) { binder.bind(Clock.class).toInstance(Clock.systemUTC()); binder.bind(LockService.class).toProvider(LockServiceProvider.class); binder.bind(FieldDependency.class).toProvider(FieldDependencyProvider.class).in(Scopes.SINGLETON); customParameters.addBinding().toProvider(ProjectPermissionParameterProvider.class); binder.bind(QueryHttpService.class).asEagerSingleton(); binder.bind(RAsyncHttpClient.class) .annotatedWith(Names.named("rakam-client")) .toProvider(() -> RAsyncHttpClient.create(1000 * 60 * 10, "rakam-custom-script")) .in(Scopes.SINGLETON); .annotatedWith(ForHttpServer.class) .to(NioEventLoopGroup.class) .in(Scopes.SINGLETON); binder.bind(WebServiceModule.class);
public static void bindAnnouncer( final Binder binder, final Class<? extends Annotation> annotation, final DiscoverySideEffectsProvider provider ) { binder.bind(DiscoverySideEffectsProvider.Child.class) .annotatedWith(annotation) .toProvider(provider) .in(LazySingleton.class); LifecycleModule.registerKey(binder, Key.get(DiscoverySideEffectsProvider.Child.class, annotation)); }
/** * 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 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, String defaultPropertyValue ) { Preconditions.checkNotNull(defaultPropertyValue); ConfiggedProvider<T> provider = new ConfiggedProvider<>(interfaceKey, property, null, defaultPropertyValue); return binder.bind(interfaceKey).toProvider(provider); }
bind(EventBus.class).toProvider(EventBusProvider.class).in(Scopes.SINGLETON); bind(OkHttpClient.class).annotatedWith(Names.named("systemHttpClient")).toProvider(SystemOkHttpClientProvider.class).asEagerSingleton(); bind(ExecutorService.class).annotatedWith(Names.named("proxiedRequestsExecutorService")).toProvider(ProxiedRequestsExecutorService.class).asEagerSingleton();
public void bindJsonCodec(Class<?> type) { requireNonNull(type, "type is null"); binder.bind(getJsonCodecKey(type)).toProvider(new JsonCodecProvider(type)).in(Scopes.SINGLETON); }
/** * 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, @Nullable Key<? extends T> defaultKey ) { ConfiggedProvider<T> provider = new ConfiggedProvider<>(interfaceKey, property, defaultKey, null); return binder.bind(interfaceKey).toProvider(provider); }
bind(key).toProvider(new Provider() { public Object get() { return instantiate(item); }).in(scope);
public static <T> void bind(Binder binder, String key, Class<T> clazz, T defaultVal) { binder.bind(Key.get(Types.newParameterizedType(Supplier.class, clazz))) .toProvider((Provider) of(key, clazz, defaultVal)) .in(LazySingleton.class); }
@Override public void configure(Binder binder) { // Binds a Map<K, Set<Provider<V>>> Provider<Map<K, Set<Provider<V>>>> multimapProvider = new RealProviderMultimapProvider<K, V>(bindingSelection.getMapKey()); binder.bind(bindingSelection.getProviderSetMultimapKey()).toProvider(multimapProvider); // Provide links from a few different public keys to the providerMultimapKey. // The collection this exposes is internally an ImmutableMap, so it's OK to massage // the guice Provider to javax Provider in the value (since the guice Provider implements // javax Provider). @SuppressWarnings({"unchecked", "rawtypes"}) Provider<Map<K, Set<javax.inject.Provider<V>>>> javaxProvider = (Provider) multimapProvider; binder.bind(bindingSelection.getJavaxProviderSetMultimapKey()).toProvider(javaxProvider); @SuppressWarnings({"unchecked", "rawtypes"}) Provider<Map<K, Collection<Provider<V>>>> collectionProvider = (Provider) multimapProvider; binder .bind(bindingSelection.getProviderCollectionMultimapKey()) .toProvider(collectionProvider); @SuppressWarnings({"unchecked", "rawtypes"}) Provider<Map<K, Collection<javax.inject.Provider<V>>>> collectionJavaxProvider = (Provider) multimapProvider; binder .bind(bindingSelection.getJavaxProviderCollectionMultimapKey()) .toProvider(collectionJavaxProvider); // Binds a Map<K, Set<V>> @SuppressWarnings({"unchecked", "rawtypes"}) Provider<Map<K, Set<V>>> realMultimapProvider = new RealMultimapProvider(bindingSelection.getMapKey()); binder.bind(bindingSelection.getMultimapKey()).toProvider(realMultimapProvider); }
.setDefault().toProvider(ObjectMapperProvider.class).in(Singleton.class); .setDefault().toProvider(XmlMapperProvider.class).in(Singleton.class);
public void bindMapJsonCodec(Class<?> keyType, Class<?> valueType) { requireNonNull(keyType, "keyType is null"); requireNonNull(valueType, "valueType is null"); ParameterizedTypeImpl mapType = new ParameterizedTypeImpl(null, Map.class, keyType, valueType); binder.bind(getJsonCodecKey(mapType)).toProvider(new JsonCodecProvider(mapType)).in(Scopes.SINGLETON); }
@Override public void bind(Binder binder, Annotation annotation, String prefix) { configBinder(binder).bindConfig(SimpleAddressSelectorConfig.class, annotation, prefix); binder.bind(AddressSelector.class) .annotatedWith(annotation) .toProvider(new ExtendedSimpleAddressSelectorProvider(annotation)); }
@Override protected void configure() { bind(a).to(b); bind(b).to(c); bind(c).toProvider(Providers.of("c")).in(ServletScopes.REQUEST); bind(d).toProvider(Providers.of("d")).in(RequestScoped.class); bind(e).to(AnnotatedRequestScopedClass.class); install( new PrivateModule() { @Override protected void configure() { bind(f).toProvider(Providers.of("f")).in(RequestScoped.class); expose(f); } }); }
public void configure(Binder binder) { binder = binder.withSource(method); if (scopeAnnotation != null) { binder.bind(key).toProvider(this).in(scopeAnnotation); } else { binder.bind(key).toProvider(this); } if (exposed) { // the cast is safe 'cause the only binder we have implements PrivateBinder. If there's a // misplaced @Exposed, calling this will add an error to the binder's error queue ((PrivateBinder) binder).expose(key); } }
/** * Adds a binding for T. Multiple calls to this are safe, and will be collapsed as duplicate * bindings. */ private void addDirectTypeBinding(Binder binder) { binder .bind(bindingSelection.getDirectKey()) .toProvider(new RealDirectTypeProvider<T>(bindingSelection)); }
@Override protected void configure() { bind(a).to(b); bind(b).to(c); bind(c).toProvider(Providers.of("c")).in(Scopes.NO_SCOPE); bind(d).toInstance("d"); bind(e).toProvider(Providers.of("e")).asEagerSingleton(); bind(f).toProvider(Providers.of("f")).in(Scopes.SINGLETON); bind(g).toProvider(Providers.of("g")).in(Singleton.class); bind(h).toProvider(Providers.of("h")).in(CustomScoped.class); bindScope(CustomScoped.class, Scopes.NO_SCOPE); install( new PrivateModule() { @Override protected void configure() { bind(i).toProvider(Providers.of("i")).in(CustomScoped.class); expose(i); } }); }