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>
21 template<
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 &) {}
118 namespace i = ::sauce::internal;
122 #endif // SAUCE_INTERNAL_BINDING_H_