Caliburn - Exception handling and Rescue

我怕爱的太早我们不能终老 提交于 2019-12-23 20:17:42

问题


I'm using C# and Caliburn.

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

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.

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.


回答1:


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

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

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.




回答2:


There is a really simple way to achieve this, just override the UnhandledException method in your Bootstrapper.

There is an example here: Global handling exception in WPF app with Caliburn.Micro



来源:https://stackoverflow.com/questions/3366817/caliburn-exception-handling-and-rescue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!