I am trying to use Weld-SE for dependency injection in a dropwizard application. I can bootstrap Weld and inject in the Application class like so:
public class App extends Application<AppConfig> {
@Inject NameService service;
@Inject RestResource resource;
public static void main(String[] args) throws Exception {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
App app = container.instance().select(App.class).get();
app.run(args);
weld.shutdown();
}
}
I have written a producer method in a separate class for the RestResource and this is also injected fine. However in the resource class the service is not injected:
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public class RestResource {
@Inject NameService service;
@GET
public String test() {
return service.getName();
}
}
Here service is always null. Does anyone know how to make this work?