|
From: <jer...@us...> - 2008-01-14 04:18:10
|
Revision: 54
http://structuremap.svn.sourceforge.net/structuremap/?rev=54&view=rev
Author: jeremydmiller
Date: 2008-01-13 20:18:06 -0800 (Sun, 13 Jan 2008)
Log Message:
-----------
moving code around
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs
trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs
trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/ObjectFactory.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapConfiguration.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs
trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
Added Paths:
-----------
trunk/Source/StructureMap/Configuration/DSL/Expressions/
trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/ChildArrayExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,50 @@
+using System;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ public class ChildArrayExpression<PLUGINTYPE> : IExpression
+ {
+ private readonly InstanceExpression _parent;
+ private readonly MemoryInstanceMemento _memento;
+ private readonly string _propertyName;
+ private IMementoBuilder[] _builders;
+ private Type _pluginType = typeof (PLUGINTYPE);
+
+ public ChildArrayExpression(InstanceExpression parent, MemoryInstanceMemento memento, string propertyName)
+ {
+ _parent = parent;
+ _memento = memento;
+ _propertyName = propertyName;
+
+ _pluginType = typeof (PLUGINTYPE).GetElementType();
+ }
+
+ void IExpression.Configure(PluginGraph graph)
+ {
+ PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
+ InstanceMemento[] childMementos = new InstanceMemento[_builders.Length];
+ for (int i = 0; i < _builders.Length; i++)
+ {
+ InstanceMemento memento = processMementoBuilder(_builders[i], family, graph);
+ childMementos[i] = memento;
+ }
+
+ _memento.AddChildArray(_propertyName, childMementos);
+ }
+
+ private InstanceMemento processMementoBuilder(IMementoBuilder builder, PluginFamily family, PluginGraph graph)
+ {
+ builder.ValidatePluggability(_pluginType);
+ builder.Configure(graph);
+ return builder.BuildMemento(family);
+ }
+
+ public InstanceExpression Contains(params IMementoBuilder[] builders)
+ {
+ _builders = builders;
+
+ return _parent;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ /// <summary>
+ /// Part of the Fluent Interface, represents a nonprimitive argument to a
+ /// constructure function
+ /// </summary>
+ public class ChildInstanceExpression : IExpression
+ {
+ private readonly InstanceExpression _instance;
+ private readonly MemoryInstanceMemento _memento;
+ private readonly string _propertyName;
+ private Type _childType;
+ private List<IExpression> _children = new List<IExpression>();
+ private IMementoBuilder _builder;
+
+
+ public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName)
+ {
+ _instance = instance;
+ _memento = memento;
+ _propertyName = propertyName;
+ }
+
+ public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName,
+ Type childType)
+ : this(instance, memento, propertyName)
+ {
+ _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);
+ _memento.AddChild(_propertyName, child);
+
+ 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);
+ ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType);
+
+
+ InstanceExpression child = new InstanceExpression(_childType);
+ child.TypeExpression().UsingConcreteType<T>();
+ _children.Add(child);
+
+ _builder = child;
+
+ return _instance;
+ }
+
+
+ void IExpression.Configure(PluginGraph graph)
+ {
+ if (_childType == null)
+ {
+ return;
+ }
+
+ PluginFamily family = graph.LocateOrCreateFamilyForType(_childType);
+ if (_builder != null)
+ {
+ InstanceMemento childMemento = _builder.BuildMemento(family);
+ _memento.AddChild(_propertyName, childMemento);
+ }
+
+ foreach (IExpression child in _children)
+ {
+ child.Configure(graph);
+ }
+ }
+
+ 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)
+ {
+ ExpressionValidator.ValidatePluggabilityOf(child.PluggedType).IntoPluginType(_childType);
+ }
+
+ _children.Add(child);
+ MemoryInstanceMemento childMemento =
+ MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey);
+ _memento.AddChild(_propertyName, childMemento);
+
+ return _instance;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/ConstructorExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,49 @@
+using System;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ public class ConstructorExpression<PLUGINTYPE> : MementoBuilder<ConstructorExpression<PLUGINTYPE>>
+ {
+ private ConstructorMemento<PLUGINTYPE> _memento;
+
+ public ConstructorExpression(BuildObjectDelegate<PLUGINTYPE> builder)
+ : base(typeof (PLUGINTYPE))
+ {
+ _memento.Builder = builder;
+ }
+
+
+ protected override InstanceMemento memento
+ {
+ get { return _memento; }
+ }
+
+ protected override ConstructorExpression<PLUGINTYPE> thisInstance
+ {
+ get { return this; }
+ }
+
+ protected override void configureMemento(PluginFamily family)
+ {
+ }
+
+ protected override void validate()
+ {
+ }
+
+ protected override void buildMemento()
+ {
+ _memento = new ConstructorMemento<PLUGINTYPE>();
+ }
+
+ public override void ValidatePluggability(Type pluginType)
+ {
+ if (!pluginType.Equals(typeof (PLUGINTYPE)))
+ {
+ throw new StructureMapException(306,
+ typeof (PLUGINTYPE).FullName, pluginType.FullName);
+ }
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,148 @@
+using System;
+using System.Collections.Generic;
+using StructureMap.Attributes;
+using StructureMap.Graph;
+using StructureMap.Interceptors;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ public delegate void AlterPluginFamilyDelegate(PluginFamily family);
+
+ /// <summary>
+ /// Represents the parameters for creating instances of a given Type
+ /// </summary>
+ public class CreatePluginFamilyExpression<PLUGINTYPE> : IExpression
+ {
+ private readonly Type _pluginType;
+ private readonly List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>();
+ private readonly InstanceScope _scope = InstanceScope.PerRequest;
+ private readonly List<IExpression> _children = new List<IExpression>();
+
+ public CreatePluginFamilyExpression()
+ {
+ _pluginType = typeof (PLUGINTYPE);
+ }
+
+ void IExpression.Configure(PluginGraph graph)
+ {
+ PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
+ InterceptorChainBuilder builder = new InterceptorChainBuilder();
+ family.InterceptionChain = builder.Build(_scope);
+
+ foreach (IExpression child in _children)
+ {
+ child.Configure(graph);
+ }
+
+ foreach (AlterPluginFamilyDelegate alteration in _alterations)
+ {
+ alteration(family);
+ }
+
+ graph.PluginFamilies.Add(family);
+
+ AssemblyGraph assembly = new AssemblyGraph(_pluginType.Assembly);
+ 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<PLUGINTYPE> TheDefaultIs(IMementoBuilder builder)
+ {
+ builder.ValidatePluggability(_pluginType);
+
+ _children.Add(builder);
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ InstanceMemento memento = builder.BuildMemento(family);
+ family.Source.AddExternalMemento(memento);
+ family.DefaultInstanceKey = memento.InstanceKey;
+ });
+
+ return this;
+ }
+
+ public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(IMementoBuilder builder)
+ {
+ builder.ValidatePluggability(_pluginType);
+
+ _children.Add(builder);
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ InstanceMemento memento = builder.BuildMemento(family);
+ family.Source.AddExternalMemento(memento);
+ });
+
+ 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="CONCRETETYPE"></typeparam>
+ /// <returns></returns>
+ public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIsConcreteType<CONCRETETYPE>()
+ where CONCRETETYPE : PLUGINTYPE
+ {
+ ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(_pluginType);
+
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ Plugin plugin = family.Plugins.FindOrCreate(typeof (CONCRETETYPE));
+ family.DefaultInstanceKey = plugin.ConcreteKey;
+ });
+
+ 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<PLUGINTYPE> CacheBy(InstanceScope scope)
+ {
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ InterceptorChainBuilder builder = new InterceptorChainBuilder();
+ family.InterceptionChain = builder.Build(scope);
+ });
+
+ return this;
+ }
+
+ /// <summary>
+ /// Convenience method to mark a PluginFamily as a Singleton
+ /// </summary>
+ /// <returns></returns>
+ public CreatePluginFamilyExpression<PLUGINTYPE> AsSingletons()
+ {
+ _alterations.Add(
+ delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(new SingletonInterceptor()); });
+ return this;
+ }
+
+
+ public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(StartupHandler<PLUGINTYPE> handler)
+ {
+ _alterations.Add(
+ delegate(PluginFamily family) { family.InstanceInterceptor = new StartupInterceptor<PLUGINTYPE>(handler); });
+
+ return this;
+ }
+
+ public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(EnrichmentHandler<PLUGINTYPE> handler)
+ {
+ _alterations.Add(
+ delegate(PluginFamily family) { family.InstanceInterceptor = new EnrichmentInterceptor<PLUGINTYPE>(handler); });
+
+ return this;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,14 @@
+using System;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ public interface IMementoBuilder : IExpression
+ {
+ InstanceMemento BuildMemento(PluginFamily family);
+ InstanceMemento BuildMemento(PluginGraph graph);
+ void SetInstanceName(string instanceKey);
+
+ void ValidatePluggability(Type pluginType);
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,70 @@
+using System;
+using StructureMap.Configuration.DSL.Expressions;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ /// <summary>
+ /// Use to express the instance of a PluginType for the containing Profile
+ /// </summary>
+ public class InstanceDefaultExpression
+ {
+ private readonly Type _pluginType;
+ private readonly ProfileExpression _parent;
+ private string _instanceKey = string.Empty;
+ private IMementoBuilder _mementoBuilder;
+
+ public InstanceDefaultExpression(Type pluginType, ProfileExpression parent)
+ {
+ _pluginType = pluginType;
+ _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;
+ return _parent;
+ }
+
+ internal void Configure(Profile profile, PluginGraph graph)
+ {
+ if (!string.IsNullOrEmpty(_instanceKey))
+ {
+ InstanceDefault instanceDefault = new InstanceDefault(_pluginType, _instanceKey);
+ profile.AddOverride(instanceDefault);
+ }
+ else if (_mementoBuilder != null)
+ {
+ string defaultKey = Profile.InstanceKeyForProfile(profile.ProfileName);
+ InstanceMemento memento = _mementoBuilder.BuildMemento(graph);
+ memento.InstanceKey = defaultKey;
+
+ graph.PluginFamilies[_pluginType].AddInstance(memento);
+
+ InstanceDefault instanceDefault = new InstanceDefault(_pluginType, defaultKey);
+ profile.AddOverride(instanceDefault);
+ }
+ else
+ {
+ throw new StructureMapException(304, TypePath.GetAssemblyQualifiedName(_pluginType));
+ }
+ }
+
+ /// <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;
+
+ return _parent;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,50 @@
+using System;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ /// <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;
+ private LiteralMemento _memento;
+
+ public LiteralExpression(T target) : base(typeof (T))
+ {
+ _target = target;
+ }
+
+
+ protected override InstanceMemento memento
+ {
+ get { return _memento; }
+ }
+
+ protected override LiteralExpression<T> thisInstance
+ {
+ get { return this; }
+ }
+
+ protected override void configureMemento(PluginFamily family)
+ {
+ _memento.Instance = _target;
+ }
+
+ protected override void validate()
+ {
+ }
+
+ protected override void buildMemento()
+ {
+ _memento = new LiteralMemento(null);
+ }
+
+ public override void ValidatePluggability(Type pluginType)
+ {
+ ExpressionValidator.ValidatePluggabilityOf(_target.GetType()).IntoPluginType(pluginType);
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,67 @@
+using System;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ public class LiteralMemento : InstanceMemento
+ {
+ private object _instance;
+
+ public LiteralMemento(object instance)
+ {
+ _instance = instance;
+ InstanceKey = Guid.NewGuid().ToString();
+ }
+
+ public LiteralMemento Named(string name)
+ {
+ InstanceKey = name;
+ return this;
+ }
+
+ public object Instance
+ {
+ get { return _instance; }
+ set { _instance = value; }
+ }
+
+ protected override string innerConcreteKey
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ protected override string innerInstanceKey
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ protected override string getPropertyValue(string Key)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override InstanceMemento getChild(string Key)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override InstanceMemento[] GetChildrenArray(string Key)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override bool IsReference
+ {
+ get { return false; }
+ }
+
+ public override string ReferenceKey
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ protected override object buildInstance(IInstanceCreator creator)
+ {
+ return _instance;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,45 @@
+using System.Configuration;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ /// <summary>
+ /// Defines the value of a primitive argument to a constructur argument
+ /// </summary>
+ public class PropertyExpression
+ {
+ private readonly InstanceExpression _instance;
+ private readonly MemoryInstanceMemento _memento;
+ private readonly string _propertyName;
+
+ public PropertyExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName)
+ {
+ _instance = instance;
+ _memento = memento;
+ _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];
+ _memento.SetProperty(_propertyName, propertyValue);
+ return _instance;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,50 @@
+using System;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ /// <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;
+ private PrototypeMemento _memento;
+
+ public PrototypeExpression(T prototype) : base(typeof (T))
+ {
+ _prototype = prototype;
+ }
+
+ protected override InstanceMemento memento
+ {
+ get { return _memento; }
+ }
+
+ protected override PrototypeExpression<T> thisInstance
+ {
+ get { return this; }
+ }
+
+ protected override void configureMemento(PluginFamily family)
+ {
+ _memento.Prototype = (ICloneable) _prototype;
+ }
+
+ protected override void validate()
+ {
+ // TODO
+ }
+
+ protected override void buildMemento()
+ {
+ _memento = new PrototypeMemento(string.Empty, (ICloneable) _prototype);
+ }
+
+ public override void ValidatePluggability(Type pluginType)
+ {
+ ExpressionValidator.ValidatePluggabilityOf(_prototype.GetType()).IntoPluginType(pluginType);
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,63 @@
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Reflection;
+using System.Threading;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ /// <summary>
+ /// Expression that directs StructureMap to scan the named assemblies
+ /// for [PluginFamily] and [Plugin] attributes
+ /// </summary>
+ public class ScanAssembliesExpression : IExpression
+ {
+ private List<AssemblyGraph> _assemblies = new List<AssemblyGraph>();
+
+ void IExpression.Configure(PluginGraph graph)
+ {
+ foreach (AssemblyGraph assembly in _assemblies)
+ {
+ graph.Assemblies.Add(assembly);
+ }
+ }
+
+ public ScanAssembliesExpression IncludeTheCallingAssembly()
+ {
+ Assembly callingAssembly = findTheCallingAssembly();
+
+ if (callingAssembly != null)
+ {
+ _assemblies.Add(new AssemblyGraph(callingAssembly));
+ }
+
+ return this;
+ }
+
+ private static Assembly findTheCallingAssembly()
+ {
+ StackTrace trace = new StackTrace(Thread.CurrentThread, false);
+
+ Assembly thisAssembly = Assembly.GetExecutingAssembly();
+ Assembly callingAssembly = null;
+ for (int i = 0; i < trace.FrameCount; i++)
+ {
+ StackFrame frame = trace.GetFrame(i);
+ Assembly assembly = frame.GetMethod().DeclaringType.Assembly;
+ if (assembly != thisAssembly)
+ {
+ callingAssembly = assembly;
+ break;
+ }
+ }
+ return callingAssembly;
+ }
+
+ public ScanAssembliesExpression IncludeAssemblyContainingType<T>()
+ {
+ _assemblies.Add(AssemblyGraph.ContainingType<T>());
+
+ return this;
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs)
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -0,0 +1,45 @@
+using System;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ public class UserControlExpression : MementoBuilder<UserControlExpression>
+ {
+ private UserControlMemento _memento;
+
+ public UserControlExpression(Type pluginType, string url) : base(pluginType)
+ {
+ _memento.Url = url;
+ }
+
+ protected override InstanceMemento memento
+ {
+ get { return _memento; }
+ }
+
+ protected override UserControlExpression thisInstance
+ {
+ get { return this; }
+ }
+
+ protected override void configureMemento(PluginFamily family)
+ {
+ // no-op
+ }
+
+ protected override void validate()
+ {
+ // no-op
+ }
+
+ protected override void buildMemento()
+ {
+ _memento = new UserControlMemento();
+ }
+
+ public override void ValidatePluggability(Type pluginType)
+ {
+ // no-op
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,4 +1,5 @@
using System;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
namespace StructureMap.Configuration.DSL
Modified: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
using StructureMap.Interceptors;
Modified: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
namespace StructureMap.Configuration.DSL
Modified: trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,4 +1,5 @@
using System;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
namespace StructureMap.Configuration.DSL
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
using StructureMap.Interceptors;
Modified: trunk/Source/StructureMap/InstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFactory.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/InstanceFactory.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Data;
using System.Reflection;
-using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Emitting;
using StructureMap.Graph;
using StructureMap.Interceptors;
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,7 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
-using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Exceptions;
using StructureMap.Graph;
using StructureMap.Interceptors;
Modified: trunk/Source/StructureMap/ObjectFactory.cs
===================================================================
--- trunk/Source/StructureMap/ObjectFactory.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/ObjectFactory.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Security.Permissions;
using System.Text;
-using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
namespace StructureMap
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/StructureMap.csproj 2008-01-14 04:18:06 UTC (rev 54)
@@ -209,26 +209,26 @@
<Compile Include="Configuration\DiagnosticGraphBuilder.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Configuration\DSL\ChildArrayExpression.cs" />
- <Compile Include="Configuration\DSL\ChildInstanceExpression.cs" />
- <Compile Include="Configuration\DSL\ConstructorExpression.cs" />
- <Compile Include="Configuration\DSL\CreatePluginFamilyExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\ChildArrayExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\ChildInstanceExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\ConstructorExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\CreatePluginFamilyExpression.cs" />
<Compile Include="Configuration\DSL\ExpressionValidator.cs" />
<Compile Include="Configuration\DSL\IExpression.cs" />
- <Compile Include="Configuration\DSL\IMementoBuilder.cs" />
- <Compile Include="Configuration\DSL\InstanceDefaultExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\IMementoBuilder.cs" />
+ <Compile Include="Configuration\DSL\Expressions\InstanceDefaultExpression.cs" />
<Compile Include="Configuration\DSL\InstanceExpression.cs" />
- <Compile Include="Configuration\DSL\LiteralExpression.cs" />
- <Compile Include="Configuration\DSL\LiteralMemento.cs" />
+ <Compile Include="Configuration\DSL\Expressions\LiteralExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\LiteralMemento.cs" />
<Compile Include="Configuration\DSL\MementoBuilder.cs" />
<Compile Include="Configuration\DSL\ProfileExpression.cs" />
- <Compile Include="Configuration\DSL\PropertyExpression.cs" />
- <Compile Include="Configuration\DSL\PrototypeExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\PropertyExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\PrototypeExpression.cs" />
<Compile Include="Configuration\DSL\PrototypeMemento.cs" />
<Compile Include="Configuration\DSL\ReferenceMementoBuilder.cs" />
<Compile Include="Configuration\DSL\Registry.cs" />
- <Compile Include="Configuration\DSL\ScanAssembliesExpression.cs" />
- <Compile Include="Configuration\DSL\UserControlExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\ScanAssembliesExpression.cs" />
+ <Compile Include="Configuration\DSL\Expressions\UserControlExpression.cs" />
<Compile Include="Configuration\FamilyParser.cs">
<SubType>Code</SubType>
</Compile>
Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs
===================================================================
--- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -4,6 +4,7 @@
using System.Xml;
using StructureMap.Configuration;
using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
using StructureMap.Verification;
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,5 +1,6 @@
using NUnit.Framework;
using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Testing.Widget4;
namespace StructureMap.Testing.Configuration.DSL
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,6 +1,7 @@
using NUnit.Framework;
using StructureMap.Attributes;
using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
using StructureMap.Interceptors;
using StructureMap.Testing.Widget;
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,5 +1,6 @@
using NUnit.Framework;
using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
using StructureMap.Testing.Widget;
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,6 +1,7 @@
using NUnit.Framework;
using Rhino.Mocks;
using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
using StructureMap.Testing.Container;
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -1,6 +1,6 @@
using NUnit.Framework;
using StructureMap.Configuration;
-using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
namespace StructureMap.Testing.Configuration.DSL
Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-01-14 03:57:47 UTC (rev 53)
+++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-01-14 04:18:06 UTC (rev 54)
@@ -3,7 +3,7 @@
using System.Collections.Generic;
using NUnit.Framework;
using Rhino.Mocks;
-using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
using StructureMap.Interceptors;
using StructureMap.Testing.Widget3;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|