Skip to content

Commit

Permalink
Add factory methods for modules that configure the Binder. This can s…
Browse files Browse the repository at this point in the history
…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 9b371d3
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions core/src/com/google/inject/util/Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.