SourceForge.net Logo

Home
StructureMap on SourceForge
Basic Architecture
Concepts
API Documentation
FAQ
Configuration Schema
    Memento Sources
    Node Normalized Xml
    Attribute Normalized Xml
    Attribute Usage
    Instance Lifecyle Scoping
Configuration Management
    StructureMapDoctor
    StructureMapExplorer
    deployment Task
    verification Task
    ValidationMethod Attribute
    Other NAnt Tasks
Troubleshooting
Singleton Injection

Configuration Schema

Sample Configuration File

 

StructureMap
Include
Assembly
Instances
log4net
Machine
PluginFamily
DefaultInstance
Profile
Instance
Interceptors
Interceptor
Override
Plugin
Setter
Source
Property


<StructureMap> Element

The root element of all StructureMap.config files

Sample

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

Optional Attributes

AttributeDescription
DefaultProfile Directs StructureMap to use the named Profile as the default profile at runtime
MementoStyle Specifies the type of Instance Memento definition between "Node" normalized and "Attribute" normalized. For backwards compatibility, the default value is "Node"

Back to Top


<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>
 

Required Attributes

AttributeDescription
File Path to a StructureMap configuration file to be included in the StructureMap.config

Back to Top


<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"/>

Required Attributes

AttributeDescription
Name The assembly name

Optional Attributes

AttributeDescription
Deploy A comma-delimited list of deployment targets used to control partial copies of the StructureMap.config file. “All” or a missing value for Deploy means the assembly configuration will always be copied.

Back to Top


<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>

Back to Top


<log4net> Element

The root node for log4net configuration. See http://log4net.sourceforge.net for details


Back to Top


<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>


Required Attributes

AttributeDescription
Name The name of the machine in all capitals

Optional Attributes

AttributeDescription
Profile Optionally sets the defaults for the named machine to the specified profile

Back to Top


<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>

Required Attributes

AttributeDescription
Type The fullname of the CLR Type to be built as a PluginFamily
Assembly The assembly where to PluginFamily Type is found

Optional Attributes

AttributeDescription
DefaultKey The InstanceKey of the default instance
Scope Controls the "scope" of the requested instance.  The default value is PerRequest.  Valid values are PerRequest, Singleton, ThreadLocal, HttpContext, and Hybrid (uses HttpContext if available, otherwise ThreadLocal)

Back to Top


<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>

Required Attributes

AttributeDescription
PluginType Assembly qualified name of the PluginType, as in PluginType instance = ObjectFactory.GetInstance<PluginType>()
PluggedType The assembly qualified name of the concrete type

Optional Attributes

AttributeDescription
Name The InstanceKey of the default instance. If unspecified, StructureMap will create a default name. This is mostly for diagnostics.
Scope Controls the "scope" of the requested instance.  The default value is PerRequest.  Valid values are PerRequest, Singleton, ThreadLocal, HttpContext, and Hybrid (uses HttpContext if available, otherwise ThreadLocal)

Back to Top


<Profile> Element

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

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>


Required Attributes

AttributeDescription
Name The name of the profile
 

Back to Top


<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>

Required Attributes

AttributeDescription
Key The InstanceKey of the configured object
Type The ConcreteKey of the configured object

Optional Attributes

AttributeDescription
PluggedType An alternative to the Type attribute. Allows you to specify the assembly qualified type of the concrete class directly
Template When using the TemplatedMementoSource this attribute directs StructureMap to apply the values of the memento against the template named in the attribute
Substitutions A comma delimited list of substitution tokens to control templating

Back to Top


<Interceptors> Element

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

Sample

<PluginFamily>
<Interceptors>
<Interceptor Type="Singleton" />
</Interceptors>
</PluginFamily>
Back to Top


<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>

Required Attributes

AttributeDescription
Type The ConcreteKey of the configured object

Back to Top


<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"/>

Required Attributes

AttributeDescription
Type The fully qualified type name of the PluginFamily
DefaultKey The InstanceKey of the desired default

Back to Top


<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>

Required Attributes

AttributeDescription
Assembly The name of the Assembly that the concrete class is in
Type The fully qualified type name of the concrete class
ConcreteKey The ConcreteKey that will be used within StructureMap to identify the concrete class

Back to Top


<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.

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

Required Attributes

AttributeDescription
Name The name of the property on the plugged type of the <Plugin> element

Back to Top


<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>

Required Attributes

AttributeDescription
Type Sets the type of MementoSource object to use by defining the ConcreteKey

Back to Top


<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>

Required Attributes

AttributeDescription
Name The case-sensitive name of the constructor argument

Optional Attributes

AttributeDescription
Value A string value for the constructor argument. Only primitive types work in this manner. DateTime structures have never been tested.
Key For constructor arguments that are non-primitive types, the argument value can be a reference to a defined instance of the member type. The member type must also be controlled by StructureMap. Omitting the Key attribute TODO
Type For constructor arguments that are non-primitive types, the Type key is the ConcreteKey to the configured child instance

Back to Top