Note
Grapht is no longer under active development. If you are interested in taking over the project, contact Michael Ekstrand.
Grapht is a light-weight dependency injector. It converts the dependency injection problem into a graph-based problem that can be solved and analyzed without constructing any components until a solution is guaranteed. The solution graph is also exposed to enable flexible extensions such as static analysis, and visualizations. Its design is discussed in our paper:
Michael D. Ekstrand and Michael Ludwig. 2016. Dependency Injection with Static Analysis and Context-Aware Policy. Journal of Object Technology 15(1) (February 1st, 2016), 1:1–31. DOI 10.5381/jot.2016.15.1.a1.
Grapht also supports specifying dependency bindings based on where in the graph the components must be injected. This allows a programmer to specify that a type Foo must be used in the context of type A, but a Bar should be used in any other context. This can be used to compliment the idea of qualifying injection points using annotations, as specified in JSR 330.
Grapht provides a fluent configuration API very similar to that of Guice's.
Grapht can be depended on from Maven's Central Repository by adding the following to the dependencies section in your POM:
<dependency>
<groupId>org.grouplens.grapht</groupId>
<artifactId>grapht</artifactId>
<version>0.6.0</version>
</dependency>
Grapht is released under the terms of the MIT license.
By submitting a pull request, you release your contribution to us under same license terms unless otherwise specified.
- Add
@AliasFor
to allow qualifiers to alias each other.
- Move
Types.getDefaultClassLoader()
toClassLoaders.inferDefault()
- Add class loader context management
- Dependency graphs now use
Dependency
andComponent
types, instead ofDesireChain
andCachedSatisfaction
, for greater forward flexibility. - Support fixed desires (will not be rewritten)
See closed issues for more details.
- Enable regular expression matching for contexts (#83)
- Allow binding to satisfactions
- Refactor the reflection abstractions, dropping the SPI in favor of the
reflect
package. - Use an immutable DAG instead of the old mutable Graph
- Support rewriting graphs using bind rules
- Make more use of Guava
- Support custom/arbitrary class loaders (typically the thread's context class loader)
See closed issues for more details.
- Added typed providers
- Add
DependencySolverBuilder
to make construction more obvious - Make instance providers serializable
See closed issues for more details.
- Rewrite serialization logic to be more robust (#54)
- Return immutable views rather than copies of sets from
Graph
(#58) - Be smarter about checking provider types (#35, #36)
- Add anchored context matchers (
at
matching) (#41) - Improve diagnostic warnings and validity checking
- Rename
Edge.getLabel()
togetDesireChain()
- Change
Graph.updateEdgeLabel
toreplaceEdge
- Remove
Binding.finalBinding
in favor of boolean parameter onto
(#46) - Add a visitor for satisfactions (#33)
- Add support for specifying default implementations and providers in properties files under the
META-INF
directory (#51) Module.bind
is now calledModule.configure
- Incompatible change: Changed default binding policy with respect to qualfier matching. Now, if you bind a type without specifying any qualifier, it defaults to binding unqualified dependencies and dependencies whose qualifiers are annotated with
@AllowUnqualifiedMatch
. To get the old behavior of matching irrespective of qualifier matcher, dobind(Type.class).withAnyQualifier()
(orbindAny(Type.class)
).
- Fix serialization of inner classes
- Fix serialization of primitive types in graphs
- Add
DefaultNull
annotation and support for it.
See closed issues for more details.
- Remove
Parameter
anotation - Add basic thread safety for injectors
- Add more error detection
- Add convenience method to bind qualified types
- Allow explicit null bindings to be created
- Refactor SPI and bind rules to allow for more flexible binding functions. This brings the implementation much closer to the theoretical formulation presented in our paper.
- Implement Provider injection, including breaking dependency cycles with Provider injection.
- Pass the JSR 330 TCK.
- Simplify and clean up Graph API to no longer take type parameters.
- Rename getFunction() to build() in BindingFunctionBuilder.
- Make dependency graph solutions serializable using Java's serialization framework.
- Add CachePolicy lifecycle specification for instances (e.g. new, memoize, etc)
- Add support for generic attribute annotations on injection points that are carried through the solution graph.
- Add slf4j logging to grapht
- Initial published release of grapht
- Supports basic and context-aware dependency injection