204 bool freeze_service_container =
true);
318 other.initialized_ =
false;
323 if (
this != &other) {
336 other.initialized_ =
false;
348 const std::string& name,
352 if (entry.first == name) {
353 entry.second = std::move(factory);
362 std::function<
void()> callback) {
370 std::function<
void()> callback) {
378 bool freeze_logger_registry,
379 bool freeze_service_container) {
391 "SystemBootstrapper already initialized",
392 "bootstrap::SystemBootstrapper"
398 if (result.is_err()) {
467 "Default logger factory returned null",
468 "bootstrap::SystemBootstrapper"
471 auto result = registry.set_default_logger(std::move(logger));
472 if (result.is_err()) {
482 auto logger = factory();
486 "Logger factory for '" + name +
"' returned null",
487 "bootstrap::SystemBootstrapper"
490 auto result = registry.register_logger(name, std::move(logger));
491 if (result.is_err()) {
Result type for error handling with member function support.
static Result< T > ok(U &&value)
Create a successful result with value (static factory)
Fluent API for system initialization and logger registration.
VoidResult register_loggers()
Register all loggers with GlobalLoggerRegistry.
std::vector< std::function< void()> > init_callbacks_
void clear_loggers()
Clear all loggers from GlobalLoggerRegistry.
void reset()
Reset the bootstrapper to initial state.
bool is_initialized() const noexcept
Check if the system is initialized.
void shutdown()
Shutdown the system.
SystemBootstrapper & with_auto_freeze(bool freeze_logger_registry=true, bool freeze_service_container=true)
Enable automatic freezing of registries after initialization.
SystemBootstrapper()=default
Default constructor.
void execute_init_callbacks()
Execute all initialization callbacks.
SystemBootstrapper & with_default_logger(interfaces::LoggerFactory factory)
Register a factory for the default logger.
~SystemBootstrapper()
Destructor with automatic shutdown.
std::vector< std::function< void()> > shutdown_callbacks_
SystemBootstrapper & with_logger(const std::string &name, interfaces::LoggerFactory factory)
Register a factory for a named logger.
std::vector< std::pair< std::string, interfaces::LoggerFactory > > named_logger_factories_
void execute_shutdown_callbacks()
Execute all shutdown callbacks in reverse order.
SystemBootstrapper & on_shutdown(std::function< void()> callback)
Register a shutdown callback.
interfaces::LoggerFactory default_logger_factory_
VoidResult initialize()
Initialize the system.
SystemBootstrapper & operator=(const SystemBootstrapper &)=delete
bool auto_freeze_service_container_
bool auto_freeze_logger_registry_
SystemBootstrapper(const SystemBootstrapper &)=delete
SystemBootstrapper & on_initialize(std::function< void()> callback)
Register an initialization callback.
void freeze()
Freeze the container to prevent further registrations.
static service_container & global()
Get the global service container instance.
static GlobalLoggerRegistry & instance()
Get the singleton instance of GlobalLoggerRegistry.
void freeze()
Freeze the registry to prevent further modifications.
void clear()
Clear all registered loggers and factories.
GlobalLoggerRegistry implementation for runtime binding.
constexpr int ALREADY_EXISTS
constexpr int INTERNAL_ERROR
std::function< std::shared_ptr< ILogger >()> LoggerFactory
Factory function type for creating logger instances.
Result< T > make_error(int code, const std::string &message, const std::string &module="")
Create an error result with code and message.
Umbrella header for Result<T> type and related utilities.
Implementation of the service container for dependency injection.