header_utils
Loading...
Searching...
No Matches
Dependency Injection

Basic dependency injection framework. More...

Concepts

concept  ghassanpl::di::has_default_lifetime
 If the interface or implementation has a DefaultLifetime static member field, that specified lifetime will be used by default for that interface/implementation.

Classes

struct  ghassanpl::di::Container
 The container for implementations; used to request interfaces. More...

Enumerations

enum class  ghassanpl::di::Lifetime {
  ghassanpl::di::Lifetime::Default , ghassanpl::di::Lifetime::Transient , ghassanpl::di::Lifetime::InstanceSingleton , ghassanpl::di::Lifetime::WeakSingleton ,
  ghassanpl::di::Lifetime::ThreadSingleton
}
 Specifies the lifetime of an implementation. More...

Variables

constexpr DefaultImplementationStruct ghassanpl::di::DefaultImplementation
 Used to specify an implementation is the default one for the interface being registered.

Detailed Description

Basic dependency injection framework.

A tiny and as-simple-as-possible Dependency Injection/IoC library, based around shared_ptrs.

Works, but might contain bugs. Still, you should be able to register types, instances, factory functions, and the construction arguments should resolve automatically, so, a basic DI container.

Supports custom instance lifetimes (strong and weak singletons, per-thread singleton, multiple-instances), naming interfaces/instances, instance creation callbacks, and probably other stuff.

Todo
example usage

Enumeration Type Documentation

◆ Lifetime

enum class ghassanpl::di::Lifetime
strong

Specifies the lifetime of an implementation.

Enumerator
Default 

Does not specify which lifetime of the implementation you want; you will be given one that's available, of unspecified lifetime.

Transient 

Will always give you a freshly instantiated implementation object when requesting the interface.

InstanceSingleton 

If a singleton instance of the implementation has not yet been created, it will be created and returned; otherwise, the existing instance will be returned.

WeakSingleton 

Same as InstanceSingleton, but will not hold on to an instance, so when your last shared_ptr to it will be destroyed, so will the instance.

ThreadSingleton 

Same as InstanceSingleton, but each thread gets its own instance.

Definition at line 36 of file di.h.

Variable Documentation

◆ DefaultImplementation

DefaultImplementationStruct ghassanpl::di::DefaultImplementation
inlineconstexpr

Used to specify an implementation is the default one for the interface being registered.

Definition at line 48 of file di.h.