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:
1 parent
f7553d10d3
commit
0e08ccaefa
6 files changed
+29
-14
No files matched your search
@@ -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
@@ -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_);
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user