Skip to content

Commit

Permalink
Adding NDoc style comments to the DSL classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Apr 1, 2007
1 parent 7dfec2b commit c3de67b
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 30 deletions.
21 changes: 20 additions & 1 deletion Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs
Expand Up @@ -4,6 +4,10 @@

namespace StructureMap.Configuration.DSL
{
/// <summary>
/// Part of the Fluent Interface, represents a nonprimitive argument to a
/// constructure function
/// </summary>
public class ChildInstanceExpression : IExpression
{
private readonly InstanceExpression _instance;
Expand All @@ -28,7 +32,11 @@ public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMement
_childType = childType;
}


/// <summary>
/// Use a previously configured and named instance for the child
/// </summary>
/// <param name="instanceKey"></param>
/// <returns></returns>
public InstanceExpression IsNamedInstance(string instanceKey)
{
MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey);
Expand All @@ -37,6 +45,11 @@ public InstanceExpression IsNamedInstance(string instanceKey)
return _instance;
}

/// <summary>
/// Start the definition of a child instance by defining the concrete type
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public InstanceExpression IsConcreteType<T>()
{
Type pluggedType = typeof (T);
Expand Down Expand Up @@ -78,6 +91,12 @@ internal Type ChildType
set { _childType = value; }
}

/// <summary>
/// Registers a configured instance to use as the argument to the parent's
/// constructor
/// </summary>
/// <param name="child"></param>
/// <returns></returns>
public InstanceExpression Is(InstanceExpression child)
{
if (child.PluggedType != null && _childType != null)
Expand Down
Expand Up @@ -8,6 +8,9 @@ namespace StructureMap.Configuration.DSL
{
public delegate void AlterPluginFamilyDelegate(PluginFamily family);

/// <summary>
/// Represents the parameters for creating instances of a given Type
/// </summary>
public class CreatePluginFamilyExpression : IExpression
{
private Type _pluginType;
Expand Down Expand Up @@ -42,6 +45,11 @@ void IExpression.Configure(PluginGraph graph)
graph.Assemblies.Add(assembly);
}

/// <summary>
/// Sets the default instance of a Type to the definition represented by builder
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public CreatePluginFamilyExpression TheDefaultIs(IMementoBuilder builder)
{
builder.ValidatePluggability(_pluginType);
Expand All @@ -57,6 +65,13 @@ public CreatePluginFamilyExpression TheDefaultIs(IMementoBuilder builder)
return this;
}

/// <summary>
/// Convenience method that sets the default concrete type of the PluginType. Type T
/// can only accept types that do not have any primitive constructor arguments.
/// StructureMap has to know how to construct all of the constructor argument types.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public CreatePluginFamilyExpression TheDefaultIsConcreteType<T>()
{
ExpressionValidator.ValidatePluggabilityOf(typeof (T)).IntoPluginType(_pluginType);
Expand All @@ -70,6 +85,12 @@ public CreatePluginFamilyExpression TheDefaultIsConcreteType<T>()
return this;
}

/// <summary>
/// Sets the object creation of the instances of the PluginType. For example: PerRequest,
/// Singleton, ThreadLocal, HttpContext, or Hybrid
/// </summary>
/// <param name="scope"></param>
/// <returns></returns>
public CreatePluginFamilyExpression CacheBy(InstanceScope scope)
{
_alterations.Add(delegate(PluginFamily family)
Expand All @@ -81,6 +102,10 @@ public CreatePluginFamilyExpression CacheBy(InstanceScope scope)
return this;
}

/// <summary>
/// Convenience method to mark a PluginFamily as a Singleton
/// </summary>
/// <returns></returns>
public CreatePluginFamilyExpression AsSingletons()
{
_alterations.Add(
Expand Down
13 changes: 13 additions & 0 deletions Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs
Expand Up @@ -3,6 +3,9 @@

namespace StructureMap.Configuration.DSL
{
/// <summary>
/// Use to express the instance of a PluginType for the containing Profile
/// </summary>
public class InstanceDefaultExpression
{
private readonly Type _pluginType;
Expand All @@ -16,6 +19,11 @@ public InstanceDefaultExpression(Type pluginType, ProfileExpression parent)
_parent = parent;
}

/// <summary>
/// Use a named, preconfigured instance as the default instance for this profile
/// </summary>
/// <param name="instanceKey"></param>
/// <returns></returns>
public ProfileExpression UseNamedInstance(string instanceKey)
{
_instanceKey = instanceKey;
Expand Down Expand Up @@ -46,6 +54,11 @@ internal void Configure(Profile profile, PluginGraph graph)
}
}

/// <summary>
/// Define the default instance of the PluginType for the containing Profile
/// </summary>
/// <param name="mementoBuilder"></param>
/// <returns></returns>
public ProfileExpression Use(IMementoBuilder mementoBuilder)
{
_mementoBuilder = mementoBuilder;
Expand Down
36 changes: 34 additions & 2 deletions Source/StructureMap/Configuration/DSL/InstanceExpression.cs
Expand Up @@ -3,6 +3,9 @@

namespace StructureMap.Configuration.DSL
{
/// <summary>
/// Used to define an Instance in code
/// </summary>
public class InstanceExpression : MementoBuilder<InstanceExpression>
{
private Type _pluggedType;
Expand Down Expand Up @@ -53,12 +56,24 @@ protected override void validate()
}


/// <summary>
/// Start the definition of a primitive argument to a constructor argument
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public PropertyExpression WithProperty(string propertyName)
{
return new PropertyExpression(this, _memento, propertyName);
}


/// <summary>
/// Starts the definition of a child instance specifying the argument name
/// in the case of a constructor function that consumes more than one argument
/// of type T
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="propertyName"></param>
/// <returns></returns>
public ChildInstanceExpression Child<T>(string propertyName)
{
ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName);
Expand All @@ -68,6 +83,11 @@ public ChildInstanceExpression Child<T>(string propertyName)
return child;
}

/// <summary>
/// Start the definition of a child instance for type T
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public ChildInstanceExpression Child<T>()
{
string propertyName = findPropertyName<T>();
Expand Down Expand Up @@ -104,7 +124,9 @@ internal InstanceTypeExpression TypeExpression()
return new InstanceTypeExpression(this);
}


/// <summary>
/// Helper class to capture the actual concrete type of an Instance
/// </summary>
public class InstanceTypeExpression
{
private readonly InstanceExpression _parent;
Expand All @@ -114,12 +136,22 @@ internal InstanceTypeExpression(InstanceExpression parent)
_parent = parent;
}

/// <summary>
/// Use type T for the concrete type of an instance
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public InstanceExpression UsingConcreteType<T>()
{
_parent._pluggedType = typeof (T);
return _parent;
}

/// <summary>
/// Use a named Plugin type denoted by a [Pluggable("Key")] attribute
/// </summary>
/// <param name="concreteKey"></param>
/// <returns></returns>
public InstanceExpression UsingConcreteTypeNamed(string concreteKey)
{
_parent._memento.ConcreteKey = concreteKey;
Expand Down
4 changes: 4 additions & 0 deletions Source/StructureMap/Configuration/DSL/LiteralExpression.cs
Expand Up @@ -3,6 +3,10 @@

namespace StructureMap.Configuration.DSL
{
/// <summary>
/// Small helper class to represent an object to be plugged into a PluginType as is
/// </summary>
/// <typeparam name="T"></typeparam>
public class LiteralExpression<T> : MementoBuilder<LiteralExpression<T>>
{
private readonly T _target;
Expand Down
8 changes: 8 additions & 0 deletions Source/StructureMap/Configuration/DSL/ProfileExpression.cs
Expand Up @@ -3,6 +3,9 @@

namespace StructureMap.Configuration.DSL
{
/// <summary>
/// Expression class to help define a runtime Profile
/// </summary>
public class ProfileExpression : IExpression
{
private readonly string _profileName;
Expand All @@ -28,6 +31,11 @@ void IExpression.Configure(PluginGraph graph)
}
}

/// <summary>
/// Starts the definition of the default instance for the containing Profile
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public InstanceDefaultExpression For<T>()
{
InstanceDefaultExpression defaultExpression = new InstanceDefaultExpression(typeof (T), this);
Expand Down
14 changes: 14 additions & 0 deletions Source/StructureMap/Configuration/DSL/PropertyExpression.cs
Expand Up @@ -2,6 +2,9 @@

namespace StructureMap.Configuration.DSL
{
/// <summary>
/// Defines the value of a primitive argument to a constructur argument
/// </summary>
public class PropertyExpression
{
private readonly InstanceExpression _instance;
Expand All @@ -15,12 +18,23 @@ public PropertyExpression(InstanceExpression instance, MemoryInstanceMemento mem
_propertyName = propertyName;
}

/// <summary>
/// Sets the value of the constructor argument
/// </summary>
/// <param name="propertyValue"></param>
/// <returns></returns>
public InstanceExpression EqualTo(object propertyValue)
{
_memento.SetProperty(_propertyName, propertyValue.ToString());
return _instance;
}

/// <summary>
/// Sets the value of the constructor argument to the key/value in the
/// AppSettings
/// </summary>
/// <param name="appSettingKey"></param>
/// <returns></returns>
public InstanceExpression EqualToAppSetting(string appSettingKey)
{
string propertyValue = ConfigurationManager.AppSettings[appSettingKey];
Expand Down
4 changes: 4 additions & 0 deletions Source/StructureMap/Configuration/DSL/PrototypeExpression.cs
Expand Up @@ -3,6 +3,10 @@

namespace StructureMap.Configuration.DSL
{
/// <summary>
/// Sets up a Prototype instance of type T
/// </summary>
/// <typeparam name="T"></typeparam>
public class PrototypeExpression<T> : MementoBuilder<PrototypeExpression<T>>
{
private readonly T _prototype;
Expand Down

0 comments on commit c3de67b

Please sign in to comment.