dropwizard-guicier icon indicating copy to clipboard operation
dropwizard-guicier copied to clipboard

Duplicate Modules Cause Injector Creation Failure

Open cielowu opened this issue 3 years ago • 2 comments

Hi,

So I'm bumping our system to Dropwizard 2.x, dropwizard-guice causes an issue because the (jersey2-guice)[https://github.com/HubSpot/dropwizard-guice] still uses prior Jersey 2.6 version.

So I'm trying to migrate from dropwizard-guice to this to give it a try. However, duplicate modules cause the creation failure of the Injector.

After digging it a little bit, this is because now the default InjectorFactory implementation uses Modules.combine to combine all the modules. This makes the uniqueness check inside LifecycleInjectorBuilderImpl.java that we use essentially become ineffective.

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

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

cielowu avatar Mar 31 '21 17:03 cielowu

Oof sorry about that. Since implementors of InjectorFactory only accept a single module, it's a bit hard to change at this point. For now you can work around the issue by supplying a custom InjectorFactory which doesn't use Modules.combine

jhaber avatar Mar 31 '21 17:03 jhaber

Yes, that does unblock the issue.

Now I face the same issue as dropwizard-guice, do you know what is the plan for supporting Dropwizard 2.x?

cielowu avatar Mar 31 '21 20:03 cielowu