Table of Contents

Class StateService

Namespace
Virtufin.Api.Services
Assembly
Virtufin.Api.dll

Implementation of the gRPC State service. Provides state management operations with Dapr backend and pub/sub notifications.

public class StateService : State.StateBase
Inheritance
State.StateBase
StateService
Inherited Members

Constructors

StateService(ServicesConfiguration, DaprClient, ILogger<StateService>)

Creates a new StateService instance.

public StateService(ServicesConfiguration config, DaprClient daprClient, ILogger<StateService> logger)

Parameters

config ServicesConfiguration

The services configuration containing state store settings.

daprClient DaprClient

The Dapr client for state operations.

logger ILogger<StateService>

The logger for recording service operations.

Methods

DeleteState(DeleteStateRequest, ServerCallContext)

Deletes state for a service and key, then broadcasts a state change event. Supports optimistic concurrency via ETag — throws Aborted on mismatch.

public override Task<DeleteStateResponse> DeleteState(DeleteStateRequest request, ServerCallContext context)

Parameters

request DeleteStateRequest

The delete state request containing service, key, optional etag, and optional includeValue.

context ServerCallContext

The server call context.

Returns

Task<DeleteStateResponse>

The delete state response with success status.

Exceptions

RpcException

StatusCode.Aborted when ETag mismatch occurs.

GetAllState(GetAllStateRequest, ServerCallContext)

Gets all registered state key-value pairs for a service. Only returns keys that have been registered via RegisterKeys.

public override Task<GetAllStateResponse> GetAllState(GetAllStateRequest request, ServerCallContext context)

Parameters

request GetAllStateRequest

The get all state request containing the service name.

context ServerCallContext

The server call context.

Returns

Task<GetAllStateResponse>

A dictionary of all state key-value pairs for the service.

GetState(GetStateRequest, ServerCallContext)

Gets a single state value for a service and key.

public override Task<GetStateResponse> GetState(GetStateRequest request, ServerCallContext context)

Parameters

request GetStateRequest

The get state request containing service and key.

context ServerCallContext

The server call context.

Returns

Task<GetStateResponse>

The state value and etag.

Exceptions

RpcException

Thrown when service/key not found or invalid arguments.

RegisterKeys(RegisterKeysRequest, ServerCallContext)

Registers state keys for a service to enable GetAllState and tracking. Services should call this on startup to re-register their known keys.

public override Task<RegisterKeysResponse> RegisterKeys(RegisterKeysRequest request, ServerCallContext context)

Parameters

request RegisterKeysRequest

The register keys request containing service name and keys to register.

context ServerCallContext

The server call context.

Returns

Task<RegisterKeysResponse>

The register keys response with success status.

SaveState(SaveStateRequest, ServerCallContext)

Saves state for a service and broadcasts a state change event. Uses optimistic concurrency when an ETag is provided.

public override Task<SaveStateResponse> SaveState(SaveStateRequest request, ServerCallContext context)

Parameters

request SaveStateRequest

The save state request containing service, key, value, and optional etag.

context ServerCallContext

The server call context.

Returns

Task<SaveStateResponse>

The save state response with success status.

Exceptions

RpcException

StatusCode.Aborted when ETag mismatch occurs.