solinject
1.0.0
C++17 Dependency Injection header-only library
|
Dependency Injection container. More...
#include <solinject.hpp>
Public Types | |
template<class T > | |
using | Factory = typename impl::IServiceTyped< T >::Factory |
Factory function that accepts a reference to a DI container and returns a pointer to an instance of a service. More... | |
template<class T > | |
using | ServicePtr = typename impl::IServiceTyped< T >::ServicePtr |
Pointer to an instance of a service. More... | |
using | DIServicePtr = impl::RegisteredServices::DIServicePtr |
Pointer to a DI service instance. More... | |
using | ScopedServiceBuilderPtr = impl::ScopedServiceBuilders::ScopedServiceBuilderPtr |
Pointer to a scoped service builder. More... | |
Public Member Functions | |
Container () | |
Default constructor. | |
Container (const Container &other)=delete | |
Copy constructor (deleted) | |
Container (Container &&other) noexcept | |
Move constructor. | |
Container & | operator= (const Container &other)=delete |
Copy-assignment operator (deleted) | |
Container & | operator= (Container &&other) noexcept |
Move-assignment operator. | |
Container | CreateScope () const |
Creates a scoped container from the current container. More... | |
bool | IsScope () |
Tells if the container is a scope container. More... | |
template<class T > | |
void | RegisterSingletonService (Factory< T > factory) |
Registers a service with singleton lifetime. More... | |
template<class T > | |
void | RegisterSingletonService (ServicePtr< T > instance) |
Registers a service with singleton lifetime. More... | |
template<class T > | |
void | RegisterTransientService (Factory< T > factory) |
Registers a service with transient lifetime. More... | |
template<class T > | |
void | RegisterSharedService (Factory< T > factory) |
Registers a service with shared lifetime. More... | |
template<class T > | |
void | RegisterScopedService (Factory< T > factory) |
Registers a service with scoped lifetime. More... | |
void | RegisterService (std::type_index type, DIServicePtr diService) |
Registers a service. More... | |
void | RegisterScopedServiceBuilder (std::type_index type, ScopedServiceBuilderPtr serviceBuilder) |
Registers a scoped service builder. More... | |
template<class T > | |
ServicePtr< T > | GetRequiredService () const |
Resolves a required service. More... | |
template<class T > | |
ServicePtr< T > | GetService () const |
Resolves an optional service. More... | |
template<class T > | |
std::vector< ServicePtr< T > > | GetServices () const |
Resolves services. More... | |
Friends | |
void | swap (Container &a, Container &b) noexcept |
Swaps two Container instances. | |
Dependency Injection container.
Pointer to a DI service instance.
using sol::di::Container::Factory = typename impl::IServiceTyped<T>::Factory |
Factory function that accepts a reference to a DI container and returns a pointer to an instance of a service.
T | the service type |
using sol::di::Container::ScopedServiceBuilderPtr = impl::ScopedServiceBuilders::ScopedServiceBuilderPtr |
Pointer to a scoped service builder.
using sol::di::Container::ServicePtr = typename impl::IServiceTyped<T>::ServicePtr |
Pointer to an instance of a service.
T | service type |
|
inline |
Creates a scoped container from the current container.
|
inline |
Resolves a required service.
T | service type |
sol::di::exc::ServiceNotRegisteredException |
|
inline |
Resolves an optional service.
T | service type |
nullptr
if the service is not registered
|
inline |
Resolves services.
T | the service type |
|
inline |
Tells if the container is a scope container.
true
if the container is a scope container, false
otherwise
|
inline |
Registers a service with scoped lifetime.
T | service type |
factory | factory function |
|
inline |
Registers a scoped service builder.
type | service type |
serviceBuilder | service builder |
|
inline |
Registers a service.
type | service type |
diService | pointer to a DI service instance |
|
inline |
Registers a service with shared lifetime.
T | service type |
factory | factory function |
|
inline |
Registers a service with singleton lifetime.
T | service type |
factory | factory function |
|
inline |
Registers a service with singleton lifetime.
T | service type |
instance | pointer to an instance of the service |
|
inline |
Registers a service with transient lifetime.
T | service type |
factory | factory function |