1#ifndef SAUCE_INTERNAL_BINDING_H_
2#define SAUCE_INTERNAL_BINDING_H_
7#include <sauce/injector.h>
8#include <sauce/memory.h>
9#include <sauce/named.h>
10#include <sauce/internal/key.h>
11#include <sauce/internal/opaque_binding.h>
12#include <sauce/internal/resolved_binding.h>
13#include <sauce/internal/type_id.h>
21template<
typename Dependency_,
typename Scope>
27 typedef typename ResolvedBinding<Dependency>::BindingPtr BindingPtr;
36 TypeId getScopeKey()
const {
37 return typeIdOf<Scope>();
45 virtual void inject(IfacePtr &, BindingPtr, InjectorPtr)
const = 0;
58 void get(IfacePtr & injected, BindingPtr binding, InjectorPtr injector)
const {
59 bool unscoped = (getScopeKey() == typeIdOf<NoScope>()) || this->
isModifier();
61 if (unscoped || !probe<Dependency>(injector, injected, getScopeKey())) {
63 assert((injected.get() != NULL) == this->isModifier());
65 inject(injected, binding, injector);
67 cache<Dependency>(injector, injected, getScopeKey());
78 void eagerlyInject(OpaqueBindingPtr opaque, InjectorPtr injector)
const {
79 if (getScopeKey() != typeIdOf<NoScope>()) {
80 BindingPtr binding = resolve<Dependency>(opaque);
84 get(injected, binding, injector);
91 virtual void setDynamicDependencyNames(std::vector<std::string>
const &) {}
118namespace i = ::sauce::internal;
Wrap dependency requests with Named to choose one of several (statically) named alternatives.
Definition: named.h:12
The base class of all actual binding implementations.
Definition: binding.h:22
void setName(std::string const name)
Set the dynamic name of this binding.
Definition: binding.h:110
std::string getName() const
The dynamic name of this binding.
Definition: binding.h:103
Definition: injector.h:196
A complete specification of a dependency request.
Definition: key.h:15
virtual bool isModifier() const
Does this binding modify an existing value?
Definition: opaque_binding.h:58
A binding for an acknowledged interface.
Definition: resolved_binding.h:20
virtual void validateAcyclic(sauce::shared_ptr< Injector >, TypeIds &) const=0
Establish that further dependencies do not introduce cycles with ones already accumulated.
A TypeSignature equipped with specific helper methods dealing in the hidden type.
Definition: type_id.h:34