StructureMap – Xml Reference

This document is a reference for older elements of the Xml configuration syntax.  This reference is valid for versions prior to 2.5.  See Xml Configuration for the preferred usages.

Next Prev

<StructureMap> Element

The root element of all StructureMap.config files

Sample
<StructureMap DefaultProfile="MyProfile"> <Include /> <Assembly/>y/> <Instances/>BR> <Machine/> <Profile/> <log4net/> </StructureMap>

<Include> Element

Allows a StructureMap.config to include the <PluginFamily> and instances from additional StructureMap configuration files.  This is useful in cases where a large component may have its own StructureMap.config file that is copied into the parent systems source code tree.

Sample
<StructureMap DefaultProfile="MyProfile"> <Include File="Component-StructureMap.config" /> </StructureMap>

<Assembly> Element

Instructs StructureMap to search the specified assembly for possible PluginFamily interfaces and Plugin classes

Sample
<Assembly Name="MyApplication.Common" Deploy="All"/> <Assembly Name="MyApplication.Persistence" Deploy="Server,Batch,Build"/>

<Instances> Element

A container node for InstanceMemento nodes. Can be used as a catch all MementoSource. May be deprecated in later versions of StructureMap

Sample
<Instances> <StructureMap.Testing.Widget.WidgetMaker Type="Color" Key="Red"> <Property Name="Color" Value="Red" /> </StructureMap.Testing.Widget.WidgetMaker> </Instances>

<Machine> Element

Machine level overrides for default instances of one or more PluginFamily’s. New in version 2.0 is the ability to define the instance for the type specified by the Type attribute inline in an embedded <Instance> node

Sample
<Machine Name="SERVER" Profile="Local"> <Override Type="StructureMap.Testing.Widget.IWidget" DefaultKey="Orange"/> </Machine> <Override Type="StructureMap.Testing.Widget.Rule"> <Instance Type="Color" Color="Green"/> </Override>

<PluginFamily> Element

Represents an explicit declaration of a PluginFamily. Explicitly directs and configures StructureMap to create instances of the CLR Type specified by the “Type” attribute

Sample
<PluginFamily Type="StructureMap.Testing.Widget.Rule" Assembly="StructureMap.Testing.Widget" DefaultKey="Blue" Scope="Singleton"> <Interceptors/> <Plugin/> <Source/> <Instance/> </PluginFamily>

<DefaultInstance> Element

Shorthand way to explicitly define the default instance of a PluginType in one element. Explicitly directs and configures StructureMap to create instances of the CLR Type specified by the “PluginType” attribute. The DefaultInstance node also represents an Instance node, and the arguments to the constructor function and setter properties follow the same rules as an Instance node.

Sample
<DefaultInstance PluginType="StructureMap.Testing.Widget.Rule,StructureMap.Testing" PluggedType="StructureMap.Testing.Widget.ColorRule,StructureMap.Testing"  Scope="Singleton"> Color="Red"
</DefaultInstance>

<Profile> Element

Models a named set of overrides for default instances of one or more PluginFamily’s. Profile level overrides supercede machine level overrides.  See Profiles for more information.

Sample
<Profile Name="Blue"> <Override Type="StructureMap.Testing.Widget.Rule" DefaultKey="Blue"/> <Override Type="StructureMap.Testing.Widget.IWidget" DefaultKey="Blue"/> </Profile> <Override Type="StructureMap.Testing.Widget.Rule"> <Instance Type="Color" Color="Green"/> </Override>

<Instance> Element

Configures an object instance within a PluginFamily

Sample
<PluginFamily> <Instance Key="Bigger" Type="GreaterThan"> <Property Name="Attribute" Value="MyDad" /> <Property Name="Value" Value="10" /> </Instance> </PluginFamily> * OR * <PluginFamily> <Instance Key="Bigger" PluggedType="Assembly Qualified Name"> <Property Name="Attribute" Value="MyDad" /> <Property Name="Value" Value="10" /> </Instance> </PluginFamily>

<Interceptors> Element

Optional within a <PluginFamily> element, holds an ordered array of <Interceptor> elements.

Sample
<PluginFamily> <Interceptors> <Interceptor Type="Singleton" /> </Interceptors> </PluginFamily>

<Interceptor> Element

Defines an InstanceFactoryInterceptor to decorate the InstanceFactory for a PluginFamily.  As of version 0.90 the only option is a Singleton interceptor to create the Injected Singleton.  In later releases this will be the mechanism for caching and security.  The <Interceptor> node has the same structure as the <Instance> node.

Sample
<Interceptors> <Interceptor Type="Singleton" /> </Interceptors>

<Override> Element

Within a Machine or Profile node, overrides the name of the default InstanceKey for a particular PluginFamily

Sample
<Override Type="StructureMap.Testing.Widget.IWidget" DefaultKey="Orange"/>

<Plugin> Element

Explicitly defines a concrete class as a Plugin to a PluginFamily. Useful for classes that are outside of your codebase.

Sample
<PluginFamily Type="StructureMap.Testing.Widget.IWidget" Assembly="StructureMap.Testing.Widget" DefaultKey="Red"> <Plugin Assembly="StructureMap.Testing.Widget" Type="StructureMap.Testing.Widget.NotPluggableWidget" ConcreteKey="NotPluggable"> <Setter/> <Setter/> </Plugin> </PluginFamily>

<Setter> Element

Explicitly marks a property on the plugged type for setter injection.  Directs StructureMap to set the value of the property from an InstanceMemento. Useful for classes that are outside of your codebase.

Sample
<Plugin> <Setter Name="prop1"/> <Setter Name="prop2"/> </Plugin>

<Source> Element

Overrides the default MementoSource for a PluginFamily with a configured MementoSource. The specific properties of the configured MementoSource object are named attributes on the Source node itself

Sample
<PluginFamily>
<Source Type="XmlFile" FilePath="FullTesting.XML" XPath="Columns" NodeName="Columns" />
</PluginFamily>

<Property> Element

Models a name/value parameter to the configured object instance constructor function. Property nodes can be nested in the case of object hierarchies

Sample
<Instance> <Property Name="Color" Value="Blue" /> <Property Name="MyGrandChild" Type="Leftie"> <Property Name="BirthYear" Value="1992"/> </Property> <Property Name="MyGrandChild" Key="Tommy"/> </Instance>
Next Prev