Package com.google.inject.util
Class Modules
- java.lang.Object
-
- com.google.inject.util.Modules
-
public final class Modules extends java.lang.Object
Static utility methods for creating and working with instances ofModule
.- Since:
- 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Modules.CombinedModule
private static class
Modules.EmptyModule
private static class
Modules.ModuleWriter
static interface
Modules.OverriddenModuleBuilder
See the EDSL example atoverride()
.(package private) static class
Modules.OverrideModule
private static class
Modules.RealOverriddenModuleBuilder
-
Field Summary
Fields Modifier and Type Field Description static Module
EMPTY_MODULE
-
Constructor Summary
Constructors Modifier Constructor Description private
Modules()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Module
combine(Module... modules)
Returns a new module that installs all ofmodules
.static Module
combine(java.lang.Iterable<? extends Module> modules)
Returns a new module that installs all ofmodules
.private static Module
extractScanners(java.lang.Iterable<Element> elements)
static Modules.OverriddenModuleBuilder
override(Module... modules)
Returns a builder that creates a module that overlays override modules over the given modules.static Modules.OverriddenModuleBuilder
override(java.lang.Iterable<? extends Module> modules)
Returns a builder that creates a module that overlays override modules over the given modules.
-
-
-
Field Detail
-
EMPTY_MODULE
public static final Module EMPTY_MODULE
-
-
Method Detail
-
override
public static Modules.OverriddenModuleBuilder override(Module... modules)
Returns a builder that creates a module that overlays override modules over the given modules. If a key is bound in both sets of modules, only the binding from the override modules is kept. If a singlePrivateModule
is supplied or all elements are from a singlePrivateBinder
, then this will overwrite the private bindings. Otherwise, private bindings will not be overwritten unless they are exposed. This can be used to replace the bindings of a production module with test bindings:Module functionalTestModule = Modules.override(new ProductionModule()).with(new TestModule());
Prefer to write smaller modules that can be reused and tested without overrides.
- Parameters:
modules
- the modules whose bindings are open to be overridden
-
override
public static Modules.OverriddenModuleBuilder override(java.lang.Iterable<? extends Module> modules)
Returns a builder that creates a module that overlays override modules over the given modules. If a key is bound in both sets of modules, only the binding from the override modules is kept. If a singlePrivateModule
is supplied or all elements are from a singlePrivateBinder
, then this will overwrite the private bindings. Otherwise, private bindings will not be overwritten unless they are exposed. This can be used to replace the bindings of a production module with test bindings:Module functionalTestModule = Modules.override(getProductionModules()).with(getTestModules());
Prefer to write smaller modules that can be reused and tested without overrides.
- Parameters:
modules
- the modules whose bindings are open to be overridden
-
combine
public static Module combine(Module... modules)
Returns a new module that installs all ofmodules
.
-
combine
public static Module combine(java.lang.Iterable<? extends Module> modules)
Returns a new module that installs all ofmodules
.
-
-