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
@@ -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).
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in new issue
Block a user