Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
aria::runtime::Container Class Reference

Type-keyed dependency-injection container. More...

#include <container.hpp>

Public Member Functions

 Container ()
 ~Container ()
 Container (const Container &)=delete
Containeroperator= (const Container &)=delete
 Container (Container &&)=delete
Containeroperator= (Container &&)=delete
template<typename Interface, typename Impl>
void register_singleton ()
template<typename Interface>
void register_instance (std::shared_ptr< Interface > ptr)
template<typename Interface, typename Impl>
void register_transient ()
template<typename Interface>
void register_factory (std::function< std::shared_ptr< Interface >()> fn)
template<typename Interface>
std::shared_ptr< Interface > resolve ()
template<typename Interface>
bool has () const
void clear ()
 Release every registration in reverse registration order (L-40).

Detailed Description

Type-keyed dependency-injection container.

Thread-safe.

Supports four registration forms:

Teardown order (contract L-40): clear() and ~Container() release registrations in reverse registration order, so a service registered after its dependency is destroyed before it. Register providers before consumers and the container will not hand a destroyed dependency to a destructor. Re-registering a type keeps its original position — the instance changed, not the dependency order. A new registration replaces both the value and lifetime mode for its type. Factories retain their captured state between resolves and run outside the registry lock; factories called concurrently must synchronize their own state.

Each registration is destroyed with the internal mutex released, so a service destructor may call back into the container (resolve / has / register_*) without deadlocking. Note that reverse order only mirrors registration, not the resolution graph; a consumer that was registered before the provider it resolves is still a bug on the caller's side.

Constructor & Destructor Documentation

◆ Container() [1/3]

aria::runtime::Container::Container ( )

◆ ~Container()

aria::runtime::Container::~Container ( )

◆ Container() [2/3]

aria::runtime::Container::Container ( const Container & )
delete

◆ Container() [3/3]

aria::runtime::Container::Container ( Container && )
delete

Member Function Documentation

◆ operator=() [1/2]

Container & aria::runtime::Container::operator= ( const Container & )
delete

◆ operator=() [2/2]

Container & aria::runtime::Container::operator= ( Container && )
delete

◆ register_singleton()

template<typename Interface, typename Impl>
void aria::runtime::Container::register_singleton ( )
inline

◆ register_instance()

template<typename Interface>
void aria::runtime::Container::register_instance ( std::shared_ptr< Interface > ptr)
inline

◆ register_transient()

template<typename Interface, typename Impl>
void aria::runtime::Container::register_transient ( )
inline

◆ register_factory()

template<typename Interface>
void aria::runtime::Container::register_factory ( std::function< std::shared_ptr< Interface >()> fn)
inline

◆ resolve()

template<typename Interface>
std::shared_ptr< Interface > aria::runtime::Container::resolve ( )
inlinenodiscard

◆ has()

template<typename Interface>
bool aria::runtime::Container::has ( ) const
inlinenodiscard

◆ clear()

void aria::runtime::Container::clear ( )

Release every registration in reverse registration order (L-40).

Each value is destroyed with the internal mutex released.


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