Skip to main content

Interface IRequestFactory

Factory contract for creating pre-configured IRequest instances corresponding to a specific transport strategy (network POST, local file, etc.).

public interface IRequestFactory

Examples​

Implement IRequestFactory and decorate the class with RequestUsageAttribute to register a new transport. RequestFactoryManager reflects over the assembly at static-constructor time and instantiates every non-abstract IRequestFactory that carries the attribute, so no call to a registration API is needed — the class just has to exist in the assembly. The pattern mirrors the built-in LocalJsonRequestFactory and JsonPostRequestFactory implementations.

// WebSocketRequestFactory.cs — dropped into the Network assembly; no other wiring needed.

[RequestUsage(RequestMethod.SendOverNetwork)] // maps this factory to the SendOverNetwork key
public sealed class WebSocketRequestFactory : RequestFactory
{
// CreateRequest() with no arguments is inherited from RequestFactory and returns
// a default-constructed WebSocketRequest (suitable for connection-test pings).

// CreateRequest(name, data) carries the participant ID and JSON payload so the
// backend can correlate the upload to the correct session record.
public override IRequest CreateRequest(string name, string data)
=> new WebSocketRequest(name, data);
}

// DataSender resolves the factory at send time via:
// RequestFactoryManager.TryGetFactoryByConfig(pendingData.Method, out var factory)
// factory.CreateRequest(pendingData.Name, pendingData.Data)
// No changes to DataSender or any other class are required.

Remarks​

RequestFactoryManager discovers implementations at startup by scanning for types decorated with RequestUsageAttribute — no explicit registration is required. Decoupling creation from dispatch means that adding a new transport (e.g., a WebSocket or message queue) only requires a new factory class; DataSender and the rest of the pipeline are unaffected.

The two overloads exist because some requests (e.g., a default health-check ping) need no payload, while study data submissions always carry a named JSON blob. Both are routed through the same factory instance so that auth credentials, endpoint URLs, and retry settings are configured in one place.

Methods​

CreateRequest()​

Creates a default IRequest with no data payload.

IRequest CreateRequest()

Returns​

IRequest — A new IRequest instance ready for execution.

Remarks​

Intended for requests that only need transport configuration (e.g., a connection test or a command-only POST). The factory supplies any required headers or endpoint URL from its own configuration.

CreateRequest(string, string)​

Creates an IRequest that will transmit a named JSON data payload.

IRequest CreateRequest(string name, string data)

Parameters​

NameTypeDescription
namestringIdentifier for the data record (e.g., participant ID + scene name).
datastringSerialised JSON string produced by the analysis pipeline.

Returns​

IRequest — A new IRequest instance initialised with the given payload.

Remarks​

name is used as the file name for local-write requests and as the name field in the JSON body for network POST requests, so that the backend can correlate incoming data to the correct participant session.