Skip to content

Guice Dependency Injection

Joe Betz edited this page Sep 11, 2013 · 5 revisions

Guice dependency injection may be used with rest.li by using the restli-guice-bridge module.

An example project using guice dependency injection is available in the rest.li codebase:

https://github.com/linkedin/rest.li/tree/master/examples/guice-server

This example shows how Rest.li's GuiceRestliServlet may be used to run rest.li servers with full guice dependency injection.

To use, first add a dependency to the restli-guice-bridge module, .e.g:


dependencies {
  compile "com.linkedin.pegasus:restli-guice-bridge:1.9.23"
}

Next, setup a setup a guice servlet, defining a guice GuiceServletContextListener for your application. For an example, see: /examples/guice-server/server/src/main/java/com/example/fortune/inject/FortunesGuiceServletConfig.java

And lastly, configure your web.xml for an example, see: /examples/guice-server/server/src/main/webapp/WEB-INF/web.xml

Clone this wiki locally