Interface BindingsSpec
-
- All Superinterfaces:
RegistrySpec
public interface BindingsSpec extends RegistrySpec
A buildable specification of Guice bindings.This type is used when bootstrapping a Guice based application to add
modules
and bindings.It is recommended to become familiar with Guice bindings, scopes and other concerns before using Guice with Ratpack.
Module order and overrides
The order in which modules are added is significant. Subsequent modules can override the bindings of previous modules. This is a very useful technique for augmenting/customising the functionality provided by modules. Many modules provide extensive bindings to facilitate such overriding.
Bindings added via the
bind()
andprovider()
methods always have the highest precedence, regardless of order. That is, non module bindings can always override module bindings regardless of whether the module is added before or after the non module binding.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <O> RegistrySpec
add(com.google.common.reflect.TypeToken<O> type, O object)
Adds a registry entry that is available by the given type.default <O> RegistrySpec
addLazy(com.google.common.reflect.TypeToken<O> type, Supplier<? extends O> supplier)
Adds a lazily created entry to the registry.default <T> BindingsSpec
bind(com.google.common.reflect.TypeToken<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec
bind(com.google.inject.TypeLiteral<T> publicType, Class<? extends T> implType)
default BindingsSpec
bind(Class<?> type)
Add a binding for the given type.default <T> BindingsSpec
bind(Class<T> publicType, Class<? extends T> implType)
Add a binding for the given public type, to the given implementation type.BindingsSpec
binder(Action<? super com.google.inject.Binder> action)
Adds bindings by directly configuring aBinder
.default <T> BindingsSpec
bindInstance(com.google.common.reflect.TypeToken<? super T> publicType, T instance)
default <T> BindingsSpec
bindInstance(com.google.inject.TypeLiteral<? super T> publicType, T instance)
Add a binding for the given public type, to the given implementing instance.default <T> BindingsSpec
bindInstance(Class<? super T> publicType, T instance)
default <T> BindingsSpec
bindInstance(T instance)
Add a binding for the given object to its concrete type.ServerConfig
getServerConfig()
The launch config for the application.BindingsSpec
module(com.google.inject.Module module)
Adds the bindings from the given module.BindingsSpec
module(Class<? extends com.google.inject.Module> moduleClass)
Adds the bindings from the given module.<C,T extends ConfigurableModule<C>>
BindingsSpecmodule(Class<T> moduleClass, Action<? super C> configurer)
Adds the bindings from the given configurable module.<C> BindingsSpec
module(ConfigurableModule<C> module, Action<? super C> configurer)
Adds the bindings from the given configurable module.default <C,T extends ConfigurableModule<C>>
BindingsSpecmoduleConfig(Class<T> moduleClass, C config)
<C,T extends ConfigurableModule<C>>
BindingsSpecmoduleConfig(Class<T> moduleClass, C config, Action<? super C> configurer)
Adds the bindings from the given configurable module.<C> BindingsSpec
moduleConfig(ConfigurableModule<C> module, C config, Action<? super C> configurer)
Adds the bindings from the given configurable module.default <C,T extends ConfigurableModule<C>>
BindingsSpecmoduleConfig(T moduleClass, C config)
default <T> BindingsSpec
multiBind(com.google.common.reflect.TypeToken<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec
multiBind(com.google.inject.TypeLiteral<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec
multiBind(Class<T> type)
default <T> BindingsSpec
multiBind(Class<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec
multiBinder(com.google.common.reflect.TypeToken<T> type, Action<? super com.google.inject.multibindings.Multibinder<T>> action)
default <T> BindingsSpec
multiBinder(com.google.inject.TypeLiteral<T> type, Action<? super com.google.inject.multibindings.Multibinder<T>> action)
default <T> BindingsSpec
multiBinder(Class<T> type, Action<? super com.google.inject.multibindings.Multibinder<T>> action)
default <T> BindingsSpec
multiBindInstance(com.google.common.reflect.TypeToken<T> publicType, T instance)
default <T> BindingsSpec
multiBindInstance(com.google.inject.TypeLiteral<T> publicType, T instance)
default <T> BindingsSpec
multiBindInstance(Class<T> publicType, T instance)
default <T> BindingsSpec
multiBindInstance(T instance)
default <T> BindingsSpec
multiBindProvider(com.google.common.reflect.TypeToken<T> publicType, com.google.inject.Provider<? extends T> provider)
default <T> BindingsSpec
multiBindProvider(com.google.inject.TypeLiteral<T> publicType, com.google.inject.Provider<? extends T> provider)
default <T> BindingsSpec
multiBindProvider(Class<T> publicType, com.google.inject.Provider<? extends T> provider)
default <T> BindingsSpec
multiBindProviderType(Class<T> publicType, Class<? extends com.google.inject.Provider<? extends T>> providerType)
default <T> BindingsSpec
provider(com.google.common.reflect.TypeToken<T> publicType, com.google.inject.Provider<? extends T> provider)
default <T> BindingsSpec
provider(com.google.inject.TypeLiteral<T> publicType, com.google.inject.Provider<? extends T> provider)
Add a binding for the given public type, to the given provider.default <T> BindingsSpec
provider(Class<T> publicType, com.google.inject.Provider<? extends T> provider)
default <T> BindingsSpec
providerType(com.google.common.reflect.TypeToken<T> publicType, Class<? extends com.google.inject.Provider<? extends T>> providerType)
default <T> BindingsSpec
providerType(com.google.inject.TypeLiteral<T> publicType, Class<? extends com.google.inject.Provider<? extends T>> providerType)
Add a binding for the given public type, to the given provider type.default <T> BindingsSpec
providerType(Class<T> publicType, Class<? extends com.google.inject.Provider<? extends T>> providerType)
-
Methods inherited from interface ratpack.exec.registry.RegistrySpec
add, add, addLazy, with
-
-
-
-
Method Detail
-
getServerConfig
ServerConfig getServerConfig()
The launch config for the application.- Returns:
- the launch config for the application
-
module
BindingsSpec module(com.google.inject.Module module)
Adds the bindings from the given module.- Parameters:
module
- module whose bindings should be added- Returns:
- this
-
module
BindingsSpec module(Class<? extends com.google.inject.Module> moduleClass)
Adds the bindings from the given module.- Parameters:
moduleClass
- type of the module whose bindings should be added- Returns:
- this
-
module
<C,T extends ConfigurableModule<C>> BindingsSpec module(Class<T> moduleClass, Action<? super C> configurer)
Adds the bindings from the given configurable module.- Type Parameters:
C
- the type of the module's config objectT
- the type of the module- Parameters:
moduleClass
- type of the module whose bindings should be addedconfigurer
- action to customize the module's config object- Returns:
- this
-
module
<C> BindingsSpec module(ConfigurableModule<C> module, Action<? super C> configurer)
Adds the bindings from the given configurable module.- Type Parameters:
C
- the type of the module's config object- Parameters:
module
- module whose bindings should be addedconfigurer
- action to customize the module's config object- Returns:
- this
-
moduleConfig
<C,T extends ConfigurableModule<C>> BindingsSpec moduleConfig(Class<T> moduleClass, C config, Action<? super C> configurer)
Adds the bindings from the given configurable module.- Type Parameters:
C
- the type of the module's config objectT
- the type of the module- Parameters:
moduleClass
- type of the module whose bindings should be addedconfig
- config object for the moduleconfigurer
- action to customize the module's config object- Returns:
- this
-
moduleConfig
default <C,T extends ConfigurableModule<C>> BindingsSpec moduleConfig(Class<T> moduleClass, C config)
-
moduleConfig
<C> BindingsSpec moduleConfig(ConfigurableModule<C> module, C config, Action<? super C> configurer)
Adds the bindings from the given configurable module.- Type Parameters:
C
- the type of the module's config object- Parameters:
module
- module whose bindings should be addedconfig
- config object for the moduleconfigurer
- action to customize the module's config object- Returns:
- this
-
moduleConfig
default <C,T extends ConfigurableModule<C>> BindingsSpec moduleConfig(T moduleClass, C config)
-
binder
BindingsSpec binder(Action<? super com.google.inject.Binder> action)
Adds bindings by directly configuring aBinder
.- Parameters:
action
- the binder configuration- Returns:
- this
-
multiBinder
default <T> BindingsSpec multiBinder(com.google.common.reflect.TypeToken<T> type, Action<? super com.google.inject.multibindings.Multibinder<T>> action) throws Exception
- Throws:
Exception
-
multiBinder
default <T> BindingsSpec multiBinder(com.google.inject.TypeLiteral<T> type, Action<? super com.google.inject.multibindings.Multibinder<T>> action) throws Exception
- Throws:
Exception
-
multiBinder
default <T> BindingsSpec multiBinder(Class<T> type, Action<? super com.google.inject.multibindings.Multibinder<T>> action) throws Exception
- Throws:
Exception
-
bind
default BindingsSpec bind(Class<?> type)
Add a binding for the given type.- Parameters:
type
- the type to add a binding for- Returns:
- this
-
multiBind
default <T> BindingsSpec multiBind(Class<T> type)
-
bind
default <T> BindingsSpec bind(Class<T> publicType, Class<? extends T> implType)
Add a binding for the given public type, to the given implementation type.- Type Parameters:
T
- the public type of the binding- Parameters:
publicType
- the public type of the bindingimplType
- the class implementing the public type- Returns:
- this
-
bind
default <T> BindingsSpec bind(com.google.common.reflect.TypeToken<T> publicType, Class<? extends T> implType)
-
bind
default <T> BindingsSpec bind(com.google.inject.TypeLiteral<T> publicType, Class<? extends T> implType)
-
multiBind
default <T> BindingsSpec multiBind(com.google.inject.TypeLiteral<T> publicType, Class<? extends T> implType)
-
multiBind
default <T> BindingsSpec multiBind(Class<T> publicType, Class<? extends T> implType)
-
multiBind
default <T> BindingsSpec multiBind(com.google.common.reflect.TypeToken<T> publicType, Class<? extends T> implType)
-
bindInstance
default <T> BindingsSpec bindInstance(com.google.inject.TypeLiteral<? super T> publicType, T instance)
Add a binding for the given public type, to the given implementing instance.- Type Parameters:
T
- the public type of the binding- Parameters:
publicType
- the public type of the bindinginstance
- the instance that implements the public type- Returns:
- this
-
bindInstance
default <T> BindingsSpec bindInstance(com.google.common.reflect.TypeToken<? super T> publicType, T instance)
-
bindInstance
default <T> BindingsSpec bindInstance(Class<? super T> publicType, T instance)
-
bindInstance
default <T> BindingsSpec bindInstance(T instance)
Add a binding for the given object to its concrete type.- Type Parameters:
T
- the type of the binding- Parameters:
instance
- the instance to bind- Returns:
- this
-
multiBindInstance
default <T> BindingsSpec multiBindInstance(Class<T> publicType, T instance)
-
multiBindInstance
default <T> BindingsSpec multiBindInstance(com.google.inject.TypeLiteral<T> publicType, T instance)
-
multiBindInstance
default <T> BindingsSpec multiBindInstance(com.google.common.reflect.TypeToken<T> publicType, T instance)
-
multiBindInstance
default <T> BindingsSpec multiBindInstance(T instance)
-
provider
default <T> BindingsSpec provider(com.google.inject.TypeLiteral<T> publicType, com.google.inject.Provider<? extends T> provider)
Add a binding for the given public type, to the given provider.- Type Parameters:
T
- The public type of the object- Parameters:
publicType
- the public type of the objectprovider
- the provider for the object- Returns:
- this
-
provider
default <T> BindingsSpec provider(com.google.common.reflect.TypeToken<T> publicType, com.google.inject.Provider<? extends T> provider)
-
provider
default <T> BindingsSpec provider(Class<T> publicType, com.google.inject.Provider<? extends T> provider)
-
multiBindProvider
default <T> BindingsSpec multiBindProvider(com.google.inject.TypeLiteral<T> publicType, com.google.inject.Provider<? extends T> provider)
-
multiBindProvider
default <T> BindingsSpec multiBindProvider(com.google.common.reflect.TypeToken<T> publicType, com.google.inject.Provider<? extends T> provider)
-
multiBindProvider
default <T> BindingsSpec multiBindProvider(Class<T> publicType, com.google.inject.Provider<? extends T> provider)
-
providerType
default <T> BindingsSpec providerType(com.google.inject.TypeLiteral<T> publicType, Class<? extends com.google.inject.Provider<? extends T>> providerType)
Add a binding for the given public type, to the given provider type.- Type Parameters:
T
- The public type of the object- Parameters:
publicType
- the public type of the objectproviderType
- the type of the provider for the object- Returns:
- this
-
providerType
default <T> BindingsSpec providerType(Class<T> publicType, Class<? extends com.google.inject.Provider<? extends T>> providerType)
-
providerType
default <T> BindingsSpec providerType(com.google.common.reflect.TypeToken<T> publicType, Class<? extends com.google.inject.Provider<? extends T>> providerType)
-
multiBindProviderType
default <T> BindingsSpec multiBindProviderType(Class<T> publicType, Class<? extends com.google.inject.Provider<? extends T>> providerType)
-
add
default <O> RegistrySpec add(com.google.common.reflect.TypeToken<O> type, O object)
Description copied from interface:RegistrySpec
Adds a registry entry that is available by the given type.- Specified by:
add
in interfaceRegistrySpec
- Type Parameters:
O
- the public type of the registry entry- Parameters:
type
- the public type of the registry entryobject
- the actual registry entry- Returns:
- this
-
addLazy
default <O> RegistrySpec addLazy(com.google.common.reflect.TypeToken<O> type, Supplier<? extends O> supplier)
Description copied from interface:RegistrySpec
Adds a lazily created entry to the registry.The supplier will be invoked exactly once, when a query is made to the registry of a compatible type of the given type.
- Specified by:
addLazy
in interfaceRegistrySpec
- Type Parameters:
O
- the public type of the registry entry- Parameters:
type
- the public type of the registry entrysupplier
- the supplier for creating the object when needed- Returns:
- this
-
-