Search code examples
c#inversion-of-controlunity-container

Unity wraps exception to the ResolutionFailedException. How to avoid?


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?


Solution

  • 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.