Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
kcenon::common::di Namespace Reference

Namespaces

namespace  di_error_codes
 Error codes specific to dependency injection.
 

Classes

struct  bootstrapper_options
 Configuration options for the unified bootstrapper. More...
 
class  IBootstrapper
 Interface for system bootstrapping. More...
 
class  IServiceContainer
 Abstract interface for dependency injection containers. More...
 
interface  IServiceScope
 Scoped service container for request-level isolation. More...
 
class  service_container
 Concrete implementation of IServiceContainer. More...
 
struct  service_descriptor
 Metadata describing a registered service. More...
 
class  service_scope
 Scoped service container implementation. More...
 
class  ServiceContainer
 Simple thread-safe service container implementation. More...
 
class  unified_bootstrapper
 Coordinates system initialization and shutdown. More...
 

Typedefs

using shutdown_hook = std::function<void(std::chrono::milliseconds remaining_timeout)>
 Shutdown hook callback type.
 
using module_registration_fn = std::function<VoidResult(IServiceContainer&)>
 Module registration callback type.
 

Enumerations

enum class  service_lifetime { singleton , transient , scoped }
 Defines the lifetime policy for registered services. More...
 

Functions

const char * to_string (service_lifetime lifetime)
 Convert service_lifetime to string representation.
 

Typedef Documentation

◆ module_registration_fn

Module registration callback type.

Each subsystem module provides a registration function that registers its services with the service container. This replaces compile-time #ifdef guards with runtime module registration.

See also
ModuleRegistrar concept for class-based registrars.

Definition at line 90 of file unified_bootstrapper.h.

◆ shutdown_hook

using kcenon::common::di::shutdown_hook = std::function<void(std::chrono::milliseconds remaining_timeout)>

Shutdown hook callback type.

Shutdown hooks are called in reverse order of registration during shutdown. Each hook receives the remaining timeout duration.

Definition at line 79 of file unified_bootstrapper.h.

Enumeration Type Documentation

◆ service_lifetime

Defines the lifetime policy for registered services.

The lifetime determines how instances are created and cached:

  • singleton: One instance shared across the entire application
  • transient: New instance created for each resolution request
  • scoped: One instance per scope (useful for request-scoped services)
Enumerator
singleton 

Single instance shared globally.

The container creates one instance on first resolution and returns the same instance for all subsequent requests. The instance lives until the container is destroyed.

Use for: Stateless services, expensive-to-create services, services that maintain global state (loggers, configuration, etc.)

transient 

New instance created for each request.

The container creates a new instance every time the service is resolved. Each instance is independent and caller owns its lifetime.

Use for: Stateful services where each consumer needs its own instance, services with short lifespans, or services that cannot be shared safely.

scoped 

Single instance within a scope.

Similar to singleton, but scoped to a particular IServiceScope. Each scope gets its own instance, which is shared within that scope but separate from instances in other scopes.

Use for: Request-scoped services (web handlers), unit-of-work patterns, services that should be isolated per logical operation.

Definition at line 52 of file service_container_interface.h.

52 {
64
75
86 scoped
87};
@ singleton
Single instance shared globally.
@ scoped
Single instance within a scope.
@ transient
New instance created for each request.

Function Documentation

◆ to_string()

const char * kcenon::common::di::to_string ( service_lifetime lifetime)
inline

Convert service_lifetime to string representation.

Parameters
lifetimeThe lifetime value to convert
Returns
Human-readable string

Definition at line 94 of file service_container_interface.h.

94 {
95 switch (lifetime) {
96 case service_lifetime::singleton: return "singleton";
97 case service_lifetime::transient: return "transient";
98 case service_lifetime::scoped: return "scoped";
99 default: return "unknown";
100 }
101}

References scoped, singleton, and transient.