solinject  1.0.0
C++17 Dependency Injection header-only library
sol::di::ContainerBuilder Class Reference

DI Container builder. More...

#include <ContainerBuilder.hpp>

Public Types

template<class T >
using Factory = Container::Factory< T >
 Factory function that accepts a reference to a DI container and returns a pointer to an instance of a service. More...
 
using Key = ConfigurationItem::Key
 Key, used to map classes, registered in a ContainerBuilder to the ones specified in a config file. More...
 
using DIServicePtr = std::shared_ptr< impl::IService >
 Pointer to an impl::IService instance.
 

Public Member Functions

template<class T >
void RegisterInterface (Key key)
 Registers an interface. More...
 
template<class TService , class... TServiceParents>
void RegisterService (Key key, Factory< TService > factory)
 Registers a service. More...
 
Container BuildContainer (const Configuration &configuration)
 Builds a DI container. More...
 

Detailed Description

DI Container builder.

Member Typedef Documentation

◆ Factory

Factory function that accepts a reference to a DI container and returns a pointer to an instance of a service.

Template Parameters
Tthe service type

◆ Key

Key, used to map classes, registered in a ContainerBuilder to the ones specified in a config file.

Member Function Documentation

◆ BuildContainer()

Container sol::di::ContainerBuilder::BuildContainer ( const Configuration configuration)
inline

Builds a DI container.

Parameters
[in]configurationthe DI configuration
Returns
built DI container
Warning
Containers, built from the same ContainerBuilder will share the same services. For example, they will share the same instances of the services with ServiceLifetime::Singleton lifetime.

◆ RegisterInterface()

template<class T >
void sol::di::ContainerBuilder::RegisterInterface ( Key  key)
inline

Registers an interface.

Template Parameters
Tthe interface type
Parameters
keythe interface key

◆ RegisterService()

template<class TService , class... TServiceParents>
void sol::di::ContainerBuilder::RegisterService ( Key  key,
Factory< TService >  factory 
)
inline

Registers a service.

Template Parameters
TServicethe service type
...TServiceParentsthe service parent types
Parameters
keythe service key
factorythe service factory
See also
FACTORY

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