Lumiera  0.pre.03
»edit your freedom«
DependInject< SRV > Class Template Reference

#include "lib/depend-inject.hpp"

Description

template<class SRV>
class lib::DependInject< SRV >

This framework allows to (re)configure the lib::Depend front-end for dependency-injection.

By default, Depend<TY> will create a singleton instance of TY lazily, on demand. When instantiating one of the configuration handles provided here – prior to anyone retrieving the instance through Depend<TY> – this default (singleton) behaviour can be reconfigured in various ways, without the client being aware of it:

  • instead of a singleton, a service instance with well defined lifecycle can be exposed through the Depend<TY> front-end. When the service is shut down, clients will receive an exception on access.
  • instead of the interface type TY mentioned in Depend<TY>, an implementation subclass can be specified, optionally with a closure for the actual creation of this subclass singleton type, which still happens lazily, on demand
  • the current state and configuration can be shadowed temporarily by a test mock instance, which is managed automatically and removed when leaving the scope of the test.
    Note
    DependInject<SRV> is declared fried by Depend<SRV> to reconfigure the latter's internals

access point to reconfigure dependency injection on a per type base

See also
depend-inject.hpp

Definition at line 157 of file depend-inject.hpp.

Static Public Member Functions

template<class SUB >
static void useSingleton ()
 configure dependency-injection for type SRV to build a subclass singleton. More...
 
template<class FUN >
static void useSingleton (FUN &&ctor)
 configure dependency-injection for type SRV to manage a subclass singleton, which is created lazily on demand by invoking the given builder function. More...
 

Classes

class  Local
 Configuration handle for temporarily shadowing a dependency by a test mock instance. More...
 
class  ServiceInstance
 Configuration handle to expose a service implementation through the Depend<SRV> front-end. More...
 
struct  SubclassFactoryType
 

Friends

template<class MOC >
class Local
 
template<class IMP >
class ServiceInstance
 

Static Protected Member Functions

template<class SUB >
static void __assert_compatible ()
 
static void __ensure_pristine ()
 
static void activateServiceAccess (SRV &newInstance)
 
static void deactivateServiceAccess ()
 
template<class SUB , typename FUN >
static void installFactory (FUN &&ctor)
 
template<class SUB >
static void installFactory ()
 
static void restoreOriginalFactory (SRV *&stashInstance, Factory &&stashFac)
 
template<typename FUN >
static void temporarilyInstallAlternateFactory (SRV *&stashInstance, Factory &stashFac, FUN &&newFac)
 

Private Types

using Factory = typename Depend< SRV >::Factory
 
using Lock = typename Depend< SRV >::Lock
 

Class Documentation

◆ lib::DependInject::SubclassFactoryType

struct lib::DependInject::SubclassFactoryType
Class Members
typedef typename _Fun< FUN >
::Functor
Functor
typedef typename _Fun< FUN >::Ret ResultVal
typedef typename Strip
< ResultVal >::TypePlain
Subclass
+ Collaboration diagram for DependInject< SRV >::SubclassFactoryType< FUN >:

Member Function Documentation

◆ useSingleton() [1/2]

static void useSingleton ( )
inlinestatic

configure dependency-injection for type SRV to build a subclass singleton.

Note
actually a delegation to Depend<SUB> is installed into Depend<SRV>
Template Parameters
SUBconcrete subclass type to build on demand when invoking Depend<SRV>
Exceptions
error::Logic(LUMIERA_ERROR_LIFECYCLE) when the default factory has already been invoked at the point when calling this (re)configuration function.

Definition at line 172 of file depend-inject.hpp.

◆ useSingleton() [2/2]

static void useSingleton ( FUN &&  ctor)
inlinestatic

configure dependency-injection for type SRV to manage a subclass singleton, which is created lazily on demand by invoking the given builder function.

Note
actual Subclass type is determined from the given functor and then a delegation to Depend<Subclass> is installed into Depend<SRV>
Parameters
ctorfunctor to create a heap allocated instance of the subclass
Exceptions
error::Logic(LUMIERA_ERROR_LIFECYCLE) when the default factory has already been invoked at the point when calling this (re)configuration function.

Definition at line 188 of file depend-inject.hpp.

+ Inheritance diagram for DependInject< SRV >:
+ Collaboration diagram for DependInject< SRV >:

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