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​(Module module)
        Adds the bindings from the given module.
        Parameters:
        module - module whose bindings should be added
        Returns:
        this
      • module

        BindingsSpec module​(java.lang.Class<? extends 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​(java.lang.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​(java.lang.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 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 Multibinder<T>> action)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • multiBinder

        default <T> BindingsSpec multiBinder​(java.lang.Class<T> type,
                                             Action<? super Multibinder<T>> action)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • bind

        default BindingsSpec bind​(java.lang.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​(java.lang.Class<T> type)
      • bind

        default <T> BindingsSpec bind​(java.lang.Class<T> publicType,
                                      java.lang.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,
                                      java.lang.Class<? extends T> implType)
      • multiBind

        default <T> BindingsSpec multiBind​(TypeLiteral<T> publicType,
                                           java.lang.Class<? extends T> implType)
      • multiBind

        default <T> BindingsSpec multiBind​(java.lang.Class<T> publicType,
                                           java.lang.Class<? extends T> implType)
      • multiBind

        default <T> BindingsSpec multiBind​(com.google.common.reflect.TypeToken<T> publicType,
                                           java.lang.Class<? extends T> implType)
      • bindInstance

        default <T> BindingsSpec bindInstance​(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​(java.lang.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​(java.lang.Class<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​(TypeLiteral<T> publicType,
                                          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,
                                          Provider<? extends T> provider)
      • provider

        default <T> BindingsSpec provider​(java.lang.Class<T> publicType,
                                          Provider<? extends T> provider)
      • multiBindProvider

        default <T> BindingsSpec multiBindProvider​(com.google.common.reflect.TypeToken<T> publicType,
                                                   Provider<? extends T> provider)
      • multiBindProvider

        default <T> BindingsSpec multiBindProvider​(java.lang.Class<T> publicType,
                                                   Provider<? extends T> provider)
      • providerType

        default <T> BindingsSpec providerType​(TypeLiteral<T> publicType,
                                              java.lang.Class<? extends 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​(java.lang.Class<T> publicType,
                                              java.lang.Class<? extends Provider<? extends T>> providerType)
      • providerType

        default <T> BindingsSpec providerType​(com.google.common.reflect.TypeToken<T> publicType,
                                              java.lang.Class<? extends Provider<? extends T>> providerType)
      • multiBindProviderType

        default <T> BindingsSpec multiBindProviderType​(java.lang.Class<T> publicType,
                                                       java.lang.Class<? extends 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,
                                         java.util.function.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