views:

610

answers:

1

I believe I came across this a couple months ago, but now I'm having trouble finding the answer. Perhaps someone can just point me to the right section in the documentation?

Using Sprint.NET, I'm combining remote XML files into a single application context where the engine objects are separate from the business rule objects. The problem is some of the business rules are values, not objects, which are needed by <property> and <constructor-arg> nodes in the engine xml:

<object name="Engine">
    <constructor-arg index="0" value="business rule" />
</object>

Either referencing a property of another object (use expression attribute instead of value?) or perhaps some specialized name/value list (e.g. Spring's version of to <appsettings>, whatever that is) would work.

A: 

Found it! Starting on page 41 of the Spring Framework (Version 1.2.0 M1) PDF in "The IoC container" chapter:

5.3.8. Setting a reference using the members of other objects and classes.

This section details those configuration scenarios that involve the setting of properties and constructor arguments using the members of other objects and classes. This kind of scenario is quite common, especially when dealing with legacy classes that you cannot (or won't) change to accommodate some of Spring.NET's conventions... consider the case of a class that has a constructor argument that can only be calculated by going to say, a database. The MethodInvokingFactoryObject handles exactly this scenario ... it will allow you to inject the result of an arbitrary method invocation into a constructor (as an argument) or as the value of a property setter. Similarly, PropertyRetrievingFactoryObject and FieldRetrievingFactoryObject allow you to retrieve values from another object's property or field value. These classes implement the IFactoryObject interface which indicates to Spring.NET that this object is itself a factory and the factories product, not the factory itself, is what will be associated with the object id. Factory objects are discussed further in ???

This is 5.3.9.1 in the latest online documentation.

Neil C. Obremski