使用 Prism 事件聚合器或任何其他拦截命令的模式取消消息?
有谁知道如何取消 Prism 事件聚合器上消息的进一步广播?
我正在尝试做一些相当标准的命令/事件消息传递 - 让我用序列图来解释:
现在我想添加验证。验证应该拦截命令,确定它是否是要应用的有效命令,如果不是则取消其广播,这是有意义的。本质上这就是我想要的:
有谁知道如何做类似的事情
public class Validator : ISubscribe<ChangePropertyCommand>
public void Handle(ChangePropertyCommand cmd) {
if(IsNotValid(cmd))
_events.Cancel(cmd);
else
...
}
}
或者还有另一个吗使用更好的模式?
Does anyone know some way to cancel any further broadcasting of a message on the Prism event aggregator?
I'm trying to do some fairly standard command/event messaging - let me explain with a sequence diagram:
Now I want to add in validation. It makes sense that the validation should intercept the command, determine whether it is a valid command to apply, and if not cancel its broadcast. In essence this is what I want:
Does anyone know how to do something along the lines of
public class Validator : ISubscribe<ChangePropertyCommand>
public void Handle(ChangePropertyCommand cmd) {
if(IsNotValid(cmd))
_events.Cancel(cmd);
else
...
}
}
Or is there another better pattern to use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑如果没有大量工作来扩展 EventAggregator,这是不可能的。在我看来,最简单的方法是只让验证器处理代表命令的事件。如果命令有效,则验证器直接执行状态更改器或通过引发状态更改器处理的新类型事件来执行状态更改器。当然,如果命令无效,您可以引发已取消的事件。
I suspect this isn't possible without a fair bit of work to extend the EventAggregator. Seems to me the easiest way to do this would be to only have your validator handle the event that represents the command. If the command is valid then the validator executes the state changer either direct or by raising a new type of event which the state changer handles. Of course if the command is invalid you instead raise your cancelled event.