/dropwizard-guice-1

A minimalistic integration of guice and dropwizard.

Primary LanguageJavaApache License 2.0Apache-2.0

Guice intergration for Dropwizard

Build Status Maven Version License Maintenance

A minimalistic integration between the dependency injection framework Guice and the microservice framework Dropwizard.

How to use?

This integration aims to introduce minimal effort to get started

Configure the Maven Dependencies

<dependency>
    <groupId>de.jakobjarosch.dropwizard</groupId>
    <artifactId>dropwizard-guice</artifactId>
    <version>{{ current-version }</version>
</dependency>

The current version can be found here.

Create your Application

To get started with Dropwizard and Guice you only need a single class which invokes the bootstrapping.

public class MyApplication implements GuiceApplication {
	public static void main(String[] args) throws Exception {
		new GuiceBootstrap<MyConfiguration>(MyConfiguration.class,
                                            MyApplication.class,
                                            new ExampleGuiceModule()) {
		}.run(args);
	}

	private final Environment environment;
	private final MyResource myResource;

	@Inject
	public MyApplication(Environment environment, MyResource myResource) {
		this.environment = environment;
		this.myResource = myResource;
	}

	public void run() throws Exception {
		environment.jersey().register(myResource);
	}
}

It is important, that the main method does invoke the GuiceBootstrap with an anonymous implementation like in the example. This is required due to the generic type paremeter resolution for Dropwizard.

More features can be found in the example.