Make the service registry a real read path for commands

The DI registry was write-only — populated in Core::initialize() but never
resolved through. Thread it into command execution so commands resolve
shared services by interface instead of constructing throwaways:

- CommandContext gains a non-owning ServiceRegistry* plus an ergonomic
  service<I>() resolver.
- CommandManager carries the registry (Core::setServices(&registry_)) and
  stamps it onto every CommandContext it builds (async + sync paths).
- RpcInfoCommand's getPublicIpAddress() now reuses the shared, initialized
  INetworkClient from the registry, falling back to a throwaway client only
  when none is registered.

Core itself (the composition root) keeps direct member wiring and commands
keep explicit MusicManager injection — converting those to a service locator
would only hide dependencies; the registry earns its keep at the genuine
seam where a command needs a service it isn't handed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-22 22:25:15 +03:00
1 parent 6c7e6a170f
commit a9ab0d6b75
5 files changed
+46 -8

No files matched your search

+11
View File
@@ -43,6 +43,13 @@ namespace Echoion::Core
// Shutdown the command manager (stops thread pool)
void shutdown();
// Provide the service registry that command contexts resolve
// shared services from (non-owning; must outlive this manager).
void setServices(const Void::Service::ServiceRegistry* services)
{
services_ = services;
}
// Disable copy
CommandManager(const CommandManager&) = delete;
CommandManager& operator=(const CommandManager&) = delete;
@@ -141,6 +148,10 @@ namespace Echoion::Core
std::string prefix_ = "!";
// Non-owning service registry threaded into each CommandContext
// so commands can resolve shared services by interface.
const Void::Service::ServiceRegistry* services_ = nullptr;
// Map for fast lookup: "play" -> PlayCommand
std::map<std::string, CommandPtr, std::less<>> commands_;
+13
View File
@@ -3,6 +3,7 @@
#include "echoion/core/MusicManager.hpp"
#include <ConfigTypes.hpp>
#include <Types.hpp>
#include <Void/Service/Registry.hpp>
#include <cstdint>
#include <functional>
#include <memory>
@@ -47,6 +48,10 @@ namespace Echoion::Core
// Dependencies
std::weak_ptr<MusicManager> musicManager;
// Service registry for resolving shared services by interface
// (non-owning; outlives the command). Populated by CommandManager.
const Void::Service::ServiceRegistry* services = nullptr;
// Reply callback - set by CommandManager
std::function<void(std::string_view)> replyCallback;
@@ -57,6 +62,14 @@ namespace Echoion::Core
replyCallback(message);
}
}
// Resolve a shared service by interface, or nullptr if the
// registry is absent / the service was not provided.
template <typename I>
[[nodiscard]] std::shared_ptr<I> service() const
{
return services ? services->get<I>() : nullptr;
}
};
/**