21#if KCENON_WITH_COMMON_SYSTEM
23#include <kcenon/common/di/service_container.h>
25#include "../core/network_context.h"
27namespace kcenon::network::di {
32struct network_registration_config {
34 size_t thread_count = 0;
37 bool initialize_on_register =
true;
40 common::di::service_lifetime lifetime = common::di::service_lifetime::singleton;
70inline common::VoidResult register_network_services(
71 common::di::IServiceContainer& container,
72 const network_registration_config&
config = {}) {
76 return common::make_error<std::monostate>(
77 common::di::di_error_codes::already_registered,
78 "network_context is already registered",
86 [
config](common::di::IServiceContainer&) -> std::shared_ptr<kcenon::network::core::network_context> {
91 if (
config.initialize_on_register && !ctx.is_initialized()) {
92 ctx.initialize(
config.thread_count);
97 return std::shared_ptr<kcenon::network::core::network_context>(
98 std::shared_ptr<void>{}, &ctx);
113inline common::VoidResult unregister_network_services(
114 common::di::IServiceContainer& container) {
128inline common::VoidResult shutdown_network_services(
129 common::di::IServiceContainer& container) {
135 return unregister_network_services(container);
159inline common::VoidResult register_all_network_services(
160 common::di::IServiceContainer& container,
161 const network_registration_config&
config = {}) {
164 auto result = register_network_services(container,
config);
165 if (result.is_err()) {
169 return common::VoidResult::ok({});
Global context for shared network system resources.
void shutdown()
Shutdown all systems.
static network_context & instance()
Get the singleton instance.
Public header for compile-time feature flags.