|
Home |
Attribute Normalized Xml MementosThis style is a more terse configuration format that was added in version 1.0. Primitive Properties (Strings and basic value types)Primitive constructor or setter arguments are defined by adding an attribute @propertyName="propertyValue" to the instance node. [Pluggable("Color", "Only for testing")]
public class ColorWidget : IWidget {
public ColorWidget(string Color) {
_Color = Color; } } <Widget Type="Color" Key="Red" Color="Red" /> Long StringsThere is an optional mode to define a property value inside a CDATA tag for very long strings like sql statements or Javascript templates. <Instance Type="Sql" Key="SomeQuery"> <bigProp>
<![CDATA[ select * from table where
somecolumn = 'something' or some_other_column = 'something else' ]]> </bigProp> </Property> Enumeration PropertiesEnumeration arguments are defined the same way as primitive properties. Use the string names of the enumeration for the values. public enum BreedEnum {
Hereford, Angus, Longhorn } [Pluggable("Cow")]
public class Cow {
public BreedEnum Breed;
public long Weight; public string Name; public Cow(long Weight, BreedEnum Breed, string Name) {
this.Breed = Breed;
this.Weight = Weight;
this.Name = Name;
} } <Instance Type="Cow" Key="Maggie" Breed="Angus" /> Child PropertiesChild properties of non-primitive types are defined as embedded memento nodes. Child properties can be either defined inline or use a reference to a named instance of the property type. If a child property is omitted or defined with no value, StructureMap will use the default instance of the property type. [PluginFamily, Pluggable("Default", "")]
public class GrandChild {
public GrandChild(bool RightHanded, int BirthYear) {
} } [Pluggable("Leftie", "")]
public class LeftieGrandChild : GrandChild {
public LeftieGrandChild(int BirthYear) : base(false, BirthYear) {
} } [PluginFamily, Pluggable("Default", "")]
public class Child {
public Child(string Name, GrandChild MyGrandChild) {
} } Inline Definition<StructureMap.Testing.Widget.Child Type="Default" Key="Tom" Name="Tom"> <MyGrandChild Name="MyGrandChild" Type="Leftie" BirthYear="1984" /> </StructureMap.Testing.Widget.Child> Reference Definition<StructureMap.Testing.Widget.Child Type="Default" Key="Marsha" Name="Marsha"> <MyGrandChild Key="Tommy"/> </StructureMap.Testing.Widget.Child> Child Array Property [Pluggable("Compound")]
public class CompoundStrategy : IStrategy {
public CompoundStrategy(IStrategy[] innerStrategies)
{
} } <Instance Key="ArrayTest" Type="Compound"> <innerStrategies Name="innerStrategies"> <!-- Referenced Instance --> <Child Key="Red" /> <Child><!-- Default Instance --></Child> <!-- Inline Definition --> <Child Type="Random" seed="0.034"/> </innerStrategies> </Instance> |