I want to use dependency inject only in certain part of my code. I am using HubSpot/dropwizard-guice to integrate drop-wizard and guice. Is there a way I can access guice object instances programmatically without changing the full project. Basically I would replace initialised objects with guice objects, So that I don't have to change everything at once.
Here is my application file
public class HelloWorldApplication extends Application<HelloWorldConfiguration> {
public static void main(String[] args) throws Exception {
new HelloWorldApplication().run(args);
}
@Override
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
GuiceBundle<HelloWorldConfiguration> guiceBundle = GuiceBundle.<HelloWorldConfiguration>newBuilder()
.addModule(new HelloWorldModule())
.enableAutoConfig(getClass().getPackage().getName())
.setConfigClass(HelloWorldConfiguration.class)
.build();
bootstrap.addBundle(guiceBundle);
}
@Override
public String getName() {
return "hello-world";
}
@Override
public void run(HelloWorldConfiguration helloWorldConfiguration, Environment environment) throws Exception {
}
}
Is there a way I can access guice injector without explicitly passing it as a method param all over my project?
Or Is there a way to directly get class instances from guice.