public interface BindingsSpec extends RegistrySpec
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.
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()
and provider()
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.
Modifier and Type | Method and Description |
---|---|
default <O> RegistrySpec |
add(TypeToken<O> type,
O object)
Adds a registry entry that is available by the given type.
|
default <O> RegistrySpec |
addLazy(TypeToken<O> type,
Supplier<? extends O> supplier)
Adds a lazily created entry to the registry.
|
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.
|
default <T> BindingsSpec |
bind(TypeLiteral<T> publicType,
Class<? extends T> implType) |
default <T> BindingsSpec |
bind(TypeToken<T> publicType,
Class<? extends T> implType) |
BindingsSpec |
binder(Action<? super Binder> action)
Adds bindings by directly configuring a
Binder . |
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.
|
default <T> BindingsSpec |
bindInstance(TypeLiteral<? super T> publicType,
T instance)
Add a binding for the given public type, to the given implementing instance.
|
default <T> BindingsSpec |
bindInstance(TypeToken<? super T> publicType,
T instance) |
ServerConfig |
getServerConfig()
The launch config for the application.
|
BindingsSpec |
module(Class<? extends Module> moduleClass)
Adds the bindings from the given module.
|
<C,T extends ConfigurableModule<C>> |
module(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.
|
BindingsSpec |
module(Module module)
Adds the bindings from the given module.
|
default <C,T extends ConfigurableModule<C>> |
moduleConfig(Class<T> moduleClass,
C config) |
<C,T extends ConfigurableModule<C>> |
moduleConfig(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>> |
moduleConfig(T moduleClass,
C config) |
default <T> BindingsSpec |
multiBind(Class<T> type) |
default <T> BindingsSpec |
multiBind(Class<T> publicType,
Class<? extends T> implType) |
default <T> BindingsSpec |
multiBind(TypeLiteral<T> publicType,
Class<? extends T> implType) |
default <T> BindingsSpec |
multiBind(TypeToken<T> publicType,
Class<? extends T> implType) |
default <T> BindingsSpec |
multiBinder(Class<T> type,
Action<? super Multibinder<T>> action) |
default <T> BindingsSpec |
multiBinder(TypeLiteral<T> type,
Action<? super Multibinder<T>> action) |
default <T> BindingsSpec |
multiBinder(TypeToken<T> type,
Action<? super Multibinder<T>> action) |
default <T> BindingsSpec |
multiBindInstance(Class<T> publicType,
T instance) |
default <T> BindingsSpec |
multiBindInstance(T instance) |
default <T> BindingsSpec |
multiBindInstance(TypeLiteral<T> publicType,
T instance) |
default <T> BindingsSpec |
multiBindInstance(TypeToken<T> publicType,
T instance) |
default <T> BindingsSpec |
multiBindProvider(Class<T> publicType,
Provider<? extends T> provider) |
default <T> BindingsSpec |
multiBindProvider(TypeLiteral<T> publicType,
Provider<? extends T> provider) |
default <T> BindingsSpec |
multiBindProvider(TypeToken<T> publicType,
Provider<? extends T> provider) |
default <T> BindingsSpec |
multiBindProviderType(Class<T> publicType,
Class<? extends Provider<? extends T>> providerType) |
default <T> BindingsSpec |
provider(Class<T> publicType,
Provider<? extends T> provider) |
default <T> BindingsSpec |
provider(TypeLiteral<T> publicType,
Provider<? extends T> provider)
Add a binding for the given public type, to the given provider.
|
default <T> BindingsSpec |
provider(TypeToken<T> publicType,
Provider<? extends T> provider) |
default <T> BindingsSpec |
providerType(Class<T> publicType,
Class<? extends Provider<? extends T>> providerType) |
default <T> BindingsSpec |
providerType(TypeLiteral<T> publicType,
Class<? extends Provider<? extends T>> providerType)
Add a binding for the given public type, to the given provider type.
|
default <T> BindingsSpec |
providerType(TypeToken<T> publicType,
Class<? extends Provider<? extends T>> providerType) |
add, add, addLazy, with
ServerConfig getServerConfig()
BindingsSpec module(Module module)
module
- module whose bindings should be addedBindingsSpec module(Class<? extends Module> moduleClass)
moduleClass
- type of the module whose bindings should be added<C,T extends ConfigurableModule<C>> BindingsSpec module(Class<T> moduleClass, Action<? super C> configurer)
C
- the type of the module's config objectT
- the type of the modulemoduleClass
- type of the module whose bindings should be addedconfigurer
- action to customize the module's config object<C> BindingsSpec module(ConfigurableModule<C> module, Action<? super C> configurer)
C
- the type of the module's config objectmodule
- module whose bindings should be addedconfigurer
- action to customize the module's config object<C,T extends ConfigurableModule<C>> BindingsSpec moduleConfig(Class<T> moduleClass, C config, Action<? super C> configurer)
C
- the type of the module's config objectT
- the type of the modulemoduleClass
- type of the module whose bindings should be addedconfig
- config object for the moduleconfigurer
- action to customize the module's config objectdefault <C,T extends ConfigurableModule<C>> BindingsSpec moduleConfig(Class<T> moduleClass, C config)
<C> BindingsSpec moduleConfig(ConfigurableModule<C> module, C config, Action<? super C> configurer)
C
- the type of the module's config objectmodule
- module whose bindings should be addedconfig
- config object for the moduleconfigurer
- action to customize the module's config objectdefault <C,T extends ConfigurableModule<C>> BindingsSpec moduleConfig(T moduleClass, C config)
BindingsSpec binder(Action<? super Binder> action)
Binder
.action
- the binder configurationdefault <T> BindingsSpec multiBinder(TypeToken<T> type, Action<? super Multibinder<T>> action) throws Exception
Exception
default <T> BindingsSpec multiBinder(TypeLiteral<T> type, Action<? super Multibinder<T>> action) throws Exception
Exception
default <T> BindingsSpec multiBinder(Class<T> type, Action<? super Multibinder<T>> action) throws Exception
Exception
default BindingsSpec bind(Class<?> type)
type
- the type to add a binding fordefault <T> BindingsSpec multiBind(Class<T> type)
default <T> BindingsSpec bind(Class<T> publicType, Class<? extends T> implType)
T
- the public type of the bindingpublicType
- the public type of the bindingimplType
- the class implementing the public typedefault <T> BindingsSpec bind(TypeToken<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec bind(TypeLiteral<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec multiBind(TypeLiteral<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec multiBind(Class<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec multiBind(TypeToken<T> publicType, Class<? extends T> implType)
default <T> BindingsSpec bindInstance(TypeLiteral<? super T> publicType, T instance)
T
- the public type of the bindingpublicType
- the public type of the bindinginstance
- the instance that implements the public typedefault <T> BindingsSpec bindInstance(TypeToken<? super T> publicType, T instance)
default <T> BindingsSpec bindInstance(Class<? super T> publicType, T instance)
default <T> BindingsSpec bindInstance(T instance)
T
- the type of the bindinginstance
- the instance to binddefault <T> BindingsSpec multiBindInstance(Class<T> publicType, T instance)
default <T> BindingsSpec multiBindInstance(TypeLiteral<T> publicType, T instance)
default <T> BindingsSpec multiBindInstance(TypeToken<T> publicType, T instance)
default <T> BindingsSpec multiBindInstance(T instance)
default <T> BindingsSpec provider(TypeLiteral<T> publicType, Provider<? extends T> provider)
T
- The public type of the objectpublicType
- the public type of the objectprovider
- the provider for the objectdefault <T> BindingsSpec provider(TypeToken<T> publicType, Provider<? extends T> provider)
default <T> BindingsSpec provider(Class<T> publicType, Provider<? extends T> provider)
default <T> BindingsSpec multiBindProvider(TypeLiteral<T> publicType, Provider<? extends T> provider)
default <T> BindingsSpec multiBindProvider(TypeToken<T> publicType, Provider<? extends T> provider)
default <T> BindingsSpec multiBindProvider(Class<T> publicType, Provider<? extends T> provider)
default <T> BindingsSpec providerType(TypeLiteral<T> publicType, Class<? extends Provider<? extends T>> providerType)
T
- The public type of the objectpublicType
- the public type of the objectproviderType
- the type of the provider for the objectdefault <T> BindingsSpec providerType(Class<T> publicType, Class<? extends Provider<? extends T>> providerType)
default <T> BindingsSpec providerType(TypeToken<T> publicType, Class<? extends Provider<? extends T>> providerType)
default <T> BindingsSpec multiBindProviderType(Class<T> publicType, Class<? extends Provider<? extends T>> providerType)
default <O> RegistrySpec add(TypeToken<O> type, O object)
RegistrySpec
add
in interface RegistrySpec
O
- the public type of the registry entrytype
- the public type of the registry entryobject
- the actual registry entrydefault <O> RegistrySpec addLazy(TypeToken<O> type, Supplier<? extends O> supplier)
RegistrySpec
The supplier will be invoked exactly once, when a query is made to the registry of a compatible type of the given type.
addLazy
in interface RegistrySpec
O
- the public type of the registry entrytype
- the public type of the registry entrysupplier
- the supplier for creating the object when needed