Unity将异常包装到ResolutionFailedException.如何避免? [英] Unity wraps exception to the ResolutionFailedException. How to avoid?

查看:62
本文介绍了Unity将异常包装到ResolutionFailedException.如何避免?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道,是否有可能问Unity在解决时不要包装任何用户异常"?

真的,为什么Unity将包装包装到ResolutionFailedException?它正在改变建筑服务合同",恕我直言,使用统一对象初始化的事实应该是透明的,这意味着如果客户端从新"运算符等待IOException例如,即使使用Unity创建了对象,也应该将其展开. >

其他IoC容器的行为是否相同?

解决方案

因为您的构造函数不应包含逻辑.

我知道这不是一个完全令人满意的答案,但是我不知道您可以在Unity中关闭此行为-我也愿意同意这是一个奇怪的设计决定...

但是,如果您简化构造函数,就不会有问题.

I want to know, is there the possibility to ask Unity "do not wrap any user exceptions at resolve time"?

Really, why Unity do wrappings to ResolutionFailedException? It is changing "construction service contract", IMHO the fact of objects initialization using unity should be transparent, that means if client waiting for example for IOException from "new" operator it should get it unwrapped also even object is created using Unity.

Do other IoC containers behave the same?

解决方案

Because your constructors should contain no logic.

I know that's not a completely satisfying answer, but I'm not aware that you can switch off this behavior in Unity - I also do agree that it's a strange design decision...

However, if you keep your constructors simple, you will not have that problem.

这篇关于Unity将异常包装到ResolutionFailedException.如何避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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