Class BindingsOverrideInjectorFactory
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.binding.BindingsOverrideInjectorFactory
-
- All Implemented Interfaces:
InjectorFactory
public class BindingsOverrideInjectorFactory extends java.lang.Object implements InjectorFactory
Custom injector factory used to override already overridden bindings. Note that in most cases direct override support inGuiceBundle.Builder.modulesOverride(Module...)
will be enough. Custom injector factory may be required to override binding, already overridden by modules override feature.Usage:
- Register custom factory in main bundle:
bundle.injectorFactory(new BindingsOverrideInjectorFactory())
- Register modules with overriding bindings using
override(Module...)
.
Note that factory may be registered using
GuiceyConfigurationHook
(in spock or junit extension). Custom modules could be registered with hook too because hook provides a good integration point before application start.It is assumed that modules will be registered at the same thread where application will initialize (thread local state used to support parallel testing).
- Since:
- 24.06.2018
-
-
Constructor Summary
Constructors Constructor Description BindingsOverrideInjectorFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.google.inject.Injector
createInjector(com.google.inject.Stage stage, java.lang.Iterable<? extends com.google.inject.Module> modules)
Creates an injector instance.static void
override(com.google.inject.Module... modules)
Overriding bindings registration.
-
-
-
Method Detail
-
createInjector
public com.google.inject.Injector createInjector(com.google.inject.Stage stage, java.lang.Iterable<? extends com.google.inject.Module> modules)
Description copied from interface:InjectorFactory
Creates an injector instance.NOTE: if overriding modules were used (
GuiceBundle.Builder.modulesOverride(Module...)
) then modules list will contain only one overridden module.Modules.override(Module...)
can be used on this module too, if required.- Specified by:
createInjector
in interfaceInjectorFactory
- Parameters:
stage
- target injector stage.modules
- modules supplied to injector- Returns:
- injector instance.
-
override
public static void override(com.google.inject.Module... modules)
Overriding bindings registration. Note that modules should contain only overriding bindings - all other will be used from main modules.- Parameters:
modules
- modules containing overriding bindings- Throws:
java.lang.IllegalStateException
- if injector was already created to prevent bad usage
-
-