Class RequestFactoryManager
Auto-discovery registry that maps each RequestMethod enum value to its corresponding IRequestFactory implementation.
public static class RequestFactoryManager
Inheritance
Remarks
Rather than maintaining a hand-written registry, the static constructor scans the assembly for every non-abstract type that implements IRequestFactory and carries a RequestUsageAttribute. This means that adding a new transport (e.g., a WebSocket factory) requires only a new class decorated with the attribute — no change to this manager or to DataSender.
The registry is intentionally static and eagerly initialized: request factories are stateless configuration objects and the scan needs to happen only once per application lifetime. Registering duplicate factories for the same RequestMethod throws immediately at startup, so misconfiguration is caught before any data is sent.
Methods
CreateRequestOfType(RequestMethod)
Convenience shortcut that resolves the factory for type and immediately
creates a default (no-payload) IRequest.
public static IRequest CreateRequestOfType(RequestMethod type)
Parameters
| Name | Type | Description |
|---|---|---|
type | RequestMethod | Transport method to use. |
Returns
IRequest — A new IRequest ready to execute.
Exceptions
ArgumentException — Thrown if no factory is registered for type.
CreateRequestOfType(RequestMethod, string, string)
Convenience shortcut that resolves the factory for type and immediately
creates a data-carrying IRequest with the given record name and JSON body.
public static IRequest CreateRequestOfType(RequestMethod type, string nameField, string dataField)
Parameters
| Name | Type | Description |
|---|---|---|
type | RequestMethod | Transport method to use. |
nameField | string | Record identifier passed to String). |
dataField | string | Serialised JSON payload passed to the factory. |
Returns
IRequest — A new IRequest initialised with the given payload.
Exceptions
ArgumentException — Thrown if no factory is registered for type.
GetFactoryByConfig(RequestMethod)
Returns the IRequestFactory registered for methodType.
public static IRequestFactory GetFactoryByConfig(RequestMethod methodType)
Parameters
| Name | Type | Description |
|---|---|---|
methodType | RequestMethod | Transport method to look up. |
Returns
IRequestFactory — The factory registered for methodType.
Remarks
Prefer IRequestFactory@) at runtime call sites where a missing factory should be handled gracefully (e.g., DataSender). Use this overload only when a missing factory is a programming error that should crash loudly.
Exceptions
KeyNotFoundException — Thrown if no factory is registered for methodType.
TryGetFactoryByConfig(RequestMethod, out IRequestFactory)
Attempts to retrieve the IRequestFactory for methodType
without throwing if the key is absent.
public static bool TryGetFactoryByConfig(RequestMethod methodType, out IRequestFactory factory)
Parameters
| Name | Type | Description |
|---|---|---|
methodType | RequestMethod | Transport method to look up. |
factory | IRequestFactory | Receives the registered factory, or null if not found. |
Returns
bool — true if a factory was found; false otherwise.