Class StateService
Implementation of the gRPC State service. Provides state management operations with Dapr backend and pub/sub notifications.
public class StateService : State.StateBase
- Inheritance
-
State.StateBaseStateService
- Inherited Members
Constructors
StateService(ServicesConfiguration, DaprClient, ILogger<StateService>)
Creates a new StateService instance.
public StateService(ServicesConfiguration config, DaprClient daprClient, ILogger<StateService> logger)
Parameters
configServicesConfigurationThe services configuration containing state store settings.
daprClientDaprClientThe Dapr client for state operations.
loggerILogger<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
requestDeleteStateRequestThe delete state request containing service, key, optional etag, and optional includeValue.
contextServerCallContextThe 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
requestGetAllStateRequestThe get all state request containing the service name.
contextServerCallContextThe 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
requestGetStateRequestThe get state request containing service and key.
contextServerCallContextThe 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
requestRegisterKeysRequestThe register keys request containing service name and keys to register.
contextServerCallContextThe 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
requestSaveStateRequestThe save state request containing service, key, value, and optional etag.
contextServerCallContextThe server call context.
Returns
- Task<SaveStateResponse>
The save state response with success status.
Exceptions
- RpcException
StatusCode.Aborted when ETag mismatch occurs.