dropwizard/dropwizard-elasticsearch

How to access client in Resource request

jensenbox opened this issue · 1 comments

Would be awesome to show exactly how to access a client instance from within a resource.

Is the prescribed method to add a parameter to the init function for the resource with the client or is there some way to do a wrapper like "@context" to grab the client?

@jensenbox You can either simply add the Client instance to the constructor parameters of your JAX-RS resource class and pass the Client instance on instantiation of that class (e. g. in the Application#run() method) or use HK2 to inject the Client instance into your resource class via the @Inject annotation.

See https://gist.github.com/joschi/f706e394172988f9200b for an example of how to do the latter.