Thursday, 24 September 2009

Using idref when configuring objects

Using the idref element is "an error-proof way" to pass the id of one object to another in Spring.Net configuration files. Using idref is preferable because the IoC will validate that referenced objects exist at deployment time rather than waiting for objects to actually be instantiated.

So, this...

<object id="theTargetObject" type="..."> 
. . . 
</object> 

<object id="theClientObject" type="..."> 
  <property name="targetName"> 
    <idref object="theTargetObject"/> 
  </property> 
</object>

is prefereable to this...

<object id="theTargetObject" type="...">
. . .
</object>
 
<object id="theClientObject" type="...">
  <property name="targetName" value="theTargetObject"/>
</object>

See the Spring.Net documentation (section 5.3.2.1.1).

0 comments:

Post a Comment

By all means leave a comment. I may not be able to get back to you as quickly as I'd like but I'll do my very best.