HubSpot/dropwizard-guice

How exactly HelloWorldConfiguration and Environment get injected in the example

Closed this issue · 1 comments

I'm new to dropwizard. In this example code:

public class HelloWorldModule extends AbstractModule {

  @Override
  protected void configure() {
    // anything you'd like to configure
  }

  @Provides
  public SomePool providesSomethingThatNeedsConfiguration(HelloWorldConfiguration configuration) {
    return new SomePool(configuration.getPoolName());
  }

  @Provides
  public SomeManager providesSomenthingThatNeedsEnvironment(Environment env) {
    return new SomeManager(env.getSomethingFromHere()));
  }
}

I don't quite understand why HelloWorldConfiguration could be injected as parameter and so does Environment

The document of Guice explicitly says the injection needs to go with annotation @Inject and the I can't find anyway in the source code of dropwizard-guice that use Automatic Injection.

Could anyone explain to my how this works?

You can check out the documentation for ProvidesMethods here. These are special methods that create Guice bindings and the method parameters are implicitly injected by Guice.