|
Common System 0.2.0
Common interfaces and patterns for system integration
|
Scoped service container for request-level isolation. More...
#include <service_container_interface.h>


Public Member Functions | |
| ~IServiceScope () override=default | |
| virtual IServiceContainer & | parent ()=0 |
| Get the parent container. | |
| virtual const IServiceContainer & | parent () const =0 |
| Get the parent container (const). | |
Public Member Functions inherited from kcenon::common::di::IServiceContainer | |
| virtual | ~IServiceContainer ()=default |
| template<concepts::ServiceInterface TInterface, concepts::ServiceImplementation< TInterface > TImpl> | |
| VoidResult | register_type (service_lifetime lifetime=service_lifetime::singleton) |
| Register a service type with its implementation. | |
| template<typename TInterface > | |
| VoidResult | register_instance (std::shared_ptr< TInterface > instance) |
| Register a pre-existing instance as a singleton. | |
| template<concepts::ServiceInterface TInterface, concepts::ServiceFactory< TInterface > TFactory> | |
| VoidResult | register_factory (TFactory &&factory, service_lifetime lifetime=service_lifetime::singleton) |
| Register a factory function for creating service instances. | |
| template<concepts::ServiceInterface TInterface, concepts::SimpleServiceFactory< TInterface > TFactory> | |
| VoidResult | register_simple_factory (TFactory &&factory, service_lifetime lifetime=service_lifetime::singleton) |
| Register a simple factory function without container access. | |
| template<typename TInterface > | |
| Result< std::shared_ptr< TInterface > > | resolve () |
| Resolve a service by its interface type. | |
| template<typename TInterface > | |
| std::shared_ptr< TInterface > | resolve_or_null () |
| Try to resolve a service, returning nullptr if not found. | |
| virtual std::unique_ptr< IServiceScope > | create_scope ()=0 |
| Create a new service scope. | |
| template<typename TInterface > | |
| bool | is_registered () const |
| Check if a service type is registered. | |
| virtual std::vector< service_descriptor > | registered_services () const =0 |
| Get list of all registered service descriptors. | |
| template<typename TInterface > | |
| VoidResult | unregister () |
| Unregister a service type. | |
| virtual VoidResult | clear ()=0 |
| Clear all registrations. | |
| virtual | ~IServiceContainer ()=default |
| template<typename Interface , typename Factory > | |
| void | register_factory (Factory &&factory) |
| Register a service with a factory function. | |
| template<typename Interface > | |
| void | register_singleton (std::shared_ptr< Interface > instance) |
| Register a singleton instance. | |
| template<typename Interface > | |
| std::shared_ptr< Interface > | resolve () |
| Resolve a service by interface type. | |
| template<typename Interface > | |
| bool | has () const |
| Check if a service is registered. | |
Additional Inherited Members | |
Protected Member Functions inherited from kcenon::common::di::IServiceContainer | |
| virtual VoidResult | register_factory_internal (std::type_index interface_type, const std::string &type_name, std::function< std::shared_ptr< void >(IServiceContainer &)> factory, service_lifetime lifetime)=0 |
| Internal factory registration (type-erased). | |
| virtual VoidResult | register_instance_internal (std::type_index interface_type, const std::string &type_name, std::shared_ptr< void > instance)=0 |
| Internal instance registration (type-erased). | |
| virtual Result< std::shared_ptr< void > > | resolve_internal (std::type_index interface_type)=0 |
| Internal service resolution (type-erased). | |
| virtual bool | is_registered_internal (std::type_index interface_type) const =0 |
| Internal registration check (type-erased). | |
| virtual VoidResult | unregister_internal (std::type_index interface_type)=0 |
| Internal unregistration (type-erased). | |
| virtual void | register_impl (std::type_index type, std::any factory)=0 |
| virtual void | register_singleton_impl (std::type_index type, std::any instance)=0 |
| virtual std::any | resolve_impl (std::type_index type)=0 |
| virtual bool | has_impl (std::type_index type) const =0 |
Scoped service container for request-level isolation.
A service scope inherits all registrations from its parent container but maintains its own instances for scoped services. When the scope is destroyed, all scoped instances are disposed.
Thread Safety:
Usage:
Definition at line 469 of file service_container_interface.h.
|
overridedefault |
|
pure virtual |
Get the parent container (const).
Implemented in kcenon::common::di::service_scope.
|
pure virtual |
Get the parent container.
Implemented in kcenon::common::di::service_scope.