public interface ModuleRegistry extends MutableRegistry<Module>
Ratpack adds the special HandlerDecoratingModule
interface that modules can implement if they want
to influence the handler “chain”.
The order that modules are registered in is important. Modules registered later can override the bindings of modules registered prior. This can be useful for overriding default implementation bindings.
Some modules have properties/methods that can be used to configure their bindings. This method can be used to retrieve such modules and configure them. The modules have have already been registered “upstream”.
import ratpack.guice.*; import ratpack.func.Action; import com.google.inject.AbstractModule; class MyService { private final String value; public MyService(String value) { this.value = value; } } class MyModule extends AbstractModule { public String serviceValue; protected void configure() { bind(MyService.class).toInstance(new MyService(serviceValue)); } } class ModuleAction implements Action<ModuleRegistry> { public void execute(ModuleRegistry modules) { // MyModule has been added by some other action that executed against this registry… modules.get(MyModule.class).serviceValue = "foo"; } }
Modifier and Type | Method and Description |
---|---|
void |
bind(Class<?> type)
Bind the given type with Guice.
|
<T> void |
bind(Class<? super T> publicType,
T instance)
Bind the given implementation with Guice, under the given public type.
|
<T> void |
bind(Class<T> publicType,
Class<? extends T> implType)
Bind the given implementation type with Guice, under the given public type.
|
<T> void |
bind(T instance)
Bind the given implementation with Guice, under its concrete type.
|
LaunchConfig |
getLaunchConfig()
The launch config for the application the module registry is for.
|
void |
init(Action<Injector> action)
Registers an action to operate on the injector when it has been finalized.
|
void |
init(Class<? extends Runnable> clazz)
Registers a runnable to instantiated via dependency injection when the injector is created from this module registry.
|
<T> void |
provider(Class<T> publicType,
Class<? extends javax.inject.Provider<? extends T>> providerType)
Bind the given provider with Guice, under the given type.
|
register, register, registerLazy, remove
LaunchConfig getLaunchConfig()
void bind(Class<?> type)
This can be used to add types to the application without writing a module.
If the type should be bound as a singleton, annotate it with Singleton
.
type
- The type to register with Guice.<T> void bind(Class<T> publicType, Class<? extends T> implType)
This can be used to add types to the application without writing a module.
If the type should be bound as a singleton, annotate it with Singleton
.
T
- The public type of the bindingpublicType
- The public type of the bindingimplType
- The class implementing the public type<T> void bind(Class<? super T> publicType, T instance)
This can be used to add types to the application without writing a module.
If the type should be bound as a singleton, annotate it with Singleton
.
T
- The public type of the bindingpublicType
- The public type of the bindinginstance
- The instance to make available<T> void bind(T instance)
This can be used to add types to the application without writing a module.
If the type should be bound as a singleton, annotate it with Singleton
.
T
- The type of the bindinginstance
- The instance to make available<T> void provider(Class<T> publicType, Class<? extends javax.inject.Provider<? extends T>> providerType)
This can be used to add types to the application without writing a module.
T
- The public type of the objectpublicType
- The public type of the objectproviderType
- The type of the provider for the objectvoid init(Action<Injector> action)
This can be used to do post processing of registered objects or application initialisation.
action
- The action to execute against the constructed injectorvoid init(Class<? extends Runnable> clazz)
This facilitates writing a Runnable
implementation that uses constructor injection to get hold of what it needs to for the initialization.
clazz
- The class of the runnable to execute as an init action