Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

PropertyPlaceholderConfigurer Class

Resolves placeholder values in one or more object definitions.

For a list of all members of this type, see PropertyPlaceholderConfigurer Members .


[Visual Basic]
<Serializable> _
Public Class PropertyPlaceholderConfigurer
    Inherits PropertyResourceConfigurer
public class PropertyPlaceholderConfigurer : PropertyResourceConfigurer

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.


The default placeholder syntax follows the NAnt style: ${...}. Instances of this class can be configured in the same way as any other object in a Spring.NET container, and so custom placeholder prefix and suffix values can be set via the PlaceholderPrefix and PlaceholderSuffix properties.

The following example XML context definition defines an object that has a number of placeholders. The placeholders can easily be distinguished by the presence of the ${} characters.

  <object id="connStringProvider" type="MyNamespace.OracleConnectionStringProvider, MyAssembly">
    <property name="dataSource" value="${database.datasource}" />
    <property name="userId" value="${database.userid}" />
    <property name="password" value="${database.password}" />
    <property name="integratedSecurity" value="${database.integratedsecurity}" />

The associated XML configuration file for the above example containing the values for the placeholders would contain a snippet such as ..

    <add key="database.datasource" value="MyOracleDB" />
    <add key="database.userid" value="sa" />
    <add key="database.password" value="g0ly4dk1n" />
    <add key="database.integratedsecurity" value="true" />

The preceding XML snippet listing the various property keys and their associated values needs to be inserted into the .NET config file of your application (or Web.config file for your ASP.NET web application, as the case may be), like so...

    <add key="database.datasource" value="MyOracleDB" />
    <add key="database.userid" value="sa" />
    <add key="database.password" value="g0ly4dk1n" />
    <add key="database.integratedsecurity" value="true" />

PropertyPlaceholderConfigurer checks simple property values, lists, dictionaries, sets, constructor values, object type name, and object names in runtime object references ( RuntimeObjectReference). Furthermore, placeholder values can also cross-reference other placeholders, in the manner of the following example where the rootPath property is cross-referenced by the subPath property.

    <add key="rootPath" value="myrootdir" />
    <add key="subPath" value="${rootPath}/subdir" />

In contrast to the PropertyOverrideConfigurer class, this configurer only permits the replacement of explicit placeholders in object definitions. Therefore, the original definition cannot specify any default values for its object properties, and the placeholder configuration file is expected to contain an entry for each defined placeholder. That is, if an object definition contains a placeholder ${foo}, there should be an associated <add key="foo" value="..."/> entry in the referenced placeholder configuration file. Default property values can be defined via the inherited Properties collection to overcome any perceived limitation of this feature.

If a configurer cannot resolve a placeholder, and the value of the IgnoreUnresolvablePlaceholders property is currently set to false, an ObjectDefinitionStoreException will be thrown. If you want to resolve properties from multiple configuration resources, simply specify multiple resources via the Locations property. Finally, please note that you can also define multiple PropertyPlaceholderConfigurer instances, each with their own custom placeholder syntax.


Namespace: Spring.Objects.Factory.Config

Assembly: Spring.Core (in Spring.Core.dll)

See Also

PropertyPlaceholderConfigurer Members | Spring.Objects.Factory.Config Namespace | PropertyResourceConfigurer | PropertyOverrideConfigurer | IObjectDefinition