public class MessageService
{
private readonly IMessageProvider_messageProvider;
private readonly Dictionary<Guid, Action<TResponse>> _dictionary = new();
public TResponse Send<TMessage, TResponse>(TMessage payload, Action<TResponse> func) where TMessage : class
{
var message = new Message<TMessage>
{
ResponseChannel = "my-channel",
Payload = payload
};
_dictionary[message.MessageId] = func;
_messageProvider.Publish(message);
}
public void OnMessage<T>(Response<T> response) where T : class
{
if (!_dictionary.TryGetValue(response.MessageId, out var action)) return;
action!.Invoke(response.Payload);
}
public async Task<TResponse> SendAsync<TMessage, TResponse>(TMessage payload, CancellationToken cancellationToken)
{
// TODO
throw new NotImplementedException();
}
}
public class MessageService
{
private readonly IMessageProvider_messageProvider;
private readonly Dictionary<Guid, Action<TResponse>> _dictionary = new();
public TResponse Send<TMessage, TResponse>(TMessage payload, Action<TResponse> func) where TMessage : class
{
var message = new Message<TMessage>
{
ResponseChannel = "my-channel",
Payload = payload
};
_dictionary[message.MessageId] = func;
_messageProvider.Publish(message);
}
public void OnMessage<T>(Response<T> response) where T : class
{
if (!_dictionary.TryGetValue(response.MessageId, out var action)) return;
action!.Invoke(response.Payload);
}
public async Task<TResponse> SendAsync<TMessage, TResponse>(TMessage payload, CancellationToken cancellationToken)
{
// TODO
throw new NotImplementedException();
}
}