1 #ifndef SAUCE_INTERNAL_BASE_INJECTOR_H_
2 #define SAUCE_INTERNAL_BASE_INJECTOR_H_
4 #include <sauce/exceptions.h>
5 #include <sauce/memory.h>
6 #include <sauce/named.h>
7 #include <sauce/provider.h>
8 #include <sauce/internal/bindings.h>
9 #include <sauce/internal/key.h>
10 #include <sauce/internal/locker_factory.h>
11 #include <sauce/internal/self_injector.h>
12 #include <sauce/internal/type_id.h>
21 template<
typename ImplicitBindings>
27 template<
typename ImplicitBindings,
typename Dependency>
36 id(namedTypeIdOf<Dependency>(name)) {
37 TypeIds::iterator
i = ids.find(
id);
50 template<
typename ImplicitBindings>
52 typedef sauce::auto_ptr<LockFactory> LockFactoryPtr;
53 typedef sauce::shared_ptr<Injector> InjectorPtr;
56 LockFactoryPtr lockFactory;
58 friend class ::sauce::Modules;
62 lockFactory(lockFactory) {}
66 template<
typename Dependency>
67 void validateAcyclic(
bool validateProviding, InjectorPtr injector, TypeIds & ids, std::string
const name)
const {
69 CircularDependencyGuard<ImplicitBindings, Normalized> guard(ids, name);
70 bindings.template validateAcyclic<Normalized>(validateProviding, injector, ids, name);
73 template<
typename Dependency>
74 void inject(
typename Key<Dependency>::Ptr & injected, InjectorPtr injector, std::string
const name)
const {
76 typedef typename Key<Dependency>::Iface Iface;
77 bindings.template get<Normalized>(injected, injector, name);
78 SelfInjector<Iface> selfInjector;
79 selfInjector.setSelf(injected);
82 template<
typename Scope>
83 void eagerlyInject(InjectorPtr injector)
const {
84 bindings.template eagerlyInject<Scope>(injector);
91 sauce::auto_ptr<Lock> lock = lockFactory->createLock();
98 namespace i = ::sauce::internal;
102 #endif // SAUCE_INTERNAL_BASE_INJECTOR_H_
Definition: base_injector.h:22
sauce::auto_ptr< Lock > acquireLock()
Create an RAII synchronization lock.
Definition: base_injector.h:90
A container for bindings.
Definition: bindings.h:50
Named< Dependency, Unnamed > Normalized
Note Normalized is not Iface, but Named.
Definition: key.h:27
Thrown when a dependency cycle is found for the given interface.
Definition: exceptions.h:67
Detects circular dependencies on behalf of injectors.
Definition: base_injector.h:28