Own ConfigManager in Core; resolve config via DI instead of the singleton

Core holds a ConfigManager member, keeps it synced (updateConfig(config_)),
and provides it as a service. ConfigManager.cpp drops the instance()
definition. MusicManager gets the manager via setConfigManager() and reads
sections through it (former ECHOION_BOT/YOUTUBE/NETWORK sites); RpcInfoCommand
resolves it from the registry via ctx.service<Api::ConfigManager>(). Build
green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-23 14:01:31 +03:00
1 parent f7553d10d3
commit 0e08ccaefa
6 files changed
+29 -14

No files matched your search

+5
View File
@@ -5,6 +5,7 @@
#include "MusicManager.hpp"
#include "NetworkClient.hpp"
#include "RpcServer.hpp"
#include <ConfigManager.hpp>
#include <ConfigTypes.hpp>
#include <CoreInterface.hpp>
#include <Void/Async/EventBus.hpp>
@@ -192,6 +193,10 @@ namespace Echoion::Core
// DB persistence. Owned by Core, provided as a service.
Void::EventBus::EventBus eventBus_{Void::EventBus::Mode::Async};
// Config holder kept in sync with config_ and provided as a service
// (replaces the former ConfigManager singleton).
Api::ConfigManager configManager_;
public:
// Access the service registry (composition root).
+10
View File
@@ -6,6 +6,7 @@
#include "RpcTypes.hpp"
#include "SubscriptionManager.hpp"
#include "YouTubeClient.hpp"
#include <ConfigManager.hpp>
#include <ConfigTypes.hpp>
#include <TrackTypes.hpp>
#include <Types.hpp>
@@ -41,6 +42,13 @@ namespace Echoion::Core
// before playback so emitted events reach subscribers.
void setEventBus(Void::EventBus::EventBus* bus) { eventBus_ = bus; }
// Inject the config holder (owned by Core). Must be set before
// initialize() so config sections resolve.
void setConfigManager(Api::ConfigManager* cfg)
{
configManager_ = cfg;
}
[[nodiscard]] Api::Result<std::string>
play(const std::string& query, uint64_t clientId);
[[nodiscard]] Api::Result<void> pause();
@@ -222,6 +230,8 @@ namespace Echoion::Core
std::shared_ptr<NetworkClient> networkClient_;
// Non-owning application event bus (provided by Core).
Void::EventBus::EventBus* eventBus_ = nullptr;
// Non-owning config holder (provided by Core).
Api::ConfigManager* configManager_ = nullptr;
std::unique_ptr<YouTubeClient> youTubeClient_;
std::unique_ptr<AudioDecoder> audioDecoder_;
std::unique_ptr<SubscriptionManager> subscriptionManager_;
-6
View File
@@ -6,12 +6,6 @@
namespace Echoion::Api
{
ConfigManager& ConfigManager::instance()
{
static ConfigManager instance;
return instance;
}
bool ConfigManager::initialize(const std::filesystem::path& configPath)
{
std::unique_lock lock(mutex_);
+3 -2
View File
@@ -65,7 +65,7 @@ namespace Echoion::Core
}
// Initialize global ConfigManager with loaded config
Api::ConfigManager::instance().updateConfig(config_, false);
configManager_.updateConfig(config_, false);
ECHOION_LOG_INFO("Global ConfigManager initialized");
// Note: logLevel was removed from BotConfig, using Debug as default
@@ -110,6 +110,7 @@ namespace Echoion::Core
// Initialize music manager
musicManager_ = std::make_shared<MusicManager>();
musicManager_->setEventBus(&eventBus_);
musicManager_->setConfigManager(&configManager_);
auto musicResult = musicManager_->initialize(networkClient_, database_);
if (!musicResult) {
return std::unexpected(musicResult.error());
@@ -306,7 +307,7 @@ namespace Echoion::Core
registry_.provide<Api::ILogger>(logger);
}
registry_.provide<Api::ConfigManager>(
alias(&Api::ConfigManager::instance()));
alias(&configManager_));
registry_.provide<Void::EventBus::EventBus>(alias(&eventBus_));
if (networkClient_) {
registry_.provide<Api::INetworkClient>(networkClient_);
+4 -4
View File
@@ -23,9 +23,9 @@ namespace Echoion::Core
database)
{
// Get config from global ConfigManager
const auto& botConfig = ECHOION_BOT;
const auto& youtubeConfig = ECHOION_YOUTUBE;
const auto& networkConfig = ECHOION_NETWORK;
const auto& botConfig = configManager_->getBot();
const auto& youtubeConfig = configManager_->getYouTube();
const auto& networkConfig = configManager_->getNetwork();
config_ = botConfig;
networkClient_ = std::move(networkClient);
@@ -229,7 +229,7 @@ namespace Echoion::Core
// If direct open fails and we have a proxy, try downloading through
// proxy
const auto& networkConfig = ECHOION_NETWORK;
const auto& networkConfig = configManager_->getNetwork();
if (!openResult && networkConfig.proxy.has_value() &&
networkConfig.proxy->enabled()) {
ECHOION_LOG_INFO(
+7 -2
View File
@@ -74,8 +74,13 @@ namespace Echoion::Core
void RpcInfoCommand::execute(const CommandContext& ctx)
{
// Get RPC configuration from global ConfigManager
const auto& networkConfig = ECHOION_NETWORK;
// Resolve RPC configuration from the service registry.
auto configManager = ctx.service<Api::ConfigManager>();
if (!configManager) {
ctx.reply("Configuration service unavailable");
return;
}
const auto& networkConfig = configManager->getNetwork();
uint16_t rpcPort = networkConfig.rpcPort;
std::string rpcBindAddress = networkConfig.rpcBindAddress;