Dependency injection with Guice - erlide/erlide_xtext GitHub Wiki
This is a new way of structuring the code, so it will take us a while to get it right. There aren't many examples on how to use it inside and across Eclipse plugins.
Overview
The basic idea with DI is that one creates the object graph for the application at startup. Of course, the creation can and should be done lazily, but the graph is defined from the Guice configuration. The more dynamic part of the graph is created using provider objects. Finally, the most dynamic objects (that depend on runtime parameters) must be handled manually.
We need to decide which objects belong to the static object graph and which ones are dynamic. For the latter we need to create them with factories and inject the dependencies manually.
The static graph has as roots each participating plugin. These define a module with the bindings they provide and the injector inherits the bindings from the plugins each one depends on.
Another set of roots is the GuiceAwareExtensionFactory, used to create objects specified in Eclipse extensions.
I'm not sure how to handle extensions we define ourselves and where for example an UI plugin provides a binding for an extension provided by a core plugin. I suppose we must use multibindings. We need to test it with a demo.
Guidelines
- The recommended kind of injection is via constructors. It is safer and the dependencies are more visible.
- For Eclipse and framework dependencies (loggers, etc) we can use field injection, it is easier to handle. We can see later if it works for us.