其他分享
首页 > 其他分享> > two kinds of messages dispatched by MediatR

two kinds of messages dispatched by MediatR

作者:互联网

https://github.com/jbogard/MediatR/wiki#basics

Basics

MediatR has two kinds of messages it dispatches:

 

Request/response

The request/response interface handles both command and query scenarios. First, create a message:

public class Ping : IRequest<string> { }

Next, create a handler:

public class PingHandler : IRequestHandler<Ping, string>
{
    public Task<string> Handle(Ping request, CancellationToken cancellationToken)
    {
        return Task.FromResult("Pong");
    }
}

Finally, send a message through the mediator:

var response = await mediator.Send(new Ping());
Debug.WriteLine(response); // "Pong"

 

标签:kinds,MediatR,Ping,dispatched,messages,public,response
来源: https://www.cnblogs.com/chucklu/p/13092768.html