DependencyInjection
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
DependencyInjection::ServiceCollection Class Reference

#include <DependencyInjection.hpp>

Inheritance diagram for DependencyInjection::ServiceCollection:
DependencyInjection::IServiceCollection

Public Member Functions

ServiceCollectionAdd (const ServiceDescriptor &descriptor) final
 
template<class TService , class TImplementation = TService>
ServiceCollectionAddSingleton ()
 
template<class TService , class TImplementation = TService>
ServiceCollectionAddSingleton (const ServiceFactory &factory)
 
template<class TService , class TImplementation = TService>
ServiceCollectionAddTransient ()
 
template<class TService , class TImplementation = TService>
ServiceCollectionAddTransient (const ServiceFactory &factory)
 
ServiceProvider BuildServiceProvider () const
 
virtual IServiceCollectionAdd (const ServiceDescriptor &descriptor)=0
 

Private Attributes

std::vector< ServiceDescriptor_descriptors
 

Member Function Documentation

◆ Add()

ServiceCollection & DependencyInjection::ServiceCollection::Add ( const ServiceDescriptor descriptor)
inlinefinalvirtual

Implements DependencyInjection::IServiceCollection.

171 {
172 _descriptors.push_back(descriptor);
173 return *this;
174 }
std::vector< ServiceDescriptor > _descriptors
Definition: DependencyInjection.hpp:167

◆ AddSingleton() [1/2]

template<class TService , class TImplementation = TService>
ServiceCollection & DependencyInjection::ServiceCollection::AddSingleton ( )
inline
178 {
179 const auto factory = [] (IServiceProvider&)
180 {
181 static const auto& service = TImplementation();
182 return service;
183 };
184 return AddSingleton<TService, TImplementation>(factory);
185 }

◆ AddSingleton() [2/2]

template<class TService , class TImplementation = TService>
ServiceCollection & DependencyInjection::ServiceCollection::AddSingleton ( const ServiceFactory factory)
inline
189 {
190 const ServiceDescriptor descriptor {
191 typeid(TService),
192 factory,
194 };
195 return Add(descriptor);
196 }
ServiceCollection & Add(const ServiceDescriptor &descriptor) final
Definition: DependencyInjection.hpp:170

◆ AddTransient() [1/2]

template<class TService , class TImplementation = TService>
ServiceCollection & DependencyInjection::ServiceCollection::AddTransient ( )
inline
200 {
201 const auto factory = [] (IServiceProvider&)
202 {
203 TImplementation service;
204 return service;
205 };
206 return AddTransient<TService, TImplementation>(factory);
207 }

◆ AddTransient() [2/2]

template<class TService , class TImplementation = TService>
ServiceCollection & DependencyInjection::ServiceCollection::AddTransient ( const ServiceFactory factory)
inline
211 {
212 const ServiceDescriptor descriptor {
213 typeid(TService),
214 factory,
216 };
217 return Add(descriptor);
218 }

◆ BuildServiceProvider()

ServiceProvider DependencyInjection::ServiceCollection::BuildServiceProvider ( ) const
inline
221 {
222 return ServiceProvider(_descriptors);
223 }

Member Data Documentation

◆ _descriptors

std::vector<ServiceDescriptor> DependencyInjection::ServiceCollection::_descriptors
private

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