Unity wraps exception to the ResolutionFailedException. How to avoid?

后端 未结 4 1397
我在风中等你
我在风中等你 2021-01-22 12:51

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?

4条回答
  •  日久生厌
    2021-01-22 13:13

    The reason Unity wraps exceptions is all about the contract - the contract of the Resolve method.

    What should an application catch when Resolve throws? Suppose you did resolve a class that you know throws IOException. So you put a catch for that exception around the resolve call.

    Then the implementation changes. Or just the configuration. Now the services throw something else.

    Now you've got a configuration change that will require a code change. Not good.

    A second reason that with the wrapped exception the container has a place to put diagnostic information about where in the resolve process the failure occurred.

提交回复
热议问题