/** * Create a new LensKit configuration. */ public LenskitConfiguration() { bindings = new BindingFunctionBuilder(true); roots = new HashSet<>(); Collections.addAll(roots, INITIAL_ROOTS); }
public DependencySolver buildDependencySolverImpl(SolveDirection direction) { DependencySolverBuilder dsb = DependencySolver.newBuilder(); for (BindingFunctionBuilder cfg: Lists.reverse(configs)) { dsb.addBindingFunction(direction.transform(cfg.build(BindingFunctionBuilder.RuleSet.EXPLICIT))); dsb.addBindingFunction(direction.transform(cfg.build(BindingFunctionBuilder.RuleSet.INTERMEDIATE_TYPES))); dsb.addBindingFunction(direction.transform(cfg.build(BindingFunctionBuilder.RuleSet.SUPER_TYPES))); } // default desire function cannot trigger rewrites dsb.addBindingFunction(DefaultDesireBindingFunction.create(classLoader), false); dsb.setDefaultPolicy(CachePolicy.MEMOIZE); dsb.setMaxDepth(RESOLVE_DEPTH_LIMIT); return dsb.build(); }
@Override public LenskitConfigContext within(Annotation qualifier, Class<?> type) { return wrapContext(bindings.getRootContext().within(qualifier, type)); }
/** * Create a new copy of a LensKit configuration. * @param other The configuration to copy. */ public LenskitConfiguration(LenskitConfiguration other) { bindings = other.bindings.clone(); roots = new HashSet<>(other.roots); }
/** * Generate bindings. * @param brb A bind rule builder, completely populated except for its {@linkplain BindRuleBuilder#setDependencyType(Class) dependency type}. * @param type The search type for {@link #generateBindPoints(Class)}. */ private void generateBindings(BindRuleBuilder brb, Class<?> type) { ContextMatcher matcher = context.getContextPattern(); BindingFunctionBuilder config = context.getBuilder(); if (config.getGenerateRules()) { Map<Class<?>, RuleSet> bindPoints = generateBindPoints(type); for (Entry<Class<?>, RuleSet> e: bindPoints.entrySet()) { config.addBindRule(e.getValue(), matcher, brb.setDependencyType(e.getKey()).build()); } } else { config.addBindRule(RuleSet.EXPLICIT, matcher, brb.setDependencyType(sourceType).build()); } }
void addBindRule(RuleSet set, ContextMatcher context, BindRule rule) { Multimap<ContextMatcher, BindRule> map = getMap(set); map.put(context, rule); }
/** * Apply a module to the root context of this InjectorBuilder (i.e. * {@link Module#configure(Context)}). * * @param module The module to apply * @return This InjectorBuilder */ public InjectorBuilder applyModule(Module module) { builder.applyModule(module); return this; }
public BindingImpl(ContextImpl context, Class<T> type) { this(context, type, context.getBuilder().getDefaultExclusions(), Qualifiers.matchDefault(), CachePolicy.NO_PREFERENCE, false); }
/** * Create a new copy of a LensKit configuration. * @param other The configuration to copy. */ public LenskitConfiguration(LenskitConfiguration other) { bindings = other.bindings.clone(); roots = new HashSet<>(other.roots); }
/** * Return the built BindingFunction for the given RuleSet. * * @param set * @return */ public BindingFunction build(RuleSet set) { return new RuleBasedBindingFunction(getMap(set)); }
@Override public <T> LenskitBinding<T> bind(Class<T> type) { return wrapContext(bindings.getRootContext()).bind(type); }
@Override public BindingFunctionBuilder clone() { return new BindingFunctionBuilder(this); }
public Injector build() { BindingFunction[] functions; if (enableProviderInjection) { functions = new BindingFunction[] { builder.build(RuleSet.EXPLICIT), builder.build(RuleSet.INTERMEDIATE_TYPES), builder.build(RuleSet.SUPER_TYPES), new ProviderBindingFunction(), // insert extra provider injection DefaultDesireBindingFunction.create(classLoader) }; } else { functions = new BindingFunction[] { builder.build(RuleSet.EXPLICIT), builder.build(RuleSet.INTERMEDIATE_TYPES), builder.build(RuleSet.SUPER_TYPES), DefaultDesireBindingFunction.create(classLoader) }; } return new DefaultInjector(cachePolicy, 100, functions); } }
@Override public LenskitConfigContext at(Class<? extends Annotation> qualifier, Class<?> type) { return wrapContext(bindings.getRootContext().at(qualifier, type)); }
/** * Create a new LensKit configuration. */ public LenskitConfiguration() { bindings = new BindingFunctionBuilder(true); roots = new HashSet<>(); Collections.addAll(roots, INITIAL_ROOTS); }
public DependencySolver buildDependencySolverImpl(SolveDirection direction) { DependencySolverBuilder dsb = DependencySolver.newBuilder(); for (BindingFunctionBuilder cfg: Lists.reverse(configs)) { dsb.addBindingFunction(direction.transform(cfg.build(BindingFunctionBuilder.RuleSet.EXPLICIT))); dsb.addBindingFunction(direction.transform(cfg.build(BindingFunctionBuilder.RuleSet.INTERMEDIATE_TYPES))); dsb.addBindingFunction(direction.transform(cfg.build(BindingFunctionBuilder.RuleSet.SUPER_TYPES))); } // default desire function cannot trigger rewrites dsb.addBindingFunction(DefaultDesireBindingFunction.create(classLoader), false); dsb.setDefaultPolicy(CachePolicy.MEMOIZE); dsb.setMaxDepth(RESOLVE_DEPTH_LIMIT); return dsb.build(); }
@Override public LenskitConfigContext at(Class<?> type) { return wrapContext(bindings.getRootContext().at(type)); }
/** * Create a new injector builder using the specified class loader. * @param loader The class loader. * @param modules The initial modules to configure. * @return The injector builder. */ public static InjectorBuilder create(ClassLoader loader, Module... modules) { InjectorBuilder bld = new InjectorBuilder(loader, new BindingFunctionBuilder(true)); for (Module m: modules) { bld.applyModule(m); } return bld; }
@Override public LenskitConfigContext at(Annotation qualifier, Class<?> type) { return wrapContext(bindings.getRootContext().at(qualifier, type)); }
/** * Create a new InjectorBuilder that automatically applies the given Modules * via {@link #applyModule(Module)}. Additional Modules can be applied later * as well. Configuration via the {@link Context} interface is also possible * (and recommended if Modules aren't used) before calling {@link #build()}. * * @param modules Any modules to apply immediately * @deprecated use {@link #create(Module...)} instead */ @Deprecated public InjectorBuilder(Module... modules) { this(Types.getDefaultClassLoader(), new BindingFunctionBuilder()); for (Module m: modules) { applyModule(m); } }