|
Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
|
Modern service container for dependency injection. More...
#include <service_container.h>

Classes | |
| struct | service_entry |
Public Types | |
| enum class | lifetime { singleton , transient } |
| Service lifetime scope. More... | |
Public Member Functions | |
| template<typename Interface , typename Implementation > | |
| void | register_singleton (std::shared_ptr< Implementation > instance) |
| Register a service with singleton lifetime. | |
| template<typename Interface > | |
| void | register_factory (std::function< std::shared_ptr< Interface >()> factory, lifetime lt=lifetime::transient) |
| Register a service with factory function. | |
| template<typename Interface , typename Implementation , typename... Args> | |
| void | register_transient () |
| Register a transient service. | |
| template<typename Interface > | |
| std::shared_ptr< Interface > | resolve () |
| Resolve a service. | |
| template<typename Interface > | |
| bool | is_registered () const |
| Check if a service is registered. | |
| void | clear () |
| Clear all registered services. | |
Static Public Member Functions | |
| static service_container & | global () |
| Get the global service container instance. | |
Private Attributes | |
| std::mutex | mutex_ |
| std::unordered_map< std::type_index, service_entry > | services_ |
Modern service container for dependency injection.
This container supports:
Definition at line 30 of file service_container.h.
|
strong |
Service lifetime scope.
| Enumerator | |
|---|---|
| singleton | |
| transient | |
Definition at line 35 of file service_container.h.
|
inline |
Clear all registered services.
Definition at line 139 of file service_container.h.
References mutex_, and services_.
Referenced by complete_integration_example(), demonstrate_minimal_usage(), dynamic_service_example(), main(), thread_pool_with_logger_example(), and thread_pool_with_monitoring_example().

|
inlinestatic |
Get the global service container instance.
Definition at line 148 of file service_container.h.
Referenced by complete_integration_example(), demonstrate_composition(), demonstrate_minimal_usage(), dynamic_service_example(), kcenon::thread::thread_context_builder::from_global_registry(), main(), kcenon::thread::scoped_service< Interface >::scoped_service(), thread_pool_with_logger_example(), and thread_pool_with_monitoring_example().

|
inline |
Check if a service is registered.
| Interface | The interface type to check |
Definition at line 131 of file service_container.h.
|
inline |
Register a service with factory function.
| Interface | The interface type |
| factory | Factory function that creates the service |
| lt | Service lifetime (default: transient) |
Definition at line 63 of file service_container.h.
References mutex_, and services_.
Referenced by register_transient().

|
inline |
Register a service with singleton lifetime.
| Interface | The interface type |
| Implementation | The concrete implementation type |
| instance | Shared pointer to the implementation |
Definition at line 47 of file service_container.h.
References mutex_, services_, and singleton.
Referenced by complete_integration_example(), dynamic_service_example(), kcenon::thread::scoped_service< Interface >::scoped_service(), thread_pool_with_logger_example(), and thread_pool_with_monitoring_example().

|
inline |
Register a transient service.
| Interface | The interface type |
| Implementation | The concrete implementation type |
| Args | Constructor argument types |
Definition at line 80 of file service_container.h.
References register_factory(), and transient.

|
inline |
Resolve a service.
| Interface | The interface type to resolve |
Definition at line 95 of file service_container.h.
References mutex_, services_, and singleton.
Referenced by kcenon::thread::thread_context_builder::from_global_registry().

|
mutableprivate |
Definition at line 160 of file service_container.h.
Referenced by clear(), is_registered(), register_factory(), register_singleton(), and resolve().
|
private |
Definition at line 161 of file service_container.h.
Referenced by clear(), is_registered(), register_factory(), register_singleton(), and resolve().