Caliburn Micro - 是否可以拦截执行命令的调用?
我想向我的视图模型添加错误处理,以便在执行命令并引发异常时,正确处理错误并显示模式对话框。
我已经做到了这一点,但我的方法太罗嗦了。错误被捕获在命令中,然后通过 IObservable 发布。行为订阅错误 - 创建适当的视图模型并传递给 WindowManager。虽然它有效,但我更喜欢更具声明性的东西。
相反,我想装饰或拦截对命令的调用(绑定到按钮)并提供通用错误处理。 try-catch 可能会调用视图模型上的方法或用 Rescue 属性修饰的命令。
我知道这在 Caliburn 中是可能的,但是可以用 Micro 来完成吗?也许还有另一种方法?
I want to add error handling to my view-models so that when a command is executed and an exception thrown, the error is handled gracefully and a modal dialog displayed.
I've got this working but my approach is a too wordy. Errors are trapped within a command and then published via an IObservable. A behavior subscribes to the errors - creating an appropriate view model and passing to the WindowManager. While it works, I'd prefer something more declarative.
Instead I want to decorate or intercept calls to commannds (bound to a button) and provide generic error handling. The try-catch might call out to a method on the view model or command that is decorated with a Rescue attribute.
I understand this is possible within Caliburn but can it be done with Micro? Perhaps there's an alternative approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看我在 SO 上提出的这个问题,随后回答了通过 CM Codeplex 论坛提供帮助。
我稍微修改了 此 CM 过滤器实现允许错误处理例程作为协程执行。
这与某些示例中提供的
ShowModal
IResult
相结合应该可以满足您的需求。Have a look at this question I asked on SO and subsequently answered with help via the CM codeplex forum.
I slightly modified the
RescueAttribute
of this CM filters implementation to allow the error handling routine to be executed as a coroutine.This in combination with the
ShowModal
IResult
available in some of the samples should get you what you want.