Class ProvidesResolver

java.lang.Object
build.codemodel.dependency.injection.ProvidesResolver
All Implemented Interfaces:
Resolver<Object>

public class ProvidesResolver extends Object implements Resolver<Object>
A Resolver of values produced by Provides-annotated methods on a provider object.

At construction, the provider object's type descriptor hierarchy is scanned via the InjectionFramework for non-static, non-abstract, non-void, no-arg methods annotated with Provides - including a concrete method that overrides an abstract Provides declaration without repeating the annotation itself (see InjectionFramework.resolveEffectivelyProvides(Collection)). Each such method is registered as resolvable by its return type together with any qualifier annotations (e.g. @Named) declared on the method itself, so differently-qualified Provides methods returning the same type do not collide. At resolve time, the matching method is invoked and its return value is wrapped in a ValueBinding.

Each call to resolve(Dependency) invokes the Provides method afresh, giving factory-per-resolution semantics (analogous to an unscoped binding in Dagger/Guice). If singleton semantics are required, the provider object should memoize the value itself.

Author:
reed.vonredwitz
See Also: