Skip to content
Permalink
Browse files

Add factory methods for modules that configure the Binder. This can s…

…ave some boilerplate in certain cases.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=272911062
  • Loading branch information
dimo414 authored and cpovirk committed Oct 4, 2019
1 parent 134db35 commit 9b371d3663db9db230417f3cc394e72b705d7d7f
Showing with 58 additions and 0 deletions.
  1. +58 −0 core/src/com/google/inject/util/Modules.java
@@ -407,4 +407,62 @@ protected void configure() {
}
};
}

/** Returns a module that will configure the injector to require explicit bindings. */
public static Module requireExplicitBindingsModule() {
return new RequireExplicitBindingsModule();
}

private static final class RequireExplicitBindingsModule implements Module {
@Override
public void configure(Binder binder) {
binder.requireExplicitBindings();
}
}

/**
* Returns a module that will configure the injector to require {@literal @}{@link Inject} on
* constructors.
*
* @see Binder#requireAtInjectOnConstructors
*/
public static Module requireAtInjectOnConstructorsModule() {
return new RequireAtInjectOnConstructorsModule();
}

private static final class RequireAtInjectOnConstructorsModule implements Module {
@Override
public void configure(Binder binder) {
binder.requireAtInjectOnConstructors();
}
}

/**
* Returns a module that will configure the injector to require an exactly matching binding
* annotation.
*
* @see Binder#requireExactBindingAnnotations
*/
public static Module requireExactBindingAnnotationsModule() {
return new RequireExactBindingAnnotationsModule();
}

private static final class RequireExactBindingAnnotationsModule implements Module {
@Override
public void configure(Binder binder) {
binder.requireExactBindingAnnotations();
}
}

/** Returns a module that will configure the injector to disable circular proxies. */
public static Module disableCircularProxiesModule() {
return new DisableCircularProxiesModule();
}

private static final class DisableCircularProxiesModule implements Module {
@Override
public void configure(Binder binder) {
binder.disableCircularProxies();
}
}
}

0 comments on commit 9b371d3

Please sign in to comment.
You can’t perform that action at this time.