Minimal Dependency Injection Framework for C++
Single file library for implementing the dependency injection pattern
dip::instance_set< Service > Struct Template Reference

Set of injected instances of a service. More...

#include <dip.hpp>

Public Types

typedef Service * service_type
 Type of the instances of the service provider.
 
typedef const Service * const_service_type
 Const type of the instances of the service provider.
 
using iterator = std::vector< service_type >::iterator
 Forward iterator.
 
using const_iterator = std::vector< service_type >::const_iterator
 Const forward iterator.
 
using reverse_iterator = std::vector< service_type >::reverse_iterator
 Reverse iterator.
 
using const_reverse_iterator = std::vector< service_type >::const_reverse_iterator
 Const reverse iterator.
 

Public Member Functions

 instance_set ()
 Retrieve a set of instances providing the service.
 
 ~instance_set () noexcept
 Remove the set of instances providing the service.
 
 instance_set (const instance_set &)=delete
 
 instance_set (instance_set &&)=delete
 
instance_setoperator= (const instance_set &)=delete
 
instance_setoperator= (instance_set &&)=delete
 
constexpr std::size_t size () const noexcept
 Get the count of instances injected into the service. More...
 
service_type operator[] (std::size_t index)
 Get a service provider instance in the set. More...
 
const_service_type operator[] (std::size_t index) const
 Get a service provider instance in the set. More...
 
service_type at (std::size_t index)
 Get a service provider instance in the set. More...
 
const_service_type at (std::size_t index) const
 Get a service provider instance in the set. More...
 
iterator begin ()
 returns an iterator to the beginning More...
 
const_iterator begin () const
 returns an iterator to the beginning More...
 
const_iterator cbegin () const noexcept
 returns an iterator to the end More...
 
iterator end ()
 returns an iterator to the end More...
 
const_iterator end () const
 returns an iterator to the end More...
 
const_iterator cend () const noexcept
 returns an iterator to the end More...
 
reverse_iterator rbegin ()
 returns a reverse iterator to the beginning More...
 
const_reverse_iterator rbegin () const
 returns a reverse iterator to the beginning More...
 
const_reverse_iterator crbegin () const noexcept
 returns a reverse iterator to the beginning More...
 
reverse_iterator rend ()
 returns a reverse iterator to the end More...
 
const_reverse_iterator rend () const
 returns a reverse iterator to the end More...
 
const_reverse_iterator crend () const noexcept
 returns a reverse iterator to the end More...
 

Static Public Member Functions

static void add (const Injector< Service > &injector) noexcept
 Inject a service provider using a custom injector. More...
 
template<class Provider , typename... _Args>
static void add_singleton (_Args &&...__args)
 Inject a service provider with singleton life cycle. More...
 
template<class Provider , typename... _Args>
static void add_thread_singleton (_Args &&...__args)
 Inject a service provider with per-thread singleton life cycle. More...
 
template<class Provider , typename... _Args>
static void add_transient (_Args &&...__args)
 Inject a service provider with transient life cycle. More...
 
static void clear_injections () noexcept
 Clear all the injected dependencies for testing purposes. More...
 

Detailed Description

template<class Service>
struct dip::instance_set< Service >

Set of injected instances of a service.

Template Parameters
ServiceService to be injected

Member Function Documentation

◆ add()

template<class Service >
static void dip::instance_set< Service >::add ( const Injector< Service > &  injector)
inlinestaticnoexcept

Inject a service provider using a custom injector.

Parameters
injectorService injector

◆ add_singleton()

template<class Service >
template<class Provider , typename... _Args>
static void dip::instance_set< Service >::add_singleton ( _Args &&...  __args)
inlinestatic

Inject a service provider with singleton life cycle.

Template Parameters
ProviderService provider
_ArgsConstructor parameter types
Parameters
__argsConstructor parameters

◆ add_thread_singleton()

template<class Service >
template<class Provider , typename... _Args>
static void dip::instance_set< Service >::add_thread_singleton ( _Args &&...  __args)
inlinestatic

Inject a service provider with per-thread singleton life cycle.

Template Parameters
ProviderService provider
_ArgsConstructor parameter types
Parameters
__argsConstructor parameters

◆ add_transient()

template<class Service >
template<class Provider , typename... _Args>
static void dip::instance_set< Service >::add_transient ( _Args &&...  __args)
inlinestatic

Inject a service provider with transient life cycle.

Template Parameters
ProviderService provider
_ArgsConstructor parameter types
Parameters
__argsConstructor parameters

◆ at() [1/2]

template<class Service >
service_type dip::instance_set< Service >::at ( std::size_t  index)
inline

Get a service provider instance in the set.

Parameters
indexIndex of the service provider instance
Returns
service_type Service provider instance

◆ at() [2/2]

template<class Service >
const_service_type dip::instance_set< Service >::at ( std::size_t  index) const
inline

Get a service provider instance in the set.

Parameters
indexIndex of the service provider instance
Returns
service_type Service provider instance

◆ begin() [1/2]

template<class Service >
iterator dip::instance_set< Service >::begin ( )
inline

returns an iterator to the beginning

Returns
Iterator

◆ begin() [2/2]

template<class Service >
const_iterator dip::instance_set< Service >::begin ( ) const
inline

returns an iterator to the beginning

Returns
Iterator

◆ cbegin()

template<class Service >
const_iterator dip::instance_set< Service >::cbegin ( ) const
inlinenoexcept

returns an iterator to the end

Returns
Iterator

◆ cend()

template<class Service >
const_iterator dip::instance_set< Service >::cend ( ) const
inlinenoexcept

returns an iterator to the end

Returns
Iterator

◆ clear_injections()

template<class Service >
static void dip::instance_set< Service >::clear_injections ( )
inlinestaticnoexcept

Clear all the injected dependencies for testing purposes.

Warning
Do not call in production code. Will cause memory leaks unless injected instances are deleted first.

◆ crbegin()

template<class Service >
const_reverse_iterator dip::instance_set< Service >::crbegin ( ) const
inlinenoexcept

returns a reverse iterator to the beginning

Returns
Iterator

◆ crend()

template<class Service >
const_reverse_iterator dip::instance_set< Service >::crend ( ) const
inlinenoexcept

returns a reverse iterator to the end

Returns
Iterator

◆ end() [1/2]

template<class Service >
iterator dip::instance_set< Service >::end ( )
inline

returns an iterator to the end

Returns
Iterator

◆ end() [2/2]

template<class Service >
const_iterator dip::instance_set< Service >::end ( ) const
inline

returns an iterator to the end

Returns
Iterator

◆ operator[]() [1/2]

template<class Service >
service_type dip::instance_set< Service >::operator[] ( std::size_t  index)
inline

Get a service provider instance in the set.

Parameters
indexIndex of the service provider instance
Returns
service_type Service provider instance

◆ operator[]() [2/2]

template<class Service >
const_service_type dip::instance_set< Service >::operator[] ( std::size_t  index) const
inline

Get a service provider instance in the set.

Parameters
indexIndex of the service provider instance
Returns
service_type Service provider instance

◆ rbegin() [1/2]

template<class Service >
reverse_iterator dip::instance_set< Service >::rbegin ( )
inline

returns a reverse iterator to the beginning

Returns
Iterator

◆ rbegin() [2/2]

template<class Service >
const_reverse_iterator dip::instance_set< Service >::rbegin ( ) const
inline

returns a reverse iterator to the beginning

Returns
Iterator

◆ rend() [1/2]

template<class Service >
reverse_iterator dip::instance_set< Service >::rend ( )
inline

returns a reverse iterator to the end

Returns
Iterator

◆ rend() [2/2]

template<class Service >
const_reverse_iterator dip::instance_set< Service >::rend ( ) const
inline

returns a reverse iterator to the end

Returns
Iterator

◆ size()

template<class Service >
constexpr std::size_t dip::instance_set< Service >::size ( ) const
inlineconstexprnoexcept

Get the count of instances injected into the service.

Returns
constexpr std::size_t Count of instances

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