This repository has been archived by the owner on Aug 31, 2019. It is now read-only.
forked from google/guice
-
Notifications
You must be signed in to change notification settings - Fork 1
ExtendingGuice
Sam Berlin edited this page Jul 10, 2014
·
2 revisions
Guice's SPI for authors of tools, extensions and plugins
The service provider interface exposes Guice's internal models to aid in the development in tools, extensions, and plugins.
InjectionPoint | A constructor, field or method that can receive injections. Typically this is a member with the @Inject annotation. For non-private, no argument constructors, the member may omit the annotation. Each injection point has a collection of dependencies. |
Key | A type, plus an optional binding annotation. |
Dependency | A key, optionally associated to an injection point. These exist for injectable fields, and for the parameters of injectable methods and constructors. Dependencies know whether they accept null values via an @Nullable annotation. |
Element | A configuration unit, such as a bind or requestInjection statement. Elements are visitable. |
Module | A collection of configuration elements. Extracting the elements of a module enables static analysis and code-rewriting. You can inspect, rewrite, and validate these elements, and use them to build new modules. |
Injector | Manages the application's object graph, as specified by modules. SPI access to the injector works like reflection. It can be used to retrieve the application's bindings and dependency graph. |
The Elements SPI page has more information about using these classes.
(New in Guice 3.0)
@Toolable | An annotation used on methods also annotated with @Inject . This instructs Guice to inject the method even in Stage.TOOL . Typically used for extensions that need to gather information to implement HasDependencies or validate requirements and fail early for easier testing. |
ProviderWithExtensionVisitor | An interface that provider instances implement to allow extensions to visit custom subinterfaces of BindingTargetVisitor. See [[Extensions SPI |
The Extensions SPI page has more information about writing extensions that expose an SPI
Log a warning for each static injection in your Modules:
public void warnOfStaticInjections(Module... modules) {
for (Element element : Elements.getElements(modules)) {
element.acceptVisitor(new DefaultElementVisitor<Void>() {
@Override
public Void visit(StaticInjectionRequest element) {
logger.warning("Static injection is fragile! Please fix "
+ element.getType().getName() + " at " + element.getSource());
return null;
}
});
}
}
- User's Guide
- Best Practices
- Frequently Asked Questions
- Integration
- Extensions
- Internals
- Releases
- Community