You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
|
Feb
(5) |
Mar
(9) |
Apr
(9) |
May
(4) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
| 2008 |
Jan
(11) |
Feb
(6) |
Mar
|
Apr
(16) |
May
(28) |
Jun
(13) |
Jul
(3) |
Aug
(19) |
Sep
(11) |
Oct
(37) |
Nov
(1) |
Dec
(17) |
| 2009 |
Jan
(16) |
Feb
(6) |
Mar
|
Apr
(6) |
May
(1) |
Jun
(10) |
Jul
(4) |
Aug
(4) |
Sep
(4) |
Oct
(8) |
Nov
(3) |
Dec
(45) |
| 2010 |
Jan
(8) |
Feb
(21) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
|
From: <jer...@us...> - 2007-03-08 11:51:51
|
Revision: 26
http://structuremap.svn.sourceforge.net/structuremap/?rev=26&view=rev
Author: jeremydmiller
Date: 2007-03-08 03:51:48 -0800 (Thu, 08 Mar 2007)
Log Message:
-----------
More work on the DSL for configuring instances
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs
trunk/Source/StructureMap/Configuration/DSL/IExpression.cs
trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs
trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs
trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs
trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs
trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs
trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs
trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Text;
using StructureMap.Graph;
namespace StructureMap.Configuration.DSL
@@ -10,9 +9,9 @@
private readonly InstanceExpression _instance;
private readonly MemoryInstanceMemento _memento;
private readonly string _propertyName;
- private Plugin _plugin;
private Type _childType;
private List<IExpression> _children = new List<IExpression>();
+ private IMementoBuilder _builder;
public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName)
@@ -23,7 +22,6 @@
}
-
public InstanceExpression IsNamedInstance(string instanceKey)
{
MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey);
@@ -35,29 +33,34 @@
// TODO -- negative case if the concrete type cannot be an implicit instance
public InstanceExpression IsConcreteType<T>()
{
- _plugin = Plugin.CreateImplicitPlugin(typeof(T));
- MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(_plugin.ConcreteKey);
- _memento.AddChild(_propertyName, child);
+ InstanceExpression child = new InstanceExpression(_childType);
+ child.UsingConcreteType<T>();
+ _children.Add(child);
+ _builder = child;
+
return _instance;
}
void IExpression.Configure(PluginGraph graph)
{
- if (_plugin == null || _childType == null)
+ if (_childType == null)
{
return;
}
PluginFamily family = graph.LocateOrCreateFamilyForType(_childType);
- family.Plugins.FindOrCreate(_plugin.PluggedType);
- }
+ if (_builder != null)
+ {
+ InstanceMemento childMemento = _builder.BuildMemento(family);
+ _memento.AddChild(_propertyName, childMemento);
+ }
-
- IExpression[] IExpression.ChildExpressions
- {
- get { return _children.ToArray(); }
+ foreach (IExpression child in _children)
+ {
+ child.Configure(graph);
+ }
}
internal Type ChildType
@@ -68,10 +71,11 @@
public InstanceExpression Is(InstanceExpression child)
{
_children.Add(child);
- MemoryInstanceMemento childMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey);
+ MemoryInstanceMemento childMemento =
+ MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey);
_memento.AddChild(_propertyName, childMemento);
return _instance;
}
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -12,7 +12,6 @@
{
private Type _pluginType;
private List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>();
- private Plugin _lastPlugin;
private InstanceScope _scope = InstanceScope.PerRequest;
public CreatePluginFamilyExpression(Type pluginType)
@@ -20,11 +19,9 @@
_pluginType = pluginType;
}
-
-
public void Configure(PluginGraph graph)
{
- PluginFamily family = PluginFamilyAttribute.CreatePluginFamily(_pluginType);
+ PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
InterceptorChainBuilder builder = new InterceptorChainBuilder();
family.InterceptionChain = builder.Build(_scope);
@@ -32,26 +29,18 @@
{
alteration(family);
}
-
+
graph.PluginFamilies.Add(family);
AssemblyGraph assembly = new AssemblyGraph(_pluginType.Assembly);
graph.Assemblies.Add(assembly);
}
- IExpression[] IExpression.ChildExpressions
- {
- get { return new IExpression[0]; }
- }
-
public CreatePluginFamilyExpression WithDefaultConcreteType<T>()
{
Plugin plugin = addPlugin<T>();
- _alterations.Add(delegate (PluginFamily family)
- {
- family.DefaultInstanceKey = plugin.ConcreteKey;
- });
+ _alterations.Add(delegate(PluginFamily family) { family.DefaultInstanceKey = plugin.ConcreteKey; });
return this;
}
@@ -60,42 +49,50 @@
{
Plugin plugin = Plugin.CreateImplicitPlugin(typeof (T));
- _alterations.Add(delegate (PluginFamily family)
- {
- family.Plugins.Add(plugin);
- });
+ _alterations.Add(delegate(PluginFamily family) { family.Plugins.Add(plugin); });
return plugin;
}
- public CreatePluginFamilyExpression PluginConcreteType<T>()
+ public CreatePluginFamilyExpression TheDefaultIs(IMementoBuilder builder)
{
- _lastPlugin = addPlugin<T>();
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ InstanceMemento memento = builder.BuildMemento(family);
+ family.Source.AddExternalMemento(memento);
+ family.DefaultInstanceKey = memento.InstanceKey;
+ });
return this;
}
- public CreatePluginFamilyExpression AliasedAs(string concreteKey)
+ public CreatePluginFamilyExpression TheDefaultIsConcreteType<T>()
{
- _lastPlugin.ConcreteKey = concreteKey;
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ Plugin plugin = family.Plugins.FindOrCreate(typeof (T));
+ family.DefaultInstanceKey = plugin.ConcreteKey;
+ });
+
return this;
}
- public CreatePluginFamilyExpression AsASingleton()
+ public CreatePluginFamilyExpression CacheBy(InstanceScope scope)
{
- _scope = InstanceScope.Singleton;
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ InterceptorChainBuilder builder = new InterceptorChainBuilder();
+ family.InterceptionChain = builder.Build(scope);
+ });
+
return this;
}
- public CreatePluginFamilyExpression CacheInstanceAtScope(InstanceScope scope)
+ public CreatePluginFamilyExpression AsSingletons()
{
- _scope = scope;
+ _alterations.Add(
+ delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(new SingletonInterceptor()); });
return this;
}
-
- public void AndTheDefaultIs(InstanceExpression expression)
- {
- throw new NotImplementedException();
- }
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -17,10 +17,5 @@
{
_configure(graph);
}
-
- IExpression[] IExpression.ChildExpressions
- {
- get { return new IExpression[0]; }
- }
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/IExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -1,6 +1,3 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
using StructureMap.Graph;
namespace StructureMap.Configuration.DSL
@@ -8,6 +5,5 @@
public interface IExpression
{
void Configure(PluginGraph graph);
- IExpression[] ChildExpressions { get;}
}
-}
+}
\ No newline at end of file
Added: trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -0,0 +1,9 @@
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL
+{
+ public interface IMementoBuilder
+ {
+ InstanceMemento BuildMemento(PluginFamily family);
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -1,81 +1,52 @@
using System;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Configuration;
-using System.Reflection;
using StructureMap.Graph;
namespace StructureMap.Configuration.DSL
{
- public class InstanceExpression : IExpression
+ public class InstanceExpression : MementoBuilder<InstanceExpression>
{
- private readonly Type _pluginType;
private Type _pluggedType;
- private string _propertyName;
private MemoryInstanceMemento _memento;
- private List<IExpression> _children = new List<IExpression>();
- private PrototypeMemento _prototypeMemento;
-
- public InstanceExpression(Type pluginType)
+ public InstanceExpression(Type pluginType) : base(pluginType)
{
- _pluginType = pluginType;
- _memento = new MemoryInstanceMemento();
- _memento.InstanceKey = Guid.NewGuid().ToString();
}
- void IExpression.Configure(PluginGraph graph)
+ protected override void buildMemento()
{
- if (_prototypeMemento == null && _pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey))
- {
- throw new StructureMapException(301, _memento.InstanceKey, TypePath.GetAssemblyQualifiedName(_pluginType));
- }
-
- PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
-
- if (_prototypeMemento == null)
- {
- Plugin plugin = _pluggedType == null
- ? family.Plugins[_memento.ConcreteKey]
- : family.Plugins.FindOrCreate(_pluggedType);
-
- _memento.ConcreteKey = plugin.ConcreteKey;
- family.Source.AddExternalMemento(_memento);
- }
- else
- {
- _prototypeMemento.InstanceKey = _memento.InstanceKey;
- family.Source.AddExternalMemento(_prototypeMemento);
- }
-
-
+ _memento = new MemoryInstanceMemento();
}
- public IExpression[] ChildExpressions
+ protected override InstanceMemento memento
{
- get { return _children.ToArray(); }
+ get { return _memento; }
}
-
- public InstanceExpression WithName(string instanceKey)
+ protected override InstanceExpression thisInstance
{
- _memento.InstanceKey = instanceKey;
- return this;
+ get { return this; }
}
-
- public string InstanceKey
+ protected override void configureMemento(PluginFamily family)
{
- get { return _memento.InstanceKey; }
- set { _memento.InstanceKey = value; }
+ Plugin plugin = _pluggedType == null
+ ? family.Plugins[_memento.ConcreteKey]
+ : family.Plugins.FindOrCreate(_pluggedType);
+
+ _memento.ConcreteKey = plugin.ConcreteKey;
}
- internal Type PluginType
+ protected override void validate()
{
- get { return _pluginType; }
+ if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey))
+ {
+ throw new StructureMapException(301, _memento.InstanceKey,
+ TypePath.GetAssemblyQualifiedName(_pluginType));
+ }
}
+
public InstanceExpression UsingConcreteType<T>()
{
_pluggedType = typeof (T);
@@ -87,25 +58,17 @@
return new PropertyExpression(this, _memento, propertyName);
}
-
-
-
- public void UsePrototype(ICloneable cloneable)
- {
- _prototypeMemento = new PrototypeMemento(_memento.InstanceKey, cloneable);
- }
-
-
public InstanceExpression UsingConcreteTypeNamed(string concreteKey)
{
_memento.ConcreteKey = concreteKey;
return this;
}
- public ChildInstanceExpression Child(string propertyName)
+ public ChildInstanceExpression Child<T>(string propertyName)
{
- ChildInstanceExpression child = new ChildInstanceExpression(this,_memento, propertyName);
- _children.Add(child);
+ ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName);
+ addChildExpression(child);
+ child.ChildType = typeof (T);
return child;
}
@@ -114,7 +77,8 @@
{
// TODO -- what if the property can't be found
string propertyName = findPropertyName<T>();
- ChildInstanceExpression child = Child(propertyName);
+ ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName);
+ addChildExpression(child);
child.ChildType = typeof (T);
return child;
}
@@ -124,8 +88,5 @@
Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType);
return plugin.FindFirstConstructorArgumentOfType<T>();
}
-
-
-
}
-}
+}
\ No newline at end of file
Added: trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -0,0 +1,40 @@
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL
+{
+ 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);
+ }
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -0,0 +1,61 @@
+using System;
+
+namespace StructureMap.Configuration.DSL
+{
+ public class LiteralMemento : InstanceMemento
+ {
+ private object _instance;
+
+ public LiteralMemento(object instance)
+ {
+ _instance = instance;
+ }
+
+
+ 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(); }
+ }
+
+ public override object Build(IInstanceCreator creator)
+ {
+ return _instance;
+ }
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL
+{
+ // TODO -- T must be constrained to be MementoBuilder
+ public abstract class MementoBuilder<T> : IExpression, IMementoBuilder
+ {
+ protected readonly Type _pluginType;
+ protected List<IExpression> _children = new List<IExpression>();
+
+ public MementoBuilder(Type pluginType)
+ {
+ _pluginType = pluginType;
+ buildMemento();
+ memento.InstanceKey = Guid.NewGuid().ToString();
+ }
+
+ void IExpression.Configure(PluginGraph graph)
+ {
+ validate();
+ PluginFamily family = graph.LocateOrCreateFamilyForType((Type) _pluginType);
+ configureMemento(family);
+ family.Source.AddExternalMemento(memento);
+
+ foreach (IExpression child in _children)
+ {
+ child.Configure(graph);
+ }
+ }
+
+ protected abstract InstanceMemento memento { get; }
+
+ protected abstract T thisInstance { get; }
+
+ protected abstract void configureMemento(PluginFamily family);
+
+ protected abstract void validate();
+
+ public T WithName(string instanceKey)
+ {
+ memento.InstanceKey = instanceKey;
+ return thisInstance;
+ }
+
+ public string InstanceKey
+ {
+ get { return memento.InstanceKey; }
+ set { memento.InstanceKey = value; }
+ }
+
+ internal Type PluginType
+ {
+ get { return _pluginType; }
+ }
+
+ protected abstract void buildMemento();
+
+ InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family)
+ {
+ validate();
+ configureMemento(family);
+ return memento;
+ }
+
+ protected void addChildExpression(IExpression expression)
+ {
+ _children.Add(expression);
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -9,10 +9,5 @@
{
throw new NotImplementedException();
}
-
- public IExpression[] ChildExpressions
- {
- get { throw new NotImplementedException(); }
- }
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
using System.Configuration;
-using System.Text;
namespace StructureMap.Configuration.DSL
{
@@ -31,4 +28,4 @@
return _instance;
}
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -1,25 +1,41 @@
using System;
-using System.Collections.Generic;
-using System.Text;
using StructureMap.Graph;
namespace StructureMap.Configuration.DSL
{
- public class PrototypeExpression : IExpression
+ public class PrototypeExpression<T> : MementoBuilder<PrototypeExpression<T>>
{
- public void Configure(PluginGraph graph)
+ private readonly T _prototype;
+ private PrototypeMemento _memento;
+
+ public PrototypeExpression(T prototype) : base(typeof (T))
{
- throw new NotImplementedException();
+ _prototype = prototype;
}
- public IExpression[] ChildExpressions
+ protected override InstanceMemento memento
{
- get { return new IExpression[0]; }
+ get { return _memento; }
}
- public void WithName(string instanceKey)
+ 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);
+ }
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -5,7 +5,7 @@
public class PrototypeMemento : InstanceMemento
{
private readonly string _instanceKey;
- private readonly ICloneable _prototype;
+ private ICloneable _prototype;
public PrototypeMemento(string instanceKey, ICloneable prototype)
{
@@ -14,6 +14,12 @@
}
+ public ICloneable Prototype
+ {
+ get { return _prototype; }
+ set { _prototype = value; }
+ }
+
public override object Build(IInstanceCreator creator)
{
return _prototype.Clone();
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -20,7 +20,6 @@
}
-
/// <summary>
/// Implement this method to
/// </summary>
@@ -38,18 +37,10 @@
{
foreach (IExpression expression in _expressions)
{
- configureExpression(expression, graph);
+ expression.Configure(graph);
}
}
- private static void configureExpression(IExpression expression, PluginGraph graph)
- {
- expression.Configure(graph);
- foreach (IExpression childExpression in expression.ChildExpressions)
- {
- configureExpression(childExpression, graph);
- }
- }
public void Dispose()
{
@@ -64,9 +55,9 @@
return expression;
}
- public CreatePluginFamilyExpression BuildInstancesOfType<T>()
+ public CreatePluginFamilyExpression BuildInstancesOf<T>()
{
- CreatePluginFamilyExpression expression = new CreatePluginFamilyExpression(typeof(T));
+ CreatePluginFamilyExpression expression = new CreatePluginFamilyExpression(typeof (T));
addExpression(expression);
return expression;
@@ -81,19 +72,30 @@
public InstanceExpression AddInstanceOf<T>()
{
- InstanceExpression expression = new InstanceExpression(typeof(T));
+ InstanceExpression expression = new InstanceExpression(typeof (T));
addExpression(expression);
return expression;
}
public static InstanceExpression Instance<T>()
{
- return new InstanceExpression(typeof(T));
+ return new InstanceExpression(typeof (T));
}
- public PrototypeExpression AddInstanceOf<T>(T prototype)
+ public LiteralExpression<T> AddInstanceOf<T>(T target)
{
- return new PrototypeExpression();
+ LiteralExpression<T> literal = new LiteralExpression<T>(target);
+ addExpression(literal);
+
+ return literal;
}
+
+ public PrototypeExpression<T> AddPrototypeInstanceOf<T>(T prototype)
+ {
+ PrototypeExpression<T> expression = new PrototypeExpression<T>(prototype);
+ addExpression(expression);
+
+ return expression;
+ }
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -1,8 +1,6 @@
-using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
-using System.Text;
using System.Threading;
using StructureMap.Graph;
@@ -63,4 +61,4 @@
return this;
}
}
-}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -158,5 +158,14 @@
{
return Contains(typeof (T));
}
+
+ public PluginFamily Add(Type pluginType)
+ {
+ PluginFamilyAttribute att = PluginFamilyAttribute.GetAttribute(pluginType);
+ PluginFamily family = att == null ? new PluginFamily(pluginType) : att.BuildPluginFamily(pluginType);
+ _pluginFamilies.Add(pluginType, family);
+
+ return family;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -152,7 +152,7 @@
{
if (!_pluginFamilies.Contains(pluginType))
{
- PluginFamily family = _pluginFamilies.Add(pluginType, string.Empty);
+ PluginFamily family = _pluginFamilies.Add(pluginType);
attachImplicitPlugins(family);
}
}
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap/StructureMap.csproj 2007-03-08 11:51:48 UTC (rev 26)
@@ -217,10 +217,15 @@
<Compile Include="Configuration\DSL\CreatePluginFamilyExpression.cs" />
<Compile Include="Configuration\DSL\DefaultExpression.cs" />
<Compile Include="Configuration\DSL\IExpression.cs" />
+ <Compile Include="Configuration\DSL\IMementoBuilder.cs" />
<Compile Include="Configuration\DSL\InstanceExpression.cs" />
+ <Compile Include="Configuration\DSL\LiteralExpression.cs" />
+ <Compile Include="Configuration\DSL\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\PrototypeMemento.cs" />
<Compile Include="Configuration\DSL\Registry.cs" />
<Compile Include="Configuration\DSL\ScanAssembliesExpression.cs" />
<Compile Include="Configuration\FamilyParser.cs">
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -4,7 +4,6 @@
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Testing.Widget;
-using IList=System.Collections.IList;
namespace StructureMap.Testing.Configuration.DSL
{
@@ -43,18 +42,6 @@
registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>();
-
-
-
-
- /*
-
-
-
-
- // Return the specific instance when an IWidget named "Julia" is requested
- registry.AddInstanceOf<IWidget>( new CloneableWidget("Julia") ).WithName("Julia");
- */
manager = registry.BuildInstanceManager();
}
@@ -64,7 +51,8 @@
Registry registry = new Registry();
// Build an instance for IWidget, then setup StructureMap to return cloned instances of the
// "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy"
- registry.AddInstanceOf<IWidget>().WithName("Jeremy").UsePrototype(new CloneableWidget("Jeremy"));
+ CloneableWidget theWidget = new CloneableWidget("Jeremy");
+ registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy");
manager = registry.BuildInstanceManager();
@@ -83,6 +71,26 @@
[Test]
+ public void UseAPreBuiltObjectWithAName()
+ {
+ Registry registry = new Registry();
+ // Return the specific instance when an IWidget named "Julia" is requested
+ CloneableWidget julia = new CloneableWidget("Julia");
+ registry.AddInstanceOf<IWidget>(julia).WithName("Julia");
+
+ manager = registry.BuildInstanceManager();
+
+ CloneableWidget widget1 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia");
+ CloneableWidget widget2 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia");
+ CloneableWidget widget3 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia");
+
+ Assert.AreSame(julia, widget1);
+ Assert.AreSame(julia, widget2);
+ Assert.AreSame(julia, widget3);
+ }
+
+
+ [Test]
public void SpecifyANewInstanceWithADependency()
{
Registry registry = new Registry();
@@ -182,7 +190,7 @@
// Specify a new Instance, override a dependency with a named instance
registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("RuleThatUsesMyInstance")
- .Child("widget").IsNamedInstance("Purple");
+ .Child<IWidget>("widget").IsNamedInstance("Purple");
manager = registry.BuildInstanceManager();
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -1,5 +1,4 @@
using NUnit.Framework;
-using Rhino.Mocks;
using StructureMap.Attributes;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
@@ -9,33 +8,35 @@
namespace StructureMap.Testing.Configuration.DSL
{
- [TestFixture, Explicit]
+ [TestFixture]
public class CreatePluginFamilyTester
{
[SetUp]
public void SetUp()
{
- PluginGraph pluginGraph = new PluginGraph();
- using (Registry registry = new Registry(pluginGraph))
- {
- // Define the default instance of IWidget
- registry.BuildInstancesOfType<IWidget>().AndTheDefaultIs(
- Registry.Instance<IWidget>()
- .UsingConcreteType<ColorWidget>()
- .WithProperty("Color").EqualTo("Red")
- );
-
- }
}
[Test]
+ public void TheDefaultInstanceIsConcreteType()
+ {
+ Registry registry = new Registry();
+
+ // Needs to blow up if the concrete type can't be used
+ registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>();
+
+ InstanceManager manager = registry.BuildInstanceManager();
+
+ Assert.IsInstanceOfType(typeof(ARule), manager.CreateInstance<Rule>());
+ }
+
+ [Test]
public void BuildInstancesOfType()
{
PluginGraph pluginGraph = new PluginGraph();
using (Registry registry = new Registry(pluginGraph))
{
- registry.BuildInstancesOfType<IGateway>();
+ registry.BuildInstancesOf<IGateway>();
}
Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>());
@@ -47,7 +48,7 @@
PluginGraph pluginGraph = new PluginGraph();
using (Registry registry = new Registry(pluginGraph))
{
- registry.BuildInstancesOfType<IGateway>();
+ registry.BuildInstancesOf<IGateway>();
}
Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>());
@@ -65,7 +66,7 @@
using (Registry registry = new Registry(pluginGraph))
{
// Specify the default implementation for an interface
- registry.BuildInstancesOfType<IGateway>().WithDefaultConcreteType<StubbedGateway>();
+ registry.BuildInstancesOf<IGateway>().WithDefaultConcreteType<StubbedGateway>();
}
Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>());
@@ -77,13 +78,28 @@
}
[Test]
+ public void CreatePluginFamilyWithADefault()
+ {
+ Registry registry = new Registry();
+ registry.BuildInstancesOf<IWidget>().TheDefaultIs(
+ Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Red")
+ );
+
+ InstanceManager manager = registry.BuildInstanceManager();
+
+ ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>();
+ Assert.AreEqual("Red", widget.Color);
+ }
+
+
+ [Test]
public void BuildPluginFamilyAsPerRequest()
{
PluginGraph pluginGraph = new PluginGraph();
using (Registry registry = new Registry(pluginGraph))
{
CreatePluginFamilyExpression expression =
- registry.BuildInstancesOfType<IGateway>();
+ registry.BuildInstancesOf<IGateway>();
Assert.IsNotNull(expression);
}
@@ -97,8 +113,7 @@
PluginGraph pluginGraph = new PluginGraph();
using (Registry registry = new Registry(pluginGraph))
{
- CreatePluginFamilyExpression expression =
- registry.BuildInstancesOfType<IGateway>().CacheInstanceAtScope(InstanceScope.ThreadLocal);
+ CreatePluginFamilyExpression expression = registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal);
Assert.IsNotNull(expression);
}
@@ -113,7 +128,7 @@
using (Registry registry = new Registry(pluginGraph))
{
CreatePluginFamilyExpression expression =
- registry.BuildInstancesOfType<IGateway>().AsASingleton();
+ registry.BuildInstancesOf<IGateway>().AsSingletons();
Assert.IsNotNull(expression);
}
@@ -127,7 +142,7 @@
PluginGraph pluginGraph = new PluginGraph();
using (Registry registry = new Registry(pluginGraph))
{
- registry.BuildInstancesOfType<IGateway>().WithDefaultConcreteType<FakeGateway>();
+ registry.BuildInstancesOf<IGateway>().WithDefaultConcreteType<FakeGateway>();
}
Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>());
@@ -138,24 +153,5 @@
Assert.IsInstanceOfType(typeof(FakeGateway), gateway);
}
- [Test]
- public void CanAddAdditionalConcreteTypes()
- {
- Registry registry = new Registry();
-
- registry.BuildInstancesOfType<IGateway>()
- .PluginConcreteType<FakeGateway>().AliasedAs("Fake")
- .PluginConcreteType<Fake2Gateway>()
- .PluginConcreteType<StubbedGateway>()
- .PluginConcreteType<Fake3Gateway>().AliasedAs("Fake3");
-
- InstanceManager manager = registry.BuildInstanceManager();
- IGateway gateway = (IGateway)manager.CreateInstance(typeof(IGateway), "Fake");
-
- Assert.IsInstanceOfType(typeof(FakeGateway), gateway);
- Assert.IsInstanceOfType(typeof(Fake3Gateway), manager.CreateInstance(typeof(IGateway), "Fake3"));
- Assert.IsInstanceOfType(typeof(StubbedGateway), manager.CreateInstance(typeof(IGateway), "Stubbed"));
- Assert.IsInstanceOfType(typeof(Fake2Gateway), manager.CreateInstance(typeof(IGateway), TypePath.GetAssemblyQualifiedName(typeof(Fake2Gateway))));
- }
}
}
Added: trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -0,0 +1,63 @@
+using NUnit.Framework;
+using Rhino.Mocks;
+using StructureMap.Configuration.DSL;
+using StructureMap.Graph;
+using StructureMap.Testing.Widget;
+
+namespace StructureMap.Testing.Configuration.DSL
+{
+ [TestFixture]
+ public class LiteralExpressionTester
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ }
+
+ [Test]
+ public void ConfiguresALiteral()
+ {
+ ColorWidget theWidget = new ColorWidget("Red");
+ LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget);
+ PluginGraph graph = new PluginGraph();
+ ((IExpression)expression).Configure(graph);
+
+ PluginFamily family = graph.PluginFamilies[typeof (IWidget)];
+ Assert.IsNotNull(family);
+
+ LiteralMemento memento = (LiteralMemento) family.Source.GetMemento(expression.InstanceKey);
+ Assert.AreSame(theWidget, memento.Build(null));
+
+ }
+
+ [Test]
+ public void BuildFromInstanceManager()
+ {
+ ColorWidget theWidget = new ColorWidget("Red");
+ LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget);
+ PluginGraph graph = new PluginGraph();
+ ((IExpression)expression).Configure(graph);
+
+ InstanceManager manager = new InstanceManager(graph);
+
+ IWidget actualWidget = manager.CreateInstance<IWidget>(expression.InstanceKey);
+ Assert.AreSame(theWidget, actualWidget);
+ }
+
+ [Test]
+ public void OverrideTheInstanceKey()
+ {
+ ColorWidget theWidget = new ColorWidget("Red");
+ LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget);
+ expression.WithName("Blue");
+ PluginGraph graph = new PluginGraph();
+ ((IExpression)expression).Configure(graph);
+
+ PluginFamily family = graph.PluginFamilies[typeof(IWidget)];
+ Assert.IsNotNull(family);
+
+ LiteralMemento memento = (LiteralMemento)family.Source.GetMemento(expression.InstanceKey);
+ Assert.AreSame(theWidget, memento.Build(null));
+ }
+ }
+}
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-03-08 11:51:48 UTC (rev 26)
@@ -24,10 +24,6 @@
IExpression expression2 = mocks.CreateMock<IExpression>();
IExpression expression3 = mocks.CreateMock<IExpression>();
- Expect.Call(expression1.ChildExpressions).Return(new IExpression[0]);
- Expect.Call(expression2.ChildExpressions).Return(new IExpression[0]);
- Expect.Call(expression3.ChildExpressions).Return(new IExpression[0]);
-
PluginGraph graph = new PluginGraph();
expression1.Configure(graph);
expression2.Configure(graph);
@@ -53,10 +49,6 @@
IExpression expression2 = mocks.CreateMock<IExpression>();
IExpression expression3 = mocks.CreateMock<IExpression>();
- Expect.Call(expression1.ChildExpressions).Return(new IExpression[0]);
- Expect.Call(expression2.ChildExpressions).Return(new IExpression[0]);
- Expect.Call(expression3.ChildExpressions).Return(new IExpression[0]);
-
PluginGraph graph = new PluginGraph();
expression1.Configure(graph);
expression2.Configure(graph);
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-02-26 03:09:23 UTC (rev 25)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-03-08 11:51:48 UTC (rev 26)
@@ -188,6 +188,7 @@
<Compile Include="Configuration\DSL\CreatePluginFamilyTester.cs" />
<Compile Include="Configuration\DSL\CreateProfileTester.cs" />
<Compile Include="Configuration\DSL\InstanceExpressionTester.cs" />
+ <Compile Include="Configuration\DSL\LiteralExpressionTester.cs" />
<Compile Include="Configuration\DSL\RegistryTester.cs" />
<Compile Include="Configuration\DSL\ScanAssembliesTester.cs" />
<Compile Include="Configuration\FamilyParserTester.cs">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2007-02-26 03:09:24
|
Revision: 25
http://structuremap.svn.sourceforge.net/structuremap/?rev=25&view=rev
Author: jeremydmiller
Date: 2007-02-25 19:09:23 -0800 (Sun, 25 Feb 2007)
Log Message:
-----------
Adding the "Prototype" option to the Fluent Interface configuration
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
Added Paths:
-----------
trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
+++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-02-26 03:09:23 UTC (rev 25)
@@ -14,7 +14,7 @@
private string _propertyName;
private MemoryInstanceMemento _memento;
private List<IExpression> _children = new List<IExpression>();
-
+ private PrototypeMemento _prototypeMemento;
public InstanceExpression(Type pluginType)
@@ -26,21 +26,29 @@
void IExpression.Configure(PluginGraph graph)
{
- if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey))
+ if (_prototypeMemento == null && _pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey))
{
throw new StructureMapException(301, _memento.InstanceKey, TypePath.GetAssemblyQualifiedName(_pluginType));
}
PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
- Plugin plugin = _pluggedType == null
- ? family.Plugins[_memento.ConcreteKey]
- : family.Plugins.FindOrCreate(_pluggedType);
- _memento.ConcreteKey = plugin.ConcreteKey;
+ if (_prototypeMemento == null)
+ {
+ Plugin plugin = _pluggedType == null
+ ? family.Plugins[_memento.ConcreteKey]
+ : family.Plugins.FindOrCreate(_pluggedType);
-
-
- family.Source.AddExternalMemento(_memento);
+ _memento.ConcreteKey = plugin.ConcreteKey;
+ family.Source.AddExternalMemento(_memento);
+ }
+ else
+ {
+ _prototypeMemento.InstanceKey = _memento.InstanceKey;
+ family.Source.AddExternalMemento(_prototypeMemento);
+ }
+
+
}
@@ -84,11 +92,10 @@
public void UsePrototype(ICloneable cloneable)
{
-
+ _prototypeMemento = new PrototypeMemento(_memento.InstanceKey, cloneable);
}
-
public InstanceExpression UsingConcreteTypeNamed(string concreteKey)
{
_memento.ConcreteKey = concreteKey;
Added: trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs 2007-02-26 03:09:23 UTC (rev 25)
@@ -0,0 +1,57 @@
+using System;
+
+namespace StructureMap.Configuration.DSL
+{
+ public class PrototypeMemento : InstanceMemento
+ {
+ private readonly string _instanceKey;
+ private readonly ICloneable _prototype;
+
+ public PrototypeMemento(string instanceKey, ICloneable prototype)
+ {
+ _instanceKey = instanceKey;
+ _prototype = prototype;
+ }
+
+
+ public override object Build(IInstanceCreator creator)
+ {
+ return _prototype.Clone();
+ }
+
+ protected override string innerConcreteKey
+ {
+ get { return string.Empty; }
+ }
+
+ protected override string innerInstanceKey
+ {
+ get { return _instanceKey; }
+ }
+
+ 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(); }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-02-25 19:29:51 UTC (rev 24)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-02-26 03:09:23 UTC (rev 25)
@@ -51,19 +51,37 @@
- // Build an instance for IWidget, then setup StructureMap to return cloned instances of the
- // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy"
- registry.AddInstanceOf<IWidget>().WithName("Jeremy").UsePrototype(new CloneableWidget("Jeremy"));
-
+
// Return the specific instance when an IWidget named "Julia" is requested
registry.AddInstanceOf<IWidget>( new CloneableWidget("Julia") ).WithName("Julia");
*/
manager = registry.BuildInstanceManager();
}
+ [Test]
+ public void UseAPreBuiltObjectForAnInstanceAsAPrototype()
+ {
+ Registry registry = new Registry();
+ // Build an instance for IWidget, then setup StructureMap to return cloned instances of the
+ // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy"
+ registry.AddInstanceOf<IWidget>().WithName("Jeremy").UsePrototype(new CloneableWidget("Jeremy"));
+ manager = registry.BuildInstanceManager();
+ CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy");
+ CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy");
+ CloneableWidget widget3 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy");
+
+ Assert.AreEqual("Jeremy", widget1.Name);
+ Assert.AreEqual("Jeremy", widget2.Name);
+ Assert.AreEqual("Jeremy", widget3.Name);
+ Assert.AreNotSame(widget1, widget2);
+ Assert.AreNotSame(widget1, widget3);
+ Assert.AreNotSame(widget2, widget3);
+ }
+
+
[Test]
public void SpecifyANewInstanceWithADependency()
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2007-02-25 19:29:52
|
Revision: 24
http://structuremap.svn.sourceforge.net/structuremap/?rev=24&view=rev
Author: jeremydmiller
Date: 2007-02-25 11:29:51 -0800 (Sun, 25 Feb 2007)
Log Message:
-----------
Working on the Fluent Interface configuration for adding instances
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs
trunk/Source/StructureMap/Configuration/DSL/IExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Graph/PluginCollection.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/InstanceMemento.cs
trunk/Source/StructureMap/MemoryInstanceMemento.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing.Widget/IWidget.cs
trunk/Source/StructureMap.Testing.Widget/Rule.cs
Added Paths:
-----------
trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs
trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs
trunk/Source/StructureMap/IInstanceCreator.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config
Added: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL
+{
+ public class ChildInstanceExpression : IExpression
+ {
+ private readonly InstanceExpression _instance;
+ private readonly MemoryInstanceMemento _memento;
+ private readonly string _propertyName;
+ private Plugin _plugin;
+ private Type _childType;
+ private List<IExpression> _children = new List<IExpression>();
+
+
+ public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName)
+ {
+ _instance = instance;
+ _memento = memento;
+ _propertyName = propertyName;
+ }
+
+
+
+ public InstanceExpression IsNamedInstance(string instanceKey)
+ {
+ MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey);
+ _memento.AddChild(_propertyName, child);
+
+ return _instance;
+ }
+
+ // TODO -- negative case if the concrete type cannot be an implicit instance
+ public InstanceExpression IsConcreteType<T>()
+ {
+ _plugin = Plugin.CreateImplicitPlugin(typeof(T));
+ MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(_plugin.ConcreteKey);
+ _memento.AddChild(_propertyName, child);
+
+ return _instance;
+ }
+
+
+ void IExpression.Configure(PluginGraph graph)
+ {
+ if (_plugin == null || _childType == null)
+ {
+ return;
+ }
+
+ PluginFamily family = graph.LocateOrCreateFamilyForType(_childType);
+ family.Plugins.FindOrCreate(_plugin.PluggedType);
+ }
+
+
+ IExpression[] IExpression.ChildExpressions
+ {
+ get { return _children.ToArray(); }
+ }
+
+ internal Type ChildType
+ {
+ set { _childType = value; }
+ }
+
+ public InstanceExpression Is(InstanceExpression child)
+ {
+ _children.Add(child);
+ MemoryInstanceMemento childMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey);
+ _memento.AddChild(_propertyName, childMemento);
+
+ return _instance;
+ }
+ }
+}
Modified: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -39,6 +39,11 @@
graph.Assemblies.Add(assembly);
}
+ IExpression[] IExpression.ChildExpressions
+ {
+ get { return new IExpression[0]; }
+ }
+
public CreatePluginFamilyExpression WithDefaultConcreteType<T>()
{
Plugin plugin = addPlugin<T>();
@@ -87,5 +92,10 @@
_scope = scope;
return this;
}
+
+ public void AndTheDefaultIs(InstanceExpression expression)
+ {
+ throw new NotImplementedException();
+ }
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -17,5 +17,10 @@
{
_configure(graph);
}
+
+ IExpression[] IExpression.ChildExpressions
+ {
+ get { return new IExpression[0]; }
+ }
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/IExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -8,5 +8,6 @@
public interface IExpression
{
void Configure(PluginGraph graph);
+ IExpression[] ChildExpressions { get;}
}
}
Added: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Configuration;
+using System.Reflection;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL
+{
+ public class InstanceExpression : IExpression
+ {
+ private readonly Type _pluginType;
+ private Type _pluggedType;
+ private string _propertyName;
+ private MemoryInstanceMemento _memento;
+ private List<IExpression> _children = new List<IExpression>();
+
+
+
+ public InstanceExpression(Type pluginType)
+ {
+ _pluginType = pluginType;
+ _memento = new MemoryInstanceMemento();
+ _memento.InstanceKey = Guid.NewGuid().ToString();
+ }
+
+ void IExpression.Configure(PluginGraph graph)
+ {
+ if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey))
+ {
+ throw new StructureMapException(301, _memento.InstanceKey, TypePath.GetAssemblyQualifiedName(_pluginType));
+ }
+
+ PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
+ Plugin plugin = _pluggedType == null
+ ? family.Plugins[_memento.ConcreteKey]
+ : family.Plugins.FindOrCreate(_pluggedType);
+
+ _memento.ConcreteKey = plugin.ConcreteKey;
+
+
+
+ family.Source.AddExternalMemento(_memento);
+ }
+
+
+ public IExpression[] ChildExpressions
+ {
+ get { return _children.ToArray(); }
+ }
+
+
+ public InstanceExpression WithName(string instanceKey)
+ {
+ _memento.InstanceKey = instanceKey;
+ return this;
+ }
+
+
+ public string InstanceKey
+ {
+ get { return _memento.InstanceKey; }
+ set { _memento.InstanceKey = value; }
+ }
+
+ internal Type PluginType
+ {
+ get { return _pluginType; }
+ }
+
+ public InstanceExpression UsingConcreteType<T>()
+ {
+ _pluggedType = typeof (T);
+ return this;
+ }
+
+ public PropertyExpression WithProperty(string propertyName)
+ {
+ return new PropertyExpression(this, _memento, propertyName);
+ }
+
+
+
+
+ public void UsePrototype(ICloneable cloneable)
+ {
+
+ }
+
+
+
+ public InstanceExpression UsingConcreteTypeNamed(string concreteKey)
+ {
+ _memento.ConcreteKey = concreteKey;
+ return this;
+ }
+
+ public ChildInstanceExpression Child(string propertyName)
+ {
+ ChildInstanceExpression child = new ChildInstanceExpression(this,_memento, propertyName);
+ _children.Add(child);
+
+ return child;
+ }
+
+ public ChildInstanceExpression Child<T>()
+ {
+ // TODO -- what if the property can't be found
+ string propertyName = findPropertyName<T>();
+ ChildInstanceExpression child = Child(propertyName);
+ child.ChildType = typeof (T);
+ return child;
+ }
+
+ private string findPropertyName<T>()
+ {
+ Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType);
+ return plugin.FindFirstConstructorArgumentOfType<T>();
+ }
+
+
+
+ }
+}
Added: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,18 @@
+using System;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL
+{
+ public class ProfileExpression : IExpression
+ {
+ public void Configure(PluginGraph graph)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IExpression[] ChildExpressions
+ {
+ get { throw new NotImplementedException(); }
+ }
+ }
+}
Added: trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Text;
+
+namespace StructureMap.Configuration.DSL
+{
+ 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;
+ }
+
+ public InstanceExpression EqualTo(object propertyValue)
+ {
+ _memento.SetProperty(_propertyName, propertyValue.ToString());
+ return _instance;
+ }
+
+ public InstanceExpression EqualToAppSetting(string appSettingKey)
+ {
+ string propertyValue = ConfigurationManager.AppSettings[appSettingKey];
+ _memento.SetProperty(_propertyName, propertyValue);
+ return _instance;
+ }
+ }
+}
Added: trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using StructureMap.Graph;
+
+namespace StructureMap.Configuration.DSL
+{
+ public class PrototypeExpression : IExpression
+ {
+ public void Configure(PluginGraph graph)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IExpression[] ChildExpressions
+ {
+ get { return new IExpression[0]; }
+ }
+
+ public void WithName(string instanceKey)
+ {
+
+ }
+ }
+}
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -7,7 +7,7 @@
public class Registry : IDisposable
{
private List<IExpression> _expressions = new List<IExpression>();
- private readonly PluginGraph _graph;
+ private PluginGraph _graph;
public Registry(PluginGraph graph)
{
@@ -16,7 +16,17 @@
public Registry()
{
+ _graph = new PluginGraph();
+ }
+
+
+ /// <summary>
+ /// Implement this method to
+ /// </summary>
+ protected virtual void configure()
+ {
+ // no-op;
}
protected void addExpression(IExpression expression)
@@ -24,17 +34,26 @@
_expressions.Add(expression);
}
- public void Configure(PluginGraph graph)
+ private void configurePluginGraph(PluginGraph graph)
{
foreach (IExpression expression in _expressions)
{
- expression.Configure(graph);
+ configureExpression(expression, graph);
}
}
+ private static void configureExpression(IExpression expression, PluginGraph graph)
+ {
+ expression.Configure(graph);
+ foreach (IExpression childExpression in expression.ChildExpressions)
+ {
+ configureExpression(childExpression, graph);
+ }
+ }
+
public void Dispose()
{
- Configure(_graph);
+ configurePluginGraph(_graph);
}
public ScanAssembliesExpression ScanAssemblies()
@@ -56,8 +75,25 @@
public InstanceManager BuildInstanceManager()
{
PluginGraph graph = new PluginGraph();
- Configure(graph);
+ configurePluginGraph(graph);
return new InstanceManager(graph);
}
+
+ public InstanceExpression AddInstanceOf<T>()
+ {
+ InstanceExpression expression = new InstanceExpression(typeof(T));
+ addExpression(expression);
+ return expression;
+ }
+
+ public static InstanceExpression Instance<T>()
+ {
+ return new InstanceExpression(typeof(T));
+ }
+
+ public PrototypeExpression AddInstanceOf<T>(T prototype)
+ {
+ return new PrototypeExpression();
+ }
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -20,6 +20,11 @@
}
}
+ public IExpression[] ChildExpressions
+ {
+ get { return new IExpression[0]; }
+ }
+
public ScanAssembliesExpression IncludeTheCallingAssembly()
{
Assembly callingAssembly = findTheCallingAssembly();
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -398,5 +398,19 @@
{
return (_pluggedType != null ? _pluggedType.GetHashCode() : 0) + 29*(_concreteKey != null ? _concreteKey.GetHashCode() : 0);
}
+
+ public string FindFirstConstructorArgumentOfType<T>()
+ {
+ ConstructorInfo ctor = this.GetConstructor();
+ foreach (ParameterInfo info in ctor.GetParameters())
+ {
+ if (info.ParameterType.Equals(typeof(T)))
+ {
+ return info.Name;
+ }
+ }
+
+ throw new StructureMapException(302, typeof (T).FullName, _pluggedType.FullName);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginCollection.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -153,5 +153,13 @@
}
}
}
+
+ public Plugin FindOrCreate(Type pluggedType)
+ {
+ Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType);
+ Add(plugin);
+
+ return plugin;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -143,13 +143,24 @@
public TypePath LocateOrCreateFamilyForType(string fullName)
{
Type pluginType = findTypeByFullName(fullName);
+ buildFamilyIfMissing(pluginType);
+
+ return new TypePath(pluginType);
+ }
+
+ private void buildFamilyIfMissing(Type pluginType)
+ {
if (!_pluginFamilies.Contains(pluginType))
{
PluginFamily family = _pluginFamilies.Add(pluginType, string.Empty);
attachImplicitPlugins(family);
}
+ }
- return new TypePath(pluginType);
+ public PluginFamily LocateOrCreateFamilyForType(Type pluginType)
+ {
+ buildFamilyIfMissing(pluginType);
+ return this.PluginFamilies[pluginType];
}
private Type findTypeByFullName(string fullName)
@@ -170,5 +181,7 @@
{
_defaultManager.ReadDefaultsFromPluginGraph(this);
}
+
+
}
}
\ No newline at end of file
Added: trunk/Source/StructureMap/IInstanceCreator.cs
===================================================================
--- trunk/Source/StructureMap/IInstanceCreator.cs (rev 0)
+++ trunk/Source/StructureMap/IInstanceCreator.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,7 @@
+namespace StructureMap
+{
+ public interface IInstanceCreator
+ {
+ object BuildInstance(InstanceMemento memento);
+ }
+}
Modified: trunk/Source/StructureMap/InstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFactory.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/InstanceFactory.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -12,7 +12,7 @@
/// <summary>
/// Default implementation of IInstanceFactory
/// </summary>
- public class InstanceFactory : IInstanceFactory
+ public class InstanceFactory : IInstanceFactory, IInstanceCreator
{
private Type _pluginType;
private string _assemblyName;
@@ -204,11 +204,13 @@
{
// Let the MementoSource fill in Templates, resolve references, etc.
InstanceMemento resolvedMemento = _source.ResolveMemento(memento);
- return buildFromInstanceBuilder(resolvedMemento);
+
+
+ return resolvedMemento.Build(this);
}
- private object buildFromInstanceBuilder(InstanceMemento memento)
+ public object BuildInstance(InstanceMemento memento)
{
if (!_instanceBuilders.Contains(memento.ConcreteKey))
{
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/InstanceManager.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -156,16 +156,9 @@
return instanceFactory.GetInstance(instanceKey);
}
- /// <summary>
- /// Creates the named instance of the PluginTypeName
- /// </summary>
- /// <param name="pluginTypeName">Fully qualified name of the CLR Type to create</param>
- /// <param name="instanceKey"></param>
- /// <returns></returns>
- public object CreateInstance(string pluginTypeName, string instanceKey)
+ public T CreateInstance<T>(string instanceKey)
{
- IInstanceFactory instanceFactory = this[pluginTypeName];
- return instanceFactory.GetInstance(instanceKey);
+ return (T) CreateInstance(typeof (T), instanceKey);
}
/// <summary>
@@ -179,6 +172,11 @@
return instanceFactory.GetInstance();
}
+ public T CreateInstance<T>()
+ {
+ return (T)CreateInstance(typeof(T));
+ }
+
/// <summary>
/// Creates a new object instance of the requested type
/// </summary>
@@ -203,6 +201,8 @@
return instanceFactory.GetInstance(instanceMemento);
}
+
+
/// <summary>
/// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other
/// classes to link children members
@@ -331,6 +331,11 @@
return factory.GetInstance();
}
+ public T FillDependencies<T>()
+ {
+ return (T) FillDependencies(typeof (T));
+ }
+
private InstanceFactory getFilledTypeFactory(Type type)
{
if (!_filledTypeFactories.Contains(type))
Modified: trunk/Source/StructureMap/InstanceMemento.cs
===================================================================
--- trunk/Source/StructureMap/InstanceMemento.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/InstanceMemento.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -41,6 +41,7 @@
return _concreteKey;
}
+ set { _concreteKey = value; }
}
protected abstract string innerConcreteKey { get; }
@@ -260,5 +261,10 @@
return Plugin.CreateImplicitPlugin(pluggedType);
}
}
+
+ public virtual object Build(IInstanceCreator creator)
+ {
+ return creator.BuildInstance(this);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/MemoryInstanceMemento.cs
===================================================================
--- trunk/Source/StructureMap/MemoryInstanceMemento.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/MemoryInstanceMemento.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -75,7 +75,7 @@
}
- private MemoryInstanceMemento()
+ public MemoryInstanceMemento()
{
}
@@ -114,7 +114,13 @@
_children.Add(name, Memento);
}
+ public void ReferenceChild(string name, string instanceKey)
+ {
+ InstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey);
+ AddChild(name, child);
+ }
+
/// <summary>
/// Links an array of InstanceMemento's to a named array property
/// </summary>
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/StructureMap.csproj 2007-02-25 19:29:51 UTC (rev 24)
@@ -103,6 +103,7 @@
<Reference Include="System">
<Name>System</Name>
</Reference>
+ <Reference Include="System.configuration" />
<Reference Include="System.Data">
<Name>System.Data</Name>
</Reference>
@@ -212,9 +213,14 @@
<Compile Include="Configuration\DiagnosticGraphBuilder.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Configuration\DSL\ChildInstanceExpression.cs" />
<Compile Include="Configuration\DSL\CreatePluginFamilyExpression.cs" />
<Compile Include="Configuration\DSL\DefaultExpression.cs" />
<Compile Include="Configuration\DSL\IExpression.cs" />
+ <Compile Include="Configuration\DSL\InstanceExpression.cs" />
+ <Compile Include="Configuration\DSL\ProfileExpression.cs" />
+ <Compile Include="Configuration\DSL\PropertyExpression.cs" />
+ <Compile Include="Configuration\DSL\PrototypeExpression.cs" />
<Compile Include="Configuration\DSL\Registry.cs" />
<Compile Include="Configuration\DSL\ScanAssembliesExpression.cs" />
<Compile Include="Configuration\FamilyParser.cs">
@@ -435,6 +441,7 @@
<Compile Include="Graph\TypePath.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="IInstanceCreator.cs" />
<Compile Include="IInstanceFactory.cs">
<SubType>Code</SubType>
</Compile>
Modified: trunk/Source/StructureMap/StructureMapException.resx
===================================================================
--- trunk/Source/StructureMap/StructureMapException.resx 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap/StructureMapException.resx 2007-02-25 19:29:51 UTC (rev 24)
@@ -231,4 +231,10 @@
<data name="300" xml:space="preserve">
<value>The implied PluginType {0} cannot be found in any of the configured assemblies </value>
</data>
+ <data name="301" xml:space="preserve">
+ <value>No concrete type or concrete key is specified for instance {0} for PluginType {1}</value>
+ </data>
+ <data name="302" xml:space="preserve">
+ <value>There is no argument of type {0} for concrete type {1}</value>
+ </data>
</root>
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,234 @@
+using System;
+using System.Configuration;
+using NUnit.Framework;
+using StructureMap.Configuration.DSL;
+using StructureMap.Graph;
+using StructureMap.Testing.Widget;
+using IList=System.Collections.IList;
+
+namespace StructureMap.Testing.Configuration.DSL
+{
+ [TestFixture]
+ public class AddInstanceTester
+ {
+ private InstanceManager manager;
+ private PluginGraph pluginGraph;
+
+ [SetUp]
+ public void SetUp()
+ {
+ pluginGraph = new PluginGraph();
+ Registry registry = new Registry(pluginGraph);
+
+ // Add an instance with properties
+ registry.AddInstanceOf<IWidget>()
+ .WithName("DarkGreen")
+ .UsingConcreteType<ColorWidget>()
+ .WithProperty("Color").EqualTo("DarkGreen");
+
+ // Add an instance by specifying the ConcreteKey
+ registry.AddInstanceOf<IWidget>()
+ .WithName("Purple")
+ .UsingConcreteTypeNamed("Color")
+ .WithProperty("Color").EqualTo("Purple");
+
+ // Pull a property from the App config
+ registry.AddInstanceOf<IWidget>()
+ .WithName("AppSetting")
+ .UsingConcreteType<ColorWidget>()
+ .WithProperty("Color").EqualToAppSetting("Color");
+
+
+
+
+ registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>();
+
+
+
+
+
+ /*
+
+
+
+ // Build an instance for IWidget, then setup StructureMap to return cloned instances of the
+ // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy"
+ registry.AddInstanceOf<IWidget>().WithName("Jeremy").UsePrototype(new CloneableWidget("Jeremy"));
+
+ // Return the specific instance when an IWidget named "Julia" is requested
+ registry.AddInstanceOf<IWidget>( new CloneableWidget("Julia") ).WithName("Julia");
+ */
+ manager = registry.BuildInstanceManager();
+ }
+
+
+
+
+ [Test]
+ public void SpecifyANewInstanceWithADependency()
+ {
+ Registry registry = new Registry();
+
+ // Specify a new Instance, create an instance for a dependency on the fly
+ string instanceKey = "OrangeWidgetRule";
+ registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey)
+ .Child<IWidget>().Is(
+ Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>()
+ .WithProperty("Color").EqualTo("Orange")
+ .WithName("Orange")
+ );
+
+ InstanceManager mgr = registry.BuildInstanceManager();
+
+ ColorWidget orange = (ColorWidget) mgr.CreateInstance<IWidget>("Orange");
+ Assert.IsNotNull(orange);
+
+ WidgetRule rule = (WidgetRule)mgr.CreateInstance<Rule>(instanceKey);
+ ColorWidget widget = (ColorWidget) rule.Widget;
+ Assert.AreEqual("Orange", widget.Color);
+ }
+
+
+ [Test]
+ public void AddInstanceAndOverrideTheConcreteTypeForADependency()
+ {
+ Registry registry = new Registry();
+
+ // Specify a new Instance that specifies the concrete type used for a dependency
+ registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("AWidgetRule")
+ .Child<IWidget>().IsConcreteType<AWidget>();
+
+ manager = registry.BuildInstanceManager();
+
+ WidgetRule rule = (WidgetRule)manager.CreateInstance<Rule>("AWidgetRule");
+ Assert.IsInstanceOfType(typeof(AWidget), rule.Widget);
+ }
+
+ [Test]
+ public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteType()
+ {
+ ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("DarkGreen");
+ Assert.AreEqual("DarkGreen", widget.Color);
+ }
+
+ [Test]
+ public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteKey()
+ {
+ ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("Purple");
+ Assert.AreEqual("Purple", widget.Color);
+ }
+
+ [Test]
+ public void CreateAnInstancePullAPropertyFromTheApplicationConfig()
+ {
+ Assert.AreEqual("Blue", ConfigurationManager.AppSettings["Color"]);
+ ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("AppSetting");
+ Assert.AreEqual("Blue", widget.Color);
+ }
+
+ [Test]
+ public void SimpleCaseWithNamedInstance()
+ {
+ Registry registry = new Registry();
+
+ // Specify a new Instance and override the Name
+ registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance");
+
+ manager = registry.BuildInstanceManager();
+
+ AWidget widget = (AWidget) manager.CreateInstance<IWidget>("MyInstance");
+ Assert.IsNotNull(widget);
+ }
+
+ [Test]
+ public void SimpleCaseByPluginName()
+ {
+ AWidget widget = (AWidget) manager.CreateInstance<IWidget>("AWidget");
+ Assert.IsNotNull(widget);
+ }
+
+ [Test]
+ public void SpecifyANewInstanceOverrideADependencyWithANamedInstance()
+ {
+ Registry registry = new Registry();
+
+ registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>();
+
+ registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias");
+
+ // Add an instance by specifying the ConcreteKey
+ registry.AddInstanceOf<IWidget>()
+ .WithName("Purple")
+ .UsingConcreteTypeNamed("Color")
+ .WithProperty("Color").EqualTo("Purple");
+
+ // Specify a new Instance, override a dependency with a named instance
+ registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("RuleThatUsesMyInstance")
+ .Child("widget").IsNamedInstance("Purple");
+
+ manager = registry.BuildInstanceManager();
+
+ Assert.IsInstanceOfType(typeof(ARule), manager.CreateInstance<Rule>("Alias"));
+
+ WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("RuleThatUsesMyInstance");
+ ColorWidget widget = (ColorWidget) rule.Widget;
+ Assert.AreEqual("Purple", widget.Color);
+ }
+ }
+
+
+ public class WidgetRule : Rule
+ {
+ private readonly IWidget _widget;
+
+ public WidgetRule(IWidget widget)
+ {
+ _widget = widget;
+ }
+
+
+ public IWidget Widget
+ {
+ get { return _widget; }
+ }
+ }
+
+ public class WidgetThing : IWidget
+ {
+ public void DoSomething()
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public class CloneableWidget : IWidget, ICloneable
+ {
+ private string _name;
+
+
+ public CloneableWidget(string name)
+ {
+ _name = name;
+ }
+
+ public string Name
+ {
+ get { return _name; }
+ }
+
+ public void DoSomething()
+ {
+ throw new NotImplementedException();
+ }
+
+ public object Clone()
+ {
+ return MemberwiseClone();
+ }
+ }
+
+ public class ARule : Rule
+ {
+
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -4,16 +4,29 @@
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Interceptors;
+using StructureMap.Testing.Widget;
using StructureMap.Testing.Widget3;
namespace StructureMap.Testing.Configuration.DSL
{
- [TestFixture]
+ [TestFixture, Explicit]
public class CreatePluginFamilyTester
{
[SetUp]
public void SetUp()
{
+ PluginGraph pluginGraph = new PluginGraph();
+ using (Registry registry = new Registry(pluginGraph))
+ {
+ // Define the default instance of IWidget
+ registry.BuildInstancesOfType<IWidget>().AndTheDefaultIs(
+ Registry.Instance<IWidget>()
+ .UsingConcreteType<ColorWidget>()
+ .WithProperty("Color").EqualTo("Red")
+ );
+
+
+ }
}
[Test]
@@ -51,6 +64,7 @@
PluginGraph pluginGraph = new PluginGraph();
using (Registry registry = new Registry(pluginGraph))
{
+ // Specify the default implementation for an interface
registry.BuildInstancesOfType<IGateway>().WithDefaultConcreteType<StubbedGateway>();
}
Added: trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,42 @@
+using NUnit.Framework;
+using StructureMap.Configuration.DSL;
+using StructureMap.Graph;
+using StructureMap.Testing.GenericWidgets;
+using StructureMap.Testing.Widget;
+
+namespace StructureMap.Testing.Configuration.DSL
+{
+ [TestFixture]
+ public class CreateProfileTester
+ {
+ private InstanceManager manager;
+ private PluginGraph pluginGraph;
+
+ [SetUp]
+ public void SetUp()
+ {
+ /*
+ pluginGraph = new PluginGraph();
+ Registry registry = new Registry(pluginGraph);
+ registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>();
+ registry.AddInstanceOf<IWidget>
+ .Called("DarkGreen").OfConcreteType<ColorWidget>.WithProperty("Color").EqualTo("DarkGreen");
+
+
+
+ registry.CreateProfile("Green")
+ .UseConcreteType<SimpleThing<string>>().For<ISimpleThing<string>>()
+
+ .UseInstanceNamed("Green").For<Rule>();
+
+ manager = registry.BuildInstanceManager();
+ */
+ }
+
+ [Test]
+ public void CreateProfile()
+ {
+
+ }
+ }
+}
Added: trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,25 @@
+using NUnit.Framework;
+using StructureMap.Configuration.DSL;
+using StructureMap.Graph;
+using StructureMap.Testing.Widget;
+
+namespace StructureMap.Testing.Configuration.DSL
+{
+ [TestFixture]
+ public class InstanceExpressionTester
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ }
+
+ [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 301\nNo concrete type or concrete key is specified for instance TheInstanceKey for PluginType StructureMap.Testing.Widget.IWidget,StructureMap.Testing.Widget")]
+ public void BlowUpIfNoConcreteKeyOrTypeDefinied()
+ {
+ InstanceExpression expression = new InstanceExpression(typeof(IWidget));
+ expression.InstanceKey = "TheInstanceKey";
+ PluginGraph pluginGraph = new PluginGraph();
+ ((IExpression)expression).Configure(pluginGraph);
+ }
+ }
+}
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -23,6 +23,10 @@
IExpression expression1 = mocks.CreateMock<IExpression>();
IExpression expression2 = mocks.CreateMock<IExpression>();
IExpression expression3 = mocks.CreateMock<IExpression>();
+
+ Expect.Call(expression1.ChildExpressions).Return(new IExpression[0]);
+ Expect.Call(expression2.ChildExpressions).Return(new IExpression[0]);
+ Expect.Call(expression3.ChildExpressions).Return(new IExpression[0]);
PluginGraph graph = new PluginGraph();
expression1.Configure(graph);
@@ -31,12 +35,12 @@
mocks.ReplayAll();
- TestRegistry registry = new TestRegistry();
+ TestRegistry registry = new TestRegistry(graph);
registry.AddExpression(expression1);
registry.AddExpression(expression2);
registry.AddExpression(expression3);
- registry.Configure(graph);
+ registry.Dispose();
mocks.VerifyAll();
}
@@ -48,7 +52,11 @@
IExpression expression1 = mocks.CreateMock<IExpression>();
IExpression expression2 = mocks.CreateMock<IExpression>();
IExpression expression3 = mocks.CreateMock<IExpression>();
-
+
+ Expect.Call(expression1.ChildExpressions).Return(new IExpression[0]);
+ Expect.Call(expression2.ChildExpressions).Return(new IExpression[0]);
+ Expect.Call(expression3.ChildExpressions).Return(new IExpression[0]);
+
PluginGraph graph = new PluginGraph();
expression1.Configure(graph);
expression2.Configure(graph);
Modified: trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -203,7 +203,7 @@
IList list = manager.GetAllInstances(typeof (IWidget));
- Assert.AreEqual(6, list.Count);
+ Assert.AreEqual(7, list.Count);
foreach (object target in list)
{
Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -163,7 +163,7 @@
public void GotRightNumberOfPluginsForIWidget()
{
PluginFamily pluginFamily = graph.PluginFamilies[typeof (IWidget)];
- Assert.AreEqual(4, pluginFamily.Plugins.Count, "Should be 4 total");
+ Assert.AreEqual(5, pluginFamily.Plugins.Count, "Should be 5 total");
}
Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -44,7 +44,7 @@
AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget");
Plugin[] plugins = graph.FindPlugins(typeof (IWidget));
Assert.IsNotNull(plugins);
- Assert.AreEqual(3, plugins.Length);
+ Assert.AreEqual(4, plugins.Length);
Assert.AreEqual(DefinitionSource.Implicit, plugins[0].DefinitionSource);
}
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -19,7 +19,7 @@
AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget");
family.SearchAssemblyGraph(graph);
- Assert.AreEqual(3, family.Plugins.Count, "Plugin Count");
+ Assert.AreEqual(4, family.Plugins.Count, "Plugin Count");
foreach (Plugin plugin in family.Plugins)
{
Assert.IsNotNull(plugin);
Modified: trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -66,7 +66,7 @@
Assert.AreEqual("Blue", family.DefaultInstanceKey);
- Assert.AreEqual(3, family.Plugins.Count, "3 different IWidget classes are marked as Pluggable");
+ Assert.AreEqual(4, family.Plugins.Count, "3 different IWidget classes are marked as Pluggable");
}
[Test]
@@ -89,9 +89,9 @@
Assert.IsNotNull(family);
Assert.AreEqual(
- 4,
+ 5,
family.Plugins.Count,
- "4 different IWidget classes are marked as Pluggable, + the manual add");
+ "5 different IWidget classes are marked as Pluggable, + the manual add");
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -75,7 +75,7 @@
Plugin[] plugs = Plugin.GetPlugins(assem, typeof (IWidget));
Assert.IsNotNull(plugs);
- Assert.AreEqual(3, plugs.Length);
+ Assert.AreEqual(4, plugs.Length);
}
@@ -294,6 +294,23 @@
Plugin plugin = Plugin.CreateImplicitPlugin(this.GetType());
Assert.AreEqual(TypePath.GetAssemblyQualifiedName(this.GetType()), plugin.ConcreteKey);
}
+
+ [Test]
+ public void FindFirstConstructorArgumentOfType()
+ {
+ Plugin plugin = Plugin.CreateImplicitPlugin(typeof (GrandPrix));
+ string expected = "engine";
+
+ string actual = plugin.FindFirstConstructorArgumentOfType<IEngine>();
+ Assert.AreEqual(expected, actual);
+ }
+
+ [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 302\nThere is no argument of type StructureMap.Testing.Widget.IWidget for concrete type StructureMap.Testing.Graph.GrandPrix")]
+ public void FindFirstConstructorArgumentOfTypeNegativeCase()
+ {
+ Plugin plugin = Plugin.CreateImplicitPlugin(typeof(GrandPrix));
+ plugin.FindFirstConstructorArgumentOfType<IWidget>();
+ }
}
[PluginFamily("Pushrod")]
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-02-25 19:29:51 UTC (rev 24)
@@ -89,6 +89,7 @@
<Reference Include="System">
<Name>System</Name>
</Reference>
+ <Reference Include="System.configuration" />
<Reference Include="System.Data">
<Name>System.Data</Name>
</Reference>
@@ -183,7 +184,10 @@
<Compile Include="Configuration\DiagnosticGraphBuilderTester.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Configuration\DSL\AddInstanceTester.cs" />
<Compile Include="Configuration\DSL\CreatePluginFamilyTester.cs" />
+ <Compile Include="Configuration\DSL\CreateProfileTester.cs" />
+ <Compile Include="Configuration\DSL\InstanceExpressionTester.cs" />
<Compile Include="Configuration\DSL\RegistryTester.cs" />
<Compile Include="Configuration\DSL\ScanAssembliesTester.cs" />
<Compile Include="Configuration\FamilyParserTester.cs">
@@ -422,6 +426,9 @@
<SubType>Code</SubType>
</Compile>
<None Include="StructureMap.config" />
+ <None Include="StructureMap.Testing.dll.config">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
<EmbeddedResource Include="Container\Source\EmbeddedMementoFile.xml" />
<EmbeddedResource Include="Container\Source\Mementos\Instance1.xml" />
<EmbeddedResource Include="Container\Source\Mementos\Instance2.xml" />
Added: trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config (rev 0)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config 2007-02-25 19:29:51 UTC (rev 24)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <appSettings>
+ <add key="Color" value="Blue"/>
+ <add key="Day" value="Monday"/>
+ </appSettings>
+</configuration>
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing.Widget/IWidget.cs
===================================================================
--- trunk/Source/StructureMap.Testing.Widget/IWidget.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing.Widget/IWidget.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -33,6 +33,20 @@
#endregion
}
+ [Pluggable("AWidget")]
+ public class AWidget : IWidget
+ {
+ public AWidget()
+ {
+ }
+
+
+ public void DoSomething()
+ {
+ throw new NotImplementedException();
+ }
+ }
+
public class NotPluggableWidget : IWidget
{
private readonly string _name;
@@ -42,6 +56,12 @@
_name = name;
}
+
+ public string Name
+ {
+ get { return _name; }
+ }
+
#region IWidget Members
public void DoSomething()
Modified: trunk/Source/StructureMap.Testing.Widget/Rule.cs
===================================================================
--- trunk/Source/StructureMap.Testing.Widget/Rule.cs 2007-02-20 23:09:00 UTC (rev 23)
+++ trunk/Source/StructureMap.Testing.Widget/Rule.cs 2007-02-25 19:29:51 UTC (rev 24)
@@ -152,4 +152,6 @@
get { return _Value; }
}
}
+
+
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2007-02-20 23:09:02
|
Revision: 23
http://structuremap.svn.sourceforge.net/structuremap/?rev=23&view=rev
Author: flimflan
Date: 2007-02-20 15:09:00 -0800 (Tue, 20 Feb 2007)
Log Message:
-----------
Confirming commit auto-notification
Modified Paths:
--------------
trunk/README.TXT
Modified: trunk/README.TXT
===================================================================
--- trunk/README.TXT 2007-02-20 22:44:48 UTC (rev 22)
+++ trunk/README.TXT 2007-02-20 23:09:00 UTC (rev 23)
@@ -5,7 +5,7 @@
Contact jer...@ya... with any questions or bugs.
+The latest code and documentation is available on SourceForge:
+http://structuremap.sourceforge.net/
+
Thanks for trying StructureMap.
-
-The latest code and documentation is available on SourceForge:
-http://structuremap.sourceforge.net/
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2007-02-20 22:44:50
|
Revision: 22
http://structuremap.svn.sourceforge.net/structuremap/?rev=22&view=rev
Author: flimflan
Date: 2007-02-20 14:44:48 -0800 (Tue, 20 Feb 2007)
Log Message:
-----------
Added reference to SF project page. (Really just testing the auto-commit notification)
Modified Paths:
--------------
trunk/README.TXT
Modified: trunk/README.TXT
===================================================================
--- trunk/README.TXT 2007-02-19 03:20:29 UTC (rev 21)
+++ trunk/README.TXT 2007-02-20 22:44:48 UTC (rev 22)
@@ -5,4 +5,7 @@
Contact jer...@ya... with any questions or bugs.
-Thanks for trying StructureMap.
\ No newline at end of file
+Thanks for trying StructureMap.
+
+The latest code and documentation is available on SourceForge:
+http://structuremap.sourceforge.net/
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: Joshua F. <jos...@ya...> - 2007-02-20 22:28:55
|
Still not seeing auto commit notifications from the mailing list.=0A=0A=0A= =0A=0A =0A_________________________________________________________________= ___________________=0ANever miss an email again!=0AYahoo! Toolbar alerts yo= u the instant new Mail arrives.=0Ahttp://tools.search.yahoo.com/toolbar/fea= tures/mail/ |
|
From: Joshua F. <jos...@ya...> - 2006-09-17 23:24:45
|
Sending out a ping to see if this mailing list is working. |
|
From: Joshua F. <jos...@ya...> - 2006-07-13 03:42:18
|
Subscribe to this list if you want notification of all checkins to Subversion. |