# Injecting RestController through the RestHandler

**URL:** <https://discuss.elastic.co/t/injecting-restcontroller-through-the-resthandler/136935>\
**Category:** Elasticsearch\
**Created:** [June 21, 2018, 8:28pm UTC](https://discuss.elastic.co/t/injecting-restcontroller-through-the-resthandler/136935 "2018-06-21T20:28:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arul\_since1975](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@arul\_since1975](https://discuss.elastic.co/u/arul_since1975)\
**Post date:** [June 21, 2018, 8:28pm UTC](https://discuss.elastic.co/t/injecting-restcontroller-through-the-resthandler/136935/1 "2018-06-21T20:28:29Z")

</div>

I have the following code in one of my plugins which works well with ES 5.1.2. However with ES 5.6.8 it compiles, but runs into problem as it is not possible to inject RestController directly.  
Please let me know the workaround for the same?  
Also could you please share any example?

public class IndexCleanerAction implements RestHandler {  
@Inject  
public IndexCleanerAction(final RestController controller) {  
controller.registerHandler(RestRequest.Method.GET, "/\_indexcleaner/indexcleanup", this);  
controller.registerHandler(RestRequest.Method.POST, "/\_indexcleaner/indexcleanup", this);  
controller.registerHandler(RestRequest.Method.PUT, "/\_indexcleaner/indexcleanup/{id}", this);  
controller.registerHandler(RestRequest.Method.DELETE, "/\_indexcleaner/indexcleanup/{id}", this);  
}

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [June 22, 2018, 6:21pm UTC](https://discuss.elastic.co/t/injecting-restcontroller-through-the-resthandler/136935/2 "2018-06-22T18:21:24Z")

</div>

Your plugin needs to implement `ActionPlugin`, and construct your rest handlers and return them from `getRestHandlers`, which takes the `RestController` as an argument.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 20, 2018, 6:21pm UTC](https://discuss.elastic.co/t/injecting-restcontroller-through-the-resthandler/136935/3 "2018-07-20T18:21:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
