#include <DependencyInjection.hpp>
◆ ServiceProvider() [1/2]
DependencyInjection::ServiceProvider::ServiceProvider |
( |
const std::vector< ServiceDescriptor > & |
descriptors | ) |
|
|
inlineexplicitprivate |
109 {
110 using std::ranges::reverse_view;
111
112 for (const auto& descriptor : reverse_view(descriptors))
113 {
114 const auto& typeInfo = descriptor.GetTypeInfo();
115 bool serviceExists =
_services.contains(typeInfo);
116 if (serviceExists)
117 {
118 _services[typeInfo].push_back(descriptor);
119 }
120 else
121 {
122 _services.insert({ typeInfo, { descriptor }});
123 }
124 }
125 }
std::map< std::type_index, std::vector< ServiceDescriptor > > _services
Definition: DependencyInjection.hpp:106
◆ ServiceProvider() [2/2]
DependencyInjection::ServiceProvider::ServiceProvider |
( |
| ) |
|
|
delete |
◆ GetService() [1/2]
template<class T >
auto DependencyInjection::ServiceProvider::GetService |
( |
| ) |
|
|
inline |
150 {
152 return std::any_cast<T>(service);
153 }
auto GetService()
Definition: DependencyInjection.hpp:149
◆ GetService() [2/2]
std::any DependencyInjection::ServiceProvider::GetService |
( |
const std::type_info & |
type | ) |
|
|
inlinefinalvirtual |
Implements DependencyInjection::IServiceProvider.
131 {
132 const auto position =
_services.find(type);
133 const auto notFound = (position ==
_services.end());
134 if (notFound)
135 {
136 return {};
137 }
138
139 const auto descriptorList = position->second;
140 const auto& descriptor = descriptorList[0];
141 const auto factory = descriptor.GetFactory();
142 auto service = factory(*this);
143
144 return service;
145 }
◆ ServiceCollection
◆ _services
std::map<std::type_index, std::vector<ServiceDescriptor> > DependencyInjection::ServiceProvider::_services |
|
private |
The documentation for this class was generated from the following file: