Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In Unity, there is indeed a <code>Container.RegisterType&lt;TFrom, TTo&gt;()</code> method set that registers types at runtime. It's probably more common to do it using an XML configuration file, but either works.</p> <p>Interestingly, in Unity there is no <code>Container.Resolve&lt;T&gt;(params object[] parameters)</code> -type method to resolve a type with specific constructor parameter values. Unity is built on top of ObjectBuilder which is the P&amp;P team's library for doing object construction and wireup (IIRC it was originally written for ObjectSpaces but has been significantly enhanced now). ObjectBuilder gives you the ability to inject dependencies in various ways, including via the constructor, so you could say - for example - that you would pass a new instance of a type it's dependent on into the constructor of a resolved type; but that type would also have to be registered. You can also pass instances of registered types (a registered instance / singleton etc). But AFAICS there is no way to simply give it a value to pass in.</p> <p>I think doing that would go against the philosophy of IoC to some extent, which is why they don't provide that facility. The container should, in theory, be able to give you a complete object graph in any given circumstance, so you should never have to pass parameters in, and making your objects dependent on constructor parameters other than injectable object dependencies (which the container will resolve for you) is seen as Bad Design.</p> <p>I can't speak for Windsor, StructureMap or the others, which may allow you to do this. I can't even say categorically that Unity has no way to do it since I'm reasonably new at it, but IIRC Chris Tavares - who basically built Unity - hangs out here from time to time, so maybe he'll drop by and answer this one :-)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload