Top Description Inners Fields Constructors Methods
com.google.inject.util

public final Class Modules

extends Object
Class Inheritance
Annotations
@CheckReturnValue
Imports
com.google.common.collect.ImmutableList, .ImmutableSet, .Iterables, .Lists, .Maps, .Sets, com.google.errorprone.annotations.CheckReturnValue, com.google.inject.AbstractModule, .Binder, .Binding, .Key, .Module, .PrivateBinder, .PrivateModule, .Scope, com.google.inject.internal.Errors, com.google.inject.spi.DefaultBindingScopingVisitor, .DefaultElementVisitor, .Element, .ElementVisitor, .Elements, .ModuleAnnotatedMethodScannerBinding, .PrivateElements, .ScopeBinding, java.lang.annotation.Annotation, java.util.Arrays, .List, .Map, .Set

Static utility methods for creating and working with instances of Module.
Author
[email protected] (Jesse Wilson)
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
public static interface
pack-priv static class
private static class
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
public static final Module

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Module
combine(Module... modules)

Returns a new module that installs all of modules.

public static Module
combine(Module module)

Deprecated there's no need to "combine" one module; just install it directly.
public static Module
combine()

Deprecated this method call is effectively a no-op, just remove it.
public static Module
combine(Iterable<? extends Module> modules)

Returns a new module that installs all of modules.

public static Module
disableCircularProxiesModule()

Returns a module that will configure the injector to disable circular proxies.

private static Module
public static Modules.OverriddenModuleBuilder
override(Module...
the modules whose bindings are open to be overridden
modules
)

Returns a builder that creates a module that overlays override modules over the given modules.

public static Modules.OverriddenModuleBuilder
override()

Deprecated there's no reason to use Modules.override() without any arguments.
public static Modules.OverriddenModuleBuilder
override(Iterable<? extends Module>
the modules whose bindings are open to be overridden
modules
)

Returns a builder that creates a module that overlays override modules over the given modules.

public static Module
requireAtInjectOnConstructorsModule()

Returns a module that will configure the injector to require @Inject on constructors.

public static Module
requireExactBindingAnnotationsModule()

Returns a module that will configure the injector to require an exactly matching binding annotation.

public static Module
requireExplicitBindingsModule()

Returns a module that will configure the injector to require explicit bindings.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EMPTY_MODULEback to summary
public static final Module EMPTY_MODULE

Constructor Detail

Modulesback to summary
private Modules()

Method Detail

combineback to summary
public static Module combine(Module... modules)

Returns a new module that installs all of modules.

Although sometimes helpful, this method is rarely necessary. Most Guice APIs accept multiple arguments or (like install()) can be called repeatedly. Where possible, external APIs that require a single module should similarly be adapted to permit multiple modules.

combineback to summary
public static Module combine(Module module)

Deprecated

there's no need to "combine" one module; just install it directly.

Annotations
@Deprecated
combineback to summary
public static Module combine()

Deprecated

this method call is effectively a no-op, just remove it.

Annotations
@Deprecated
combineback to summary
public static Module combine(Iterable<? extends Module> modules)

Returns a new module that installs all of modules.

Although sometimes helpful, this method is rarely necessary. Most Guice APIs accept multiple arguments or (like install()) can be called repeatedly. Where possible, external APIs that require a single module should similarly be adapted to permit multiple modules.

disableCircularProxiesModuleback to summary
public static Module disableCircularProxiesModule()

Returns a module that will configure the injector to disable circular proxies.

Since
4.2.3
extractScannersback to summary
private static Module extractScanners(Iterable<Element> elements)
overrideback to summary
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 single PrivateModule is supplied or all elements are from a single PrivateBinder, 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:Module[]

the modules whose bindings are open to be overridden

overrideback to summary
public static Modules.OverriddenModuleBuilder override()

Deprecated

there's no reason to use Modules.override() without any arguments.

Annotations
@Deprecated
overrideback to summary
public static Modules.OverriddenModuleBuilder override(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 single PrivateModule is supplied or all elements are from a single PrivateBinder, 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:Iterable<? extends Module>

the modules whose bindings are open to be overridden

requireAtInjectOnConstructorsModuleback to summary
public static Module requireAtInjectOnConstructorsModule()

Returns a module that will configure the injector to require @Inject on constructors.

Since
4.2.3
See Also
Binder#requireAtInjectOnConstructors
requireExactBindingAnnotationsModuleback to summary
public static Module requireExactBindingAnnotationsModule()

Returns a module that will configure the injector to require an exactly matching binding annotation.

Since
4.2.3
See Also
Binder#requireExactBindingAnnotations
requireExplicitBindingsModuleback to summary
public static Module requireExplicitBindingsModule()

Returns a module that will configure the injector to require explicit bindings.

Since
4.2.3
com.google.inject.util back to summary

private Class Modules.CombinedModule

extends Object
implements Module
Class Inheritance
All Implemented Interfaces
com.google.inject.Module

Field Summary

Modifier and TypeField and Description
pack-priv final Set<Module>

Constructor Summary

AccessConstructor and Description
pack-priv
CombinedModule(Iterable<? extends Module> modules)

Method Summary

Modifier and TypeMethod and Description
public void
configure(Binder binder)

Implements com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

modulesSetback to summary
pack-priv final Set<Module> modulesSet

Constructor Detail

CombinedModuleback to summary
pack-priv CombinedModule(Iterable<? extends Module> modules)

Method Detail

configureback to summary
public void configure(Binder binder)

Implements com.google.inject.Module.configure.

Doc from com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.

Do not invoke this method directly to install submodules. Instead use Binder#install(Module), which ensures that provider methods are discovered.

Annotations
@Override
com.google.inject.util back to summary

private final Class Modules.DisableCircularProxiesModule

extends Object
implements Module
Class Inheritance
All Implemented Interfaces
com.google.inject.Module

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
configure(Binder binder)

Implements com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DisableCircularProxiesModuleback to summary
private DisableCircularProxiesModule()

Method Detail

configureback to summary
public void configure(Binder binder)

Implements com.google.inject.Module.configure.

Doc from com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.

Do not invoke this method directly to install submodules. Instead use Binder#install(Module), which ensures that provider methods are discovered.

Annotations
@Override
com.google.inject.util back to summary

private Class Modules.EmptyModule

extends Object
implements Module
Class Inheritance
All Implemented Interfaces
com.google.inject.Module

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
configure(Binder binder)

Implements com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EmptyModuleback to summary
private EmptyModule()

Method Detail

configureback to summary
public void configure(Binder binder)

Implements com.google.inject.Module.configure.

Doc from com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.

Do not invoke this method directly to install submodules. Instead use Binder#install(Module), which ensures that provider methods are discovered.

Annotations
@Override
com.google.inject.util back to summary

private Class Modules.ModuleWriter

extends DefaultElementVisitor<Void>
Class Inheritance

Field Summary

Modifier and TypeField and Description
protected final Binder

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected Void
visitOther(Element element)

Overrides com.google.inject.spi.DefaultElementVisitor.visitOther.

Default visit implementation.
pack-priv void
writeAll(Iterable<? extends Element> elements)

Inherited from com.google.inject.spi.DefaultElementVisitor:
visitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisitvisit

Field Detail

binderback to summary
protected final Binder binder

Constructor Detail

ModuleWriterback to summary
pack-priv ModuleWriter(Binder binder)

Method Detail

visitOtherback to summary
protected Void visitOther(Element element)

Overrides com.google.inject.spi.DefaultElementVisitor.visitOther.

Doc from com.google.inject.spi.DefaultElementVisitor.visitOther.

Default visit implementation. Returns null.

Annotations
@Override
writeAllback to summary
pack-priv void writeAll(Iterable<? extends Element> elements)
com.google.inject.util back to summary

public Interface Modules.OverriddenModuleBuilder

Known Direct Implementers
com.google.inject.util.Modules.RealOverriddenModuleBuilder

See the EDSL example at override().

Method Summary

Modifier and TypeMethod and Description
public Module
with(Module... overrides)

See the EDSL example at override().

public Module
with()

Deprecated there's no reason to use .with() without any arguments.
public Module
with(Iterable<? extends Module> overrides)

See the EDSL example at override().

Method Detail

withback to summary
public Module with(Module... overrides)

See the EDSL example at override().

withback to summary
public Module with()

Deprecated

there's no reason to use .with() without any arguments.

Annotations
@Deprecated
withback to summary
public Module with(Iterable<? extends Module> overrides)

See the EDSL example at override().

com.google.inject.util back to summary

pack-priv Class Modules.OverrideModule

extends AbstractModule
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ImmutableSet<Module>
private final ImmutableSet<Module>

Constructor Summary

AccessConstructor and Description
pack-priv
OverrideModule(Iterable<? extends Module> overrides, ImmutableSet<Module> baseModules)

Method Summary

Modifier and TypeMethod and Description
public void
configure()

Overrides com.google.inject.AbstractModule.configure.

Configures a Binder via the exposed methods.
private Scope
Inherited from com.google.inject.AbstractModule:
addErroraddErroraddErrorbindbindbindbindConstantbinderbindInterceptorbindListenerbindListenerbindScopeconfigureconvertToTypescurrentStagegetMembersInjectorgetMembersInjectorgetProvidergetProviderinstallrequestInjectionrequestInjectionrequestStaticInjectionrequireBindingrequireBinding

Field Detail

baseModulesback to summary
private final ImmutableSet<Module> baseModules
overridesback to summary
private final ImmutableSet<Module> overrides

Constructor Detail

OverrideModuleback to summary
pack-priv OverrideModule(Iterable<? extends Module> overrides, ImmutableSet<Module> baseModules)

Method Detail

configureback to summary
public void configure()

Overrides com.google.inject.AbstractModule.configure.

Doc from com.google.inject.AbstractModule.configure.

Configures a Binder via the exposed methods.

Annotations
@Override
getScopeInstanceOrNullback to summary
private Scope getScopeInstanceOrNull(Binding<?> binding)
com.google.inject.util back to summary

private final Class Modules.RealOverriddenModuleBuilder

extends Object
implements OverriddenModuleBuilder
Class Inheritance
All Implemented Interfaces
com.google.inject.util.Modules.OverriddenModuleBuilder

Field Summary

Modifier and TypeField and Description
private final ImmutableSet<Module>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Module
with(Module... overrides)

Implements com.google.inject.util.Modules.OverriddenModuleBuilder.with.

See the EDSL example at override().
public Module
public Module
with(Iterable<? extends Module> overrides)

Implements com.google.inject.util.Modules.OverriddenModuleBuilder.with.

See the EDSL example at override().
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseModulesback to summary
private final ImmutableSet<Module> baseModules

Constructor Detail

RealOverriddenModuleBuilderback to summary
private RealOverriddenModuleBuilder(Iterable<? extends Module> baseModules)

Method Detail

withback to summary
public Module with(Module... overrides)

Implements com.google.inject.util.Modules.OverriddenModuleBuilder.with.

Doc from com.google.inject.util.Modules.OverriddenModuleBuilder.with.

See the EDSL example at override().

Annotations
@Override
withback to summary
public Module with()

Implements com.google.inject.util.Modules.OverriddenModuleBuilder.with.

Annotations
@Override
withback to summary
public Module with(Iterable<? extends Module> overrides)

Implements com.google.inject.util.Modules.OverriddenModuleBuilder.with.

Doc from com.google.inject.util.Modules.OverriddenModuleBuilder.with.

See the EDSL example at override().

Annotations
@Override
com.google.inject.util back to summary

private final Class Modules.RequireAtInjectOnConstructorsModule

extends Object
implements Module
Class Inheritance
  • java.lang.Object
  • com.google.inject.util.Modules.RequireAtInjectOnConstructorsModule
All Implemented Interfaces
com.google.inject.Module

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
configure(Binder binder)

Implements com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RequireAtInjectOnConstructorsModuleback to summary
private RequireAtInjectOnConstructorsModule()

Method Detail

configureback to summary
public void configure(Binder binder)

Implements com.google.inject.Module.configure.

Doc from com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.

Do not invoke this method directly to install submodules. Instead use Binder#install(Module), which ensures that provider methods are discovered.

Annotations
@Override
com.google.inject.util back to summary

private final Class Modules.RequireExactBindingAnnotationsModule

extends Object
implements Module
Class Inheritance
  • java.lang.Object
  • com.google.inject.util.Modules.RequireExactBindingAnnotationsModule
All Implemented Interfaces
com.google.inject.Module

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
configure(Binder binder)

Implements com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RequireExactBindingAnnotationsModuleback to summary
private RequireExactBindingAnnotationsModule()

Method Detail

configureback to summary
public void configure(Binder binder)

Implements com.google.inject.Module.configure.

Doc from com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.

Do not invoke this method directly to install submodules. Instead use Binder#install(Module), which ensures that provider methods are discovered.

Annotations
@Override
com.google.inject.util back to summary

private final Class Modules.RequireExplicitBindingsModule

extends Object
implements Module
Class Inheritance
All Implemented Interfaces
com.google.inject.Module

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
configure(Binder binder)

Implements com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RequireExplicitBindingsModuleback to summary
private RequireExplicitBindingsModule()

Method Detail

configureback to summary
public void configure(Binder binder)

Implements com.google.inject.Module.configure.

Doc from com.google.inject.Module.configure.

Contributes bindings and other configurations for this module to binder.

Do not invoke this method directly to install submodules. Instead use Binder#install(Module), which ensures that provider methods are discovered.

Annotations
@Override