105#ifndef LIB_DEPEND_INJECT_H
106#define LIB_DEPEND_INJECT_H
117#include <type_traits>
165 __assert_compatible<SUB>();
166 installFactory<SUB>();
184 __assert_compatible<Sub>();
185 installFactory<Sub,Fun> (forward<FUN> (ctor));
201 template<
class IMP =SRV>
208 template<
typename...ARGS>
210 :
instance_{new IMP(forward<ARGS> (ctorArgs)...)}
212 __assert_compatible<IMP>();
222 __assert_compatible<IMP>();
230 template<
typename...ARGS>
234 instance_.reset (
new IMP(forward<ARGS> (ctorArgs)...));
251 operator bool()
const
280 template<
class MOC =SRV>
291 :
Local([]{
return new MOC{}; })
298 __assert_compatible<MOC>();
299 __assert_compatible<typename SubclassFactoryType<FUN>::Subclass>();
302 ,[
this, buildInstance=forward<FUN> (_buildInstance)]
304 mock_.reset (buildInstance());
314 operator bool()
const
357 ,
"Installed implementation class must be compatible to the interface.");
364 throw error::Logic(
"Attempt to reconfigure dependency injection after the fact. "
365 "The previously installed factory (typically Singleton) was already used."
366 , error::LUMIERA_ERROR_LIFECYCLE);
369 template<
typename FUN>
373 "Need a Lambda or Function object to create a heap allocated instance");
379 static_assert (std::is_pointer<ResultVal>::value,
380 "Function must yield a pointer to a heap allocated instance");
384 template<
class SUB,
typename FUN>
389 if (std::is_same<SRV,SUB>())
406 if (not std::is_same<SRV,SUB>())
416 template<
typename FUN>
440 throw error::Logic(
"Attempt to activate an external service implementation, "
441 "but another instance has already been dependency-injected."
442 , error::LUMIERA_ERROR_LIFECYCLE);
Configuration handle for temporarily shadowing a dependency by a test mock instance.
Local(FUN &&_buildInstance)
MOC & triggerCreate()
trigger lazy service object instantiation
std::unique_ptr< MOC > mock_
Configuration handle to expose a service implementation through the Depend<SRV> front-end.
ServiceInstance(StartMode)
create in deactivated state.
IMP & createInstance(ARGS &&...ctorArgs)
std::unique_ptr< IMP > instance_
ServiceInstance(ARGS &&...ctorArgs)
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
meta::Strip< ResultVal >::TypePlain Subclass
static void __assert_compatible()
static void restoreOriginalFactory(SRV *&stashInstance, Factory &&stashFac)
static void useSingleton(FUN &&ctor)
configure dependency-injection for type SRV to manage a subclass singleton, which is created lazily o...
static void installFactory()
meta::_Fun< FUN >::Ret ResultVal
static void __ensure_pristine()
static void installFactory(FUN &&ctor)
static void deactivateServiceAccess()
Depend< SRV >::Factory Factory
meta::_Fun< FUN >::Functor Functor
static void temporarilyInstallAlternateFactory(SRV *&stashInstance, Factory &stashFac, FUN &&newFac)
static void activateServiceAccess(SRV &newInstance)
static void useSingleton()
configure dependency-injection for type SRV to build a subclass singleton.
Access point to singletons and other kinds of dependencies designated by type.
ClassLock< SRV, NonrecursiveLock_NoWait > Lock
DependencyFactory< SRV > Factory
static Factory & factory()
Types marked with this mix-in may be moved but not copied.
Not meant to be instantiated in any way.
Singleton services and Dependency Injection.
Lumiera error handling (C++ interface).
Metaprogramming tools for detecting and transforming function types.
Implementation namespace for support and library code.
LumieraError< LERR_(LOGIC)> Logic
Mix-Ins to allow or prohibit various degrees of copying and cloning.
A special implementation of lib::Sync, where the storage of the object monitor is associated directly...
Helpers for type detection, type rewriting and metaprogramming.