Sauce-0.10.1: sauce/internal/implicit_provider_binding.h Source File

Sauce-0.10.1 A C++ Dependency Injection Framework

- Main Page
- Classes
- Files

- File List

implicit_provider_binding.h
1 #ifndef SAUCE_INTERNAL_IMPLICIT_PROVIDER_BINDING_H_
2 #define SAUCE_INTERNAL_IMPLICIT_PROVIDER_BINDING_H_
3
4 #include <cassert>
5
6 #include <sauce/injector.h>
7 #include <sauce/memory.h>
8 #include <sauce/named.h>
9 #include <sauce/internal/resolved_binding.h>
10 #include <sauce/internal/binding.h>
11 #include <sauce/internal/key.h>
12
13 namespace sauce {
14 namespace internal {
15
16 template<typename Dependency, typename Name>
17 class ImplicitProviderBinding;
18
22 template<typename Dependency, typename Name>
23 class ImplicitProvider: public Provider<Dependency> {
24 typedef typename Key<Dependency>::Normalized Normalized;
25 typedef typename ResolvedBinding<Normalized>::BindingPtr BindingPtr;
26
27 BindingPtr binding;
28 InjectorPtr injector;
29
30 friend class ImplicitProviderBinding<Dependency, Name>;
31
32 ImplicitProvider(BindingPtr binding, InjectorPtr injector):
33 Provider<Dependency>(),
34 binding(binding),
35 injector(injector) {}
36
37 public:
38
39 typename Key<Dependency>::Ptr get() {
40 typename Key<Dependency>::Ptr injected;
41 binding->get(injected, binding, injector);
42 return injected;
43 }
44 };
45
49 template<typename Dependency, typename Name>
50 class ImplicitProviderBinding: public Binding<Named<Provider<Dependency>, Name>, NoScope> {
51
52 typedef typename Key<Dependency>::Normalized Normalized;
53 typedef typename ResolvedBinding<Normalized>::BindingPtr ProvidedBindingPtr;
54 typedef Named<Provider<Dependency>, Name> ProviderDependency;
55 typedef typename Key<ProviderDependency>::Ptr ProviderPtr;
56
57 ProvidedBindingPtr providedBinding;
58
59 void validateAcyclic(InjectorPtr, TypeIds &) const {}
60
61 public:
62
63 typedef typename ResolvedBinding<ProviderDependency>::BindingPtr BindingPtr;
64
65 ImplicitProviderBinding(ProvidedBindingPtr providedBinding):
66 Binding<Named<Provider<Dependency>, Name>, NoScope>(),
67 providedBinding(providedBinding) {}
68
69 void inject(ProviderPtr & injected, BindingPtr, InjectorPtr injector) const {
70 injected.reset(new ImplicitProvider<Dependency, Name>(providedBinding, injector));
71 }
72 };
73
74 }
75
76 namespace i = ::sauce::internal;
77
78 }
79
80 #endif // SAUCE_INTERNAL_IMPLICIT_PROVIDER_BINDING_H_