MessagePipe
MessagePipe copied to clipboard
Is RequestHandler stateless?
Am I realized correctly that IRequestHandler<, >
class is stateless? I would like to have IRequestHandler singleton with its own state. But IRequestHandler seams to creating inside of BuildServiceProvider. Can I make it outside and just somehow register?
Example:
public class ToDoServiceHandlers : MonoBehaviour,
IRequestHandler<InitialStateRequest, InitialStateResponse>,
IRequestHandler<ClearItemsRequest, ClearItemsResponse>,
IRequestHandler<AddItemRequest, AddItemResponse>
{
private ToDoState _model;
private void Awake()
{
_model = ToDoState.InitialState;;
}
public InitialStateResponse Invoke(InitialStateRequest request)
{
var response = GlobalMessagePipe.GetRequestHandler<LoadToDoItemsRequest, LoadToDoItemsResponse>().Invoke(default);
_model.Items = response.Value;
return new InitialStateResponse {Value = _model.Items};
}
}