Sauce-0.10.1
A C++ Dependency Injection Framework
Public Member Functions | Friends | List of all members
sauce::Injector Class Reference

Public Member Functions

template<typename Dependency >
void inject (typename i::Key< Dependency >::Ptr &injected, std::string const name=unnamed())
 
template<typename Iface , typename Name >
void inject (typename i::Key< Named< Iface, Name > >::Ptr &injected, std::string const name=unnamed())
 
template<typename Dependency >
i::Key< Dependency >::Ptr get (std::string const name=unnamed())
 
template<typename Iface , typename Name >
i::Key< Named< Iface, Name > >::Ptr get (std::string const name=unnamed())
 
template<typename Scope >
i::InjectorPtr enter () const
 
i::InjectorPtr exit () const
 
template<typename Scope >
void eagerlyInject ()
 

Friends

class Modules
 
class i::InjectorFriend
 

Member Function Documentation

◆ eagerlyInject()

template<typename Scope >
void sauce::Injector::eagerlyInject ( )
inline
187 {
188 sauce::auto_ptr<i::Lock> lock = acquireLock();
189 eagerlyInject<Scope>(getSelf());
190 }

◆ enter()

template<typename Scope >
i::InjectorPtr sauce::Injector::enter ( ) const
inline
168 {
169 if (alreadyInScope<Scope>()) {
170 throw AlreadyInScopeExceptionFor<Scope>();
171 }
172
173 i::InjectorPtr scoped(new Injector(i::typeIdOf<Scope>(), getSelf()));
174 scoped->setSelfPtr(scoped);
175 return scoped;
176 }

◆ exit()

i::InjectorPtr sauce::Injector::exit ( ) const
inline
178 {
179 if (next.get() == NULL) {
180 throw ExitingSingletonScopeException();
181 } else {
182 return next;
183 }
184 }

◆ get() [1/2]

template<typename Dependency >
i::Key< Dependency >::Ptr sauce::Injector::get ( std::string const  name = unnamed())
inline
156 {
157 typename i::Key<Dependency>::Ptr injected;
158 inject<Dependency>(injected, name);
159 return injected;
160 }
A complete specification of a dependency request.
Definition: key.h:15

◆ get() [2/2]

template<typename Iface , typename Name >
i::Key< Named< Iface, Name > >::Ptr sauce::Injector::get ( std::string const  name = unnamed())
inline
163 {
164 return get<Named<Iface, Name> >(name);
165 }

◆ inject() [1/2]

template<typename Dependency >
void sauce::Injector::inject ( typename i::Key< Dependency >::Ptr &  injected,
std::string const  name = unnamed() 
)
inline
137 {
138 typedef typename i::Key<Dependency>::Ptr Ptr;
139 typedef typename i::Key<Dependency>::Normalized Normalized;
140
141 sauce::auto_ptr<i::Lock> lock = acquireLock();
142
143 i::TypeIds ids;
144 bool validateProviding = (injected.get() == NULL);
145 validateAcyclic<Normalized>(validateProviding, getSelf(), ids, name); // TODO Make this check optional.
146
147 inject<Normalized>(injected, getSelf(), name);
148 }

◆ inject() [2/2]

template<typename Iface , typename Name >
void sauce::Injector::inject ( typename i::Key< Named< Iface, Name > >::Ptr &  injected,
std::string const  name = unnamed() 
)
inline
151 {
152 inject<Named<Iface, Name> >(injected, name);
153 }

The documentation for this class was generated from the following file: