# Elasticsearch and Guice

**URL:** <https://discuss.elastic.co/t/elasticsearch-and-guice/57822>\
**Category:** Elasticsearch\
**Created:** [August 11, 2016, 1:20pm UTC](https://discuss.elastic.co/t/elasticsearch-and-guice/57822 "2016-08-11T13:20:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![psynaps3](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@psynaps3](https://discuss.elastic.co/u/psynaps3)\
**Post date:** [August 11, 2016, 1:20pm UTC](https://discuss.elastic.co/t/elasticsearch-and-guice/57822/1 "2016-08-11T13:20:04Z")

</div>

Hi,

Just wanted to know if elasticsearch is moving away from using Guice to wire dependencies? If yes, are there any discussion posts where I can read more about the reasons behind it?

Thanks.

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [August 11, 2016, 5:19pm UTC](https://discuss.elastic.co/t/elasticsearch-and-guice/57822/2 "2016-08-11T17:19:37Z")

</div>

For some developer comments about dependency injection modules in ES, see

> <https://github.com/elastic/elasticsearch/issues/12783#issuecomment-129743779>

> <https://github.com/elastic/elasticsearch/pull/15687>

> <https://github.com/elastic/elasticsearch/issues/17754#issuecomment-209990542>

Please note that ES has always used an older (and somewhat optimized) shadowed version of Guice 2 while Guice is now at 4.1. This brought some challenges concerning the tracing and backporting of fixed bugs, see [https://github.com/elastic/elasticsearch/issues/283](https://github.com/elastic/elasticsearch/issues/283) and [https://github.com/elastic/elasticsearch/pull/17921](https://github.com/elastic/elasticsearch/pull/17921)

---

<div class="post-metadata">

**Author:** ![psynaps3](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@psynaps3](https://discuss.elastic.co/u/psynaps3)\
**Post date:** [August 12, 2016, 6:27am UTC](https://discuss.elastic.co/t/elasticsearch-and-guice/57822/3 "2016-08-12T06:27:30Z")

</div>

Thanks Jörg, that was helpful.

Is the plan to **completely** remove Guice from the elasticsearch codebase in favour of constructor injection by hand, or to have a small set of modules for top level services (e.g. SearchModule, TransportModule) that has a flat structure and then use Guice to wire only these top level modules and use @Inject for their discovery?

If you are completely removing Guice, then what approach are you taking to lookup (inject) a specific service from a different service?

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [August 12, 2016, 7:27am UTC](https://discuss.elastic.co/t/elasticsearch-and-guice/57822/4 "2016-08-12T07:27:04Z")

</div>

I can not speak for the ES developers but what I can read between the lines is that Guice shall completely disappear in 5.0

From ES plugin developer perspective, I'm bound to that decision and I hope I can navigate through the labyrinth of factories, registries, modules and services that would have to be wired by hand into the code - kind of a struggle, like back in the old days of Java 2 and J2EE. But, I understand that because Guice ignores plugin isolation and collides with classloading as long as the software around Guice is not providing classloader separated dependency injection aka "everything is a plugin" design pattern, which ES never tried consequently enough. I mean, initiate plugin code first, then create separate Guice injectors each with all ES modules for each plugin. Instead, all plugins were considered a module within the Guice hierarchy.

From the perspective as a great fan of the magic of Guice (and Guava), I would have to follow my own code base in order to use Guice again, which means, wrap my own code base around Elasticsearch, including a web app platform with plugins, custom bootstrapping (aka embedding Elasticsearch) - yes, reinventing the wheel. I doubt this could be a satisfying solution for everyone.

I haven't tried ES 5.0 - it is moving too fast and it collides with several other projects in my timeline - so I am still confident all will work out well in the end.

---

<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 5, 2017, 10:28pm UTC](https://discuss.elastic.co/t/elasticsearch-and-guice/57822/5 "2017-07-05T22:28:08Z")

</div>


