Container.BuildUp() throws InvalidOperationExcetption when the object instance does not have a Public constructor.
description
<p>Hello, - I had previously posted this as a workitem on enterprise library codeplex: http://entlib.codeplex.com/workitem/28939 - but to outline the issue and add some more detail:-</p>
<p> </p>
<p>Unity v1.2 let you BuildUp() against an existing instance, and it would inject the dependencies into that instance (via method / property injection), even though the instances type in question did not have a public constructor. Which makes perfect sense to me, as why would unity possibly need to know about a constructor when all its doing is injecting into an existing instance all the time!</p>
<p> </p>
<p>Unity 2 throws an exception if you BuildUp() there is no public constructor. I have outlined this in the tests.</p>
<p> </p>
<p>I understand from ctavares comment on previous workitem at entlib codeplex, that when unity encounters a type it tries to find a public constructor "in case" you need to do a resolve() later on down the line.</p>
<p>If this is correct, then call me a simpleton, but in this instance this optimisation feature of unity seems a waste of resources and a breaking change from v1.2 that will mean that I have to give all my classes public constructors, even though unity will never actually need to construct a single one. Its common to have private / internal constructors especially when your object instances are obtained through factories for example.</p>
<p> </p>
<p>I am guessing a solution here would be some mechanism by which to tell unity that for particular types, it can disable its "public constructor" checks as unity will never be asked to create / Resolve() an instance of that type. BuildUp() would then succeed for those types - as it will not have to check for a public constructor as it will know it will never be needed.</p>
<p> </p>
<p>Kind Regards</p>
<p>Darrell</p>