我有一个有界的上下文,它监听来自远程有界上下文的事件(即UserBecameEligible
),当它们进入事件总线时,通过映射到并引发本地命令处理程序来执行某个操作,即:
// command class
public class Sendlert
{
int UserId {get;set;}
string Message {get;set;}
}
// handler code
public class SendAlertCommandHandler
{
public class SendAlert: ICommandHandler<SendAlert>
{
public void Handle(SendAlert command)
{
// ...
// this.alertStrategy.Send(command.UserId, comnmand.Message);
}
}
}
为了实现自动化,我正在考虑使用以下的映射字典:
Dictionary<Type,Action<object,object>> externalEventToLocalCommands
第一种类型是外部事件类型,以及调用从外部事件转换为本地命令的函数,即:
object UserBecameEligibelToSendSmsConverter(object obj)
{
UserBecameEligableEvent evnt = obj as UserBecameEligableEvent;
return new SendAlert()
{
UserId = evnt.UserId,
Message = "Congrats " + evnt.FirstName + "you are now eligable for an account upgrade".
}
}
我不记得在Vernon实施领域驱动设计中阅读此ExternalEventToLocalCommandTranslator
,是否有其他DDD专家使用的上述替代策略或名称,以及任何可以学习实现的开源库?