ConnectorFactory¶
ConnectorFactory is a global registry and dynamic constructor for IExchangeConnector instances, used to instantiate exchange adapters based on type and symbol at runtime.
class ConnectorFactory
{
public:
using CreatorFunc =
MoveOnlyFunction<std::shared_ptr<IExchangeConnector>(const std::string&)>;
static ConnectorFactory& instance();
void registerConnector(const std::string& type, CreatorFunc creator);
std::shared_ptr<IExchangeConnector> createConnector(const std::string& type,
const std::string& symbol);
private:
ConnectorFactory() = default;
std::unordered_map<std::string, CreatorFunc> _creators;
};
Purpose¶
- Enable pluggable, type-based instantiation of exchange connectors without static bindings.
Responsibilities¶
| Aspect | Details |
|---|---|
| Registration | Maps string identifiers (e.g. "bybit", "mock") to creator functions. |
| Construction | Calls registered factory to produce a connector for a given symbol. |
| Lifetime | Singleton pattern via instance(); all connectors share same registry. |
Notes¶
- Supports dynamic module systems or runtime configuration of connector types.
- Not thread-safe by default — external synchronization may be required during registration.
- Returns
nullptrif the requested connector type is not registered.