From fcc397153df82a14a59a9c41572e0b21942b0171 Mon Sep 17 00:00:00 2001 From: jhaber Date: Tue, 13 Aug 2019 19:26:16 -0400 Subject: [PATCH 1/2] Pass all modules to injector factory --- .../hubspot/dropwizard/guicier/GuiceBundle.java | 14 +++++--------- .../dropwizard/guicier/InjectorFactory.java | 7 +++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/hubspot/dropwizard/guicier/GuiceBundle.java b/src/main/java/com/hubspot/dropwizard/guicier/GuiceBundle.java index 6a85009..214599b 100644 --- a/src/main/java/com/hubspot/dropwizard/guicier/GuiceBundle.java +++ b/src/main/java/com/hubspot/dropwizard/guicier/GuiceBundle.java @@ -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; @@ -93,17 +92,14 @@ 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_")) { @@ -111,7 +107,7 @@ public void configure(final Binder binder) { } 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); } }); diff --git a/src/main/java/com/hubspot/dropwizard/guicier/InjectorFactory.java b/src/main/java/com/hubspot/dropwizard/guicier/InjectorFactory.java index 276858b..002b995 100644 --- a/src/main/java/com/hubspot/dropwizard/guicier/InjectorFactory.java +++ b/src/main/java/com/hubspot/dropwizard/guicier/InjectorFactory.java @@ -1,9 +1,16 @@ package com.hubspot.dropwizard.guicier; +import java.util.Collection; + 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, Collection modules) { + return create(stage, Modules.combine(modules)); + } } From 0de427ca0537d6d6887aac686ef3582bcb3ddd00 Mon Sep 17 00:00:00 2001 From: jhaber Date: Tue, 13 Aug 2019 19:33:06 -0400 Subject: [PATCH 2/2] More lenient signature --- .../java/com/hubspot/dropwizard/guicier/InjectorFactory.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/hubspot/dropwizard/guicier/InjectorFactory.java b/src/main/java/com/hubspot/dropwizard/guicier/InjectorFactory.java index 002b995..2004e59 100644 --- a/src/main/java/com/hubspot/dropwizard/guicier/InjectorFactory.java +++ b/src/main/java/com/hubspot/dropwizard/guicier/InjectorFactory.java @@ -1,7 +1,5 @@ package com.hubspot.dropwizard.guicier; -import java.util.Collection; - import com.google.inject.Injector; import com.google.inject.Module; import com.google.inject.Stage; @@ -10,7 +8,7 @@ public interface InjectorFactory { Injector create(Stage stage, Module module); - default Injector create(Stage stage, Collection modules) { + default Injector create(Stage stage, Iterable modules) { return create(stage, Modules.combine(modules)); } }