Caliburn-异常处理和救援 [英] Caliburn - Exception handling and Rescue

查看:101
本文介绍了Caliburn-异常处理和救援的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#和Caliburn。

I'm using C# and Caliburn.

是否存在一种全局方法来捕获所有视图模型中的所有异常?

Is there a global way to catch all exceptions in all view models?

从DI / IoC容器导入时,如果出现某种异常怎么办?

What about when there is some kind of exception during import from a DI/IoC container?

我基本上想在发生这种情况时显示一个消息框。

I basically want to display a message box when this occurs.

RescueAttribute在我看来必须放在每个单个视图模型类上,并且当您同时使用AsyncActionAttribute时似乎不起作用时间。

The RescueAttribute looks to me like it would have to be put on every single view model class, and it doesn't seem like it works when you use AsyncActionAttribute at the same time.

推荐答案

方法 IConventionManager.ApplyActionCreationConventions(IAction action,IMethod targetMethod)并可以向其中添加过滤器。

The method IConventionManager.ApplyActionCreationConventions(IAction action, IMethod targetMethod) is invoked just after an action creation and can add filters to it.

您可以提供自定义的 IConventionManager 覆盖 DefaultConventionManager.ApplyActionCreationConventions 并在操作中推送救援过滤器。

You can provide a custom IConventionManager overriding DefaultConventionManager.ApplyActionCreationConventions and pushing in the action a rescue filter.

请注意,在这种情况下,无论如何,您必须在每个ViewModel上提供一种救援方法;为了克服这个问题,您可以构建一个新的自定义应急过滤器(按照原始过滤器的要求),然后将异常分发到您的基础结构中。

Note that in this case you have to provide a rescue method on every ViewModel anyway; to overcome this, you can build a new custom rescue filter (following the line of the original one) and dispatch the exception to your infrastructure.

这篇关于Caliburn-异常处理和救援的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆