一、简介
通知消息,分派给多个处理程序
二、配置信息
notiConmmand
public class notiConmmand:INotification
{
public string name { get; set; }
public string addr { get; set; }
}
GoogleCommandHandle.cs
添加谷歌处理类
public class GoogleCommandHandle : INotificationHandler<notiConmmand>
{
public Task Handle(notiConmmand notiConmmand, CancellationToken cancellationToken)
{
Console.WriteLine($"Google{notiConmmand.name},{notiConmmand.addr}");
return Task.CompletedTask;
}
}
再添加,qq,微信的处理类,仅改输出的内容,例将 $"Google 换为 $"QQ
OrderController.cs
[HttpGet]
public async Task<ActionResult<string>> Notification([FromBody]notiConmmand notiConmmand)
{
notiConmmand notiConmmand1 = new notiConmmand
{
name = notiConmmand.name,
addr = notiConmmand.addr
};
await _mediator.Publish(notiConmmand1);
return Ok(notiConmmand1);
}
三、执行结果
INotification通过Publish广播给所有处理类,然后三个处理类都会执行