1 #ifndef SAUCE_BINDER_H_
2 #define SAUCE_BINDER_H_
8 #include <sauce/named.h>
9 #include <sauce/provider.h>
10 #include <sauce/scopes.h>
11 #include <sauce/internal/bindings.h>
12 #include <sauce/internal/clause.h>
13 #include <sauce/internal/implicit_provider_binding.h>
14 #include <sauce/internal/injector_binding.h>
15 #include <sauce/internal/key.h>
16 #include <sauce/internal/new_binding.h>
17 #include <sauce/internal/opaque_binding.h>
18 #include <sauce/internal/pending_thrower.h>
19 #include <sauce/internal/provider_binding.h>
26 template<
typename Dependency,
typename Scope,
typename Ctor,
typename Allocator>
28 virtual void onComplete() {
30 this->getState()->bind(pendingBinding);
37 template<
typename Dependency,
typename Scope,
typename Ctor>
41 virtual void onComplete() {
42 i::OpaqueBindingPtr pendingBinding(
new i::NewBinding<Dependency, Scope, Ctor, std::allocator<int> >());
43 this->getState()->bind(pendingBinding);
48 template<
typename Allocator>
57 template<
typename Prov
iderDependency,
typename Scope,
typename Prov
iderCtor>
65 i::OpaqueBindingPtr pendingBinding(
new i::NewBinding<ProviderDependency, Scope, ProviderCtor, std::allocator<int> >());
66 this->getState()->bind(pendingBinding);
69 this->getState()->bindProvider(providerBinding);
74 template<
typename Allocator>
83 template<
typename Dependency,
typename Scope>
91 template<
typename Ctor>
96 template<
typename Prov
iderCtor>
102 template<
typename Dependency>
105 template<
typename Iface>
111 template<
typename Dependency,
typename Signature>
114 typedef typename MethodBinding_::Method Method;
118 friend class BindClause<typename i::Key<Dependency>::Iface>;
121 i::OpaqueBindingPtr methodBinding(
new MethodBinding_(method));
122 this->getState()->bind(methodBinding);
133 template<
typename Dependency,
typename Signature>
136 typedef typename MethodBinding_::Method Method;
140 friend class BindClause<typename i::Key<Dependency>::Iface>;
143 i::OpaqueBindingPtr methodBinding(
new MethodBinding_(method));
144 this->getState()->bind(methodBinding);
160 template<
typename Dependency>
167 i::OpaqueBindingPtr instanceBinding(
new InstanceBinding_(iface));
168 this->getState()->bind(instanceBinding);
185 template<
typename Dependency>
198 template<
typename Method>
199 ToMethodClause<Dependency, Method> toMethod(Method method) {
200 return this->pass(ToMethodClause<Dependency, Method>(method));
203 template<
typename Signature>
204 ToMethodNamingClause<Dependency, Signature> toMethodNaming(
205 typename ToMethodNamingClause<Dependency, Signature>::Method method) {
206 return this->pass(ToMethodNamingClause<Dependency, Signature>(method));
209 template<
typename SetDependency>
210 ToMethodNamingClause<Dependency, void(Iface::*) (SetDependency)> setting(
211 typename ToMethodNamingClause<Dependency,
void(Iface::*) (SetDependency)>::Method method,
212 std::string name = unnamed()) {
213 ToMethodNamingClause<Dependency, void(Iface::*) (SetDependency)> toMethodNamingClause(method);
214 toMethodNamingClause = this->pass(toMethodNamingClause);
215 toMethodNamingClause.bindDynamicDependencyName(0, name);
216 return toMethodNamingClause;
219 template<
typename Iface,
typename Name>
220 ToMethodNamingClause<Dependency, void(Iface::*) (Named<Iface, Name>)> setting(
221 typename ToMethodNamingClause<Dependency,
void(Iface::*) (Named<Iface, Name>)>::Method method) {
222 return this->pass(ToMethodNamingClause<Dependency,
void(Iface::*) (Named<Iface, Name>)>(method));
225 template<
typename Scope>
226 InClause<Dependency, Scope> in() {
227 return this->pass(InClause<Dependency, Scope>());
230 template<
typename Ctor>
231 ToClause<Dependency, NoScope, Ctor> to() {
232 return this->pass(ToClause<Dependency, NoScope, Ctor>());
235 template<
typename Prov
iderCtor>
236 ToProviderClause<ProviderDependency, NoScope, ProviderCtor> toProvider() {
237 return this->pass(ToProviderClause<ProviderDependency, NoScope, ProviderCtor>());
246 template<
typename Iface>
247 class BindClause:
public i::Clause<Named<Iface, Unnamed> > {
249 typedef Named<Provider<Iface>, Unnamed> ProviderDependency;
251 BindClause(i::ClauseStatePtr state):
252 i::Clause<Named<Iface, Unnamed> >(state) {}
258 template<
typename Name>
259 NamedClause<Named<Iface, Name> > named() {
260 return this->pass(NamedClause<Named<Iface, Name> >());
263 NamedClause<Named<Iface, Unnamed> > named(std::string
const name) {
264 this->setDynamicName(name);
265 return this->pass(NamedClause<Named<Iface, Unnamed> >());
268 ToInstanceClause<Named<Iface, Unnamed> > toInstance(IfacePtr iface) {
269 return this->pass(ToInstanceClause<Named<Iface, Unnamed> >(iface));
272 template<
typename Method>
273 ToMethodClause<Named<Iface, Unnamed>, Method> toMethod(Method method) {
274 return this->pass(ToMethodClause<Named<Iface, Unnamed>, Method>(method));
277 template<
typename Signature>
278 ToMethodNamingClause<Named<Iface, Unnamed>, Signature> toMethodNaming(
279 typename ToMethodNamingClause<Named<Iface, Unnamed>, Signature>::Method method) {
280 return this->pass(ToMethodNamingClause<Named<Iface, Unnamed>, Signature>(method));
283 template<
typename SetDependency>
284 ToMethodNamingClause<Named<Iface, Unnamed>, void(Iface::*) (SetDependency)> setting(
285 typename ToMethodNamingClause<Named<Iface, Unnamed>,
void(Iface::*) (SetDependency)>::Method method,
286 std::string name = unnamed()) {
287 ToMethodNamingClause<Named<Iface, Unnamed>, void(Iface::*) (SetDependency)> toMethodNamingClause(method);
288 toMethodNamingClause = this->pass(toMethodNamingClause);
289 toMethodNamingClause.bindDynamicDependencyName(0, name);
290 return toMethodNamingClause;
293 template<
typename SetIface,
typename Name>
294 ToMethodNamingClause<Named<Iface, Unnamed>, void(Iface::*) (Named<SetIface, Name>)> setting(
295 typename ToMethodNamingClause<Named<Iface, Unnamed>,
void(Iface::*) (Named<SetIface, Name>)>::Method method) {
296 return this->pass(ToMethodNamingClause<Named<Iface, Unnamed>,
void(Iface::*) (Named<SetIface, Name>)>(method));
299 template<
typename Scope>
300 InClause<Named<Iface, Unnamed>, Scope> in() {
301 return this->pass(InClause<Named<Iface, Unnamed>, Scope>());
304 template<
typename Ctor>
305 ToClause<Named<Iface, Unnamed>, NoScope, Ctor> to() {
306 return this->pass(ToClause<Named<Iface, Unnamed>, NoScope, Ctor>());
309 template<
typename Prov
iderCtor>
310 ToProviderClause<ProviderDependency, NoScope, ProviderCtor> toProvider() {
311 return this->pass(ToProviderClause<ProviderDependency, NoScope, ProviderCtor>());
318 class ImplicitBindings;
331 bindings(bindings) {}
338 template<
typename Iface>
340 i::ClauseStatePtr clauseState(
new i::ClauseState(bindings, *
this));
348 #endif // SAUCE_BINDER_H_
BindClause< Iface > bind()
Begin binding the chosen interface.
Definition: binder.h:339
Binds to a specific constructor and allocator.
Definition: binder.h:27
Wrap dependency requests with Named to choose one of several (statically) named alternatives.
Definition: named.h:12
Passed to modules to create bindings.
Definition: binder.h:324
i::Key< Dependency >::Iface Provides
Indicates to template magic that this type exposes sauce::shared_ptr
get(). Definition: provider.h:27
Binds to a specific method.
Definition: binder.h:112
Names the binding.
Definition: binder.h:103
A builder that creates a single binding.
Definition: binder.h:106
A factory that accepts Modules and creates Injectors.
Definition: modules.h:77
Scopes the binding.
Definition: binder.h:84
Binds to a specific single instance.
Definition: binder.h:161
An injection that provides from the configured provider.
Definition: provider_binding.h:18
Binds to a provider with a specific constructor, allocating from the heap.
Definition: binder.h:58
An injection that provides the value passed at construction.
Definition: instance_binding.h:17
Definition: new_binding.h:19
Base class for parts of the fluent binding API.
Definition: clause.h:98
Binds to a specific method with possible static dependency names.
Definition: binder.h:134
The accumulated state passed between Clauses that ultimately results in a new Binding.
Definition: clause.h:26
Definition: method_binding.h:14
A mixin to defer and throw pending exceptions.
Definition: pending_thrower.h:23
A complete specification of a dependency request.
Definition: key.h:15
An interface for including custom factories in an Injector.
Definition: provider.h:15
Binds to a specific constructor, allocating from the heap.
Definition: binder.h:38