Sauce-0.10.1
A C++ Dependency Injection Framework
Public Member Functions | List of all members
sauce::internal::Bindings< ImplicitBindings > Class Template Reference

A container for bindings. More...

#include <sauce/internal/bindings.h>

Public Member Functions

void put (OpaqueBindingPtr binding)
 Insert the given binding.
 
template<typename Dependency >
sauce::shared_ptr< ResolvedBinding< Dependency > > getProvidingBinding (std::string const name) const
 
template<typename Dependency >
std::vector< sauce::shared_ptr< ResolvedBinding< Dependency > > > getModifierBindings (std::string const name) const
 
template<typename Dependency >
void validateAcyclic (bool validateProviding, InjectorPtr injector, TypeIds &ids, std::string const name) const
 
template<typename Dependency >
void get (typename Key< Dependency >::Ptr &injected, InjectorPtr injector, std::string const name) const
 Inject the named Dependency. More...
 
template<typename Scope >
void eagerlyInject (InjectorPtr injector) const
 

Detailed Description

template<typename ImplicitBindings>
class sauce::internal::Bindings< ImplicitBindings >

A container for bindings.

Each Modules objects creates a Bindings, and passes a const copy to each Injector it creates. The set of bindings an Injector uses is therefore read-only.

When providing instances (eagerly and not) the injector is passed in and the dependency is returned directly, instead of giving the binding to the injector (the binding details stay hidden.)

The template parameter is a strategy type that attempts to located unknown bindings dynamically (implicitly.) Due to the threat of circular dependencies (in Sauce's type space), Bindings itself can't be aware of concrete Binding implementations. The only time it needs to know about them is when resolving implicit bindings. So, this functionality is hidden behind the templated strategy.

Member Function Documentation

template<typename ImplicitBindings>
template<typename Dependency >
void sauce::internal::Bindings< ImplicitBindings >::get ( typename Key< Dependency >::Ptr &  injected,
InjectorPtr  injector,
std::string const  name 
) const
inline

Inject the named Dependency.

If no binding is found, the implicit bindings are checked.

138  {
139  typedef sauce::shared_ptr<ResolvedBinding<Dependency> > BindingPtr;
140  BindingPtr binding;
141 
142  if (injected.get() == NULL) {
143  binding = getProvidingBinding<Dependency>(name);
144  binding->get(injected, binding, injector);
145  }
146 
147  typedef std::vector<BindingPtr> BindingPtrs;
148  BindingPtrs bindings = getModifierBindings<Dependency>(name);
149 
150  for (typename BindingPtrs::iterator i = bindings.begin(); i != bindings.end(); ++i) {
151  binding = *i;
152  binding->get(injected, binding, injector);
153  }
154  }
Definition: binder.h:317

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