Skip to content

Commit

Permalink
Merge pull request #56 from HubSpot/injector-factory-tweak
Browse files Browse the repository at this point in the history
Pass all modules to injector factory
  • Loading branch information
jhaber authored Aug 16, 2019
2 parents d85ef2d + 0de427c commit 9664745
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/main/java/com/hubspot/dropwizard/guicier/GuiceBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.google.inject.servlet.GuiceFilter;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
import com.google.inject.util.Modules;
import com.squarespace.jersey2.guice.JerseyGuiceModule;
import com.squarespace.jersey2.guice.JerseyGuiceUtils;

Expand Down Expand Up @@ -93,25 +92,22 @@ public void run(final T configuration, final Environment environment) throws Exc
.add(dropwizardModule)
.add(new JerseyGuiceModule(serviceLocatorName))
.add(new JerseyGuicierModule())
.add(new Module() {
@Override
public void configure(final Binder binder) {
binder.bind(Environment.class).toInstance(environment);
binder.bind(configClass).toInstance(configuration);
}
.add(binder -> {
binder.bind(Environment.class).toInstance(environment);
binder.bind(configClass).toInstance(configuration);
});
if (enableGuiceEnforcer) {
modulesBuilder.add(new GuiceEnforcerModule());
}
this.injector = injectorFactory.create(guiceStage, Modules.combine(modulesBuilder.build()));
this.injector = injectorFactory.create(guiceStage, modulesBuilder.build());

JerseyGuiceUtils.install((name, parent) -> {
if (!name.startsWith("__HK2_")) {
return null;
} else if (serviceLocatorName.equals(name)) {
return injector.getInstance(ServiceLocator.class);
} else {
LOG.debug("Returning a new ServiceLocator for name '%s'", name);
LOG.debug("Returning a new ServiceLocator for name '{}'", name);
return JerseyGuiceUtils.newServiceLocator(name, parent);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Stage;
import com.google.inject.util.Modules;

public interface InjectorFactory {
Injector create(Stage stage, Module module);

default Injector create(Stage stage, Iterable<? extends Module> modules) {
return create(stage, Modules.combine(modules));
}
}

0 comments on commit 9664745

Please sign in to comment.