public class RuleBasedBindingFunction extends Object implements BindingFunction
BindingFunction that uses BindRules created by the fluent API to bind desires to other desires or satisfactions.
For more details on context management, see ContextPattern
,
ContextElementMatcher
, and QualifierMatcher
. This function uses the
context to activate and select BindRules. A number of rules are used to order
applicable BindRules and choose the best. When any of these rules rely on the
current dependency context, the deepest node in the context has the most
influence. Put another way, if contexts were strings, they could be ordered
lexicographically from the right to the left.
When selecting BindRules to apply to a Desire, BindRules are ordered first by context match, then by the ordering defined by the bind rule itself.
A summary of these rules is that the best specified BindRule is applied, where the context that the BindRule is activated in has more priority than the type of the BindRule. If multiple rules tie for best, then the solver fails with a checked exception.
Constructor and Description |
---|
RuleBasedBindingFunction(com.google.common.collect.Multimap<ContextMatcher,BindRule> rules) |
Modifier and Type | Method and Description |
---|---|
BindingResult |
bind(InjectionContext context,
DesireChain desire)
Find the applicable binding, if any, for a desire in a particular context.
|
com.google.common.collect.ListMultimap<ContextMatcher,BindRule> |
getRules()
Get the rules underlying this binding function.
|
public RuleBasedBindingFunction(com.google.common.collect.Multimap<ContextMatcher,BindRule> rules)
public com.google.common.collect.ListMultimap<ContextMatcher,BindRule> getRules()
public BindingResult bind(InjectionContext context, DesireChain desire) throws ResolutionException
BindingFunction
bind
in interface BindingFunction
context
- The context.desire
- The desire.desire
, or null
if there is no binding.ResolutionException
- If there is an error (such as ambiguous bindings).Copyright © 2016 GroupLens Research. All rights reserved.