Package ratpack.guice

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() 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.

    • 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 object
        T - the type of the module
        Parameters:
        moduleClass - type of the module whose bindings should be added
        configurer - 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 added
        configurer - 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 object
        T - the type of the module
        Parameters:
        moduleClass - type of the module whose bindings should be added
        config - config object for the module
        configurer - action to customize the module's config object
        Returns:
        this
      • 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 added
        config - config object for the module
        configurer - action to customize the module's config object
        Returns:
        this
      • binder

        BindingsSpec binder​(Action<? super com.google.inject.Binder> action)
        Adds bindings by directly configuring a Binder.
        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
      • bind

        default BindingsSpec bind​(Class<?> type)
        Add a binding for the given type.
        Parameters:
        type - the type to add a binding for
        Returns:
        this
      • 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 binding
        implType - 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​(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 binding
        instance - 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 object
        provider - 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 object
        providerType - 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 interface RegistrySpec
        Type Parameters:
        O - the public type of the registry entry
        Parameters:
        type - the public type of the registry entry
        object - 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 interface RegistrySpec
        Type Parameters:
        O - the public type of the registry entry
        Parameters:
        type - the public type of the registry entry
        supplier - the supplier for creating the object when needed
        Returns:
        this