|
From: <jer...@us...> - 2008-04-07 14:07:55
|
Revision: 76
http://structuremap.svn.sourceforge.net/structuremap/?rev=76&view=rev
Author: jeremydmiller
Date: 2008-04-07 07:00:27 -0700 (Mon, 07 Apr 2008)
Log Message:
-----------
Moving the InstanceManager reference to InstanceFactory
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/InstanceBuilder.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/Instance.cs
trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs
trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs
trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs
trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs
trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
trunk/Source/StructureMap.Testing/ObjectMother.cs
trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -240,13 +240,13 @@
ConstructorInfo ctor = GetConstructor();
foreach (ParameterInfo parameter in ctor.GetParameters())
{
- returnValue = returnValue && canTypeBeAutoFilled(parameter.ParameterType);
+ returnValue = returnValue && TypeCanBeAutoFilled(parameter.ParameterType);
}
foreach (SetterProperty setter in Setters)
{
Type propertyType = setter.Property.PropertyType;
- returnValue = returnValue && canTypeBeAutoFilled(propertyType);
+ returnValue = returnValue && TypeCanBeAutoFilled(propertyType);
}
return returnValue;
@@ -377,7 +377,7 @@
return returnValue;
}
- private bool canTypeBeAutoFilled(Type parameterType)
+ public static bool TypeCanBeAutoFilled(Type parameterType)
{
bool cannotBeFilled = false;
@@ -388,6 +388,11 @@
return !cannotBeFilled;
}
+
+ public static bool TypeIsPrimitive(Type parameterType)
+ {
+ return parameterType.IsValueType || parameterType.Equals(typeof (string));
+ }
public override bool Equals(object obj)
{
Modified: trunk/Source/StructureMap/InstanceBuilder.cs
===================================================================
--- trunk/Source/StructureMap/InstanceBuilder.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -19,18 +19,8 @@
public abstract string PluggedType { get; }
public abstract string ConcreteTypeKey { get; }
- public InstanceManager Manager
- {
- get { return _manager; }
- }
-
public abstract object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator);
- public void SetInstanceManager(InstanceManager manager)
- {
- _manager = manager;
- }
-
public bool IsType(Type type)
{
Type plugged = Type.GetType(PluggedType);
Modified: trunk/Source/StructureMap/InstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFactory.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap/InstanceFactory.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -19,8 +19,8 @@
private readonly Dictionary<string, InstanceBuilder> _instanceBuilders;
private readonly InstanceInterceptor _interceptor = new NulloInterceptor();
private readonly Type _pluginType;
- private InterceptorLibrary _interceptorLibrary = InterceptorLibrary.Empty;
private MementoSource _source;
+ private InstanceManager _manager = new InstanceManager();
#region static constructors
@@ -145,8 +145,8 @@
try
{
InstanceBuilder builder = _instanceBuilders[memento.ConcreteKey];
- object constructedInstance = builder.BuildInstance(memento, builder.Manager);
- CompoundInterceptor interceptor = _interceptorLibrary.FindInterceptor(constructedInstance.GetType());
+ object constructedInstance = builder.BuildInstance(memento, _manager);
+ InstanceInterceptor interceptor = _manager.FindInterceptor(constructedInstance.GetType());
return interceptor.Process(constructedInstance);
}
catch (StructureMapException)
@@ -178,11 +178,7 @@
/// <param name="instanceManager"></param>
public void SetInstanceManager(InstanceManager instanceManager)
{
- _interceptorLibrary = instanceManager.InterceptorLibrary;
- foreach (InstanceBuilder builder in _instanceBuilders.Values)
- {
- builder.SetInstanceManager(instanceManager);
- }
+ _manager = instanceManager;
}
/// <summary>
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -70,12 +70,6 @@
}
}
-
- public InterceptorLibrary InterceptorLibrary
- {
- get { return _interceptorLibrary; }
- }
-
public virtual IInstanceFactory this[Type pluginType]
{
get
@@ -502,5 +496,10 @@
protected delegate InstanceFactory CreateFactoryDelegate(Type type);
#endregion
+
+ public InstanceInterceptor FindInterceptor(Type type)
+ {
+ return _interceptorLibrary.FindInterceptor(type);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
namespace StructureMap.Pipeline
{
@@ -11,9 +12,28 @@
public class ConfiguredInstance : Instance
{
+ private readonly Dictionary<string, string> _properties = new Dictionary<string, string>();
+ private Dictionary<string, Instance> _children = new Dictionary<string, Instance>();
+
protected override object build(Type type, IInstanceCreator creator)
{
throw new NotImplementedException();
}
+
+ public string GetProperty(string propertyName)
+ {
+ if (!_properties.ContainsKey(propertyName))
+ {
+ throw new StructureMapException(205, propertyName, Name);
+ }
+
+ return _properties[propertyName];
+ }
+
+ public ConfiguredInstance SetProperty(string propertyName, string propertyValue)
+ {
+ _properties[propertyName] = propertyValue;
+ return this;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/Instance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -12,6 +12,7 @@
object CreateInstance(string typeName, InstanceMemento memento);
object CreateInstance(string typeName);
object CreateInstance(Type type);
+ InstanceInterceptor FindInterceptor(Type type);
}
public interface IInstanceDiagnostics
@@ -35,10 +36,15 @@
set { _interceptor = value; }
}
- public object Build(Type type, IInstanceCreator creator)
+ public virtual object Build(Type type, IInstanceCreator creator)
{
object rawValue = build(type, creator);
- return _interceptor.Process(rawValue);
+
+ // Intercept with the Instance-specific InstanceInterceptor
+ object interceptedValue = _interceptor.Process(rawValue);
+
+ // Now, give the at large Interceptors a chance to intercept
+ return creator.FindInterceptor(interceptedValue.GetType()).Process(interceptedValue);
}
protected abstract object build(Type type, IInstanceCreator creator);
Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -112,6 +112,8 @@
family.Plugins.Add(typeof (SomethingOne), "One");
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
+
InstanceMemento memento = factory.AddType<SomethingOne>();
Assert.AreEqual("One", memento.InstanceKey);
Assert.AreEqual("One", memento.ConcreteKey);
@@ -127,6 +129,7 @@
public void AddPluginForTypeWhenThePluginDoesNotAlreadyExistsDoesNothing()
{
InstanceFactory factory = ObjectMother.Factory<ISomething>();
+ factory.SetInstanceManager(new InstanceManager());
InstanceMemento memento = factory.AddType<SomethingOne>();
Assert.IsNotNull(memento);
Modified: trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -23,6 +23,8 @@
InstanceFactory cowFactory = new InstanceFactory(family, true);
+ cowFactory.SetInstanceManager(new InstanceManager());
+
MemoryInstanceMemento memento = new MemoryInstanceMemento("Default", "Angus");
memento.SetProperty("Name", "Bessie");
Modified: trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -13,6 +13,8 @@
typeof (IGateway),
new string[] {"StructureMap.Testing.Widget3"});
+
+
DefaultGateway gateway = factory.GetInstance() as DefaultGateway;
Assert.IsNotNull(gateway);
}
Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -160,6 +160,7 @@
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
Assert.AreSame(factory.GetInstance("Red"), recordedService);
}
Modified: trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -17,6 +17,7 @@
{
PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule));
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
_interceptor = new SingletonInterceptor();
_interceptor.InnerInstanceFactory = factory;
Modified: trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -16,6 +16,7 @@
{
PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule));
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
_interceptor = new ThreadLocalStorageInterceptor();
_interceptor.InnerInstanceFactory = factory;
Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -196,6 +196,8 @@
// Just for fun, test with InstanceFactory too.
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
+
MemoryInstanceMemento memento = new MemoryInstanceMemento("NotPluggable", string.Empty);
memento.SetProperty("name", "DorothyTheDinosaur");
Modified: trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -57,6 +57,8 @@
family.Plugins.Add(plugin, true);
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
+
InstanceMemento memento = _source.GetMemento("Enum");
EnumGridColumn column = (EnumGridColumn) factory.GetInstance(memento);
@@ -72,6 +74,8 @@
family.Plugins.Add(plugin, true);
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
+
InstanceMemento memento = _source.GetMemento("Long");
long count = long.Parse(memento.GetProperty("Count"));
@@ -89,6 +93,8 @@
family.Plugins.Add(plugin, true);
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
+
InstanceMemento memento = _source.GetMemento("String");
StringGridColumn column = (StringGridColumn) factory.GetInstance(memento);
Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -95,6 +95,7 @@
family.Plugins.Add(typeof (ComplexType<int>), "complex");
InstanceFactory factory = new InstanceFactory(family, true);
+ factory.SetInstanceManager(new InstanceManager());
MemoryInstanceMemento memento = new MemoryInstanceMemento("complex", "Me");
memento.SetProperty("name", "Jeremy");
Modified: trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -39,8 +39,11 @@
PluginFamily stringFamily = family.CreateTemplatedClone(typeof (string));
InstanceFactory intFactory = new InstanceFactory(intFamily, true);
+ intFactory.SetInstanceManager(new InstanceManager());
+
InstanceFactory stringFactory = new InstanceFactory(stringFamily, true);
-
+ stringFactory.SetInstanceManager(new InstanceManager());
+
GenericService<int> intService = (GenericService<int>) intFactory.GetInstance();
Assert.AreEqual(typeof (int), intService.GetT());
Modified: trunk/Source/StructureMap.Testing/ObjectMother.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ObjectMother.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/ObjectMother.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -96,7 +96,10 @@
pluginGraph.Seal();
PluginFamily family = pluginGraph.PluginFamilies[pluginType];
- return new InstanceFactory(family, false);
+ InstanceFactory factory = new InstanceFactory(family, false);
+ factory.SetInstanceManager(new InstanceManager());
+
+ return factory;
}
public static InstanceFactory Factory<T>()
Modified: trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -1,5 +1,6 @@
using NUnit.Framework;
using Rhino.Mocks;
+using StructureMap.Interceptors;
using StructureMap.Pipeline;
namespace StructureMap.Testing.Pipeline
@@ -29,6 +30,7 @@
using (mocks.Record())
{
Expect.Call(instanceCreator.CreateInstance(typeof(IDefault))).Return(theDefault);
+ Expect.Call(instanceCreator.FindInterceptor(theDefault.GetType())).Return(new NulloInterceptor());
}
using (mocks.Playback())
Modified: trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -22,7 +22,10 @@
{
MockRepository mocks = new MockRepository();
InstanceInterceptor interceptor = mocks.CreateMock<InstanceInterceptor>();
+ InstanceInterceptor interceptor2 = mocks.CreateMock<InstanceInterceptor>();
+ StructureMap.Pipeline.IInstanceCreator instanceCreator = mocks.CreateMock<StructureMap.Pipeline.IInstanceCreator>();
+
InstanceUnderTest instanceUnderTest = new InstanceUnderTest();
instanceUnderTest.Interceptor = interceptor;
@@ -30,11 +33,16 @@
using (mocks.Record())
{
Expect.Call(interceptor.Process(instanceUnderTest.TheInstanceThatWasBuilt)).Return(objectReturnedByInterceptor);
+ Expect.Call(instanceCreator.FindInterceptor(instanceUnderTest.TheInstanceThatWasBuilt.GetType())).Return
+ (interceptor2);
+
+ Expect.Call(interceptor2.Process(objectReturnedByInterceptor)).Return(objectReturnedByInterceptor);
}
using (mocks.Playback())
{
- Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build(typeof(object), null));
+ Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build(typeof(object), instanceCreator));
+
}
}
Modified: trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -17,7 +17,7 @@
{
ATarget target = new ATarget();
LiteralInstance<ITarget> instance = new LiteralInstance<ITarget>(target);
- Assert.AreSame(target, instance.Build(typeof(ITarget), null));
+ Assert.AreSame(target, instance.Build(typeof(ITarget), new StubInstanceCreator()));
}
public interface ITarget
Modified: trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -19,7 +19,7 @@
PrototypeTarget target = new PrototypeTarget("Jeremy");
PrototypeInstance instance = new PrototypeInstance(target);
- object returnedValue = instance.Build(typeof(PrototypeTarget), null);
+ object returnedValue = instance.Build(typeof(PrototypeTarget), new StubInstanceCreator());
Assert.AreEqual(target, returnedValue);
Assert.AreNotSame(target, returnedValue);
Modified: trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -1,5 +1,6 @@
using NUnit.Framework;
using Rhino.Mocks;
+using StructureMap.Interceptors;
using StructureMap.Pipeline;
namespace StructureMap.Testing.Pipeline
@@ -24,6 +25,7 @@
using (mocks.Record())
{
+ Expect.Call(instanceCreator.FindInterceptor(returnedValue.GetType())).Return(new NulloInterceptor());
Expect.Call(instanceCreator.CreateInstance(typeof(IReferenced), theReferenceKey)).Return(returnedValue);
}
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-07 14:00:27 UTC (rev 76)
@@ -365,11 +365,13 @@
<Compile Include="ObjectMother.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Pipeline\ConfiguredInstanceTester.cs" />
<Compile Include="Pipeline\DefaultInstanceTester.cs" />
<Compile Include="Pipeline\InstanceTester.cs" />
<Compile Include="Pipeline\LiteralInstanceTester.cs" />
<Compile Include="Pipeline\PrototypeInstanceTester.cs" />
<Compile Include="Pipeline\ReferencedInstanceTester.cs" />
+ <Compile Include="Pipeline\StubInstanceCreator.cs" />
<Compile Include="StructureMapConfigCreator.cs" />
<Compile Include="StructureMapConfigurationTester.cs" />
<Compile Include="TestData\DataMother.cs">
Modified: trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs
===================================================================
--- trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-04-06 23:53:49 UTC (rev 75)
+++ trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-04-07 14:00:27 UTC (rev 76)
@@ -43,7 +43,7 @@
column.Rules =
(Rule[])
- Manager.CreateInstanceArray("StructureMap.Testing.Widget.Rule", instance.GetChildrenArray("Rules"));
+ creator.CreateInstanceArray("StructureMap.Testing.Widget.Rule", instance.GetChildrenArray("Rules"));
//
// column.WrapLines = bool.Parse(Memento.GetProperty("WrapLines"));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-04-07 15:00:08
|
Revision: 77
http://structuremap.svn.sourceforge.net/structuremap/?rev=77&view=rev
Author: jeremydmiller
Date: 2008-04-07 08:00:00 -0700 (Mon, 07 Apr 2008)
Log Message:
-----------
getting ready to break up InstanceMemento
Modified Paths:
--------------
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2008-04-07 14:00:27 UTC (rev 76)
+++ trunk/Source/StructureMap/StructureMap.csproj 2008-04-07 15:00:00 UTC (rev 77)
@@ -115,6 +115,7 @@
<Link>CommonAssemblyInfo.cs</Link>
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Configuration\ConfiguredInstanceReader.cs" />
<Compile Include="Pipeline\ConfiguredInstance.cs" />
<Compile Include="Pipeline\DefaultInstance.cs" />
<Compile Include="Pipeline\Instance.cs" />
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-07 14:00:27 UTC (rev 76)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-07 15:00:00 UTC (rev 77)
@@ -167,6 +167,7 @@
<Compile Include="Caching\StorageAndCacheItemTester.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Configuration\ConfigurationInstanceReaderTester.cs" />
<Compile Include="Configuration\ConfigurationParserCollectionTester.cs" />
<Compile Include="Configuration\ConfigurationParserTester.cs" />
<Compile Include="Configuration\DefaultInstanceNodeTester.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-04-11 23:32:30
|
Revision: 79
http://structuremap.svn.sourceforge.net/structuremap/?rev=79&view=rev
Author: jeremydmiller
Date: 2008-04-11 16:32:28 -0700 (Fri, 11 Apr 2008)
Log Message:
-----------
The Great Refactoring of 2008. Generics are temporarily broken however
Added Paths:
-----------
trunk/Source/StructureMap/InstanceBuilderList.cs
trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs
trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs
trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/StubInstanceCreator.cs
Added: trunk/Source/StructureMap/InstanceBuilderList.cs
===================================================================
--- trunk/Source/StructureMap/InstanceBuilderList.cs (rev 0)
+++ trunk/Source/StructureMap/InstanceBuilderList.cs 2008-04-11 23:32:28 UTC (rev 79)
@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using StructureMap.Emitting;
+using StructureMap.Graph;
+
+namespace StructureMap
+{
+ public class InstanceBuilderList
+ {
+ private readonly Dictionary<Type, InstanceBuilder> _builders = new Dictionary<Type, InstanceBuilder>();
+ private Type _pluginType;
+
+
+ public InstanceBuilderList(Type pluginType, Plugin[] plugins)
+ {
+ _pluginType = pluginType;
+ processPlugins(plugins);
+ }
+
+
+ public InstanceBuilder FindByType(Type pluggedType)
+ {
+ if (_builders.ContainsKey(pluggedType))
+ {
+ return _builders[pluggedType];
+ }
+
+ // Add a missing PluggedType if we can
+ if (Plugin.CanBeCast(_pluginType, pluggedType))
+ {
+ Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType);
+ processPlugins(new Plugin[]{plugin});
+
+ return _builders[pluggedType];
+ }
+
+ return null;
+ }
+
+ public InstanceBuilder FindByConcreteKey(string concreteKey)
+ {
+ foreach (KeyValuePair<Type, InstanceBuilder> pair in _builders)
+ {
+ if (pair.Value.ConcreteTypeKey == concreteKey)
+ {
+ return pair.Value;
+ }
+ }
+
+ return null;
+ }
+
+ public void Add(Type pluggedType, InstanceBuilder builder)
+ {
+ _builders.Add(pluggedType, builder);
+ }
+
+ private void processPlugins(IEnumerable<Plugin> plugins)
+ {
+ Assembly assembly = createInstanceBuilderAssembly(plugins);
+ foreach (Plugin plugin in plugins)
+ {
+ addPlugin(assembly, plugin);
+ }
+ }
+
+ private Assembly createInstanceBuilderAssembly(IEnumerable<Plugin> plugins)
+ {
+ string assemblyName = Guid.NewGuid().ToString().Replace(".", "") + "InstanceBuilderAssembly";
+ InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(assemblyName, _pluginType);
+
+ foreach (Plugin plugin in plugins)
+ {
+ builderAssembly.AddPlugin(plugin);
+ }
+
+ return builderAssembly.Compile();
+ }
+
+
+ private void addPlugin(Assembly assembly, Plugin plugin)
+ {
+ string instanceBuilderClassName = plugin.GetInstanceBuilderClassName();
+ InstanceBuilder builder = (InstanceBuilder)assembly.CreateInstance(instanceBuilderClassName);
+
+ _builders.Add(plugin.PluggedType, builder);
+ }
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs (rev 0)
+++ trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2008-04-11 23:32:28 UTC (rev 79)
@@ -0,0 +1,33 @@
+using System;
+
+namespace StructureMap.Pipeline
+{
+ public delegate object BuildObjectDelegate();
+
+ public class ConstructorInstance : ExpressedInstance<ConstructorInstance>
+ {
+ private BuildObjectDelegate _builder;
+
+
+ public ConstructorInstance(BuildObjectDelegate builder)
+ {
+ _builder = builder;
+ }
+
+ public BuildObjectDelegate Builder
+ {
+ get { return _builder; }
+ set { _builder = value; }
+ }
+
+ protected override ConstructorInstance thisInstance
+ {
+ get { return this; }
+ }
+
+ protected override object build(Type pluginType, IInstanceCreator creator)
+ {
+ return _builder();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs (rev 0)
+++ trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2008-04-11 23:32:28 UTC (rev 79)
@@ -0,0 +1,18 @@
+namespace StructureMap.Pipeline
+{
+ public interface IConfiguredInstance
+ {
+ Instance[] GetChildrenArray(string propertyName);
+ string GetProperty(string propertyName);
+ object GetChild(string propertyName, string typeName, IInstanceCreator instanceCreator);
+ InstanceBuilder FindBuilder(InstanceBuilderList builders);
+
+ string ConcreteKey
+ {
+ get;
+ set;
+ }
+
+ string Name { get;}
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs (rev 0)
+++ trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-04-11 23:32:28 UTC (rev 79)
@@ -0,0 +1,54 @@
+using System;
+using StructureMap.Graph;
+
+namespace StructureMap.Pipeline
+{
+ public class InstanceMementoPropertyReader : IPluginArgumentVisitor
+ {
+ private readonly ConfiguredInstance _instance;
+ private readonly InstanceMemento _memento;
+ private readonly PluginGraph _pluginGraph;
+ private readonly Type _pluginType;
+
+ public InstanceMementoPropertyReader(ConfiguredInstance instance, InstanceMemento memento, PluginGraph pluginGraph, Type pluginType)
+ {
+ _instance = instance;
+ _memento = memento;
+ _pluginGraph = pluginGraph;
+ _pluginType = pluginType;
+ }
+
+ public void Primitive(string name)
+ {
+ _instance.SetProperty(name, _memento.GetProperty(name));
+ }
+
+ public void Child(string name, Type childType)
+ {
+ InstanceMemento child = _memento.GetChildMemento(name);
+
+ Instance childInstance = child == null ? new DefaultInstance() : child.ReadInstance(_pluginGraph, childType);
+ _instance.SetChild(name, childInstance);
+ }
+
+ public void ChildArray(string name, Type childType)
+ {
+ InstanceMemento[] mementoes = _memento.GetChildrenArray(name);
+
+ // TODO -- want to default to mementoes == null is all
+ if (mementoes == null)
+ {
+ mementoes = new InstanceMemento[0];
+ }
+
+ Instance[] children = new Instance[mementoes.Length];
+ for (int i = 0; i < mementoes.Length; i++)
+ {
+ InstanceMemento memento = mementoes[i];
+ children[i] = memento.ReadInstance(_pluginGraph, childType);
+ }
+
+ _instance.SetChildArray(name, children);
+ }
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-04-11 23:32:28 UTC (rev 79)
@@ -0,0 +1,262 @@
+using System.Drawing;
+using NUnit.Framework;
+using StructureMap.Configuration;
+using StructureMap.Configuration.Mementos;
+using StructureMap.Graph;
+using StructureMap.Pipeline;
+using StructureMap.Testing.Widget3;
+
+namespace StructureMap.Testing
+{
+ [TestFixture]
+ public class InstanceMementoInstanceCreationTester
+ {
+ private PluginGraph _graph;
+
+ #region Setup/Teardown
+
+ [SetUp]
+ public void SetUp()
+ {
+ _graph = new PluginGraph();
+ PluginFamily family = _graph.PluginFamilies.Add(typeof (IService));
+ family.Plugins.Add(typeof(ColorService), "Color");
+
+ _graph.PluginFamilies.Add(typeof (Rule));
+ }
+
+ #endregion
+
+ public class Rule
+ {
+ }
+
+ public class ComplexRule : Rule
+ {
+ private readonly Color _color;
+ private bool _Bool;
+ private byte _Byte;
+ private double _Double;
+ private int _Int;
+ private long _Long;
+ private string _String;
+
+
+ [DefaultConstructor]
+ public ComplexRule(string String, Color color, int Int, long Long, byte Byte, double Double, bool Bool,
+ IAutomobile car, IAutomobile[] cars)
+ {
+ _String = String;
+ _color = color;
+ _Int = Int;
+ _Long = Long;
+ _Byte = Byte;
+ _Double = Double;
+ _Bool = Bool;
+ }
+
+ /// <summary>
+ /// Plugin should find the constructor above, not the "greedy" one below.
+ /// </summary>
+ /// <param name="String"></param>
+ /// <param name="String2"></param>
+ /// <param name="Int"></param>
+ /// <param name="Long"></param>
+ /// <param name="Byte"></param>
+ /// <param name="Double"></param>
+ /// <param name="Bool"></param>
+ /// <param name="extra"></param>
+ public ComplexRule(string String, string String2, int Int, long Long, byte Byte, double Double, bool Bool,
+ string extra)
+ {
+ }
+
+ public string String
+ {
+ get { return _String; }
+ }
+
+
+ public int Int
+ {
+ get { return _Int; }
+ }
+
+ public byte Byte
+ {
+ get { return _Byte; }
+ }
+
+ public long Long
+ {
+ get { return _Long; }
+ }
+
+ public double Double
+ {
+ get { return _Double; }
+ }
+
+ public bool Bool
+ {
+ get { return _Bool; }
+ }
+
+ public static MemoryInstanceMemento GetMemento()
+ {
+ MemoryInstanceMemento memento = new MemoryInstanceMemento("", "Sample");
+ memento.SetProperty("String", "Red");
+ memento.SetProperty("color", "Green");
+ memento.SetProperty("Int", "1");
+ memento.SetProperty("Long", "2");
+ memento.SetProperty("Byte", "3");
+ memento.SetProperty("Double", "4");
+ memento.SetProperty("Bool", "true");
+
+ return memento;
+ }
+ }
+
+
+ public interface IAutomobile
+ {
+ }
+
+ public class GrandPrix : IAutomobile
+ {
+ private readonly string _color;
+ private readonly int _horsePower;
+
+ public GrandPrix(int horsePower, string color)
+ {
+ _horsePower = horsePower;
+ _color = color;
+ }
+ }
+
+ public class Mustang : IAutomobile
+ {
+ public Mustang()
+ {
+ }
+ }
+
+ [Test]
+ public void Create_a_default_instance()
+ {
+ MemoryInstanceMemento memento = MemoryInstanceMemento.CreateDefaultInstanceMemento();
+ Instance instance = memento.ReadInstance(null, null);
+
+ Assert.IsInstanceOfType(typeof (DefaultInstance), instance);
+ }
+
+ [Test]
+ public void Create_a_referenced_instance()
+ {
+ MemoryInstanceMemento memento = MemoryInstanceMemento.CreateReferencedInstanceMemento("blue");
+ ReferencedInstance instance = (ReferencedInstance) memento.ReadInstance(null, null);
+
+ Assert.AreEqual("blue", instance.ReferenceKey);
+ }
+
+
+ [Test]
+ public void Get_the_instance_name()
+ {
+ MemoryInstanceMemento memento = new MemoryInstanceMemento("Color", "Red");
+ memento.SetProperty("Color", "Red");
+ memento.InstanceKey = "Red";
+
+ Assert.AreEqual("Red", memento.ReadInstance(_graph, typeof(IService)).Name);
+ }
+
+ [Test]
+ public void ReadChildArrayProperty()
+ {
+ PluginGraph graph = new PluginGraph();
+ Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule));
+
+ graph.PluginFamilies.Add(typeof (Rule)).Plugins.Add(plugin);
+
+ MemoryInstanceMemento memento = ComplexRule.GetMemento();
+ memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName);
+ memento.AddChildArray("cars", new InstanceMemento[]
+ {
+ MemoryInstanceMemento.CreateReferencedInstanceMemento("Ford"),
+ MemoryInstanceMemento.CreateReferencedInstanceMemento("Chevy"),
+ MemoryInstanceMemento.CreateReferencedInstanceMemento("Dodge"),
+ });
+
+ ConfiguredInstance instance = (ConfiguredInstance)memento.ReadInstance(graph, typeof(Rule));
+ Instance[] instances = instance.GetChildArray("cars");
+ Assert.AreEqual(3, instances.Length);
+
+ assertIsReference(instances[0], "Ford");
+ assertIsReference(instances[1], "Chevy");
+ assertIsReference(instances[2], "Dodge");
+
+ }
+
+ private void assertIsReference(Instance instance, string referenceKey)
+ {
+ ReferencedInstance referencedInstance = (ReferencedInstance) instance;
+ Assert.AreEqual(referenceKey, referencedInstance.ReferenceKey);
+ }
+
+ [Test]
+ public void ReadChildProperty_child_property_is_defined_build_child()
+ {
+ PluginGraph graph = new PluginGraph();
+ Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule));
+
+ graph.PluginFamilies.Add(typeof (Rule)).Plugins.Add(plugin);
+
+ MemoryInstanceMemento memento = ComplexRule.GetMemento();
+ memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName);
+ MemoryInstanceMemento carMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento("GrandPrix");
+ memento.AddChild("car", carMemento);
+
+ ConfiguredInstance instance = (ConfiguredInstance) memento.ReadInstance(graph, typeof (Rule));
+ ReferencedInstance child = (ReferencedInstance) instance.GetChild("car");
+
+ Assert.AreEqual("GrandPrix", child.ReferenceKey);
+ }
+
+ [Test]
+ public void ReadChildProperty_child_property_is_not_defined_so_use_default()
+ {
+ PluginGraph graph = new PluginGraph();
+ Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule));
+
+ graph.PluginFamilies.Add(typeof (Rule)).Plugins.Add(plugin);
+
+ MemoryInstanceMemento memento = ComplexRule.GetMemento();
+ memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName);
+
+ ConfiguredInstance instance = (ConfiguredInstance) memento.ReadInstance(graph, typeof (Rule));
+ Assert.IsInstanceOfType(typeof (DefaultInstance), instance.GetChild("car"));
+ }
+
+ [Test]
+ public void ReadPrimitivePropertiesHappyPath()
+ {
+ PluginGraph graph = new PluginGraph();
+ Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule));
+
+ graph.PluginFamilies.Add(typeof (Rule)).Plugins.Add(plugin);
+
+ MemoryInstanceMemento memento = ComplexRule.GetMemento();
+ memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName);
+
+ IConfiguredInstance instance = (IConfiguredInstance) memento.ReadInstance(graph, typeof (Rule));
+
+ Assert.AreEqual(memento.GetProperty("String"), instance.GetProperty("String"));
+ Assert.AreEqual(memento.GetProperty("color"), instance.GetProperty("color"));
+ Assert.AreEqual(memento.GetProperty("Int"), instance.GetProperty("Int"));
+ Assert.AreEqual(memento.GetProperty("Long"), instance.GetProperty("Long"));
+ Assert.AreEqual(memento.GetProperty("Byte"), instance.GetProperty("Byte"));
+ Assert.AreEqual(memento.GetProperty("Double"), instance.GetProperty("Double"));
+ Assert.AreEqual(memento.GetProperty("Bool"), instance.GetProperty("Bool"));
+ }
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-04-11 23:32:28 UTC (rev 79)
@@ -0,0 +1,48 @@
+using NUnit.Framework;
+using Rhino.Mocks;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Testing.Pipeline
+{
+ [TestFixture]
+ public class ConfiguredInstanceTester
+ {
+ private ConfiguredInstance instance;
+
+ [SetUp]
+ public void SetUp()
+ {
+ instance = new ConfiguredInstance();
+ }
+
+ [Test]
+ public void GetProperty_happy_path()
+ {
+ instance.SetProperty("Color", "Red")
+ .SetProperty("Age", "34");
+
+ IConfiguredInstance configuredInstance = instance;
+
+ Assert.AreEqual("Red", configuredInstance.GetProperty("Color"));
+ Assert.AreEqual("34", configuredInstance.GetProperty("Age"));
+
+ instance.SetProperty("Color", "Blue");
+ Assert.AreEqual("Blue", configuredInstance.GetProperty("Color"));
+ }
+
+ [Test]
+ public void Property_cannot_be_found_so_throw_205()
+ {
+ try
+ {
+ IConfiguredInstance configuredInstance = instance;
+ configuredInstance.GetProperty("anything");
+ Assert.Fail("Did not throw exception");
+ }
+ catch (StructureMapException ex)
+ {
+ Assert.AreEqual(205, ex.ErrorCode);
+ }
+ }
+ }
+}
Added: trunk/Source/StructureMap.Testing/Pipeline/StubInstanceCreator.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/StubInstanceCreator.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Pipeline/StubInstanceCreator.cs 2008-04-11 23:32:28 UTC (rev 79)
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using StructureMap.Interceptors;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Testing.Pipeline
+{
+ public class StubInstanceCreator : StructureMap.Pipeline.IInstanceCreator
+ {
+ public object CreateInstance(Type type, string referenceKey)
+ {
+ throw new NotImplementedException();
+ }
+
+ public Array CreateInstanceArray(string pluginTypeName, Instance[] instances)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object CreateInstance(string typeName, IConfiguredInstance instance)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object CreateInstance(string typeName)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object CreateInstance(Type pluginType)
+ {
+ throw new NotImplementedException();
+ }
+
+ public object CreateInstance(Type pluginType, IConfiguredInstance instance)
+ {
+ throw new NotImplementedException();
+ }
+
+ public InstanceBuilder FindInstanceBuilder(Type pluginType, string concreteKey)
+ {
+ throw new NotImplementedException();
+ }
+
+ public InstanceBuilder FindInstanceBuilder(Type pluginType, Type pluggedType)
+ {
+ throw new NotImplementedException();
+ }
+
+
+ public object ApplyInterception(Type pluginType, object actualValue)
+ {
+ return actualValue;
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-04-12 13:45:11
|
Revision: 80
http://structuremap.svn.sourceforge.net/structuremap/?rev=80&view=rev
Author: jeremydmiller
Date: 2008-04-12 06:45:08 -0700 (Sat, 12 Apr 2008)
Log Message:
-----------
fixing generics tests
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/Instance.cs
trunk/Source/StructureMap/Properties/AssemblyInfo.cs
trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs
trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs
trunk/Source/StructureMap.Testing.GenericWidgets/StructureMap.Testing.GenericWidgets.csproj
Removed Paths:
-------------
trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs
trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs
trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs
trunk/Source/StructureMap/ConstructorMemento.cs
trunk/Source/StructureMap/Graph/DefinitionSource.cs
trunk/Source/StructureMap/Graph/Deployable.cs
trunk/Source/StructureMap/Graph/PluginGraphObjectCollection.cs
trunk/Source/StructureMap/IInstanceCreator.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs
trunk/Source/StructureMap.Testing/ConstructorMementoTester.cs
trunk/Source/StructureMap.Testing/Graph/GraphDeploymentTester.cs
trunk/Source/StructureMap.Testing/InstanceMementoTester.cs
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,55 +0,0 @@
-using System;
-using StructureMap.Configuration.Mementos;
-using StructureMap.Graph;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- public class ChildArrayExpression<PLUGINTYPE> : IExpression
- {
- private readonly MemoryInstanceMemento _memento;
- private readonly InstanceExpression _parent;
- private readonly string _propertyName;
- private IMementoBuilder[] _builders;
- private Type _pluginType = typeof (PLUGINTYPE);
-
- public ChildArrayExpression(InstanceExpression parent, MemoryInstanceMemento memento, string propertyName)
- {
- _parent = parent;
- _memento = memento;
- _propertyName = propertyName;
-
- _pluginType = typeof (PLUGINTYPE).GetElementType();
- }
-
- #region IExpression Members
-
- void IExpression.Configure(PluginGraph graph)
- {
- PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
- InstanceMemento[] childMementos = new InstanceMemento[_builders.Length];
- for (int i = 0; i < _builders.Length; i++)
- {
- InstanceMemento memento = processMementoBuilder(_builders[i], family, graph);
- childMementos[i] = memento;
- }
-
- _memento.AddChildArray(_propertyName, childMementos);
- }
-
- #endregion
-
- private InstanceMemento processMementoBuilder(IMementoBuilder builder, PluginFamily family, PluginGraph graph)
- {
- builder.ValidatePluggability(_pluginType);
- builder.Configure(graph);
- return builder.BuildMemento(family);
- }
-
- public InstanceExpression Contains(params IMementoBuilder[] builders)
- {
- _builders = builders;
-
- return _parent;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,120 +0,0 @@
-using System;
-using System.Collections.Generic;
-using StructureMap.Configuration.Mementos;
-using StructureMap.Graph;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- /// <summary>
- /// Part of the Fluent Interface, represents a nonprimitive argument to a
- /// constructure function
- /// </summary>
- public class ChildInstanceExpression : IExpression
- {
- private readonly InstanceExpression _instance;
- private readonly MemoryInstanceMemento _memento;
- private readonly string _propertyName;
- private IMementoBuilder _builder;
- private List<IExpression> _children = new List<IExpression>();
- private Type _childType;
-
-
- public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName)
- {
- _instance = instance;
- _memento = memento;
- _propertyName = propertyName;
- }
-
- public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName,
- Type childType)
- : this(instance, memento, propertyName)
- {
- _childType = childType;
- }
-
- internal Type ChildType
- {
- set { _childType = value; }
- }
-
- #region IExpression Members
-
- void IExpression.Configure(PluginGraph graph)
- {
- if (_childType == null)
- {
- return;
- }
-
- PluginFamily family = graph.LocateOrCreateFamilyForType(_childType);
- if (_builder != null)
- {
- InstanceMemento childMemento = _builder.BuildMemento(family);
- _memento.AddChild(_propertyName, childMemento);
- }
-
- foreach (IExpression child in _children)
- {
- child.Configure(graph);
- }
- }
-
- #endregion
-
- /// <summary>
- /// Use a previously configured and named instance for the child
- /// </summary>
- /// <param name="instanceKey"></param>
- /// <returns></returns>
- public InstanceExpression IsNamedInstance(string instanceKey)
- {
- MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey);
- _memento.AddChild(_propertyName, child);
-
- return _instance;
- }
-
- /// <summary>
- /// Start the definition of a child instance by defining the concrete type
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- public InstanceExpression IsConcreteType<T>()
- {
- Type pluggedType = typeof (T);
- ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType);
-
-
- InstanceExpression child = new InstanceExpression(_childType);
- child.TypeExpression().UsingConcreteType<T>();
- _children.Add(child);
-
- _builder = child;
-
- return _instance;
- }
-
-
- /// <summary>
- /// Registers a configured instance to use as the argument to the parent's
- /// constructor
- /// </summary>
- /// <param name="child"></param>
- /// <returns></returns>
- public InstanceExpression Is(InstanceExpression child)
- {
- if (child.PluggedType != null && _childType != null)
- {
- ExpressionValidator.ValidatePluggabilityOf(child.PluggedType).IntoPluginType(_childType);
- }
-
- _children.Add(child);
- MemoryInstanceMemento childMemento =
- MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey);
- _memento.AddChild(_propertyName, childMemento);
-
- return _instance;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,49 +0,0 @@
-using System;
-using StructureMap.Graph;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- public class ConstructorExpression<PLUGINTYPE> : MementoBuilder<ConstructorExpression<PLUGINTYPE>>
- {
- private ConstructorMemento<PLUGINTYPE> _memento;
-
- public ConstructorExpression(BuildObjectDelegate<PLUGINTYPE> builder)
- : base(typeof (PLUGINTYPE))
- {
- _memento.Builder = builder;
- }
-
-
- protected override InstanceMemento memento
- {
- get { return _memento; }
- }
-
- protected override ConstructorExpression<PLUGINTYPE> thisInstance
- {
- get { return this; }
- }
-
- protected override void configureMemento(PluginFamily family)
- {
- }
-
- protected override void validate()
- {
- }
-
- protected override void buildMemento()
- {
- _memento = new ConstructorMemento<PLUGINTYPE>();
- }
-
- public override void ValidatePluggability(Type pluginType)
- {
- if (!pluginType.Equals(typeof (PLUGINTYPE)))
- {
- throw new StructureMapException(306,
- typeof (PLUGINTYPE).FullName, pluginType.FullName);
- }
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,14 +0,0 @@
-using System;
-using StructureMap.Graph;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- public interface IMementoBuilder : IExpression
- {
- InstanceMemento BuildMemento(PluginFamily family);
- InstanceMemento BuildMemento(PluginGraph graph);
- void SetInstanceName(string instanceKey);
-
- void ValidatePluggability(Type pluginType);
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,197 +0,0 @@
-using System;
-using StructureMap.Configuration.Mementos;
-using StructureMap.Graph;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- /// <summary>
- /// Used to define an Instance in code
- /// </summary>
- public class InstanceExpression : MementoBuilder<InstanceExpression>
- {
- private MemoryInstanceMemento _memento;
- private Type _pluggedType;
-
- public InstanceExpression(Type pluginType) : base(pluginType)
- {
- }
-
-
- internal Type PluggedType
- {
- get { return _pluggedType; }
- }
-
-
- protected override InstanceMemento memento
- {
- get { return _memento; }
- }
-
- protected override InstanceExpression thisInstance
- {
- get { return this; }
- }
-
- protected override void buildMemento()
- {
- _memento = new MemoryInstanceMemento();
- }
-
- protected override void configureMemento(PluginFamily family)
- {
- Plugin plugin = _pluggedType == null
- ? family.Plugins[_memento.ConcreteKey]
- : family.Plugins.FindOrCreate(_pluggedType, false);
-
- _memento.ConcreteKey = plugin.ConcreteKey;
- }
-
- protected override void validate()
- {
- if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey))
- {
- throw new StructureMapException(301, _memento.InstanceKey,
- TypePath.GetAssemblyQualifiedName(_pluginType));
- }
- }
-
-
- /// <summary>
- /// Start the definition of a primitive argument to a constructor argument
- /// </summary>
- /// <param name="propertyName"></param>
- /// <returns></returns>
- public PropertyExpression WithProperty(string propertyName)
- {
- return new PropertyExpression(this, _memento, propertyName);
- }
-
- /// <summary>
- /// Starts the definition of a child instance specifying the argument name
- /// in the case of a constructor function that consumes more than one argument
- /// of type T
- /// </summary>
- /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam>
- /// <param name="propertyName"></param>
- /// <returns></returns>
- public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>(string propertyName)
- {
- ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName);
- addChildExpression(child);
- child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE);
-
- return child;
- }
-
- /// <summary>
- /// Start the definition of a child instance for type CONSTRUCTORARGUMENTTYPE
- /// </summary>
- /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam>
- /// <returns></returns>
- public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>()
- {
- string propertyName = findPropertyName<CONSTRUCTORARGUMENTTYPE>();
-
- ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName);
- addChildExpression(child);
- child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE);
- return child;
- }
-
- private string findPropertyName<T>()
- {
- Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType);
- string propertyName = plugin.FindFirstConstructorArgumentOfType<T>();
-
- if (string.IsNullOrEmpty(propertyName))
- {
- throw new StructureMapException(305, TypePath.GetAssemblyQualifiedName(typeof (T)));
- }
-
- return propertyName;
- }
-
- public override void ValidatePluggability(Type pluginType)
- {
- if (_pluggedType == null)
- {
- return;
- }
-
- ExpressionValidator.ValidatePluggabilityOf(_pluggedType).IntoPluginType(pluginType);
- }
-
- internal InstanceTypeExpression TypeExpression()
- {
- return new InstanceTypeExpression(this);
- }
-
- public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>()
- {
- validateTypeIsArray<PLUGINTYPE>();
-
- string propertyName = findPropertyName<PLUGINTYPE>();
- return ChildArray<PLUGINTYPE>(propertyName);
- }
-
- public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>(string propertyName)
- {
- validateTypeIsArray<PLUGINTYPE>();
-
- ChildArrayExpression<PLUGINTYPE> expression =
- new ChildArrayExpression<PLUGINTYPE>(this, _memento, propertyName);
- addChildExpression(expression);
-
- return expression;
- }
-
- private static void validateTypeIsArray<PLUGINTYPE>()
- {
- if (!typeof (PLUGINTYPE).IsArray)
- {
- throw new StructureMapException(307);
- }
- }
-
- #region Nested type: InstanceTypeExpression
-
- /// <summary>
- /// Helper class to capture the actual concrete type of an Instance
- /// </summary>
- public class InstanceTypeExpression
- {
- private readonly InstanceExpression _parent;
-
- internal InstanceTypeExpression(InstanceExpression parent)
- {
- _parent = parent;
- }
-
- /// <summary>
- /// Use type T for the concrete type of an instance
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- public InstanceExpression UsingConcreteType<T>()
- {
- _parent._pluggedType = typeof (T);
- _parent._memento.InstanceKey = typeof (T).Name;
- return _parent;
- }
-
- /// <summary>
- /// Use a named Plugin type denoted by a [Pluggable("Key")] attribute
- /// </summary>
- /// <param name="concreteKey"></param>
- /// <returns></returns>
- public InstanceExpression UsingConcreteTypeNamed(string concreteKey)
- {
- _parent._memento.ConcreteKey = concreteKey;
- return _parent;
- }
- }
-
- #endregion
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,51 +0,0 @@
-using System;
-using StructureMap.Configuration.Mementos;
-using StructureMap.Graph;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- /// <summary>
- /// Small helper class to represent an object to be plugged into a PluginType as is
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class LiteralExpression<T> : MementoBuilder<LiteralExpression<T>>
- {
- private readonly T _target;
- private LiteralMemento _memento;
-
- public LiteralExpression(T target) : base(typeof (T))
- {
- _target = target;
- }
-
-
- protected override InstanceMemento memento
- {
- get { return _memento; }
- }
-
- protected override LiteralExpression<T> thisInstance
- {
- get { return this; }
- }
-
- protected override void configureMemento(PluginFamily family)
- {
- _memento.Instance = _target;
- }
-
- protected override void validate()
- {
- }
-
- protected override void buildMemento()
- {
- _memento = new LiteralMemento(null);
- }
-
- public override void ValidatePluggability(Type pluginType)
- {
- ExpressionValidator.ValidatePluggabilityOf(_target.GetType()).IntoPluginType(pluginType);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,122 +0,0 @@
-using System;
-using System.Collections.Generic;
-using StructureMap.Graph;
-using StructureMap.Interceptors;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- public abstract class MementoBuilder<T> : IExpression, IMementoBuilder
- {
- protected readonly Type _pluginType;
- protected List<IExpression> _children = new List<IExpression>();
- private string _instanceKey = null;
-
- public MementoBuilder(Type pluginType)
- {
- _pluginType = pluginType;
- buildMemento();
- memento.InstanceKey = Guid.NewGuid().ToString();
- }
-
- protected abstract InstanceMemento memento { get; }
-
- protected abstract T thisInstance { get; }
-
- public string InstanceKey
- {
- get { return memento.InstanceKey; }
- set { memento.InstanceKey = value; }
- }
-
- internal Type PluginType
- {
- get { return _pluginType; }
- }
-
- #region IExpression Members
-
- void IExpression.Configure(PluginGraph graph)
- {
- validate();
- PluginFamily family = graph.LocateOrCreateFamilyForType((Type) _pluginType);
- configureMemento(family);
-
- if (!string.IsNullOrEmpty(_instanceKey))
- {
- memento.InstanceKey = _instanceKey;
- }
-
- family.Source.AddExternalMemento(memento);
-
- foreach (IExpression child in _children)
- {
- child.Configure(graph);
- }
- }
-
- #endregion
-
- #region IMementoBuilder Members
-
- InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family)
- {
- return buildMementoFromFamily(family);
- }
-
- InstanceMemento IMementoBuilder.BuildMemento(PluginGraph graph)
- {
- PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
- return buildMementoFromFamily(family);
- }
-
- public void SetInstanceName(string instanceKey)
- {
- _instanceKey = instanceKey;
- }
-
- public abstract void ValidatePluggability(Type pluginType);
-
- #endregion
-
- protected abstract void configureMemento(PluginFamily family);
-
- protected abstract void validate();
-
- public T WithName(string instanceKey)
- {
- memento.InstanceKey = instanceKey;
- return thisInstance;
- }
-
- public T OnCreation<TYPE>(StartupHandler<TYPE> handler)
- {
- StartupInterceptor<TYPE> interceptor = new StartupInterceptor<TYPE>(handler);
- memento.Interceptor = interceptor;
-
- return thisInstance;
- }
-
- public T EnrichWith<TYPE>(EnrichmentHandler<TYPE> handler)
- {
- EnrichmentInterceptor<TYPE> interceptor = new EnrichmentInterceptor<TYPE>(handler);
- memento.Interceptor = interceptor;
-
- return thisInstance;
- }
-
- protected abstract void buildMemento();
-
- private InstanceMemento buildMementoFromFamily(PluginFamily family)
- {
- validate();
- configureMemento(family);
- return memento;
- }
-
-
- protected void addChildExpression(IExpression expression)
- {
- _children.Add(expression);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,46 +0,0 @@
-using System.Configuration;
-using StructureMap.Configuration.Mementos;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- /// <summary>
- /// Defines the value of a primitive argument to a constructur argument
- /// </summary>
- public class PropertyExpression
- {
- private readonly InstanceExpression _instance;
- private readonly MemoryInstanceMemento _memento;
- private readonly string _propertyName;
-
- public PropertyExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName)
- {
- _instance = instance;
- _memento = memento;
- _propertyName = propertyName;
- }
-
- /// <summary>
- /// Sets the value of the constructor argument
- /// </summary>
- /// <param name="propertyValue"></param>
- /// <returns></returns>
- public InstanceExpression EqualTo(object propertyValue)
- {
- _memento.SetProperty(_propertyName, propertyValue.ToString());
- return _instance;
- }
-
- /// <summary>
- /// Sets the value of the constructor argument to the key/value in the
- /// AppSettings
- /// </summary>
- /// <param name="appSettingKey"></param>
- /// <returns></returns>
- public InstanceExpression EqualToAppSetting(string appSettingKey)
- {
- string propertyValue = ConfigurationManager.AppSettings[appSettingKey];
- _memento.SetProperty(_propertyName, propertyValue);
- return _instance;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,51 +0,0 @@
-using System;
-using StructureMap.Configuration.Mementos;
-using StructureMap.Graph;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- /// <summary>
- /// Sets up a Prototype instance of type T
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class PrototypeExpression<T> : MementoBuilder<PrototypeExpression<T>>
- {
- private readonly T _prototype;
- private PrototypeMemento _memento;
-
- public PrototypeExpression(T prototype) : base(typeof (T))
- {
- _prototype = prototype;
- }
-
- protected override InstanceMemento memento
- {
- get { return _memento; }
- }
-
- protected override PrototypeExpression<T> thisInstance
- {
- get { return this; }
- }
-
- protected override void configureMemento(PluginFamily family)
- {
- _memento.Prototype = (ICloneable) _prototype;
- }
-
- protected override void validate()
- {
- // TODO
- }
-
- protected override void buildMemento()
- {
- _memento = new PrototypeMemento(string.Empty, (ICloneable) _prototype);
- }
-
- public override void ValidatePluggability(Type pluginType)
- {
- ExpressionValidator.ValidatePluggabilityOf(_prototype.GetType()).IntoPluginType(pluginType);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs 2008-04-11 23:32:28 UTC (rev 79)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs 2008-04-12 13:45:08 UTC (rev 80)
@@ -1,46 +0,0 @@
-using System;
-using StructureMap.Configuration.Mementos;
-using StructureMap.Graph;
-
-namespace StructureMap.Configuration.DSL.Expressions
-{
- public class UserControlExpression : MementoBuilder<UserControlExpression>
- {
- private UserControlMemento _memento;
-
- public UserControlExpression(Type pluginType, string url) : base(pluginType)
- {
- _memento.Url = url;
- }
-
- protected override InstanceMemento memento
- {
- get { return _memento; }
- }
-
- protected override UserControlExpression thisInstance
- {
- get { return this; }
- }
-
- protected override void configureMemento(PluginFamily family)
- {
- // no-op
- }
-
- protected override void validate()
- {
- // no-op
- }
-
- protected override void buildMemento()
- {
- _memento = new UserControlMemento();
- }
-
- public override void ValidatePluggability(Type pluginType)
- {
- // no-op
- }
...
[truncated message content] |
|
From: <jer...@us...> - 2008-04-25 17:26:17
|
Revision: 81
http://structuremap.svn.sourceforge.net/structuremap/?rev=81&view=rev
Author: jeremydmiller
Date: 2008-04-25 10:26:13 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
introducing the BuildPolicy refactoring
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs
trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs
trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs
trunk/Source/StructureMap/Graph/InterceptionChain.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/InstanceBuilder.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceMemento.cs
trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs
trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/Instance.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/EmittingTester.cs
trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs
trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs
trunk/Source/StructureMap.Testing.Widget/Decision.cs
trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs
trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs
trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs
Added Paths:
-----------
trunk/Source/StructureMap/Diagnostics/
trunk/Source/StructureMap/Diagnostics/Tokens.cs
trunk/Source/StructureMap/InstanceFamily.cs
trunk/Source/StructureMap/Pipeline/BuildStrategies.cs
trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs
trunk/Source/StructureMap/Pipeline/ILocationPolicy.cs
trunk/Source/StructureMap/Pipeline/Profile.cs
trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs
trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs
trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ThreadLocalStoragePolicyTester.cs
trunk/Source/StructureMap.Testing.GenericWidgets/structuremap.snk
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -83,7 +83,8 @@
if (profile == null)
{
- throw new StructureMapException(195, profileName, machineName);
+ _pluginGraph.Log.RegisterError(195, profileName, machineName);
+ return;
}
_machine = new MachineOverride(machineName, profile);
@@ -155,13 +156,13 @@
public void AttachSource(TypePath pluginTypePath, MementoSource source)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath];
+ PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
family.AddMementoSource(source);
}
public Plugin AddPlugin(TypePath pluginTypePath, TypePath pluginPath, string concreteKey)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath];
+ PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
if (family == null)
{
string message =
@@ -177,14 +178,14 @@
public SetterProperty AddSetter(TypePath pluginTypePath, string concreteKey, string setterName)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath];
+ PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
Plugin plugin = family.Plugins[concreteKey];
return plugin.Setters.Add(setterName);
}
public virtual void AddInterceptor(TypePath pluginTypePath, InstanceMemento interceptorMemento)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath];
+ PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
try
{
InstanceFactoryInterceptor interceptor =
Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -1,3 +1,4 @@
+using System;
using System.Xml;
using StructureMap.Graph;
using StructureMap.Source;
@@ -4,6 +5,7 @@
namespace StructureMap.Configuration
{
+ [Obsolete("This puppy needs to be rewritten")]
public class ProfileAndMachineParser
{
private readonly IGraphBuilder _builder;
Added: trunk/Source/StructureMap/Diagnostics/Tokens.cs
===================================================================
--- trunk/Source/StructureMap/Diagnostics/Tokens.cs (rev 0)
+++ trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -0,0 +1,270 @@
+using System;
+using System.Collections.Generic;
+using System.Resources;
+using StructureMap.Graph;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Diagnostics
+{
+ public class GraphLog
+ {
+ private List<Error> _errors = new List<Error>();
+ private readonly List<Source> _sources = new List<Source>();
+ private Source _currentSource;
+
+ public void StartSource(string description)
+ {
+ Source source = new Source(description);
+ _sources.Add(source);
+
+ _currentSource = source;
+ }
+
+ public void RegisterError(Instance instance, int code, params object[] args)
+ {
+ Error error = new Error(code, args);
+ error.Instance = instance.CreateToken();
+ addError(error);
+ }
+
+ public void RegisterError(int code, params object[] args)
+ {
+ Error error = new Error(code, args);
+ addError(error);
+ }
+
+ private void addError(Error error)
+ {
+ error.Source = _currentSource;
+ _errors.Add(error);
+ }
+
+ public void AssertHasError(int errorCode, string message)
+ {
+ Error error = Error.FromMessage(errorCode, message);
+ if (!_errors.Contains(error))
+ {
+ string msg = "Did not have the requested Error. Had:\n\n";
+ foreach (Error err in _errors)
+ {
+ msg += err.ToString() + "\n";
+ }
+
+ throw new ApplicationException(msg);
+ }
+ }
+ }
+
+ public class Source
+ {
+ private string _description;
+
+ public Source(string description)
+ {
+ _description = description;
+ }
+
+ public string Description
+ {
+ get { return _description; }
+ set { _description = value; }
+ }
+ }
+
+ public class PluginType : IEquatable<PluginType>
+ {
+ private readonly List<InstanceToken> _instances = new List<InstanceToken>();
+ private readonly string _typeName;
+
+
+ public PluginType(string fullName)
+ {
+ _typeName = fullName;
+ }
+
+ public PluginType(TypePath path) : this(path.AssemblyQualifiedName)
+ {
+ }
+
+ public PluginType(Type pluginType) : this(pluginType.AssemblyQualifiedName)
+ {
+ }
+
+ public string TypeName
+ {
+ get { return _typeName; }
+ }
+
+ #region IEquatable<PluginType> Members
+
+ public bool Equals(PluginType pluginType)
+ {
+ if (pluginType == null) return false;
+ return Equals(_typeName, pluginType._typeName);
+ }
+
+ #endregion
+
+ public void AddInstance(InstanceToken token)
+ {
+ if (!_instances.Contains(token))
+ {
+ _instances.Add(token);
+ }
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(this, obj)) return true;
+ return Equals(obj as PluginType);
+ }
+
+ public override int GetHashCode()
+ {
+ return _typeName != null ? _typeName.GetHashCode() : 0;
+ }
+ }
+
+ public class InstanceToken : IEquatable<InstanceToken>
+ {
+ private readonly string _description;
+ private readonly string _name;
+ private PluginType _pluginType;
+
+ public InstanceToken(string name, string description, PluginType pluginType)
+ {
+ _name = name;
+ _description = description;
+ _pluginType = pluginType;
+ }
+
+
+ public string Name
+ {
+ get { return _name; }
+ }
+
+ public string Description
+ {
+ get { return _description; }
+ }
+
+
+ public PluginType PluginType
+ {
+ get { return _pluginType; }
+ }
+
+ #region IEquatable<InstanceToken> Members
+
+ public bool Equals(InstanceToken instanceToken)
+ {
+ if (instanceToken == null) return false;
+ if (!Equals(_name, instanceToken._name)) return false;
+ if (!Equals(_description, instanceToken._description)) return false;
+ if (!Equals(_pluginType, instanceToken._pluginType)) return false;
+ return true;
+ }
+
+ #endregion
+
+ public override string ToString()
+ {
+ return string.Format("Instance {0} ({1})", _name, _description);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(this, obj)) return true;
+ return Equals(obj as InstanceToken);
+ }
+
+ public override int GetHashCode()
+ {
+ int result = _name != null ? _name.GetHashCode() : 0;
+ result = 29*result + (_description != null ? _description.GetHashCode() : 0);
+ result = 29*result + (_pluginType != null ? _pluginType.GetHashCode() : 0);
+ return result;
+ }
+ }
+
+ public class Error : IEquatable<Error>
+ {
+ private int _code;
+ private string _message;
+ private string _stackTrace = string.Empty;
+ public InstanceToken Instance;
+ public PluginType PluginType;
+ public Source Source;
+
+
+ private Error(int code, string message)
+ {
+ _code = code;
+ _message = message;
+ }
+
+ public Error(int errorCode, params object[] args)
+ {
+ _code = errorCode;
+ string template = getMessage(errorCode);
+ if (template == null) template = string.Empty;
+
+ _message = string.Format(template, args);
+ }
+
+ public Error(StructureMapException exception)
+ {
+ _code = exception.ErrorCode;
+ _message = exception.Message;
+ _stackTrace = exception.StackTrace;
+ }
+
+ private string getMessage(int errorCode)
+ {
+ ResourceManager resources = new ResourceManager(typeof(StructureMapException));
+ return resources.GetString(errorCode.ToString());
+ }
+
+
+ public bool Equals(Error error)
+ {
+ if (error == null) return false;
+ if (_code != error._code) return false;
+ if (!Equals(_message, error._message)) return false;
+ if (!Equals(_stackTrace, error._stackTrace)) return false;
+ if (!Equals(Instance, error.Instance)) return false;
+ if (!Equals(PluginType, error.PluginType)) return false;
+ if (!Equals(Source, error.Source)) return false;
+ return true;
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (ReferenceEquals(this, obj)) return true;
+ return Equals(obj as Error);
+ }
+
+ public override int GetHashCode()
+ {
+ int result = _code;
+ result = 29*result + (_message != null ? _message.GetHashCode() : 0);
+ result = 29*result + (_stackTrace != null ? _stackTrace.GetHashCode() : 0);
+ result = 29*result + (Instance != null ? Instance.GetHashCode() : 0);
+ result = 29*result + (PluginType != null ? PluginType.GetHashCode() : 0);
+ result = 29*result + (Source != null ? Source.GetHashCode() : 0);
+ return result;
+ }
+
+
+ public override string ToString()
+ {
+ return string.Format("Error {0} -- {1}", _code, _message);
+ }
+
+ public static Error FromMessage(int code, string message)
+ {
+ return new Error(code, message);
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs
===================================================================
--- trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -42,9 +42,6 @@
private void configureClassBuilder(ClassBuilder builderClass, Plugin plugin)
{
builderClass.AddReadonlyStringProperty("ConcreteTypeKey", plugin.ConcreteKey, true);
- builderClass.AddReadonlyStringProperty("PluginType", TypePath.GetAssemblyQualifiedName(_pluginType), true);
- builderClass.AddReadonlyStringProperty("PluggedType", TypePath.GetAssemblyQualifiedName(plugin.PluggedType),
- true);
BuildInstanceMethod method = new BuildInstanceMethod(plugin);
builderClass.AddMethod(method);
Modified: trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs
===================================================================
--- trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -19,17 +19,20 @@
{
Type parameterType = parameter.ParameterType;
string parameterName = parameter.Name;
- string fullName = parameterType.AssemblyQualifiedName;
-
- putChildObjectOnStack(ilgen, parameterName, fullName, parameterType);
+ putChildObjectOnStack(ilgen, parameterName, parameterType);
}
- private void putChildObjectOnStack(ILGenerator ilgen, string parameterName, string fullName, Type parameterType)
+ private void putChildObjectOnStack(ILGenerator ilgen, string parameterName, Type parameterType)
{
ilgen.Emit(OpCodes.Ldarg_1);
ilgen.Emit(OpCodes.Ldstr, parameterName);
- ilgen.Emit(OpCodes.Ldstr, fullName);
+
+ ilgen.Emit(OpCodes.Ldtoken, parameterType);
+
+ MethodInfo method = typeof (Type).GetMethod("GetTypeFromHandle");
+ ilgen.Emit(OpCodes.Call, method);
+
ilgen.Emit(OpCodes.Ldarg_2);
callInstanceMemento(ilgen, "GetChild");
@@ -40,8 +43,7 @@
{
ilgen.Emit(OpCodes.Ldloc_0);
- putChildObjectOnStack(ilgen, property.Name, property.PropertyType.AssemblyQualifiedName,
- property.PropertyType);
+ putChildObjectOnStack(ilgen, property.Name, property.PropertyType);
MethodInfo method = property.GetSetMethod();
ilgen.Emit(OpCodes.Callvirt, method);
Modified: trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs
===================================================================
--- trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -8,7 +8,7 @@
/// InstanceManager for any combination of profile and machine name.
/// </summary>
[Serializable]
- public class InstanceDefaultManager
+ [Obsolete] public class InstanceDefaultManager
{
private string _defaultProfileName = string.Empty;
private List<InstanceDefault> _defaults;
@@ -204,55 +204,6 @@
return answer;
}
- /// <summary>
- /// Returns the defaults for the current machine name and the default profile
- /// </summary>
- /// <returns></returns>
- public Profile CalculateDefaults()
- {
- string profileName = DefaultProfileName;
- string machinceName = GetMachineName();
-
- return CalculateDefaults(machinceName, profileName);
- }
-
- /// <summary>
- /// Determines ONLY overriden defaults. Used by the Deployment NAnt task to
- /// filter a PluginGraph prior to deploying a subset of the StructureMap.config
- /// file
- /// </summary>
- /// <param name="machineName"></param>
- /// <param name="profileName"></param>
- /// <returns></returns>
- public Profile CalculateOverridenDefaults(string machineName, string profileName)
- {
- MachineOverride machine = GetMachineOverride(machineName);
- Profile profile = findCurrentProfile(profileName);
-
- Profile answer = new Profile("Defaults");
- foreach (InstanceDefault instance in machine.Defaults)
- {
- answer.AddOverride((InstanceDefault) instance.Clone());
- }
-
- foreach (InstanceDefault instance in profile.Defaults)
- {
- answer.AddOverride((InstanceDefault) instance.Clone());
- }
-
- return answer;
- }
-
- public void ClearMachineOverrides()
- {
- _machineOverrides.Clear();
- }
-
- public void ClearProfiles()
- {
- _profiles.Clear();
- }
-
public string[] GetMachineNames()
{
string[] names = new string[_machineOverrides.Count];
Modified: trunk/Source/StructureMap/Graph/InterceptionChain.cs
===================================================================
--- trunk/Source/StructureMap/Graph/InterceptionChain.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Graph/InterceptionChain.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -9,7 +9,7 @@
/// Manages a list of InstanceFactoryInterceptor's. Design-time model of an array
/// of decorators to alter the InstanceFactory behavior for a PluginType.
/// </summary>
- public class InterceptionChain : IEnumerable<InstanceFactoryInterceptor>, IEquatable<InterceptionChain>
+ [Obsolete] public class InterceptionChain : IEnumerable<InstanceFactoryInterceptor>, IEquatable<InterceptionChain>
{
private List<InstanceFactoryInterceptor> _interceptorList;
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -42,6 +42,7 @@
private Type _pluginType;
private string _pluginTypeName;
private List<Instance> _instances = new List<Instance>();
+ private IBuildPolicy _buildPolicy = new BuildPolicy();
#region constructors
@@ -121,6 +122,7 @@
PluginFamily templatedFamily = new PluginFamily(templatedType);
templatedFamily._defaultKey = _defaultKey;
templatedFamily.Parent = Parent;
+ templatedFamily._buildPolicy = _buildPolicy.Clone();
foreach (InstanceFactoryInterceptor interceptor in _interceptionChain)
{
@@ -286,6 +288,11 @@
set { _canUseUnMarkedPlugins = value; }
}
+ public IBuildPolicy Policy
+ {
+ get { return _buildPolicy; }
+ }
+
#endregion
public Instance[] GetAllInstances()
@@ -293,7 +300,8 @@
List<Instance> list = new List<Instance>();
foreach (InstanceMemento memento in _mementoList)
{
- list.Add(memento.ReadInstance(Parent, _pluginType));
+ Instance instance = memento.ReadInstance(Parent, _pluginType);
+ list.Add(instance);
}
list.AddRange(_instances);
@@ -305,5 +313,6 @@
{
return _instances.Find(delegate(Instance i) { return i.Name == name; });
}
+
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -10,7 +10,7 @@
public class PluginFamilyCollection : IEnumerable<PluginFamily>
{
private readonly PluginGraph _pluginGraph;
- private Dictionary<Type, PluginFamily> _pluginFamilies;
+ private readonly Dictionary<Type, PluginFamily> _pluginFamilies;
public PluginFamilyCollection(PluginGraph pluginGraph)
{
@@ -32,22 +32,6 @@
}
- public PluginFamily this[TypePath pluginTypePath]
- {
- get
- {
- foreach (KeyValuePair<Type, PluginFamily> pair in _pluginFamilies)
- {
- if (pluginTypePath.Matches(pair.Key))
- {
- return pair.Value;
- }
- }
-
- return null;
- }
- }
-
public PluginFamily this[int index]
{
get
Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Reflection;
using StructureMap.Configuration.DSL;
+using StructureMap.Diagnostics;
using StructureMap.Interceptors;
namespace StructureMap.Graph
@@ -21,7 +22,8 @@
private readonly InterceptorLibrary _interceptorLibrary = new InterceptorLibrary();
private readonly PluginFamilyCollection _pluginFamilies;
private bool _sealed = false;
- private bool _useExternalRegistries = true;
+ private readonly bool _useExternalRegistries = true;
+ private readonly GraphLog _log = new GraphLog();
/// <summary>
/// Default constructor
@@ -48,6 +50,12 @@
get { return _pluginFamilies; }
}
+
+ public GraphLog Log
+ {
+ get { return _log; }
+ }
+
#region seal
public bool IsSealed
@@ -183,6 +191,7 @@
throw new StructureMapException(300, fullName);
}
+ [Obsolete]
public void ReadDefaults()
{
_defaultManager.ReadDefaultsFromPluginGraph(this);
Modified: trunk/Source/StructureMap/InstanceBuilder.cs
===================================================================
--- trunk/Source/StructureMap/InstanceBuilder.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -15,16 +15,8 @@
{
}
- public abstract string PluginType { get; }
- public abstract string PluggedType { get; }
public abstract string ConcreteTypeKey { get; }
public abstract object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator);
-
- public bool IsType(Type type)
- {
- Type plugged = Type.GetType(PluggedType);
- return plugged.Equals(type);
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/InstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFactory.cs 2008-04-12 13:45:08 UTC (rev 80)
+++ trunk/Source/StructureMap/InstanceFactory.cs 2008-04-25 17:26:13 UTC (rev 81)
@@ -2,11 +2,9 @@
using System.Collections;
using System.Collections.Generic;
using System.Data;
-using StructureMap.Configuration.Mementos;
using StructureMap.Graph;
using StructureMap.Interceptors;
using StructureMap.Pipeline;
-using StructureMap.Source;
namespace StructureMap
{
@@ -16,11 +14,12 @@
public class InstanceFactory : IInstanceFactory
{
private readonly InstanceBuilderList _instanceBuilders;
+ private readonly Dictionary<string, Instance> _instances = new Dictionary<string, Instance>();
private readonly InstanceInterceptor _interceptor = new NulloInterceptor();
private readonly Type _pluginType;
- private InstanceManager _manager = new InstanceManager();
- private readonly Dictionary<string, Instance> _instances = new Dictionary<string, Instance>();
private Instance _defaultInstance;
+ private InstanceManager _manager = new InstanceManager();
+ private IBuildPolicy _policy = new BuildPolicy();
#region static constructors
@@ -54,6 +53,7 @@
try
{
_interceptor = family.InstanceInterceptor;
+ _policy = family.Policy;
_pluginType = family.PluginType;
_instanceBuilders = new InstanceBuilderList(family.PluginType, family.Plugins.All);
@@ -75,11 +75,6 @@
}
}
- public static InstanceFactory CreateInstanceFactoryForType(Type concreteType)
- {
- return new InstanceFactory(concreteType);
- }
-
private InstanceFactory(Type concreteType)
{
_interceptor = new NulloInterceptor();
@@ -94,7 +89,7 @@
Plugin plugin = new Plugin(new TypePath(concreteType), Guid.NewGuid().ToString());
if (plugin.CanBeAutoFilled)
{
- _instanceBuilders = new InstanceBuilderList(_pluginType, new Plugin[]{plugin});
+ _instanceBuilders = new InstanceBuilderList(_pluginType, new Plugin[] {plugin});
ConfiguredInstance instance = new ConfiguredInstance();
instance.PluggedType = concreteType;
@@ -106,6 +101,10 @@
}
}
+ public static InstanceFactory CreateInstanceFactoryForType(Type concreteType)
+ {
+ return new InstanceFactory(concreteType);
+ }
private void determineDefaultKey(PluginFamily family, bool failOnException)
@@ -148,51 +147,6 @@
#endregion
-
- #region IInstanceCreator Members
-
- // TODO: This code needs to move somewhere else
- //object IInstanceCreator.BuildInstance(InstanceMemento memento)
- //{
- // InstanceBuilder builder = memento.FindBuilder(_instanceBuilders);
-
- // if (builder == null)
- // {
- // throw new StructureMapException(
- // 201, memento.ConcreteKey, memento.InstanceKey, PluginType.FullName);
- // }
-
- // try
- // {
- // object constructedInstance = builder.BuildInstance(memento, _manager);
- // InstanceInterceptor interceptor = _manager.FindInterceptor(constructedInstance.GetType());
- // return interceptor.Process(constructedInstance);
- // }
- // catch (StructureMapException)
- // {
- // throw;
- // }
- // catch (InvalidCastException ex)
- // {
- // throw new StructureMapException(206, ex, memento.InstanceKey);
- // }
- // catch (Exception ex)
- // {
- // throw new StructureMapException(207, ex, memento.InstanceKey, PluginType.FullName);
- // }
- //}
-
- //InstanceMemento IInstanceCreator.DefaultMemento
- //{
- // get
- // {
- // throw new NotImplementedException();
- // //return _source.DefaultMemento;
- // }
- //}
-
- #endregion
-
#region IInstanceFactory Members
/// <summary>
@@ -227,7 +181,7 @@
Instance instance = _instances[instanceKey];
- return instance.Build(_pluginType, _manager);
+ return _policy.Build(_manager, PluginType, instance);
}
@@ -268,14 +222,14 @@
/// Builds a new instance of the default instance of the PluginType
/// </summary>
/// <returns></returns>
- public object GetInstance()
+ [Obsolete("Want to remove this eventually")] public object GetInstance()
{
if (_defaultInstance == null)
{
throw new StructureMapException(202, PluginType.FullName);
}
- object builtObject = _defaultInstance.Build(_plugin...
[truncated message content] |
|
From: <jer...@us...> - 2008-04-25 18:03:00
|
Revision: 82
http://structuremap.svn.sourceforge.net/structuremap/?rev=82&view=rev
Author: jeremydmiller
Date: 2008-04-25 11:02:44 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
little refactoring for the build policies. Making sure that the attribute builds the PluginFamily correctly
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-25 17:26:13 UTC (rev 81)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-25 18:02:44 UTC (rev 82)
@@ -146,8 +146,9 @@
PluginFamily family = new PluginFamily(exportedType, DefaultKey);
family.AddMementoSource(source);
- InterceptorChainBuilder builder = new InterceptorChainBuilder();
- family.InterceptionChain = builder.Build(Scope);
+ family.SetScopeTo(Scope);
+ //InterceptorChainBuilder builder = new InterceptorChainBuilder();
+ //family.InterceptionChain = builder.Build(Scope);
return family;
}
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-25 17:26:13 UTC (rev 81)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-25 18:02:44 UTC (rev 82)
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
+using StructureMap.Attributes;
using StructureMap.Interceptors;
using StructureMap.Pipeline;
@@ -255,6 +256,7 @@
set { _defaultKey = value ?? string.Empty; }
}
+ [Obsolete("Make this go away")]
public InterceptionChain InterceptionChain
{
get { return _interceptionChain; }
@@ -314,5 +316,32 @@
return _instances.Find(delegate(Instance i) { return i.Name == name; });
}
+ public void SetScopeTo(InstanceScope scope)
+ {
+ switch(scope)
+ {
+ case InstanceScope.Singleton:
+ AddInterceptor(new SingletonPolicy());
+ break;
+
+ case InstanceScope.HttpContext:
+ AddInterceptor(new HttpContextBuildPolicy());
+ break;
+
+ case InstanceScope.ThreadLocal:
+ AddInterceptor(new ThreadLocalStoragePolicy());
+ break;
+
+ case InstanceScope.Hybrid:
+ AddInterceptor(new HybridBuildPolicy());
+ break;
+ }
+ }
+
+ public void AddInterceptor(IInstanceInterceptor interceptor)
+ {
+ interceptor.InnerPolicy = _buildPolicy;
+ _buildPolicy = interceptor;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-04-25 17:26:13 UTC (rev 81)
+++ trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-04-25 18:02:44 UTC (rev 82)
@@ -3,6 +3,7 @@
using StructureMap.Attributes;
using StructureMap.Graph;
using StructureMap.Interceptors;
+using StructureMap.Pipeline;
using StructureMap.Source;
namespace StructureMap.Testing.Attributes
@@ -16,9 +17,7 @@
att.Scope = scope;
PluginFamily family = att.BuildPluginFamily(typeof (Target1));
- Assert.AreEqual(1, family.InterceptionChain.Count);
- Type actualType = family.InterceptionChain[0].GetType();
- Assert.IsTrue(actualType.Equals(interceptorType));
+ Assert.IsInstanceOfType(interceptorType, family.Policy);
}
[PluginFamily]
@@ -92,10 +91,10 @@
[Test]
public void ScopeToInterceptorTypes()
{
- assertScopeLeadsToInterceptor(InstanceScope.HttpContext, typeof (HttpContextItemInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.Hybrid, typeof (HybridCacheInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.Singleton, typeof (SingletonInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.ThreadLocal, typeof (ThreadLocalStorageInterceptor));
+ assertScopeLeadsToInterceptor(InstanceScope.HttpContext, typeof (HttpContextBuildPolicy));
+ assertScopeLeadsToInterceptor(InstanceScope.Hybrid, typeof (HybridBuildPolicy));
+ assertScopeLeadsToInterceptor(InstanceScope.Singleton, typeof (SingletonPolicy));
+ assertScopeLeadsToInterceptor(InstanceScope.ThreadLocal, typeof (ThreadLocalStoragePolicy));
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-04-25 17:26:13 UTC (rev 81)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-04-25 18:02:44 UTC (rev 82)
@@ -1,8 +1,10 @@
using System;
using System.Reflection;
using NUnit.Framework;
+using StructureMap.Attributes;
using StructureMap.Graph;
using StructureMap.Interceptors;
+using StructureMap.Pipeline;
using StructureMap.Source;
using StructureMap.Testing.Widget;
@@ -86,10 +88,6 @@
pluginGraph.Assemblies.Add(Assembly.GetExecutingAssembly());
pluginGraph.Seal();
- PluginFamily family = pluginGraph.PluginFamilies[typeof (ISingletonRepository)];
- Assert.AreEqual(1, family.InterceptionChain.Count);
- Assert.IsTrue(family.InterceptionChain[0] is SingletonInterceptor);
-
InstanceManager manager = new InstanceManager(pluginGraph);
ISingletonRepository repository1 =
@@ -108,8 +106,54 @@
Assert.AreSame(repository1, repository4);
Assert.AreSame(repository1, repository5);
}
+
+
+ [Test]
+ public void SetScopeToSingleton()
+ {
+ PluginFamily family = new PluginFamily(typeof(IServiceProvider));
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
+
+ family.SetScopeTo(InstanceScope.Singleton);
+ Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy);
+ }
+
+ [Test]
+ public void SetScopeToThreadLocal()
+ {
+ PluginFamily family = new PluginFamily(typeof(IServiceProvider));
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
+
+ family.SetScopeTo(InstanceScope.ThreadLocal);
+ Assert.IsInstanceOfType(typeof(ThreadLocalStoragePolicy), family.Policy);
+ }
+
+
+ [Test]
+ public void SetScopeToHttpContext()
+ {
+ PluginFamily family = new PluginFamily(typeof(IServiceProvider));
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
+
+ family.SetScopeTo(InstanceScope.HttpContext);
+ Assert.IsInstanceOfType(typeof(HttpContextBuildPolicy), family.Policy);
+ }
+
+
+ [Test]
+ public void SetScopeToHybrid()
+ {
+ PluginFamily family = new PluginFamily(typeof(IServiceProvider));
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
+
+ family.SetScopeTo(InstanceScope.Hybrid);
+ Assert.IsInstanceOfType(typeof(HybridBuildPolicy), family.Policy);
+ }
+
}
+
+
/// <summary>
/// Specifying the default instance is "Default" and marking the PluginFamily
/// as an injected Singleton
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-04-26 01:57:27
|
Revision: 83
http://structuremap.svn.sourceforge.net/structuremap/?rev=83&view=rev
Author: jeremydmiller
Date: 2008-04-25 18:57:25 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
Eliminated the InterceptionChain business
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/Pipeline/BuildStrategies.cs
trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Removed Paths:
-------------
trunk/Source/StructureMap/Graph/InterceptionChain.cs
trunk/Source/StructureMap/Interceptors/CacheInterceptor.cs
trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs
trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs
trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs
trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs
trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs
trunk/Source/StructureMap/Interceptors/SingletonInterceptor.cs
trunk/Source/StructureMap/Interceptors/ThreadLocalStorageInterceptor.cs
trunk/Source/StructureMap/XmlMapping/
trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs
trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs
trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs
trunk/Source/StructureMap.Testing/NewFolder1/
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -147,8 +147,6 @@
family.AddMementoSource(source);
family.SetScopeTo(Scope);
- //InterceptorChainBuilder builder = new InterceptorChainBuilder();
- //family.InterceptionChain = builder.Build(Scope);
return family;
}
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -29,8 +29,7 @@
void IExpression.Configure(PluginGraph graph)
{
PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
- InterceptorChainBuilder builder = new InterceptorChainBuilder();
- family.InterceptionChain = builder.Build(_scope);
+ family.SetScopeTo(_scope);
foreach (IExpression child in _children)
{
@@ -108,8 +107,7 @@
{
_alterations.Add(delegate(PluginFamily family)
{
- InterceptorChainBuilder builder = new InterceptorChainBuilder();
- family.InterceptionChain = builder.Build(scope);
+ family.SetScopeTo(scope);
});
return this;
@@ -122,7 +120,7 @@
public CreatePluginFamilyExpression<PLUGINTYPE> AsSingletons()
{
_alterations.Add(
- delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(new SingletonInterceptor()); });
+ delegate(PluginFamily family) { family.SetScopeTo(InstanceScope.Singleton); });
return this;
}
@@ -165,9 +163,12 @@
return this;
}
- public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(InstanceFactoryInterceptor interceptor)
+ public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(IInstanceInterceptor interceptor)
{
- _alterations.Add(delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(interceptor); });
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ family.AddInterceptor(interceptor);
+ });
return this;
}
}
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -11,22 +11,14 @@
{
public class NormalGraphBuilder : IGraphBuilder
{
- private readonly IInterceptorChainBuilder _builder;
private MachineOverride _machine;
private PluginGraph _pluginGraph;
private Profile _profile;
private PluginGraph _systemGraph;
private InstanceManager _systemInstanceManager;
-
- public NormalGraphBuilder(Registry[] registries) : this(new InterceptorChainBuilder(), registries)
+ public NormalGraphBuilder(Registry[] registries)
{
- }
-
- public NormalGraphBuilder(IInterceptorChainBuilder builder, Registry[] registries)
- {
- _builder = builder;
-
_pluginGraph = new PluginGraph();
foreach (Registry registry in registries)
{
@@ -137,8 +129,7 @@
// Xml configuration wins
family.DefaultInstanceKey = defaultKey;
- InterceptionChain interceptionChain = _builder.Build(scope);
- family.AddInterceptionChain(interceptionChain);
+ family.SetScopeTo(scope);
}
public virtual void AttachSource(TypePath pluginTypePath, InstanceMemento sourceMemento)
@@ -188,11 +179,11 @@
PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
try
{
- InstanceFactoryInterceptor interceptor =
- (InstanceFactoryInterceptor)
- buildSystemObject(typeof (InstanceFactoryInterceptor), interceptorMemento);
+ IInstanceInterceptor interceptor =
+ (IInstanceInterceptor)
+ buildSystemObject(typeof(IInstanceInterceptor), interceptorMemento);
- family.InterceptionChain.AddInterceptor(interceptor);
+ family.AddInterceptor(interceptor);
}
catch (Exception ex)
{
Deleted: trunk/Source/StructureMap/Graph/InterceptionChain.cs
===================================================================
--- trunk/Source/StructureMap/Graph/InterceptionChain.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Graph/InterceptionChain.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,104 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using StructureMap.Interceptors;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// Manages a list of InstanceFactoryInterceptor's. Design-time model of an array
- /// of decorators to alter the InstanceFactory behavior for a PluginType.
- /// </summary>
- [Obsolete] public class InterceptionChain : IEnumerable<InstanceFactoryInterceptor>, IEquatable<InterceptionChain>
- {
- private List<InstanceFactoryInterceptor> _interceptorList;
-
- public InterceptionChain()
- {
- _interceptorList = new List<InstanceFactoryInterceptor>();
- }
-
- public int Count
- {
- get { return _interceptorList.Count; }
- }
-
- public InstanceFactoryInterceptor this[int index]
- {
- get { return _interceptorList[index]; }
- }
-
- #region IEnumerable<InstanceFactoryInterceptor> Members
-
- IEnumerator<InstanceFactoryInterceptor> IEnumerable<InstanceFactoryInterceptor>.GetEnumerator()
- {
- return _interceptorList.GetEnumerator();
- }
-
- public IEnumerator GetEnumerator()
- {
- return _interceptorList.GetEnumerator();
- }
-
- #endregion
-
- public IInstanceFactory WrapInstanceFactory(IInstanceFactory factory)
- {
- IInstanceFactory outerFactory = factory;
-
- for (int i = _interceptorList.Count - 1; i >= 0; i--)
- {
- InstanceFactoryInterceptor interceptor = _interceptorList[i];
- interceptor.InnerInstanceFactory = outerFactory;
- outerFactory = interceptor;
- }
-
- return outerFactory;
- }
-
- public void AddInterceptor(InstanceFactoryInterceptor interceptor)
- {
- _interceptorList.Add(interceptor);
- }
-
- public bool Contains(Type interceptorType)
- {
- foreach (InstanceFactoryInterceptor interceptor in _interceptorList)
- {
- if (interceptor.GetType() == interceptorType)
- {
- return true;
- }
- }
-
- return false;
- }
-
- public bool Equals(InterceptionChain interceptionChain)
- {
- if (interceptionChain == null) return false;
-
-
- if (!Equals(_interceptorList.Count, interceptionChain._interceptorList.Count)) return false;
-
- for (int i = 0; i < _interceptorList.Count; i++)
- {
- if (!Equals(_interceptorList[i], interceptionChain._interceptorList[i])) return false;
-
- }
-
- return true;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(this, obj)) return true;
- return Equals(obj as InterceptionChain);
- }
-
- public override int GetHashCode()
- {
- return _interceptorList != null ? _interceptorList.GetHashCode() : 0;
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -38,7 +38,6 @@
private bool _canUseUnMarkedPlugins = false;
private string _defaultKey = string.Empty;
private InstanceInterceptor _instanceInterceptor = new NulloInterceptor();
- private InterceptionChain _interceptionChain;
private PluginGraph _parent;
private Type _pluginType;
private string _pluginTypeName;
@@ -53,11 +52,9 @@
_pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
_defaultKey = defaultInstanceKey;
_plugins = new PluginCollection(this);
-
- _interceptionChain = new InterceptionChain();
}
-
+ // TODO: Need to unit test the scope from the attribute
/// <summary>
/// Testing constructor
/// </summary>
@@ -65,10 +62,12 @@
public PluginFamily(Type pluginType) :
this(pluginType, PluginFamilyAttribute.GetDefaultKey(pluginType))
{
- if (PluginFamilyAttribute.IsMarkedAsSingleton(pluginType))
+ PluginFamilyAttribute attribute = PluginFamilyAttribute.GetAttribute(pluginType);
+ if (attribute != null)
{
- InterceptionChain.AddInterceptor(new SingletonInterceptor());
+ SetScopeTo(attribute.Scope);
}
+
}
@@ -82,7 +81,6 @@
{
_plugins = new PluginCollection(this);
_pluginTypeName = path.AssemblyQualifiedName;
- _interceptionChain = new InterceptionChain();
initializeExplicit(path, defaultKey);
}
@@ -125,12 +123,6 @@
templatedFamily.Parent = Parent;
templatedFamily._buildPolicy = _buildPolicy.Clone();
- foreach (InstanceFactoryInterceptor interceptor in _interceptionChain)
- {
- InstanceFactoryInterceptor clonedInterceptor = (InstanceFactoryInterceptor) interceptor.Clone();
- templatedFamily.InterceptionChain.AddInterceptor(clonedInterceptor);
- }
-
// Add Plugins
foreach (Plugin plugin in _plugins)
{
@@ -207,21 +199,6 @@
return _mementoList.Find(delegate(InstanceMemento m) { return m.InstanceKey == instanceKey; });
}
- public void AddInterceptionChain(InterceptionChain chain)
- {
- if (_interceptionChain == null)
- {
- _interceptionChain = chain;
- }
- else
- {
- foreach (InstanceFactoryInterceptor interceptor in chain)
- {
- _interceptionChain.AddInterceptor(interceptor);
- }
- }
- }
-
public void DiscoverImplicitInstances()
{
List<Plugin> list = _plugins.FindAutoFillablePlugins();
@@ -256,13 +233,6 @@
set { _defaultKey = value ?? string.Empty; }
}
- [Obsolete("Make this go away")]
- public InterceptionChain InterceptionChain
- {
- get { return _interceptionChain; }
- set { _interceptionChain = value; }
- }
-
public PluginCollection Plugins
{
get { return _plugins; }
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -351,11 +351,9 @@
private IInstanceFactory registerPluginFamily(PluginFamily family)
{
InstanceFactory factory = new InstanceFactory(family, _failOnException);
- IInstanceFactory wrappedFactory = family.InterceptionChain.WrapInstanceFactory(factory);
+ RegisterType(factory);
- RegisterType(wrappedFactory);
-
- return wrappedFactory;
+ return factory;
}
/// <summary>
@@ -511,15 +509,7 @@
#endregion
- //public InstanceInterceptor FindInterceptor(Type pluginType, Type actualType)
- //{
- // InstanceInterceptor interceptor = getOrCreateFactory(pluginType).GetInterceptor();
- // CompoundInterceptor compoundInterceptor = _interceptorLibrary.FindInterceptor(actualType);
-
- // return compoundInterceptor.Merge(interceptor);
- //}
-
object IInstanceCreator.ApplyInterception(Type pluginType, object actualValue)
{
IInstanceFactory factory = getOrCreateFactory(pluginType);
Deleted: trunk/Source/StructureMap/Interceptors/CacheInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/CacheInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/CacheInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,41 +0,0 @@
-namespace StructureMap.Interceptors
-{
- public abstract class CacheInterceptor : InstanceFactoryInterceptor
- {
- public CacheInterceptor() : base()
- {
- }
-
- public override object GetInstance()
- {
- return GetInstance(DefaultInstanceKey);
- }
-
- public override object GetInstance(string instanceKey)
- {
- ensureInstanceIsCached(instanceKey);
- return getInstance(instanceKey);
- }
-
- private void ensureInstanceIsCached(string instanceKey)
- {
- if (!isCached(instanceKey))
- {
- lock (this)
- {
- if (!isCached(instanceKey))
- {
- object instance = InnerInstanceFactory.GetInstance(instanceKey);
- cache(instanceKey, instance);
- }
- }
- }
- }
-
- protected abstract void cache(string instanceKey, object instance);
-
- protected abstract bool isCached(string instanceKey);
-
- protected abstract object getInstance(string instanceKey);
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,45 +0,0 @@
-using System.Web;
-
-namespace StructureMap.Interceptors
-{
- [Pluggable("HttpContext")]
- public class HttpContextItemInterceptor : CacheInterceptor
- {
- public HttpContextItemInterceptor() : base()
- {
- }
-
- public static bool HasContext()
- {
- return HttpContext.Current != null;
- }
-
- private string getKey(string instanceKey)
- {
- return string.Format("{0}:{1}", InnerInstanceFactory.PluginType.AssemblyQualifiedName, instanceKey);
- }
-
- protected override void cache(string instanceKey, object instance)
- {
- string key = getKey(instanceKey);
- HttpContext.Current.Items.Add(key, instance);
- }
-
- protected override bool isCached(string instanceKey)
- {
- string key = getKey(instanceKey);
- return HttpContext.Current.Items.Contains(key);
- }
-
- protected override object getInstance(string instanceKey)
- {
- string key = getKey(instanceKey);
- return HttpContext.Current.Items[key];
- }
-
- public override object Clone()
- {
- return MemberwiseClone();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,48 +0,0 @@
-using StructureMap.Pipeline;
-
-namespace StructureMap.Interceptors
-{
- [Pluggable("Hybrid")]
- public class HybridCacheInterceptor : InstanceFactoryInterceptor
- {
- private InstanceFactoryInterceptor _innerInterceptor;
-
- public HybridCacheInterceptor() : base()
- {
- if (HttpContextItemInterceptor.HasContext())
- {
- _innerInterceptor = new HttpContextItemInterceptor();
- }
- else
- {
- _innerInterceptor = new ThreadLocalStorageInterceptor();
- }
- }
-
- public override IInstanceFactory InnerInstanceFactory
- {
- get { return _innerInterceptor.InnerInstanceFactory; }
- set { _innerInterceptor.InnerInstanceFactory = value; }
- }
-
- public override object GetInstance(string instanceKey)
- {
- return _innerInterceptor.GetInstance(instanceKey);
- }
-
- public override object GetInstance(IConfiguredInstance instance, IInstanceCreator instanceCreator)
- {
- return _innerInterceptor.GetInstance(instance, instanceCreator);
- }
-
- public override object GetInstance()
- {
- return _innerInterceptor.GetInstance();
- }
-
- public override object Clone()
- {
- return new HybridCacheInterceptor();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,13 +0,0 @@
-using System;
-using StructureMap.Attributes;
-using StructureMap.Graph;
-
-namespace StructureMap.Interceptors
-{
- [Obsolete]
- public interface IInterceptorChainBuilder
- {
- [Obsolete]
- InterceptionChain Build(InstanceScope scope);
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,141 +0,0 @@
-using System;
-using System.Collections;
-using StructureMap.Pipeline;
-
-namespace StructureMap.Interceptors
-{
- /// <summary>
- /// Base "Decorator" class around IInstanceFactory to alter the object creation process
- /// for a PluginType. The SingletonInterceptor is an example subclass that ensures that
- /// only one instance is created for a given InstanceKey as a more testable alternative to
- /// the GoF Singleton pattern.
- /// </summary>
- [PluginFamily]
- public abstract class InstanceFactoryInterceptor : IInstanceFactory, ICloneable
- {
- private IInstanceFactory _innerInstanceFactory;
-
-
- public virtual IInstanceFactory InnerInstanceFactory
- {
- get { return _innerInstanceFactory; }
- set { _innerInstanceFactory = value; }
- }
-
- /// <summary>
- /// Declares whether or not the interceptor creates a stubbed or mocked version of the PluginType
- /// </summary>
- public virtual bool IsMockedOrStubbed
- {
- get { return false; }
- }
-
- #region ICloneable Members
-
- public abstract object Clone();
-
- #endregion
-
- #region IInstanceFactory Members
-
- /// <summary>
- /// Establishes a reference to the parent InstanceManager
- /// </summary>
- /// <param name="instanceManager"></param>
- public void SetInstanceManager(InstanceManager instanceManager)
- {
- InnerInstanceFactory.SetInstanceManager(instanceManager);
- }
-
- /// <summary>
- /// The CLR System.Type that the IInstanceManager builds instances
- /// </summary>
- public Type PluginType
- {
- get { return InnerInstanceFactory.PluginType; }
- }
-
- /// <summary>
- /// Creates an object instance for the InstanceKey
- /// </summary>
- /// <param name="instanceKey">The named instance</param>
- /// <returns></returns>
- public virtual object GetInstance(string instanceKey)
- {
- return InnerInstanceFactory.GetInstance(instanceKey);
- }
-
- /// <summary>
- /// Creates an object instance directly from the Memento
- /// </summary>
- /// <param name="instance">A representation of an object instance</param>
- /// <returns></returns>
- public virtual object GetInstance(IConfiguredInstance instance, IInstanceCreator instanceCreator)
- {
- return InnerInstanceFactory.GetInstance(instance, instanceCreator);
- }
-
- /// <summary>
- /// Creates a new object instance of the default instance memento
- /// </summary>
- /// <returns></returns>
- public virtual object GetInstance()
- {
- return InnerInstanceFactory.GetInstance();
- }
-
- /// <summary>
- /// Sets the default instance
- /// </summary>
- /// <param name="instanceKey"></param>
- public void SetDefault(string instanceKey)
- {
- InnerInstanceFactory.SetDefault(instanceKey);
- }
-
- /// <summary>
- /// Makes the InstanceMemento the basis of the default instance
- /// </summary>
- /// <param name="instance"></param>
- public void SetDefault(Instance instance)
- {
- InnerInstanceFactory.SetDefault(instance);
- }
-
- /// <summary>
- /// The InstanceKey of the default instance built by this IInstanceFactory
- /// </summary>
- public string DefaultInstanceKey
- {
- get { return InnerInstanceFactory.DefaultInstanceKey; }
- }
-
- public IList GetAllInstances()
- {
- return InnerInstanceFactory.GetAllInstances();
- }
-
- public void AddInstance(Instance instance)
- {
- InnerInstanceFactory.AddInstance(instance);
- }
-
- public Instance AddType<T>()
- {
- return InnerInstanceFactory.AddType<T>();
- }
-
- public Instance GetDefault()
- {
- return InnerInstanceFactory.GetDefault();
- }
-
-
- public virtual object ApplyInterception(object rawValue)
- {
- return InnerInstanceFactory.ApplyInterception(rawValue);
- }
-
- #endregion
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,46 +0,0 @@
-using System;
-using StructureMap.Attributes;
-using StructureMap.Graph;
-
-namespace StructureMap.Interceptors
-{
- [Obsolete]
- public class InterceptorChainBuilder : IInterceptorChainBuilder
- {
- public InterceptorChainBuilder()
- {
- }
-
- #region IInterceptorChainBuilder Members
-
- [Obsolete]
- public InterceptionChain Build(InstanceScope scope)
- {
- InterceptionChain returnValue = new InterceptionChain();
-
- switch (scope)
- {
- case (InstanceScope.HttpContext):
- returnValue.AddInterceptor(new HttpContextItemInterceptor());
- break;
-
- case (InstanceScope.Hybrid):
- returnValue.AddInterceptor(new HybridCacheInterceptor());
- break;
-
- case (InstanceScope.Singleton):
- returnValue.AddInterceptor(new SingletonInterceptor());
- break;
-
- case (InstanceScope.ThreadLocal):
- returnValue.AddInterceptor(new ThreadLocalStorageInterceptor());
- break;
- }
-
-
- return returnValue;
- }
-
- #endregion
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/SingletonInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/SingletonInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/SingletonInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,46 +0,0 @@
-using System.Collections;
-
-namespace StructureMap.Interceptors
-{
- /// <summary>
- /// The SingletonInterceptor is a GoF Decorator around an IInstanceFactory that ensures that
- /// only one instance is created for a given InstanceKey as a more testable alternative to
- /// the GoF Singleton pattern.
- /// </summary>
- [Pluggable("Singleton")]
- public class SingletonInterceptor : CacheInterceptor
- {
- private IDictionary _instances;
-
- [DefaultConstructor]
- public SingletonInterceptor() : this(new Hashtable())
- {
- }
-
- public SingletonInterceptor(IDictionary instances) : base()
- {
- _instances = instances;
- }
-
-
- protected override void cache(string instanceKey, object instance)
- {
- _instances.Add(instanceKey, instance);
- }
-
- protected override bool isCached(string instanceKey)
- {
- return _instances.Contains(instanceKey);
- }
-
- protected override object getInstance(string instanceKey)
- {
- return _instances[instanceKey];
- }
-
- public override object Clone()
- {
- return new SingletonInterceptor();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/ThreadLocalStorageInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/ThreadLocalStorageInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/ThreadLocalStorageInterceptor.cs 2008-04-26 01:...
[truncated message content] |
|
From: <jer...@us...> - 2008-04-29 04:19:22
|
Revision: 84
http://structuremap.svn.sourceforge.net/structuremap/?rev=84&view=rev
Author: jeremydmiller
Date: 2008-04-28 21:19:20 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
BIG REFACTORING. Rewrote the Profile/Machine/Defaults functionality. Simplified NormalGraphBuilder and InstanceFactory. Using the BuildPolicy now. Killed off the InstanceFactoryInterceptor
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/Graph/TypePath.cs
trunk/Source/StructureMap/IInstanceFactory.cs
trunk/Source/StructureMap/IInstanceManager.cs
trunk/Source/StructureMap/IPluginGraphSource.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/InstanceMemento.cs
trunk/Source/StructureMap/ObjectFactory.cs
trunk/Source/StructureMap/Pipeline/Instance.cs
trunk/Source/StructureMap/Pipeline/Profile.cs
trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs
trunk/Source/StructureMap/PluginGraphBuilder.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapConfiguration.cs
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs
trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs
trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs
trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs
trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs
trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs
trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs
trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs
trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs
trunk/Source/StructureMap.Testing/ObjectMother.cs
trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing/StructureMap.config
trunk/Source/StructureMap.Testing/TestData/DefaultProfileConfig.xml
trunk/Source/StructureMap.Testing/TestData/InlineInstanceInProfileAndMachine.xml
trunk/Source/StructureMap.Testing/TestData/ObjectMother.config
trunk/Source/StructureMap.Testing/TestData/SampleConfig.xml
trunk/Source/StructureMap.Testing/TestData/StructureMap.config
Added Paths:
-----------
trunk/Source/StructureMap/Configuration/ProfileBuilder.cs
trunk/Source/StructureMap/Pipeline/ProfileManager.cs
trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs
Removed Paths:
-------------
trunk/Source/StructureMap/Graph/InstanceDefault.cs
trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs
trunk/Source/StructureMap/Graph/MachineOverride.cs
trunk/Source/StructureMap/Graph/Profile.cs
trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Graph/OverrideGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/OverrideTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -31,22 +31,22 @@
return _parent;
}
- internal void Configure(Profile profile, PluginGraph graph)
+ internal void Configure(string profileName, PluginGraph pluginGraph)
{
- if (!string.IsNullOrEmpty(_instanceKey))
+ if (_instance != null)
{
- InstanceDefault instanceDefault = new InstanceDefault(_pluginType, _instanceKey);
- profile.AddOverride(instanceDefault);
+ _instanceKey = Profile.InstanceKeyForProfile(profileName);
+ _instance.Name = _instanceKey;
+ pluginGraph.LocateOrCreateFamilyForType(_pluginType).AddInstance(_instance);
}
- else if (_instance != null)
+ else if (!string.IsNullOrEmpty(_instanceKey))
{
- string defaultKey = Profile.InstanceKeyForProfile(profile.ProfileName);
-
- _instance.Name = defaultKey;
- graph.LocateOrCreateFamilyForType(_pluginType).AddInstance(_instance);
+ _instance = new ReferencedInstance(_instanceKey);
+ }
- InstanceDefault instanceDefault = new InstanceDefault(_pluginType, defaultKey);
- profile.AddOverride(instanceDefault);
+ if (_instance != null)
+ {
+ pluginGraph.ProfileManager.SetDefault(profileName, _pluginType, _instance);
}
else
{
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using StructureMap.Graph;
@@ -20,16 +21,9 @@
void IExpression.Configure(PluginGraph graph)
{
- Profile profile = graph.DefaultManager.GetProfile(_profileName);
- if (profile == null)
- {
- profile = new Profile(_profileName);
- graph.DefaultManager.AddProfile(profile);
- }
-
foreach (InstanceDefaultExpression expression in _defaults)
{
- expression.Configure(profile, graph);
+ expression.Configure(_profileName, graph);
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -94,7 +94,6 @@
public IInstanceManager BuildInstanceManager()
{
ConfigurePluginGraph(_graph);
- _graph.ReadDefaults();
return new InstanceManager(_graph);
}
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -34,7 +34,7 @@
public void ParseDefaultElement(XmlElement element)
{
- TypePath pluginTypePath = TypePath.GetTypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
+ TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
InstanceScope scope = findScope(element);
string name = element.GetAttribute(XmlConstants.NAME);
if (string.IsNullOrEmpty(name))
@@ -51,7 +51,7 @@
public void ParseInstanceElement(XmlElement element)
{
- TypePath pluginTypePath = TypePath.GetTypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
+ TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
InstanceScope scope = findScope(element);
InstanceMemento memento = _mementoCreator.CreateMemento(element);
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,3 +1,4 @@
+using System;
using StructureMap.Attributes;
using StructureMap.Graph;
@@ -3,12 +4,23 @@
namespace StructureMap.Configuration
{
+ public interface IProfileBuilder
+ {
+ void AddProfile(string profileName);
+ void OverrideProfile(TypePath typePath, string instanceKey);
+ void AddMachine(string machineName, string profileName);
+ void OverrideMachine(TypePath typePath, string instanceKey);
+ void SetDefaultProfileName(string profileName);
+ }
+
+
public interface IGraphBuilder
{
PluginGraph SystemGraph { get; }
- InstanceDefaultManager DefaultManager { get; }
PluginGraph PluginGraph { get; }
void AddAssembly(string assemblyName);
void StartFamilies();
+ void FinishFamilies();
+ PluginGraph CreatePluginGraph();
void AddPluginFamily(TypePath typePath, string defaultKey, InstanceScope scope);
@@ -19,17 +31,8 @@
SetterProperty AddSetter(TypePath pluginTypePath, string concreteKey, string setterName);
void AddInterceptor(TypePath pluginTypePath, InstanceMemento interceptorMemento);
- void FinishFamilies();
-
- PluginGraph CreatePluginGraph();
-
void RegisterMemento(TypePath pluginTypePath, InstanceMemento memento);
- void AddProfile(string profileName);
- void OverrideProfile(string fullTypeName, string instanceKey);
- void AddMachine(string machineName, string profileName);
- void OverrideMachine(string fullTypeName, string instanceKey);
-
- TypePath LocateOrCreateFamilyForType(string fullName);
+ IProfileBuilder GetProfileBuilder();
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,22 +1,20 @@
using System;
-using System.Diagnostics;
using System.Reflection;
using StructureMap.Attributes;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
-using StructureMap.Interceptors;
using StructureMap.Pipeline;
namespace StructureMap.Configuration
{
public class NormalGraphBuilder : IGraphBuilder
{
- private MachineOverride _machine;
- private PluginGraph _pluginGraph;
+ private readonly PluginGraph _pluginGraph;
+ private readonly PluginGraph _systemGraph;
private Profile _profile;
- private PluginGraph _systemGraph;
private InstanceManager _systemInstanceManager;
+
public NormalGraphBuilder(Registry[] registries)
{
_pluginGraph = new PluginGraph();
@@ -36,9 +34,8 @@
_pluginGraph.Seal();
}
- public PluginGraph CreatePluginGraph()
+ [Obsolete("Do away?")] public PluginGraph CreatePluginGraph()
{
- _pluginGraph.ReadDefaults();
return _pluginGraph;
}
@@ -52,50 +49,6 @@
get { return _pluginGraph; }
}
- public void AddProfile(string profileName)
- {
- _profile = new Profile(profileName);
- _pluginGraph.DefaultManager.AddProfile(_profile);
- }
-
- public void OverrideProfile(string fullTypeName, string instanceKey)
- {
- _profile.AddOverride(fullTypeName, instanceKey);
- }
-
- public void AddMachine(string machineName, string profileName)
- {
- if (string.IsNullOrEmpty(profileName))
- {
- _machine = new MachineOverride(machineName, null);
- }
- else
- {
- Profile profile = _pluginGraph.DefaultManager.GetProfile(profileName);
-
- if (profile == null)
- {
- _pluginGraph.Log.RegisterError(195, profileName, machineName);
- return;
- }
-
- _machine = new MachineOverride(machineName, profile);
- }
-
-
- _pluginGraph.DefaultManager.AddMachineOverride(_machine);
- }
-
- public void OverrideMachine(string fullTypeName, string instanceKey)
- {
- _machine.AddMachineOverride(fullTypeName, instanceKey);
- }
-
- public TypePath LocateOrCreateFamilyForType(string fullName)
- {
- return _pluginGraph.LocateOrCreateFamilyForType(fullName);
- }
-
public void AddAssembly(string assemblyName)
{
AssemblyGraph assemblyGraph = new AssemblyGraph(assemblyName);
@@ -181,7 +134,7 @@
{
IInstanceInterceptor interceptor =
(IInstanceInterceptor)
- buildSystemObject(typeof(IInstanceInterceptor), interceptorMemento);
+ buildSystemObject(typeof (IInstanceInterceptor), interceptorMemento);
family.AddInterceptor(interceptor);
}
@@ -191,17 +144,17 @@
}
}
- public InstanceDefaultManager DefaultManager
- {
- get { return _pluginGraph.DefaultManager; }
- }
-
public void RegisterMemento(TypePath pluginTypePath, InstanceMemento memento)
{
PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(pluginTypePath.FindType());
family.AddInstance(memento);
}
+ public IProfileBuilder GetProfileBuilder()
+ {
+ return new ProfileBuilder(_pluginGraph);
+ }
+
#endregion
private object buildSystemObject(Type type, InstanceMemento memento)
Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,20 +1,22 @@
using System;
using System.Xml;
using StructureMap.Graph;
+using StructureMap.Pipeline;
using StructureMap.Source;
namespace StructureMap.Configuration
{
- [Obsolete("This puppy needs to be rewritten")]
public class ProfileAndMachineParser
{
- private readonly IGraphBuilder _builder;
+ private readonly IProfileBuilder _profileBuilder;
+ private readonly IGraphBuilder _graphBuilder;
private readonly XmlMementoCreator _creator;
private readonly XmlNode _structureMapNode;
- public ProfileAndMachineParser(IGraphBuilder builder, XmlNode structureMapNode, XmlMementoCreator creator)
+ public ProfileAndMachineParser(IGraphBuilder graphBuilder, XmlNode structureMapNode, XmlMementoCreator creator)
{
- _builder = builder;
+ _profileBuilder = graphBuilder.GetProfileBuilder();
+ _graphBuilder = graphBuilder;
_structureMapNode = structureMapNode;
_creator = creator;
}
@@ -24,16 +26,16 @@
XmlNode defaultProfileNode = _structureMapNode.Attributes.GetNamedItem(XmlConstants.DEFAULT_PROFILE);
if (defaultProfileNode != null)
{
- _builder.DefaultManager.DefaultProfileName = defaultProfileNode.InnerText;
+ _profileBuilder.SetDefaultProfileName(defaultProfileNode.InnerText);
}
foreach (XmlElement profileElement in findNodes(XmlConstants.PROFILE_NODE))
{
string profileName = profileElement.GetAttribute(XmlConstants.NAME);
- _builder.AddProfile(profileName);
+ _profileBuilder.AddProfile(profileName);
writeOverrides(profileElement,
- delegate(string fullName, string defaultKey) { _builder.OverrideProfile(fullName, defaultKey); }, profileName);
+ delegate(string fullName, string defaultKey) { _profileBuilder.OverrideProfile(new TypePath(fullName), defaultKey); }, profileName);
}
foreach (XmlElement machineElement in findNodes(XmlConstants.MACHINE_NODE))
@@ -41,10 +43,10 @@
string machineName = machineElement.GetAttribute(XmlConstants.NAME);
string profileName = machineElement.GetAttribute(XmlConstants.PROFILE_NODE);
- _builder.AddMachine(machineName, profileName);
+ _profileBuilder.AddMachine(machineName, profileName);
writeOverrides(machineElement,
- delegate(string fullName, string defaultKey) { _builder.OverrideMachine(fullName, defaultKey); }, machineName);
+ delegate(string fullName, string defaultKey) { _profileBuilder.OverrideMachine(new TypePath(fullName), defaultKey); }, machineName);
}
}
@@ -80,8 +82,8 @@
InstanceMemento memento = _creator.CreateMemento(instanceElement);
memento.InstanceKey = key;
- TypePath familyPath = _builder.LocateOrCreateFamilyForType(fullName);
- _builder.RegisterMemento(familyPath, memento);
+ TypePath familyPath = new TypePath(fullName);
+ _graphBuilder.RegisterMemento(familyPath, memento);
function(fullName, key);
}
Added: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using StructureMap.Graph;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Configuration
+{
+ public class ProfileBuilder : IProfileBuilder
+ {
+ public static string GetMachineName()
+ {
+ string machineName = string.Empty;
+ try
+ {
+ machineName = Environment.MachineName.ToUpper();
+ }
+ finally
+ {
+ }
+
+ return machineName;
+ }
+
+ private readonly PluginGraph _pluginGraph;
+ private readonly string _machineName;
+ private string _lastProfile;
+ private bool _useMachineOverrides;
+ private readonly ProfileManager _profileManager;
+
+
+ public ProfileBuilder(PluginGraph pluginGraph, string machineName)
+ {
+ _pluginGraph = pluginGraph;
+ _profileManager = pluginGraph.ProfileManager;
+ _machineName = machineName;
+ }
+
+
+ public ProfileBuilder(PluginGraph pluginGraph)
+ : this(pluginGraph, GetMachineName())
+ {
+ }
+
+ public void AddProfile(string profileName)
+ {
+ _lastProfile = profileName;
+ }
+
+ public void OverrideProfile(TypePath typePath, string instanceKey)
+ {
+ // TODO: what if the Type cannot be found?
+
+ ReferencedInstance instance = new ReferencedInstance(instanceKey);
+ _profileManager.SetDefault(_lastProfile, typePath.FindType(), instance);
+ }
+
+ public void AddMachine(string machineName, string profileName)
+ {
+ _useMachineOverrides = machineName == _machineName;
+
+ if (_useMachineOverrides)
+ {
+ _profileManager.DefaultMachineProfileName = profileName;
+ }
+ }
+
+ public void OverrideMachine(TypePath typePath, string instanceKey)
+ {
+ if (!_useMachineOverrides)
+ {
+ return;
+ }
+
+ // TODO: what if the Type cannot be found?
+ ReferencedInstance instance = new ReferencedInstance(instanceKey);
+ _profileManager.SetMachineDefault(typePath.FindType(), instance);
+ }
+
+ public void SetDefaultProfileName(string profileName)
+ {
+ _profileManager.DefaultProfileName = profileName;
+ }
+ }
+}
Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using StructureMap.Pipeline;
namespace StructureMap.Graph
{
@@ -86,7 +87,7 @@
}
- public PluginFamily CreateTemplatedFamily(Type templatedType)
+ public PluginFamily CreateTemplatedFamily(Type templatedType, ProfileManager profileManager)
{
Type basicType = templatedType.GetGenericTypeDefinition();
@@ -95,6 +96,8 @@
PluginFamily basicFamily = _families[basicType];
Type[] templatedParameterTypes = templatedType.GetGenericArguments();
+ profileManager.CopyDefaults(basicType, templatedType);
+
return basicFamily.CreateTemplatedClone(templatedParameterTypes);
}
else
@@ -102,17 +105,5 @@
return null;
}
}
-
- public PluginFamily CreateTemplatedFamily(string pluginTypeName)
- {
- Type type = Type.GetType(pluginTypeName, true);
-
- if (!type.IsGenericType)
- {
- return null;
- }
-
- return CreateTemplatedFamily(type);
- }
}
}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Graph/InstanceDefault.cs
===================================================================
--- trunk/Source/StructureMap/Graph/InstanceDefault.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/InstanceDefault.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,66 +0,0 @@
-using System;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// Stores the default instance key for a PluginType. Member of the <see cref="Profile"/>
- /// and <see cref="MachineOverride"/> classes
- /// </summary>
- [Serializable]
- public class InstanceDefault : ICloneable
- {
- private string _defaultKey;
- private string _pluginTypeName;
-
- public InstanceDefault(string pluginTypeName, string defaultKey) : base()
- {
- _pluginTypeName = pluginTypeName;
- _defaultKey = defaultKey;
- }
-
- public InstanceDefault(Type pluginType, string defaultKey) : this(pluginType.FullName, defaultKey)
- {
- }
-
- public string PluginTypeName
- {
- get { return _pluginTypeName; }
- }
-
- /// <summary>
- /// Default instance key
- /// </summary>
- public string DefaultKey
- {
- get { return _defaultKey; }
- set { _defaultKey = value; }
- }
-
- #region ICloneable Members
-
- public object Clone()
- {
- object clone = MemberwiseClone();
- return clone;
- }
-
- #endregion
-
- public override bool Equals(object obj)
- {
- if (this == obj) return true;
- InstanceDefault instanceDefault = obj as InstanceDefault;
- if (instanceDefault == null) return false;
- return
- Equals(_pluginTypeName, instanceDefault._pluginTypeName) &&
- Equals(_defaultKey, instanceDefault._defaultKey);
- }
-
- public override int GetHashCode()
- {
- return
- (_pluginTypeName != null ? _pluginTypeName.GetHashCode() : 0) +
- 29*(_defaultKey != null ? _defaultKey.GetHashCode() : 0);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs
===================================================================
--- trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,231 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// Contains the logic rules to determine the default instances for a PluginGraph and/or
- /// InstanceManager for any combination of profile and machine name.
- /// </summary>
- [Serializable]
- [Obsolete] public class InstanceDefaultManager
- {
- private string _defaultProfileName = string.Empty;
- private List<InstanceDefault> _defaults;
- private Dictionary<string, MachineOverride> _machineOverrides;
- private Dictionary<string, Profile> _profiles;
-
- public InstanceDefaultManager() : base()
- {
- _defaults = new List<InstanceDefault>();
- _machineOverrides = new Dictionary<string, MachineOverride>();
- _profiles = new Dictionary<string, Profile>();
- }
-
- /// <summary>
- /// If defined, sets the default Profile to be used if no other profile
- /// is requested
- /// </summary>
- public string DefaultProfileName
- {
- get { return _defaultProfileName; }
- set { _defaultProfileName = value == null ? string.Empty : value; }
- }
-
- public Profile[] Profiles
- {
- get
- {
- Profile[] returnValue = new Profile[_profiles.Count];
- _profiles.Values.CopyTo(returnValue, 0);
- Array.Sort(returnValue);
- return returnValue;
- }
- }
-
- public MachineOverride[] MachineOverrides
- {
- get
- {
- MachineOverride[] returnValue = new MachineOverride[_machineOverrides.Count];
- _machineOverrides.Values.CopyTo(returnValue, 0);
- Array.Sort(returnValue);
- return returnValue;
- }
- }
-
- public static string GetMachineName()
- {
- string machineName = string.Empty;
- try
- {
- machineName = Environment.MachineName.ToUpper();
- }
- finally
- {
- }
-
- return machineName;
- }
-
- public void ReadDefaultsFromPluginGraph(PluginGraph graph)
- {
- _defaults = new List<InstanceDefault>();
-
- foreach (PluginFamily family in graph.PluginFamilies)
- {
- InstanceDefault instanceDefault = new InstanceDefault(family.PluginType, family.DefaultInstanceKey);
- _defaults.Add(instanceDefault);
- }
- }
-
-
- /// <summary>
- /// Adds the InstanceDefault from a PluginFamily
- /// </summary>
- /// <param name="instanceDefault"></param>
- public void AddPluginFamilyDefault(InstanceDefault instanceDefault)
- {
- _defaults.Add(instanceDefault);
- }
-
- /// <summary>
- /// Adds the InstanceDefault from a PluginFamily
- /// </summary>
- /// <param name="pluginTypeName"></param>
- /// <param name="defaultKey"></param>
- public void AddPluginFamilyDefault(string pluginTypeName, string defaultKey)
- {
- if (defaultKey == null)
- {
- defaultKey = string.Empty;
- }
-
- AddPluginFamilyDefault(new InstanceDefault(pluginTypeName, defaultKey));
- }
-
-
- /// <summary>
- /// Register a MachineOverride
- /// </summary>
- /// <param name="machine"></param>
- public void AddMachineOverride(MachineOverride machine)
- {
- _machineOverrides.Add(machine.MachineName, machine);
- }
-
- /// <summary>
- /// Register a Profile
- /// </summary>
- /// <param name="profile"></param>
- public void AddProfile(Profile profile)
- {
- _profiles.Add(profile.ProfileName, profile);
- }
-
- /// <summary>
- /// Fetches the named Profile
- /// </summary>
- /// <param name="profileName"></param>
- /// <returns></returns>
- public Profile GetProfile(string profileName)
- {
- if (!_profiles.ContainsKey(profileName))
- ...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-03 03:25:11
|
Revision: 85
http://structuremap.svn.sourceforge.net/structuremap/?rev=85&view=rev
Author: jeremydmiller
Date: 2008-05-02 20:24:24 -0700 (Fri, 02 May 2008)
Log Message:
-----------
refactoring PluginGraph and FamilyParser, deleting Caching
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs
trunk/Source/StructureMap/Configuration/ConfigurationParser.cs
trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
trunk/Source/StructureMap/Graph/AssemblyGraph.cs
trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/ObjectFactory.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/Profile.cs
trunk/Source/StructureMap/Source/XmlMementoCreator.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs
trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs
trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Removed Paths:
-------------
trunk/Source/StructureMap/Caching/
trunk/Source/StructureMap/Configuration/Problem.cs
trunk/Source/StructureMap/ObjectFactoryCacheCallback.cs
trunk/Source/StructureMap.Testing/Caching/
Modified: trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -1,6 +1,6 @@
namespace StructureMap.Configuration
{
- public class ConfigurationConstants
+ public static class ConfigurationConstants
{
public const string CONFIGURED_DEFAULT_KEY_CANNOT_BE_FOUND =
"The default instance key configured for this PluginFamily cannot be found";
@@ -45,9 +45,5 @@
public const string UNKNOWN_PLUGIN_PROBLEM = "Exception occured while attaching a Plugin to a PluginFamily";
public const string VALIDATION_METHOD_FAILURE = "A Validation Method Failed";
-
- private ConfigurationConstants()
- {
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -1,5 +1,6 @@
using System;
using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Xml;
using StructureMap.Graph;
@@ -14,15 +15,15 @@
public static ConfigurationParser[] GetParsers(XmlDocument document, string includePath)
{
XmlElement node = document.DocumentElement;
-
return GetParsers(node, includePath);
}
+ // TODO -- Clean up. Maybe use some Lambda magic with .Net 3.5?
public static ConfigurationParser[] GetParsers(XmlNode node, string includePath)
{
string folder = string.IsNullOrEmpty(includePath) ? string.Empty : Path.GetDirectoryName(includePath);
- ArrayList list = new ArrayList();
+ List<ConfigurationParser> list = new List<ConfigurationParser>();
list.Add(new ConfigurationParser(node));
@@ -38,6 +39,7 @@
if (fileName == string.Empty)
{
+ // TODO: get rid of throw, put on PluginGraph here
throw new ApplicationException("The File attribute on the Include node is required");
}
@@ -46,6 +48,7 @@
includedPath = Path.Combine(folder, fileName);
includedDoc.Load(includedPath);
+ // TODO: get rid of throw, put on PluginGraph here
ConfigurationParser parser = new ConfigurationParser(includedDoc.DocumentElement);
list.Add(parser);
}
@@ -57,10 +60,11 @@
}
catch (Exception ex)
{
+ // TODO: get rid of throw, put on PluginGraph here
throw new StructureMapException(100, includedPath, ex);
}
- return (ConfigurationParser[]) list.ToArray(typeof (ConfigurationParser));
+ return list.ToArray();
}
@@ -81,6 +85,8 @@
public ConfigurationParser(XmlNode structureMapNode)
{
_structureMapNode = structureMapNode;
+
+ // TODO: 3.5 cleanup with extension method
XmlMementoStyle mementoStyle = XmlMementoStyle.NodeNormalized;
@@ -121,7 +127,11 @@
foreach (XmlElement familyElement in familyNodes)
{
TypePath typePath = TypePath.CreateFromXmlNode(familyElement);
- attachInstances(typePath, familyElement, builder);
+
+ // TODO: Edge case if the PluginType cannot be found
+ Type pluginType = typePath.FindType();
+
+ attachInstances(pluginType, familyElement, builder);
}
}
@@ -166,7 +176,7 @@
}
- private void attachInstances(TypePath pluginTypePath, XmlElement familyElement, IGraphBuilder builder)
+ private void attachInstances(Type pluginType, XmlElement familyElement, IGraphBuilder builder)
{
foreach (XmlNode instanceNode in familyElement.ChildNodes)
{
@@ -176,7 +186,7 @@
}
InstanceMemento memento = _mementoCreator.CreateMemento(instanceNode);
- builder.RegisterMemento(pluginTypePath, memento);
+ builder.RegisterMemento(pluginType, memento);
}
}
Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -5,19 +5,20 @@
namespace StructureMap.Configuration
{
+ // TODO: 3.5 cleanup here
public delegate XmlNode FetchNodeDelegate();
public class ConfigurationParserCollection
{
- private List<FetchNodeDelegate> _fetchers = new List<FetchNodeDelegate>();
+ private readonly List<FetchNodeDelegate> _fetchers = new List<FetchNodeDelegate>();
private bool _ignoreDefaultFile = false;
- private List<string> _otherFiles = new List<string>();
- private bool _UseAndEnforceExistenceOfDefaultFile = false;
+ private readonly List<string> _otherFiles = new List<string>();
+ private bool _useAndEnforceExistenceOfDefaultFile = false;
public bool UseAndEnforceExistenceOfDefaultFile
{
- get { return _UseAndEnforceExistenceOfDefaultFile; }
- set { _UseAndEnforceExistenceOfDefaultFile = value; }
+ get { return _useAndEnforceExistenceOfDefaultFile; }
+ set { _useAndEnforceExistenceOfDefaultFile = value; }
}
@@ -33,7 +34,7 @@
// Pick up the configuration in the default StructureMap.config
string pathToStructureMapConfig = StructureMapConfiguration.GetStructureMapConfigurationPath();
- if ((_UseAndEnforceExistenceOfDefaultFile || File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile)
+ if (shouldUseStructureMapConfigFile(pathToStructureMapConfig))
{
addParsersFromFile(pathToStructureMapConfig, list);
}
@@ -52,6 +53,11 @@
return list.ToArray();
}
+ private bool shouldUseStructureMapConfigFile(string pathToStructureMapConfig)
+ {
+ return (_useAndEnforceExistenceOfDefaultFile || File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile;
+ }
+
private static void addParsersFromFile(string filename, List<ConfigurationParser> list)
{
try
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -28,7 +28,7 @@
void IExpression.Configure(PluginGraph graph)
{
- PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
+ PluginFamily family = graph.FindFamily(_pluginType);
family.SetScopeTo(_scope);
foreach (IExpression child in _children)
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -37,7 +37,7 @@
{
_instanceKey = Profile.InstanceKeyForProfile(profileName);
_instance.Name = _instanceKey;
- pluginGraph.LocateOrCreateFamilyForType(_pluginType).AddInstance(_instance);
+ pluginGraph.FindFamily(_pluginType).AddInstance(_instance);
}
else if (!string.IsNullOrEmpty(_instanceKey))
{
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -75,7 +75,7 @@
_registry.addExpression(delegate(PluginGraph pluginGraph)
{
PluginFamily family =
- pluginGraph.LocateOrCreateFamilyForType(typeof (PLUGINTYPE));
+ pluginGraph.FindFamily(typeof (PLUGINTYPE));
family.CanUseUnMarkedPlugins = true;
});
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -108,7 +108,7 @@
addExpression(delegate (PluginGraph pluginGraph)
{
- pluginGraph.LocateOrCreateFamilyForType(typeof(PLUGINTYPE)).AddInstance(instance);
+ pluginGraph.FindFamily(typeof(PLUGINTYPE)).AddInstance(instance);
});
return instance;
@@ -159,7 +159,7 @@
public LiteralInstance AddInstanceOf<PLUGINTYPE>(PLUGINTYPE target)
{
LiteralInstance literal = new LiteralInstance(target);
- _graph.LocateOrCreateFamilyForType(typeof(PLUGINTYPE)).AddInstance(literal);
+ _graph.FindFamily(typeof(PLUGINTYPE)).AddInstance(literal);
return literal;
}
@@ -173,7 +173,7 @@
public PrototypeInstance AddPrototypeInstanceOf<PLUGINTYPE>(PLUGINTYPE prototype)
{
PrototypeInstance expression = new PrototypeInstance((ICloneable) prototype);
- _graph.LocateOrCreateFamilyForType(typeof(PLUGINTYPE)).AddInstance(expression);
+ _graph.FindFamily(typeof(PLUGINTYPE)).AddInstance(expression);
return expression;
}
@@ -227,7 +227,7 @@
{
UserControlInstance instance = new UserControlInstance(url);
- PluginFamily family = _graph.LocateOrCreateFamilyForType(typeof (PLUGINTYPE));
+ PluginFamily family = _graph.FindFamily(typeof (PLUGINTYPE));
family.AddInstance(instance);
return instance;
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -17,24 +17,43 @@
_mementoCreator = mementoCreator;
}
+ // TODO: Standard way in this class to get a PluginType, Maybe more into IGraphBuilder
public void ParseFamily(XmlElement familyElement)
{
TypePath typePath = TypePath.CreateFromXmlNode(familyElement);
+
+ // TODO: throw error if PluginType cannot be found. Right here!
+ Type pluginType;
+ try
+ {
+ pluginType = typePath.FindType();
+ }
+ catch (Exception ex)
+ {
+ // TODO: put error in PluginGraph
+ throw new StructureMapException(103, ex, typePath.ClassName, typePath.AssemblyName);
+ }
+
+
string defaultKey = familyElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE);
-
InstanceScope scope = findScope(familyElement);
- _builder.AddPluginFamily(typePath, defaultKey, scope);
+ _builder.AddPluginFamily(pluginType, defaultKey, scope);
- attachMementoSource(familyElement, typePath);
- attachPlugins(typePath, familyElement);
- attachInterceptors(typePath, familyElement);
+ attachMementoSource(pluginType, familyElement);
+ attachPlugins(pluginType, familyElement);
+ attachInterceptors(pluginType, familyElement);
}
public void ParseDefaultElement(XmlElement element)
{
TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
+ // TODO: Gotta throw exception if the type cannot be found
+
+ Type pluginType = pluginTypePath.FindType();
+
+
InstanceScope scope = findScope(element);
string name = element.GetAttribute(XmlConstants.NAME);
if (string.IsNullOrEmpty(name))
@@ -45,18 +64,21 @@
InstanceMemento memento = _mementoCreator.CreateMemento(element);
memento.InstanceKey = name;
- _builder.AddPluginFamily(pluginTypePath, name, scope);
- _builder.RegisterMemento(pluginTypePath, memento);
+ _builder.AddPluginFamily(pluginType, name, scope);
+ _builder.RegisterMemento(pluginType, memento);
}
public void ParseInstanceElement(XmlElement element)
{
TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
+ // TODO: gotta throw if type cannot be found
+ Type pluginType = pluginTypePath.FindType();
+
InstanceScope scope = findScope(element);
InstanceMemento memento = _mementoCreator.CreateMemento(element);
- _builder.RegisterMemento(pluginTypePath, memento);
+ _builder.RegisterMemento(pluginType, memento);
}
private InstanceScope findScope(XmlElement familyElement)
@@ -72,35 +94,38 @@
return returnValue;
}
- private void attachMementoSource(XmlElement familyElement, TypePath pluginTypePath)
+ // TODO: change to many
+ private void attachMementoSource(Type pluginType, XmlElement familyElement)
{
XmlNode sourceNode = familyElement[XmlConstants.MEMENTO_SOURCE_NODE];
if (sourceNode != null)
{
InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(sourceNode);
- _builder.AttachSource(pluginTypePath, sourceMemento);
+ _builder.AttachSource(pluginType, sourceMemento);
}
}
- private void attachPlugins(TypePath pluginTypePath, XmlElement familyElement)
+ private void attachPlugins(Type pluginType, XmlElement familyElement)
{
+ // TODO: 3.5 lambda cleanup
XmlNodeList pluginNodes = familyElement.SelectNodes(XmlConstants.PLUGIN_NODE);
foreach (XmlElement pluginElement in pluginNodes)
{
TypePath pluginPath = TypePath.CreateFromXmlNode(pluginElement);
string concreteKey = pluginElement.GetAttribute(XmlConstants.CONCRETE_KEY_ATTRIBUTE);
- _builder.AddPlugin(pluginTypePath, pluginPath, concreteKey);
+ _builder.AddPlugin(pluginType, pluginPath, concreteKey);
foreach (XmlElement setterElement in pluginElement.ChildNodes)
{
string setterName = setterElement.GetAttribute("Name");
- _builder.AddSetter(pluginTypePath, concreteKey, setterName);
+ _builder.AddSetter(pluginType, concreteKey, setterName);
}
}
}
- private void attachInterceptors(TypePath pluginTypePath, XmlElement familyElement)
+ // TODO: 3.5 lambda cleanup
+ private void attachInterceptors(Type pluginType, XmlElement familyElement)
{
XmlNode interceptorChainNode = familyElement[XmlConstants.INTERCEPTORS_NODE];
if (interceptorChainNode == null)
@@ -111,7 +136,7 @@
foreach (XmlNode interceptorNode in interceptorChainNode.ChildNodes)
{
XmlAttributeInstanceMemento interceptorMemento = new XmlAttributeInstanceMemento(interceptorNode);
- _builder.AddInterceptor(pluginTypePath, interceptorMemento);
+ _builder.AddInterceptor(pluginType, interceptorMemento);
}
}
}
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -24,14 +24,14 @@
void FinishFamilies();
PluginGraph CreatePluginGraph();
- void AddPluginFamily(TypePath typePath, string defaultKey, InstanceScope scope);
- void AttachSource(TypePath pluginTypePath, InstanceMemento sourceMemento);
- void AttachSource(TypePath pluginTypePath, MementoSource source);
- Plugin AddPlugin(TypePath pluginTypePath, TypePath pluginPath, string concreteKey);
- SetterProperty AddSetter(TypePath pluginTypePath, string concreteKey, string setterName);
- void AddInterceptor(TypePath pluginTypePath, InstanceMemento interceptorMemento);
+ void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope);
+ void AttachSource(Type pluginType, InstanceMemento sourceMemento);
+ void AttachSource(Type pluginType, MementoSource source);
+ Plugin AddPlugin(Type pluginType, TypePath pluginPath, string concreteKey);
+ SetterProperty AddSetter(Type pluginType, string concreteKey, string setterName);
+ void AddInterceptor(Type pluginType, InstanceMemento interceptorMemento);
- void RegisterMemento(TypePath pluginTypePath, InstanceMemento memento);
+ void RegisterMemento(Type pluginType, InstanceMemento memento);
IProfileBuilder GetProfileBuilder();
}
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -65,52 +65,45 @@
_systemInstanceManager = new InstanceManager(_systemGraph);
}
- public void AddPluginFamily(TypePath typePath, string defaultKey, InstanceScope scope)
+ public void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope)
{
- Type pluginType;
- try
- {
- pluginType = typePath.FindType();
- }
- catch (Exception ex)
- {
- throw new StructureMapException(103, ex, typePath.ClassName, typePath.AssemblyName);
- }
+ PluginFamily family = _pluginGraph.FindFamily(pluginType);
-
- PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(pluginType);
-
// Xml configuration wins
family.DefaultInstanceKey = defaultKey;
family.SetScopeTo(scope);
}
- public virtual void AttachSource(TypePath pluginTypePath, InstanceMemento sourceMemento)
+ public virtual void AttachSource(Type pluginType, InstanceMemento sourceMemento)
{
try
{
MementoSource source = (MementoSource) buildSystemObject(typeof (MementoSource), sourceMemento);
- AttachSource(pluginTypePath, source);
+ AttachSource(pluginType, source);
}
catch (Exception ex)
{
- throw new StructureMapException(120, ex, pluginTypePath);
+ // TODO: put error in PluginGraph
+ throw new StructureMapException(120, ex, TypePath.GetAssemblyQualifiedName(pluginType));
}
}
- public void AttachSource(TypePath pluginTypePath, MementoSource source)
+ public void AttachSource(Type pluginType, MementoSource source)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
+ PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
family.AddMementoSource(source);
}
- public Plugin AddPlugin(TypePath pluginTypePath, TypePath pluginPath, string concreteKey)
+ public Plugin AddPlugin(Type pluginType, TypePath pluginPath, string concreteKey)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
+ // TODO: Make this go through PluginGraph.FindFamily()
+ PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
if (family == null)
{
string message =
- string.Format("Could not find a PluginFamily for {0}", pluginTypePath.AssemblyQualifiedName);
+ string.Format("Could not find a PluginFamily for {0}", pluginType.AssemblyQualifiedName);
+
+ // TODO: put error in PluginGraph
throw new ApplicationException(message);
}
@@ -120,16 +113,17 @@
return plugin;
}
- public SetterProperty AddSetter(TypePath pluginTypePath, string concreteKey, string setterName)
+ public SetterProperty AddSetter(Type pluginType, string concreteKey, string setterName)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
+ // TODO: Make this go through PluginGraph.FindFamily()
+ PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
Plugin plugin = family.Plugins[concreteKey];
return plugin.Setters.Add(setterName);
}
- public virtual void AddInterceptor(TypePath pluginTypePath, InstanceMemento interceptorMemento)
+ public virtual void AddInterceptor(Type pluginType, InstanceMemento interceptorMemento)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
+ PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
try
{
IInstanceInterceptor interceptor =
@@ -140,13 +134,14 @@
}
catch (Exception ex)
{
- throw new StructureMapException(121, ex, pluginTypePath);
+ // TODO: put error in PluginGraph
+ throw new StructureMapException(121, ex, TypePath.GetAssemblyQualifiedName(pluginType));
}
}
- public void RegisterMemento(TypePath pluginTypePath, InstanceMemento memento)
+ public void RegisterMemento(Type pluginType, InstanceMemento memento)
{
- PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(pluginTypePath.FindType());
+ PluginFamily family = _pluginGraph.FindFamily(pluginType);
family.AddInstance(memento);
}
Deleted: trunk/Source/StructureMap/Configuration/Problem.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/Problem.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/Problem.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -1,88 +0,0 @@
-using System;
-using System.Text;
-
-namespace StructureMap.Configuration
-{
- [Serializable]
- public class Problem
- {
- private string _message;
- private Guid _objectId = Guid.Empty;
- private string _path = string.Empty;
- private string _title;
-
- public Problem()
- {
- }
-
- public Problem(string title, string message)
- {
- _title = title;
- _message = message;
- }
-
- public Problem(string title, Exception ex)
- {
- _title = title;
-
- StringBuilder sb = new StringBuilder();
- Exception exception = ex;
- while (exception != null)
- {
- sb.Append("\n");
- sb.Append(exception.Message);
- sb.Append("\n");
- sb.Append(exception.StackTrace);
-
- exception = exception.InnerException;
- }
-
- _message = sb.ToString();
- }
-
- public string Path
- {
- get { return _path; }
- set { _path = value; }
- }
-
- public string Title
- {
- get { return _title; }
- set { _title = value; }
- }
-
- public string Message
- {
- get { return _message; }
- set { _message = value; }
- }
-
- public Guid ObjectId
- {
- get { return _objectId; }
- set { _objectId = value; }
- }
-
- public override string ToString()
- {
- return string.Format("Problem: {0}\n{1}", Title, Message);
- }
-
- public override bool Equals(object obj)
- {
- Problem peer = obj as Problem;
- if (peer == null)
- {
- return false;
- }
-
- return Title == peer.Title;
- }
-
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-05-03 03:24:24 UTC (rev 85)
@@ -6,6 +6,7 @@
namespace StructureMap.Configuration
{
+ // TODO: 3.5 cleanup
public class ProfileAndMachineParser
{
private readonly IProfileBuilder _profileBuilder;
@@ -23,6 +24,7 @@
public void Parse()
{
+ // TODO: 3.5 cleanup
XmlNode defaultProfileNode = _structureMapNode.Attributes.GetNamedItem(XmlConstants.DEFAULT_PROFILE);
if (defaultProfileNode != null)
{
@@ -83,8 +85,11 @@
memento.InstanceKey = key;
TypePath familyPath = new TypePath(fullName);
- _graphBuilder.RegisterMemento(familyPath, memento);
+ // TODO: failure point
+ Type pluginType = familyPath.FindType();
+ _graphBuilder.RegisterMemento(pluginType, memento);
+
function(fullName, key);
}
Modified: trunk/Source/StructureMap/Graph/AssemblyGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2008-04-29 04:19:20 UTC (rev 84)
+++ trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2008-05-0...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-03 03:52:31
|
Revision: 86
http://structuremap.svn.sourceforge.net/structuremap/?rev=86&view=rev
Author: jeremydmiller
Date: 2008-05-02 20:52:25 -0700 (Fri, 02 May 2008)
Log Message:
-----------
Added some behavior to NormalGraphBuilder in preparation for a big refactoring to come
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Diagnostics/Tokens.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 03:24:24 UTC (rev 85)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 03:52:25 UTC (rev 86)
@@ -24,15 +24,20 @@
void FinishFamilies();
PluginGraph CreatePluginGraph();
+
+ // All of these need to DIE!
void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope);
void AttachSource(Type pluginType, InstanceMemento sourceMemento);
void AttachSource(Type pluginType, MementoSource source);
Plugin AddPlugin(Type pluginType, TypePath pluginPath, string concreteKey);
SetterProperty AddSetter(Type pluginType, string concreteKey, string setterName);
void AddInterceptor(Type pluginType, InstanceMemento interceptorMemento);
-
void RegisterMemento(Type pluginType, InstanceMemento memento);
+
+
IProfileBuilder GetProfileBuilder();
+
+ void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action);
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 03:24:24 UTC (rev 85)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 03:52:25 UTC (rev 86)
@@ -7,6 +7,9 @@
namespace StructureMap.Configuration
{
+ // TODO: Kill in 3.5
+ public delegate void Action<T>(T subject);
+
public class NormalGraphBuilder : IGraphBuilder
{
private readonly PluginGraph _pluginGraph;
@@ -150,6 +153,20 @@
return new ProfileBuilder(_pluginGraph);
}
+ public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
+ {
+ try
+ {
+ Type pluginType = pluginTypePath.FindType();
+ PluginFamily family = _pluginGraph.FindFamily(pluginType);
+ action(family);
+ }
+ catch (Exception ex)
+ {
+ _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.ClassName, pluginTypePath.AssemblyName);
+ }
+ }
+
#endregion
private object buildSystemObject(Type type, InstanceMemento memento)
Modified: trunk/Source/StructureMap/Diagnostics/Tokens.cs
===================================================================
--- trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-03 03:24:24 UTC (rev 85)
+++ trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-03 03:52:25 UTC (rev 86)
@@ -33,6 +33,13 @@
addError(error);
}
+ public void RegisterError(int code, Exception ex, params object[] args)
+ {
+ Error error = new Error(code, ex, args);
+ addError(error);
+ }
+
+
private void addError(Error error)
{
error.Source = _currentSource;
@@ -53,6 +60,19 @@
throw new ApplicationException(msg);
}
}
+
+ public void AssertHasError(int errorCode)
+ {
+ foreach (Error error in _errors)
+ {
+ if (error.Code == errorCode)
+ {
+ return;
+ }
+ }
+
+ throw new ApplicationException("No error with code " + errorCode);
+ }
}
public class Source
@@ -213,6 +233,18 @@
_message = string.Format(template, args);
}
+ public Error(int errorCode, Exception ex, params object[] args) : this(errorCode, args)
+ {
+ _message += "\n\n" + ex.ToString();
+ _stackTrace = ex.StackTrace;
+ }
+
+
+ public int Code
+ {
+ get { return _code; }
+ }
+
public Error(StructureMapException exception)
{
_code = exception.ErrorCode;
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-03 03:24:24 UTC (rev 85)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-03 03:52:25 UTC (rev 86)
@@ -180,6 +180,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Configuration\InlineInstanceDefinitionInProfileAndMachineNodesTester.cs" />
+ <Compile Include="Configuration\NormalGraphBuilderTester.cs" />
<Compile Include="Configuration\ProfileBuilderTester.cs" />
<Compile Include="Configuration\ShortcuttedInstanceNodeTester.cs" />
<Compile Include="Container\ArrayConstructorTester.cs">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-05-03 04:15:53
|
Revision: 87
http://structuremap.svn.sourceforge.net/structuremap/?rev=87&view=rev
Author: jeremydmiller
Date: 2008-05-02 21:15:51 -0700 (Fri, 02 May 2008)
Log Message:
-----------
More refactoring for the family parsing
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs
trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-03 03:52:25 UTC (rev 86)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-03 04:15:51 UTC (rev 87)
@@ -21,29 +21,20 @@
public void ParseFamily(XmlElement familyElement)
{
TypePath typePath = TypePath.CreateFromXmlNode(familyElement);
+ _builder.ConfigureFamily(typePath, delegate(PluginFamily family)
+ {
+ family.DefaultInstanceKey =
+ familyElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE);
- // TODO: throw error if PluginType cannot be found. Right here!
- Type pluginType;
- try
- {
- pluginType = typePath.FindType();
- }
- catch (Exception ex)
- {
- // TODO: put error in PluginGraph
- throw new StructureMapException(103, ex, typePath.ClassName, typePath.AssemblyName);
- }
+ InstanceScope scope = findScope(familyElement);
+ family.SetScopeTo(scope);
-
- string defaultKey = familyElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE);
-
- InstanceScope scope = findScope(familyElement);
-
- _builder.AddPluginFamily(pluginType, defaultKey, scope);
-
- attachMementoSource(pluginType, familyElement);
- attachPlugins(pluginType, familyElement);
- attachInterceptors(pluginType, familyElement);
+ // TODO: Very temporary
+ Type pluginType = family.PluginType;
+ attachMementoSource(pluginType, familyElement);
+ attachPlugins(pluginType, familyElement);
+ attachInterceptors(pluginType, familyElement);
+ });
}
public void ParseDefaultElement(XmlElement element)
@@ -51,21 +42,29 @@
TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
// TODO: Gotta throw exception if the type cannot be found
- Type pluginType = pluginTypePath.FindType();
+ _builder.ConfigureFamily(pluginTypePath,
+ delegate(PluginFamily family)
+ {
+ // TODO: there's a little duplication here
+ InstanceScope scope = findScope(element);
+ family.SetScopeTo(scope);
- InstanceScope scope = findScope(element);
- string name = element.GetAttribute(XmlConstants.NAME);
- if (string.IsNullOrEmpty(name))
- {
- name = "DefaultInstanceOf" + pluginTypePath.AssemblyQualifiedName;
- }
+ Type pluginType = family.PluginType;
- InstanceMemento memento = _mementoCreator.CreateMemento(element);
- memento.InstanceKey = name;
+ string name = element.GetAttribute(XmlConstants.NAME);
+ if (string.IsNullOrEmpty(name))
+ {
+ name = "DefaultInstanceOf" + pluginTypePath.AssemblyQualifiedName;
+ }
- _builder.AddPluginFamily(pluginType, name, scope);
- _builder.RegisterMemento(pluginType, memento);
+ InstanceMemento memento = _mementoCreator.CreateMemento(element);
+ memento.InstanceKey = name;
+
+ family.DefaultInstanceKey = name;
+
+ _builder.RegisterMemento(pluginType, memento);
+ });
}
public void ParseInstanceElement(XmlElement element)
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 03:52:25 UTC (rev 86)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 04:15:51 UTC (rev 87)
@@ -26,7 +26,7 @@
// All of these need to DIE!
- void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope);
+ //void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope);
void AttachSource(Type pluginType, InstanceMemento sourceMemento);
void AttachSource(Type pluginType, MementoSource source);
Plugin AddPlugin(Type pluginType, TypePath pluginPath, string concreteKey);
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 03:52:25 UTC (rev 86)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 04:15:51 UTC (rev 87)
@@ -68,14 +68,15 @@
_systemInstanceManager = new InstanceManager(_systemGraph);
}
- public void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope)
- {
- PluginFamily family = _pluginGraph.FindFamily(pluginType);
+ // TODO: Cleanup
+ //public void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope)
+ //{
+ // PluginFamily family = _pluginGraph.FindFamily(pluginType);
- // Xml configuration wins
- family.DefaultInstanceKey = defaultKey;
- family.SetScopeTo(scope);
- }
+ // // Xml configuration wins
+ // family.DefaultInstanceKey = defaultKey;
+ // family.SetScopeTo(scope);
+ //}
public virtual void AttachSource(Type pluginType, InstanceMemento sourceMemento)
{
Modified: trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs 2008-05-03 03:52:25 UTC (rev 86)
+++ trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs 2008-05-03 04:15:51 UTC (rev 87)
@@ -4,7 +4,9 @@
using NUnit.Framework;
using StructureMap.Attributes;
using StructureMap.Configuration;
+using StructureMap.Configuration.DSL;
using StructureMap.Graph;
+using StructureMap.Pipeline;
using StructureMap.Source;
using StructureMap.Testing.Widget3;
@@ -18,9 +20,11 @@
[SetUp]
public void SetUp()
{
- _builderMock = new DynamicMock(typeof (IGraphBuilder));
+ NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]);
+ _graph = builder.PluginGraph;
+
_parser =
- new FamilyParser((IGraphBuilder) _builderMock.MockInstance,
+ new FamilyParser(builder,
new XmlMementoCreator(XmlMementoStyle.NodeNormalized, XmlConstants.TYPE_ATTRIBUTE,
XmlConstants.ATTRIBUTE_STYLE));
@@ -35,21 +39,25 @@
#endregion
- private DynamicMock _builderMock;
private FamilyParser _parser;
private XmlDocument _document;
private XmlElement _familyElement;
private Type thePluginType;
+ private PluginGraph _graph;
+ private void assertThatTheFamilyPolicyIs<T>()
+ {
+ _parser.ParseFamily(_familyElement);
+ PluginFamily family = _graph.FindFamily(thePluginType);
+ Assert.IsInstanceOfType(typeof(T), family.Policy);
+ }
+
+
[Test]
public void ScopeIsBlank()
{
- _builderMock.Expect("AddPluginFamily", thePluginType, string.Empty, InstanceScope.PerRequest);
-
- _parser.ParseFamily(_familyElement);
-
- _builderMock.Verify();
+ assertThatTheFamilyPolicyIs<BuildPolicy>();
}
@@ -57,11 +65,7 @@
public void ScopeIsBlank2()
{
_familyElement.SetAttribute(XmlConstants.SCOPE_ATTRIBUTE, "");
- _builderMock.Expect("AddPluginFamily", thePluginType, string.Empty, InstanceScope.PerRequest);
-
- _parser.ParseFamily(_familyElement);
-
- _builderMock.Verify();
+ assertThatTheFamilyPolicyIs<BuildPolicy>();
}
@@ -69,11 +73,7 @@
public void ScopeIsSingleton()
{
_familyElement.SetAttribute(XmlConstants.SCOPE_ATTRIBUTE, InstanceScope.Singleton.ToString());
- _builderMock.Expect("AddPluginFamily", thePluginType, string.Empty, InstanceScope.Singleton);
-
- _parser.ParseFamily(_familyElement);
-
- _builderMock.Verify();
+ assertThatTheFamilyPolicyIs<SingletonPolicy>();
}
@@ -81,11 +81,7 @@
public void ScopeIsThreadLocal()
{
_familyElement.SetAttribute(XmlConstants.SCOPE_ATTRIBUTE, InstanceScope.ThreadLocal.ToString());
- _builderMock.Expect("AddPluginFamily", thePluginType, string.Empty, InstanceScope.ThreadLocal);
-
- _parser.ParseFamily(_familyElement);
-
- _builderMock.Verify();
+ assertThatTheFamilyPolicyIs<ThreadLocalStoragePolicy>();
}
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs 2008-05-03 03:52:25 UTC (rev 86)
+++ trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs 2008-05-03 04:15:51 UTC (rev 87)
@@ -6,7 +6,7 @@
namespace StructureMap.Testing.Container.ExceptionHandling
{
- [TestFixture]
+ [TestFixture, Ignore("Busted at the moment")]
public class StructureMapExceptionTester
{
#region Setup/Teardown
Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-03 03:52:25 UTC (rev 86)
+++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-03 04:15:51 UTC (rev 87)
@@ -39,7 +39,8 @@
{
NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]);
Type thePluginType = typeof (IGateway);
- builder.AddPluginFamily(thePluginType, _memento.InstanceKey, InstanceScope.PerRequest);
+ PluginFamily family = builder.PluginGraph.FindFamily(thePluginType);
+ family.DefaultInstanceKey = _memento.InstanceKey;
builder.RegisterMemento(thePluginType, _memento);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-05-03 17:52:07
|
Revision: 88
http://structuremap.svn.sourceforge.net/structuremap/?rev=88&view=rev
Author: jeremydmiller
Date: 2008-05-03 10:52:03 -0700 (Sat, 03 May 2008)
Log Message:
-----------
cleaning up NormalGraphBuilder
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/ConfigurationParser.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -128,10 +128,12 @@
{
TypePath typePath = TypePath.CreateFromXmlNode(familyElement);
- // TODO: Edge case if the PluginType cannot be found
- Type pluginType = typePath.FindType();
+ builder.ConfigureFamily(typePath, delegate(PluginFamily family)
+ {
+ attachInstances(family, familyElement, builder);
+ });
- attachInstances(pluginType, familyElement, builder);
+
}
}
@@ -176,7 +178,7 @@
}
- private void attachInstances(Type pluginType, XmlElement familyElement, IGraphBuilder builder)
+ private void attachInstances(PluginFamily family, XmlElement familyElement, IGraphBuilder builder)
{
foreach (XmlNode instanceNode in familyElement.ChildNodes)
{
@@ -186,7 +188,7 @@
}
InstanceMemento memento = _mementoCreator.CreateMemento(instanceNode);
- builder.RegisterMemento(pluginType, memento);
+ family.AddInstance(memento);
}
}
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -2,6 +2,8 @@
using System.Xml;
using StructureMap.Attributes;
using StructureMap.Graph;
+using StructureMap.Interceptors;
+using StructureMap.Pipeline;
using StructureMap.Source;
namespace StructureMap.Configuration
@@ -29,11 +31,9 @@
InstanceScope scope = findScope(familyElement);
family.SetScopeTo(scope);
- // TODO: Very temporary
- Type pluginType = family.PluginType;
- attachMementoSource(pluginType, familyElement);
- attachPlugins(pluginType, familyElement);
- attachInterceptors(pluginType, familyElement);
+ attachMementoSource(family, familyElement);
+ attachPlugins(family, familyElement);
+ attachInterceptors(family, familyElement);
});
}
@@ -63,21 +63,19 @@
family.DefaultInstanceKey = name;
- _builder.RegisterMemento(pluginType, memento);
+ family.AddInstance(memento);
});
}
public void ParseInstanceElement(XmlElement element)
{
TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
- // TODO: gotta throw if type cannot be found
- Type pluginType = pluginTypePath.FindType();
-
- InstanceScope scope = findScope(element);
-
- InstanceMemento memento = _mementoCreator.CreateMemento(element);
-
- _builder.RegisterMemento(pluginType, memento);
+
+ _builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family)
+ {
+ InstanceMemento memento = _mementoCreator.CreateMemento(element);
+ family.AddInstance(memento);
+ });
}
private InstanceScope findScope(XmlElement familyElement)
@@ -94,17 +92,24 @@
}
// TODO: change to many
- private void attachMementoSource(Type pluginType, XmlElement familyElement)
+ private void attachMementoSource(PluginFamily family, XmlElement familyElement)
{
XmlNode sourceNode = familyElement[XmlConstants.MEMENTO_SOURCE_NODE];
if (sourceNode != null)
{
InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(sourceNode);
- _builder.AttachSource(pluginType, sourceMemento);
+
+ string context = "MementoSource for " + TypePath.GetAssemblyQualifiedName(family.PluginType);
+ _builder.WithSystemObject<MementoSource>(sourceMemento, context, delegate (MementoSource source)
+ {
+ family.AddMementoSource(source);
+ });
+
+
}
}
- private void attachPlugins(Type pluginType, XmlElement familyElement)
+ private void attachPlugins(PluginFamily family, XmlElement familyElement)
{
// TODO: 3.5 lambda cleanup
XmlNodeList pluginNodes = familyElement.SelectNodes(XmlConstants.PLUGIN_NODE);
@@ -113,18 +118,26 @@
TypePath pluginPath = TypePath.CreateFromXmlNode(pluginElement);
string concreteKey = pluginElement.GetAttribute(XmlConstants.CONCRETE_KEY_ATTRIBUTE);
- _builder.AddPlugin(pluginType, pluginPath, concreteKey);
+ string context = "creating a Plugin for " + family.PluginTypeName;
+ _builder.WithType(pluginPath, context, delegate(Type pluggedType)
+ {
+ Plugin plugin =
+ Plugin.CreateExplicitPlugin(pluggedType, concreteKey, "");
+ family.Plugins.Add(plugin);
- foreach (XmlElement setterElement in pluginElement.ChildNodes)
- {
- string setterName = setterElement.GetAttribute("Name");
- _builder.AddSetter(pluginType, concreteKey, setterName);
- }
+ foreach (XmlElement setterElement in pluginElement.ChildNodes)
+ {
+ string setterName = setterElement.GetAttribute("Name");
+ plugin.Setters.Add(setterName);
+ }
+ });
+
+
}
}
// TODO: 3.5 lambda cleanup
- private void attachInterceptors(Type pluginType, XmlElement familyElement)
+ private void attachInterceptors(PluginFamily family, XmlElement familyElement)
{
XmlNode interceptorChainNode = familyElement[XmlConstants.INTERCEPTORS_NODE];
if (interceptorChainNode == null)
@@ -132,10 +145,17 @@
return;
}
+ string context = "Creating an InstanceInterceptor for " + TypePath.GetAssemblyQualifiedName(family.PluginType);
foreach (XmlNode interceptorNode in interceptorChainNode.ChildNodes)
{
XmlAttributeInstanceMemento interceptorMemento = new XmlAttributeInstanceMemento(interceptorNode);
- _builder.AddInterceptor(pluginType, interceptorMemento);
+
+
+ _builder.WithSystemObject<IInstanceInterceptor>(interceptorMemento, context, delegate(IInstanceInterceptor interceptor)
+ {
+ family.AddInterceptor(interceptor);
+ });
+
}
}
}
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -24,20 +24,12 @@
void FinishFamilies();
PluginGraph CreatePluginGraph();
-
- // All of these need to DIE!
- //void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope);
- void AttachSource(Type pluginType, InstanceMemento sourceMemento);
- void AttachSource(Type pluginType, MementoSource source);
- Plugin AddPlugin(Type pluginType, TypePath pluginPath, string concreteKey);
- SetterProperty AddSetter(Type pluginType, string concreteKey, string setterName);
- void AddInterceptor(Type pluginType, InstanceMemento interceptorMemento);
- void RegisterMemento(Type pluginType, InstanceMemento memento);
-
-
-
IProfileBuilder GetProfileBuilder();
void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action);
+
+ void WithSystemObject<T>(InstanceMemento memento, string context, Action<T> action);
+ void WithType(TypePath path, string context, Action<Type> action);
}
+
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -64,116 +64,69 @@
public void StartFamilies()
{
+ // TODO: is this a problem here?
_systemGraph.Seal();
- _systemInstanceManager = new InstanceManager(_systemGraph);
}
- // TODO: Cleanup
- //public void AddPluginFamily(Type pluginType, string defaultKey, InstanceScope scope)
- //{
- // PluginFamily family = _pluginGraph.FindFamily(pluginType);
+ public IProfileBuilder GetProfileBuilder()
+ {
+ return new ProfileBuilder(_pluginGraph);
+ }
- // // Xml configuration wins
- // family.DefaultInstanceKey = defaultKey;
- // family.SetScopeTo(scope);
- //}
-
- public virtual void AttachSource(Type pluginType, InstanceMemento sourceMemento)
+ public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
{
try
{
- MementoSource source = (MementoSource) buildSystemObject(typeof (MementoSource), sourceMemento);
- AttachSource(pluginType, source);
+ Type pluginType = pluginTypePath.FindType();
+ PluginFamily family = _pluginGraph.FindFamily(pluginType);
+ action(family);
}
catch (Exception ex)
{
- // TODO: put error in PluginGraph
- throw new StructureMapException(120, ex, TypePath.GetAssemblyQualifiedName(pluginType));
+ _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.ClassName, pluginTypePath.AssemblyName);
}
}
- public void AttachSource(Type pluginType, MementoSource source)
- {
- PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
- family.AddMementoSource(source);
- }
+ #endregion
- public Plugin AddPlugin(Type pluginType, TypePath pluginPath, string concreteKey)
+ private object buildSystemObject(Type type, InstanceMemento memento)
{
- // TODO: Make this go through PluginGraph.FindFamily()
- PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
- if (family == null)
- {
- string message =
- string.Format("Could not find a PluginFamily for {0}", pluginType.AssemblyQualifiedName);
+ Instance instance = memento.ReadInstance(_systemGraph, type);
- // TODO: put error in PluginGraph
- throw new ApplicationException(message);
+ if (_systemInstanceManager == null)
+ {
+ _systemInstanceManager = new InstanceManager(_systemGraph);
}
- Plugin plugin = new Plugin(pluginPath, concreteKey);
- family.Plugins.Add(plugin);
-
- return plugin;
+ return _systemInstanceManager.CreateInstance(type, instance);
}
- public SetterProperty AddSetter(Type pluginType, string concreteKey, string setterName)
- {
- // TODO: Make this go through PluginGraph.FindFamily()
- PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
- Plugin plugin = family.Plugins[concreteKey];
- return plugin.Setters.Add(setterName);
- }
- public virtual void AddInterceptor(Type pluginType, InstanceMemento interceptorMemento)
+ public void WithSystemObject<T>(InstanceMemento memento, string context, Action<T> action)
{
- PluginFamily family = _pluginGraph.PluginFamilies[pluginType];
try
{
- IInstanceInterceptor interceptor =
- (IInstanceInterceptor)
- buildSystemObject(typeof (IInstanceInterceptor), interceptorMemento);
-
- family.AddInterceptor(interceptor);
+ T systemObject = (T) buildSystemObject(typeof (T), memento);
+ action(systemObject);
}
catch (Exception ex)
{
- // TODO: put error in PluginGraph
- throw new StructureMapException(121, ex, TypePath.GetAssemblyQualifiedName(pluginType));
+ _pluginGraph.Log.RegisterError(130, ex, context);
}
}
- public void RegisterMemento(Type pluginType, InstanceMemento memento)
- {
- PluginFamily family = _pluginGraph.FindFamily(pluginType);
- family.AddInstance(memento);
- }
- public IProfileBuilder GetProfileBuilder()
+ public void WithType(TypePath path, string context, Action<Type> action)
{
- return new ProfileBuilder(_pluginGraph);
- }
-
- public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
- {
try
{
- Type pluginType = pluginTypePath.FindType();
- PluginFamily family = _pluginGraph.FindFamily(pluginType);
- action(family);
+ Type type = path.FindType();
+ action(type);
}
catch (Exception ex)
{
- _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.ClassName, pluginTypePath.AssemblyName);
+ _pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context);
}
}
-
- #endregion
-
- private object buildSystemObject(Type type, InstanceMemento memento)
- {
- Instance instance = memento.ReadInstance(_systemGraph, type);
- return _systemInstanceManager.CreateInstance(type, instance);
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -85,12 +85,15 @@
memento.InstanceKey = key;
TypePath familyPath = new TypePath(fullName);
- // TODO: failure point
- Type pluginType = familyPath.FindType();
- _graphBuilder.RegisterMemento(pluginType, memento);
+ _graphBuilder.ConfigureFamily(familyPath, delegate(PluginFamily family)
+ {
+ family.AddInstance(memento);
+ function(fullName, key);
+ });
- function(fullName, key);
+
+
}
private XmlNodeList findNodes(string nodeName)
Modified: trunk/Source/StructureMap/StructureMapException.resx
===================================================================
--- trunk/Source/StructureMap/StructureMapException.resx 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap/StructureMapException.resx 2008-05-03 17:52:03 UTC (rev 88)
@@ -267,4 +267,10 @@
<data name="107" xml:space="preserve">
<value>Type named {0} cannot be resolved. Make sure the type is defined in Assembly Qualified Name form</value>
</data>
+ <data name="130" xml:space="preserve">
+ <value>System object for {0} could not be created</value>
+ </data>
+ <data name="131" xml:space="preserve">
+ <value>Requested type {0} could not be found while {1}</value>
+ </data>
</root>
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-03 04:15:51 UTC (rev 87)
+++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-03 17:52:03 UTC (rev 88)
@@ -42,7 +42,7 @@
PluginFamily family = builder.PluginGraph.FindFamily(thePluginType);
family.DefaultInstanceKey = _memento.InstanceKey;
- builder.RegisterMemento(thePluginType, _memento);
+ family.AddInstance(_memento);
PluginGraph graph = builder.CreatePluginGraph();
InstanceManager manager = new InstanceManager(graph);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-05-04 01:11:32
|
Revision: 89
http://structuremap.svn.sourceforge.net/structuremap/?rev=89&view=rev
Author: jeremydmiller
Date: 2008-05-03 18:11:30 -0700 (Sat, 03 May 2008)
Log Message:
-----------
Cutting the ties to PluginFamilyCollection to eliminate it
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs
trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs
trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs
trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs
trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs
trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
trunk/Source/StructureMap.Testing/ObjectMother.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -154,6 +154,12 @@
public static PluginFamily CreatePluginFamily(Type exportedType)
{
PluginFamilyAttribute att = GetAttribute(exportedType);
+
+ if (att == null)
+ {
+ return new PluginFamily(exportedType);
+ }
+
PluginFamily family = att.BuildPluginFamily(exportedType);
return family;
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -41,8 +41,6 @@
alteration(family);
}
- graph.PluginFamilies.Add(family);
-
AssemblyGraph assembly = new AssemblyGraph(_pluginType.Assembly);
graph.Assemblies.Add(assembly);
}
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -62,6 +62,7 @@
public PluginFamily(Type pluginType) :
this(pluginType, PluginFamilyAttribute.GetDefaultKey(pluginType))
{
+ // TODO -- Merge functionality with PluginFamilyAttribute
PluginFamilyAttribute attribute = PluginFamilyAttribute.GetAttribute(pluginType);
if (attribute != null)
{
Modified: trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -71,21 +71,7 @@
get { return _pluginFamilies.Count; }
}
- public PluginFamily Add(Type pluginType, string defaultInstanceKey)
- {
- PluginFamily family = new PluginFamily(pluginType, defaultInstanceKey);
- return Add(family);
- }
- public PluginFamily Add(Type pluginType)
- {
- PluginFamilyAttribute att = PluginFamilyAttribute.GetAttribute(pluginType);
- PluginFamily family = att == null ? new PluginFamily(pluginType) : att.BuildPluginFamily(pluginType);
- Add(family);
-
- return family;
- }
-
public PluginFamily Add(PluginFamily family)
{
family.Parent = _pluginGraph;
Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -71,6 +71,11 @@
get { return _interceptorLibrary; }
}
+ public int FamilyCount
+ {
+ get { return _pluginFamilies.Count; }
+ }
+
/// <summary>
/// Closes the PluginGraph for adding or removing members. Searches all of the
/// AssemblyGraph's for implicit Plugin and PluginFamily's
@@ -164,7 +169,8 @@
{
if (!_pluginFamilies.Contains(pluginType))
{
- PluginFamily family = _pluginFamilies.Add(pluginType);
+ PluginFamily family = PluginFamilyAttribute.CreatePluginFamily(pluginType);
+ _pluginFamilies.Add(family);
attachImplicitPlugins(family);
}
}
@@ -174,5 +180,10 @@
buildFamilyIfMissing(pluginType);
return PluginFamilies[pluginType];
}
+
+ public bool ContainsFamily(Type pluginType)
+ {
+ return _pluginFamilies.Contains(pluginType);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -73,7 +73,7 @@
Assert.IsNotNull(expression);
}
- PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)];
+ PluginFamily family = pluginGraph.FindFamily(typeof (IGateway));
Assert.IsInstanceOfType(typeof(ThreadLocalStoragePolicy), family.Policy);
}
@@ -86,7 +86,7 @@
registry.BuildInstancesOf<IGateway>();
}
- Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>());
+ Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway)));
}
@@ -101,7 +101,7 @@
Assert.IsNotNull(expression);
}
- PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)];
+ PluginFamily family = pluginGraph.FindFamily(typeof (IGateway));
Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
}
@@ -116,7 +116,7 @@
Assert.IsNotNull(expression);
}
- PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)];
+ PluginFamily family = pluginGraph.FindFamily(typeof (IGateway));
Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy);
}
@@ -130,7 +130,7 @@
registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<StubbedGateway>();
}
- Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>());
+ Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway)));
InstanceManager manager = new InstanceManager(pluginGraph);
IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway));
@@ -147,7 +147,7 @@
registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<FakeGateway>();
}
- Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>());
+ Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway)));
InstanceManager manager = new InstanceManager(pluginGraph);
IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway));
@@ -180,7 +180,7 @@
registry.BuildInstancesOf<IGateway>().InterceptConstructionWith(factoryInterceptor);
}
- Assert.AreSame(pluginGraph.PluginFamilies[typeof(IGateway)].Policy, factoryInterceptor);
+ Assert.AreSame(pluginGraph.FindFamily(typeof(IGateway)).Policy, factoryInterceptor);
}
[Test]
@@ -205,7 +205,7 @@
registry.BuildInstancesOf<IGateway>();
}
- Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>());
+ Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway)));
InstanceManager manager = new InstanceManager(pluginGraph);
IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway));
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -76,7 +76,7 @@
graph.Seal();
List<string> colors = new List<string>();
- foreach (Instance instance in graph.PluginFamilies[typeof (IWidget)].GetAllInstances())
+ foreach (Instance instance in graph.FindFamily(typeof (IWidget)).GetAllInstances())
{
colors.Add(instance.Name);
}
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -83,7 +83,7 @@
registry.Dispose();
- PluginFamily family = graph.PluginFamilies[typeof (IGateway)];
+ PluginFamily family = graph.FindFamily(typeof (IGateway));
UserControlInstance instance = (UserControlInstance) family.GetInstance(theKey);
Assert.IsNotNull(instance);
Modified: trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -25,7 +25,7 @@
[Test]
public void DefaultNameOfRule()
{
- PluginFamily family = _graph.PluginFamilies[typeof (Rule)];
+ PluginFamily family = _graph.FindFamily(typeof (Rule));
Assert.AreEqual("TheBlueOne", family.DefaultInstanceKey);
}
Modified: trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -25,7 +25,7 @@
public void AddAnInstanceFromMasterConfigToAFamilyInInclude()
{
PluginGraph graph = buildGraph();
- PluginFamily family = graph.PluginFamilies[typeof (IStrategy)];
+ PluginFamily family = graph.FindFamily(typeof (IStrategy));
Assert.IsNotNull(family.GetMemento("Blue"));
Assert.IsNotNull(family.GetMemento("Red"));
Assert.IsNotNull(family.GetMemento("DeepTest")); // from include
@@ -49,7 +49,8 @@
{
PluginGraph graph = buildGraph();
- Assert.IsTrue(graph.PluginFamilies.Contains(typeof (IStrategy)));
+
+ Assert.IsTrue(graph.ContainsFamily(typeof (IStrategy)));
}
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -27,7 +27,7 @@
public void CreateTheInferredPluginCorrectly()
{
// Who needs the Law of Demeter?
- InstanceMemento[] mementoArray = _graph.PluginFamilies[typeof (IWidget)].GetAllMementos();
+ InstanceMemento[] mementoArray = _graph.FindFamily(typeof (IWidget)).GetAllMementos();
Assert.AreEqual(4, mementoArray.Length);
}
Modified: trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -29,7 +29,7 @@
XmlMementoSource source = new XmlFileMementoSource("Array.xml", string.Empty, "Decision");
- PluginFamily family = graph.PluginFamilies.Add(typeof(Decision), string.Empty);
+ PluginFamily family = graph.FindFamily(typeof(Decision));
family.AddMementoSource(source);
family.Plugins.Add(typeof (Decision), "Default");
Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -96,7 +96,7 @@
public void AddPluginForTypeWhenThePluginAlreadyExists()
{
PluginGraph pluginGraph = new PluginGraph();
- PluginFamily family = pluginGraph.PluginFamilies.Add(typeof(ISomething));
+ PluginFamily family = pluginGraph.FindFamily(typeof(ISomething));
family.Plugins.Add(typeof (SomethingOne), "One");
InstanceManager manager = new InstanceManager(pluginGraph);
@@ -149,7 +149,7 @@
private IInstanceFactory getISomethingFactory()
{
PluginGraph pluginGraph = new PluginGraph();
- pluginGraph.PluginFamilies.Add(typeof (ISomething));
+ pluginGraph.FindFamily(typeof (ISomething));
InstanceManager manager = new InstanceManager(pluginGraph);
return manager[typeof(ISomething)];
}
Modified: trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -20,7 +20,7 @@
PluginGraph graph = new PluginGraph();
- PluginFamily family = graph.PluginFamilies.Add(typeof (Cow), string.Empty);
+ PluginFamily family = graph.FindFamily(typeof (Cow));
family.Plugins.Add(typeof (Cow), "Default");
Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -41,18 +41,18 @@
{
PluginGraph pluginGraph = DataMother.GetDiagnosticPluginGraph("SingletonIntercepterTest.xml");
- PluginFamily family = pluginGraph.PluginFamilies[typeof (Rule)];
+ PluginFamily family = pluginGraph.FindFamily(typeof (Rule));
Assert.IsInstanceOfType(typeof (SingletonPolicy), family.Policy);
// The PluginFamily for IWidget has no intercepters configured
- PluginFamily widgetFamily = pluginGraph.PluginFamilies[typeof (IWidget)];
+ PluginFamily widgetFamily = pluginGraph.FindFamily(typeof (IWidget));
Assert.IsInstanceOfType(typeof (BuildPolicy), widgetFamily.Policy);
}
[Test]
public void CanDefinedSourceBuildMemento()
{
- PluginFamily family = graph.PluginFamilies[typeof (IWidget)];
+ PluginFamily family = graph.FindFamily(typeof (IWidget));
InstanceMemento memento = family.GetMemento("Red");
@@ -62,7 +62,7 @@
[Test]
public void CanImpliedInlineSourceBuildMemento()
{
- PluginFamily family = graph.PluginFamilies[typeof (Rule)];
+ PluginFamily family = graph.FindFamily(typeof (Rule));
InstanceMemento memento = family.GetMemento("Red");
@@ -73,7 +73,7 @@
[Test]
public void CanImpliedNOTInlineSourceBuildMemento()
{
- PluginFamily family = graph.PluginFamilies[typeof (Parent)];
+ PluginFamily family = graph.FindFamily(typeof (Parent));
InstanceMemento memento = family.GetMemento("Jerry");
@@ -85,7 +85,7 @@
{
PluginGraph pluginGraph = DataMother.GetPluginGraph("ExplicitPluginFamilyOverridesImplicitPluginFamily.xml");
- PluginFamily family = pluginGraph.PluginFamilies[typeof (GrandChild)];
+ PluginFamily family = pluginGraph.FindFamily(typeof (GrandChild));
Assert.AreEqual("Fred", family.DefaultInstanceKey);
}
@@ -108,21 +108,21 @@
[Test]
public void GotPluginFamiliesThatAreDefinedInConfigXml()
{
- Assert.IsNotNull(graph.PluginFamilies[typeof (Rule)]);
- Assert.IsNotNull(graph.PluginFamilies[typeof (Column)]);
+ Assert.IsNotNull(graph.FindFamily(typeof (Rule)));
+ Assert.IsNotNull(graph.FindFamily(typeof (Column)));
- PluginFamily family = graph.PluginFamilies[typeof (Rule)];
+ PluginFamily family = graph.FindFamily(typeof (Rule));
}
[Test]
public void GotPluginFamiliesThatAreMarkedByAttributes()
{
- Assert.IsNotNull(graph.PluginFamilies[typeof (GrandChild)]);
- Assert.IsNotNull(graph.PluginFamilies[typeof (Child)]);
- Assert.IsNotNull(graph.PluginFamilies[typeof (Parent)]);
- Assert.IsNotNull(graph.PluginFamilies[typeof (WidgetMaker)]);
+ Assert.IsNotNull(graph.FindFamily(typeof (GrandChild)));
+ Assert.IsNotNull(graph.FindFamily(typeof (Child)));
+ Assert.IsNotNull(graph.FindFamily(typeof (Parent)));
+ Assert.IsNotNull(graph.FindFamily(typeof (WidgetMaker)));
- PluginFamily family = graph.PluginFamilies[typeof (Child)];
+ PluginFamily family = graph.FindFamily(typeof (Child));
}
[Test]
@@ -141,7 +141,7 @@
[Test]
public void GotPluginsThatAreMarkedAsPluggable()
{
- PluginFamily pluginFamily = graph.PluginFamilies[typeof (IWidget)];
+ PluginFamily pluginFamily = graph.FindFamily(typeof (IWidget));
Plugin plugin = pluginFamily.Plugins[typeof (ColorWidget)];
Assert.IsNotNull(plugin);
}
@@ -150,7 +150,7 @@
[Test]
public void GotPluginThatIsAddedInConfigXml()
{
- PluginFamily family = graph.PluginFamilies[typeof (IWidget)];
+ PluginFamily family = graph.FindFamily(typeof (IWidget));
Plugin plugin = family.Plugins[typeof (NotPluggableWidget)];
Assert.IsNotNull(plugin);
Assert.AreEqual("NotPluggable", plugin.ConcreteKey);
@@ -171,7 +171,7 @@
[Test]
public void GotRightNumberOfPluginsForIWidget()
{
- PluginFamily pluginFamily = graph.PluginFamilies[typeof (IWidget)];
+ PluginFamily pluginFamily = graph.FindFamily(typeof (IWidget));
Assert.AreEqual(5, pluginFamily.Plugins.Count, "Should be 5 total");
}
@@ -179,7 +179,7 @@
[Test]
public void GotRightNumberOfPluginsForMultipleAssemblies()
{
- PluginFamily pluginFamily = graph.PluginFamilies[typeof (Rule)];
+ PluginFamily pluginFamily = graph.FindFamily(typeof (Rule));
Assert.AreEqual(5, pluginFamily.Plugins.Count, "Should be 5 total");
}
@@ -194,7 +194,7 @@
[Test]
public void SetsTheDefaultInstanceKey()
{
- PluginFamily family = graph.PluginFamilies[typeof (IWidget)];
+ PluginFamily family = graph.FindFamily(typeof (IWidget));
Assert.AreEqual("Red", family.DefaultInstanceKey);
}
}
Modified: trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -53,7 +53,7 @@
public void EnumSetter()
{
PluginGraph graph = new PluginGraph();
- PluginFamily family = graph.PluginFamilies.Add(typeof (IGridColumn));
+ PluginFamily family = graph.FindFamily(typeof (IGridColumn));
Plugin plugin = Plugin.CreateImplicitPlugin(typeof(EnumGridColumn));
family.Plugins.Add(plugin);
@@ -70,7 +70,7 @@
public void PrimitiveNonStringSetter()
{
PluginGraph graph = new PluginGraph();
- PluginFamily family = graph.PluginFamilies.Add(typeof(IGridColumn));
+ PluginFamily family = graph.FindFamily(typeof(IGridColumn));
Plugin plugin = Plugin.CreateImplicitPlugin(typeof(LongGridColumn));
family.Plugins.Add(plugin);
@@ -89,7 +89,7 @@
public void StringSetter()
{
PluginGraph graph = new PluginGraph();
- PluginFamily family = graph.PluginFamilies.Add(typeof(IGridColumn));
+ PluginFamily family = graph.FindFamily(typeof(IGridColumn));
Plugin plugin = Plugin.CreateImplicitPlugin(typeof(StringGridColumn));
family.Plugins.Add(plugin);
Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -24,7 +24,8 @@
{
PluginGraph graph = new PluginGraph();
graph.Assemblies.Add(Assembly.GetExecutingAssembly());
- PluginFamily family = graph.PluginFamilies.Add(typeof (IGenericService<>), "Default");
+ PluginFamily family = graph.FindFamily(typeof (IGenericService<>));
+ family.DefaultInstanceKey = "Default";
family.Plugins.Add(typeof (GenericService<>), "Default");
graph.Seal();
@@ -92,7 +93,7 @@
public void CanEmitInstanceBuilderForATypeWithConstructorArguments()
{
PluginGraph graph = new PluginGraph();
- PluginFamily family = graph.PluginFamilies.Add(typeof (ComplexType<int>));
+ PluginFamily family = graph.FindFamily(typeof (ComplexType<int>));
family.Plugins.Add(typeof (ComplexType<int>), "complex");
InstanceManager manager = new InstanceManager(graph);
@@ -112,13 +113,13 @@
{
PluginGraph graph = new PluginGraph();
graph.Assemblies.Add(Assembly.GetExecutingAssembly());
- PluginFamily family1 = graph.PluginFamilies.Add(typeof (IGenericService<int>), string.Empty);
- PluginFamily family2 = graph.PluginFamilies.Add(typeof (IGenericService<string>), string.Empty);
- PluginFamily family3 = graph.PluginFamilies.Add(typeof (IGenericService<>), string.Empty);
+ PluginFamily family1 = graph.FindFamily(typeof (IGenericService<int>));
+ PluginFamily family2 = graph.FindFamily(typeof (IGenericService<string>));
+ PluginFamily family3 = graph.FindFamily(typeof (IGenericService<>));
- Assert.AreSame(graph.PluginFamilies[typeof (IGenericService<int>)], family1);
- Assert.AreSame(graph.PluginFamilies[typeof (IGenericService<string>)], family2);
- Assert.AreSame(graph.PluginFamilies[typeof (IGenericService<>)], family3);
+ Assert.AreSame(graph.FindFamily(typeof(IGenericService<int>)), family1);
+ Assert.AreSame(graph.FindFamily(typeof(IGenericService<string>)), family2);
+ Assert.AreSame(graph.FindFamily(typeof(IGenericService<>)), family3);
}
[Test]
@@ -126,11 +127,11 @@
{
PluginGraph graph = new PluginGraph();
graph.Assemblies.Add(Assembly.GetExecutingAssembly());
- PluginFamily family1 = graph.PluginFamilies.Add(typeof (IGenericService<int>), string.Empty);
- PluginFamily family2 = graph.PluginFamilies.Add(typeof (IGenericService<string>), string.Empty);
+ PluginFamily family1 = graph.FindFamily(typeof (IGenericService<int>));
+ PluginFamily family2 = graph.FindFamily(typeof (IGenericService<string>));
- Assert.AreSame(graph.PluginFamilies[typeof (IGenericService<int>)], family1);
- Assert.AreSame(graph.PluginFamilies[typeof (IGenericService<string>)], family2);
+ Assert.AreSame(graph.FindFamily(typeof (IGenericService<int>)), family1);
+ Assert.AreSame(graph.FindFamily(typeof (IGenericService<string>)), family2);
}
Modified: trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -31,7 +31,7 @@
public void BuildAnInstanceManagerFromTemplatedPluginFamily()
{
PluginGraph pluginGraph = new PluginGraph();
- PluginFamily family = pluginGraph.PluginFamilies.Add(typeof (IGenericService<>));
+ PluginFamily family = pluginGraph.FindFamily(typeof (IGenericService<>));
family.DefaultInstanceKey = "Default";
family.Plugins.Add(typeof (GenericService<>), "Default");
family.Plugins.Add(typeof (SecondGenericService<>), "Second");
@@ -52,7 +52,7 @@
public void BuildTemplatedFamilyWithOnlyOneTemplateParameter()
{
PluginGraph pluginGraph = new PluginGraph();
- PluginFamily family = pluginGraph.PluginFamilies.Add(typeof(IGenericService<>));
+ PluginFamily family = pluginGraph.FindFamily(typeof(IGenericService<>));
family.Plugins.Add(typeof (GenericService<>), "Default");
family.Plugins.Add(typeof (SecondGenericService<>), "Second");
family.Plugins.Add(typeof (ThirdGenericService<>), "Third");
@@ -72,7 +72,7 @@
public void BuildTemplatedFamilyWithThreeTemplateParameters()
{
PluginGraph pluginGraph = new PluginGraph();
- PluginFamily family = pluginGraph.PluginFamilies.Add(typeof(IGenericService3<,,>));
+ PluginFamily family = pluginGraph.FindFamily(typeof(IGenericService3<,,>));
family.Plugins.Add(typeof (GenericService3<,,>), "Default");
family.Plugins.Add(typeof (SecondGenericService3<,,>), "Second");
family.Plugins.Add(typeof (ThirdGenericService3<,,>), "Third");
@@ -108,7 +108,7 @@
public void GetTemplatedFamily()
{
PluginGraph pluginGraph = new PluginGraph();
- PluginFamily family = pluginGraph.PluginFamilies.Add(typeof(IGenericService<>));
+ PluginFamily family = pluginGraph.FindFamily(typeof(IGenericService<>));
family.Plugins.Add(typeof (GenericService<>), "Default");
family.Plugins.Add(typeof (SecondGenericService<>), "Second");
family.Plugins.Add(typeof (ThirdGenericService<>), "Third");
Modified: trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs 2008-05-03 17:52:03 UTC (rev 88)
+++ trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs 2008-05-04 01:11:30 UTC (rev 89)
@@ -26,8 +26,8 @@
graph.Assemblies.Add("StructureMap.Testing.Widget");
- graph.PluginFamilies.Add(typeof (IWidget), "Blue");
- graph.PluginFamilies.Add(typeof (WidgetMaker), "");
+ graph.FindFamily(typeof (IWi...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-04 01:29:32
|
Revision: 90
http://structuremap.svn.sourceforge.net/structuremap/?rev=90&view=rev
Author: jeremydmiller
Date: 2008-05-03 18:29:30 -0700 (Sat, 03 May 2008)
Log Message:
-----------
Eliminated a superfluous ctor on PluginFamily and killed off a static method on PluginFamily.
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 01:11:30 UTC (rev 89)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 01:29:30 UTC (rev 90)
@@ -15,23 +15,6 @@
/// </summary>
public class PluginFamily
{
- #region statics
-
- [Obsolete]
- public static PluginFamily CreateAutoFilledPluginFamily(Type pluginType)
- {
- Plugin plugin = Plugin.CreateAutofilledPlugin(pluginType);
-
- PluginFamily family = new PluginFamily(pluginType);
-
- family.Plugins.Add(plugin);
- family.DefaultInstanceKey = plugin.ConcreteKey;
-
- return family;
- }
-
- #endregion
-
public const string CONCRETE_KEY = "CONCRETE";
private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>();
private readonly PluginCollection _plugins;
@@ -72,41 +55,12 @@
}
- /// <summary>
- /// Troubleshooting constructor to find potential problems with a PluginFamily's
- /// configuration
- /// </summary>
- /// <param name="path"></param>
- /// <param name="defaultKey"></param>
- public PluginFamily(TypePath path, string defaultKey)
- {
- _plugins = new PluginCollection(this);
- _pluginTypeName = path.AssemblyQualifiedName;
- initializeExplicit(path, defaultKey);
- }
-
-
public PluginGraph Parent
{
get { return _parent; }
set { _parent = value; }
}
- private void initializeExplicit(TypePath path, string defaultKey)
- {
- try
- {
- _pluginType = path.FindType();
- _pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
- }
- catch (Exception ex)
- {
- throw new StructureMapException(103, ex, path.ClassName, path.AssemblyName);
- }
-
- _defaultKey = defaultKey;
- }
-
#endregion
public InstanceInterceptor InstanceInterceptor
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-05-04 01:11:30 UTC (rev 89)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-04 01:29:30 UTC (rev 90)
@@ -273,11 +273,13 @@
/// <returns></returns>
public object FillDependencies(Type type)
{
+ // TODO: Want all type knowledge into Plugin
if (type.IsInterface || type.IsAbstract)
{
throw new StructureMapException(230, type.FullName);
}
+ // TODO: Little bit of smelliness here
Plugin plugin = Plugin.CreateImplicitPlugin(type);
if (!plugin.CanBeAutoFilled)
{
Modified: trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs 2008-05-04 01:11:30 UTC (rev 89)
+++ trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs 2008-05-04 01:29:30 UTC (rev 90)
@@ -9,15 +9,6 @@
[TestFixture]
public class FillDependenciesTester
{
- private PluginFamily _family;
-
- [TestFixtureSetUp]
- public void TestFixtureSetUp()
- {
- _family = PluginFamily.CreateAutoFilledPluginFamily(typeof (FilledConcreteClass));
- Assert.IsNotNull(_family);
- }
-
[Test]
public void CanFillDependenciesSuccessfully()
{
@@ -38,24 +29,6 @@
Assert.IsNotNull(concreteClass.Strategy);
}
- [Test]
- public void CreateAutoFilledPluginFamily()
- {
- Assert.IsNotNull(_family);
- Assert.AreEqual(typeof (FilledConcreteClass), _family.PluginType);
- }
-
-
- [Test]
- public void CreatesPlugin()
- {
- Assert.AreEqual(1, _family.Plugins.Count);
- Plugin plugin = _family.Plugins.All[0];
- Assert.IsNotNull(plugin);
-
- Assert.AreEqual(typeof (FilledConcreteClass), plugin.PluggedType);
- }
-
[Test, ExpectedException(typeof (StructureMapException))]
public void TryToFillDependenciesOnAbstractClassThrowsException()
{
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-04 01:11:30 UTC (rev 89)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-04 01:29:30 UTC (rev 90)
@@ -29,23 +29,7 @@
family.Plugins.Add(typeof (Rule), "Rule");
}
- [Test, ExpectedException(typeof (StructureMapException))]
- public void CreateExplicitWithNonexistentAssembly()
- {
- TypePath path = new TypePath("NonexistentAssembly", "NonexistentAssembly.Class1");
- PluginFamily family = new PluginFamily(path, "");
- }
-
- [Test, ExpectedException(typeof (StructureMapException))]
- public void CreateExplicitWithNonexistentClass()
- {
- TypePath path =
- new TypePath("StructureMap.Testing.Widget", "StructureMap.Testing.Widget.NonExistentInterface");
-
- PluginFamily family = new PluginFamily(path, "");
- }
-
[Test]
public void GetPlugins()
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-05-04 02:28:20
|
Revision: 91
http://structuremap.svn.sourceforge.net/structuremap/?rev=91&view=rev
Author: jeremydmiller
Date: 2008-05-03 19:28:19 -0700 (Sat, 03 May 2008)
Log Message:
-----------
cleaned up PluginGraphBuilder
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/PluginGraphBuilder.cs
trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -143,7 +143,8 @@
}
MementoSource source = CreateSource(exportedType);
- PluginFamily family = new PluginFamily(exportedType, DefaultKey);
+ PluginFamily family = new PluginFamily(exportedType);
+ family.DefaultInstanceKey = DefaultKey;
family.AddMementoSource(source);
family.SetScopeTo(Scope);
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -19,7 +19,6 @@
_mementoCreator = mementoCreator;
}
- // TODO: Standard way in this class to get a PluginType, Maybe more into IGraphBuilder
public void ParseFamily(XmlElement familyElement)
{
TypePath typePath = TypePath.CreateFromXmlNode(familyElement);
@@ -40,7 +39,6 @@
public void ParseDefaultElement(XmlElement element)
{
TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
- // TODO: Gotta throw exception if the type cannot be found
_builder.ConfigureFamily(pluginTypePath,
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -22,7 +22,6 @@
void StartFamilies();
void FinishFamilies();
- PluginGraph CreatePluginGraph();
IProfileBuilder GetProfileBuilder();
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -1,15 +1,11 @@
using System;
using System.Reflection;
-using StructureMap.Attributes;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Pipeline;
namespace StructureMap.Configuration
{
- // TODO: Kill in 3.5
- public delegate void Action<T>(T subject);
-
public class NormalGraphBuilder : IGraphBuilder
{
private readonly PluginGraph _pluginGraph;
@@ -18,9 +14,13 @@
private InstanceManager _systemInstanceManager;
- public NormalGraphBuilder(Registry[] registries)
+ public NormalGraphBuilder(Registry[] registries) : this(registries, new PluginGraph())
{
- _pluginGraph = new PluginGraph();
+ }
+
+ public NormalGraphBuilder(Registry[] registries, PluginGraph pluginGraph)
+ {
+ _pluginGraph = pluginGraph;
foreach (Registry registry in registries)
{
registry.ConfigurePluginGraph(_pluginGraph);
@@ -37,11 +37,6 @@
_pluginGraph.Seal();
}
- [Obsolete("Do away?")] public PluginGraph CreatePluginGraph()
- {
- return _pluginGraph;
- }
-
public PluginGraph SystemGraph
{
get { return _systemGraph; }
@@ -87,21 +82,7 @@
}
}
- #endregion
- private object buildSystemObject(Type type, InstanceMemento memento)
- {
- Instance instance = memento.ReadInstance(_systemGraph, type);
-
- if (_systemInstanceManager == null)
- {
- _systemInstanceManager = new InstanceManager(_systemGraph);
- }
-
- return _systemInstanceManager.CreateInstance(type, instance);
- }
-
-
public void WithSystemObject<T>(InstanceMemento memento, string context, Action<T> action)
{
try
@@ -128,5 +109,19 @@
_pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context);
}
}
+
+ #endregion
+
+ private object buildSystemObject(Type type, InstanceMemento memento)
+ {
+ Instance instance = memento.ReadInstance(_systemGraph, type);
+
+ if (_systemInstanceManager == null)
+ {
+ _systemInstanceManager = new InstanceManager(_systemGraph);
+ }
+
+ return _systemInstanceManager.CreateInstance(type, instance);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -27,24 +27,18 @@
private List<Instance> _instances = new List<Instance>();
private IBuildPolicy _buildPolicy = new BuildPolicy();
- #region constructors
- public PluginFamily(Type pluginType, string defaultInstanceKey)
- {
- _pluginType = pluginType;
- _pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
- _defaultKey = defaultInstanceKey;
- _plugins = new PluginCollection(this);
- }
-
// TODO: Need to unit test the scope from the attribute
/// <summary>
/// Testing constructor
/// </summary>
/// <param name="pluginType"></param>
- public PluginFamily(Type pluginType) :
- this(pluginType, PluginFamilyAttribute.GetDefaultKey(pluginType))
+ public PluginFamily(Type pluginType)
{
+ _pluginType = pluginType;
+ _pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
+ _plugins = new PluginCollection(this);
+
// TODO -- Merge functionality with PluginFamilyAttribute
PluginFamilyAttribute attribute = PluginFamilyAttribute.GetAttribute(pluginType);
if (attribute != null)
@@ -61,8 +55,6 @@
set { _parent = value; }
}
- #endregion
-
public InstanceInterceptor InstanceInterceptor
{
get { return _instanceInterceptor; }
@@ -103,12 +95,13 @@
return templatedFamily;
}
+ // TODO: Move this into TypeScanner
/// <summary>
/// Finds Plugin's that match the PluginType from the assembly and add to the internal
/// collection of Plugin's
/// </summary>
/// <param name="assembly"></param>
- public Plugin[] FindPlugins(AssemblyGraph assembly)
+ [Obsolete] public Plugin[] FindPlugins(AssemblyGraph assembly)
{
Predicate<Type> pluggedTypeFilter =
delegate(Type type) { return Plugin.IsAnExplicitPlugin(PluginType, type); };
@@ -143,17 +136,13 @@
_mementoList.AddRange(source.GetAllMementos());
}
- public InstanceMemento[] GetAllMementos()
- {
- return _mementoList.ToArray();
- }
-
// For testing
public InstanceMemento GetMemento(string instanceKey)
{
return _mementoList.Find(delegate(InstanceMemento m) { return m.InstanceKey == instanceKey; });
}
+ // TODO -- Move out into TypeScanner
public void DiscoverImplicitInstances()
{
List<Plugin> list = _plugins.FindAutoFillablePlugins();
Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -32,9 +32,9 @@
#endregion
+ private readonly ConfigurationParser[] _parsers;
private readonly Registry[] _registries = new Registry[0];
private PluginGraph _graph;
- private ConfigurationParser[] _parsers;
#region constructors
@@ -47,38 +47,9 @@
{
_parsers = parsers;
_registries = registries;
+ _graph = new PluginGraph();
}
-
- /// <summary>
- /// Creates a PluginGraphBuilder that reads configuration from the filePath
- /// </summary>
- /// <param name="filePath">The path to the configuration file</param>
- [Obsolete("Elimating direct usage of PluginGraphBuilder")]
- public PluginGraphBuilder(string filePath)
- {
- try
- {
- XmlDocument doc = new XmlDocument();
- doc.Load(filePath);
-
- _parsers = ConfigurationParser.GetParsers(doc, filePath);
- }
- catch (Exception ex)
- {
- throw new StructureMapException(100, filePath, ex);
- }
- }
-
- /// <summary>
- /// Default constructor reads configuration from the StructureMap.config file
- /// in the application folder
- /// </summary>
- [Obsolete("Elimating direct usage of PluginGraphBuilder")]
- public PluginGraphBuilder() : this(StructureMapConfiguration.GetStructureMapConfigurationPath())
- {
- }
-
#endregion
#region IPluginGraphSource Members
@@ -90,57 +61,33 @@
/// <returns></returns>
public PluginGraph Build()
{
- NormalGraphBuilder graphBuilder = new NormalGraphBuilder(_registries);
- PluginGraph pluginGraph = buildPluginGraph(graphBuilder);
- return pluginGraph;
+ NormalGraphBuilder graphBuilder = new NormalGraphBuilder(_registries, _graph);
+ buildPluginGraph(graphBuilder);
+ return _graph;
}
#endregion
- private PluginGraph buildPluginGraph(IGraphBuilder graphBuilder)
+ private void forAllParsers(Action<ConfigurationParser> action)
{
- readAssemblies(graphBuilder);
-
- readFamilies(graphBuilder);
-
foreach (ConfigurationParser parser in _parsers)
{
- parser.ParseInstances(graphBuilder);
+ action(parser);
}
-
- _graph = graphBuilder.CreatePluginGraph();
-
- return _graph;
}
- private void readInstanceDefaults(IGraphBuilder graphBuilder)
+ private void buildPluginGraph(IGraphBuilder graphBuilder)
{
- foreach (ConfigurationParser parser in _parsers)
- {
- parser.ParseProfilesAndMachines(graphBuilder);
- }
- }
+ forAllParsers(delegate(ConfigurationParser p) { p.ParseAssemblies(graphBuilder); });
- private void readFamilies(IGraphBuilder graphBuilder)
- {
graphBuilder.StartFamilies();
- foreach (ConfigurationParser parser in _parsers)
- {
- parser.ParseFamilies(graphBuilder);
- }
-
- readInstanceDefaults(graphBuilder);
-
-
+ forAllParsers(delegate(ConfigurationParser p)
+ {
+ p.ParseFamilies(graphBuilder);
+ p.ParseProfilesAndMachines(graphBuilder);
+ p.ParseInstances(graphBuilder);
+ });
}
-
- private void readAssemblies(IGraphBuilder graphBuilder)
- {
- foreach (ConfigurationParser parser in _parsers)
- {
- parser.ParseAssemblies(graphBuilder);
- }
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using NUnit.Framework;
using StructureMap.Graph;
+using StructureMap.Pipeline;
using StructureMap.Testing.TestData;
using StructureMap.Testing.Widget;
@@ -27,8 +28,10 @@
public void CreateTheInferredPluginCorrectly()
{
// Who needs the Law of Demeter?
- InstanceMemento[] mementoArray = _graph.FindFamily(typeof (IWidget)).GetAllMementos();
- Assert.AreEqual(4, mementoArray.Length);
+ _graph.Seal();
+
+ Instance[] instances = _graph.FindFamily(typeof (IWidget)).GetAllInstances();
+ Assert.AreEqual(4, instances.Length);
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -16,7 +16,8 @@
[Test]
public void AddAPluggedType()
{
- PluginFamily family = new PluginFamily(typeof (IWidget), "DefaultKey");
+ PluginFamily family = new PluginFamily(typeof (IWidget));
+ family.DefaultInstanceKey = "DefaultKey";
family.Plugins.Add(typeof (NotPluggableWidget), "NotPlugged");
Assert.AreEqual(1, family.Plugins.Count, "Plugin Count");
@@ -25,7 +26,8 @@
[Test, ExpectedException(typeof (StructureMapException))]
public void AddAWrongType()
{
- PluginFamily family = new PluginFamily(typeof (IWidget), "DefaultKey");
+ PluginFamily family = new PluginFamily(typeof(IWidget));
+ family.DefaultInstanceKey = "DefaultKey";
family.Plugins.Add(typeof (Rule), "Rule");
}
@@ -33,7 +35,8 @@
[Test]
public void GetPlugins()
{
- PluginFamily family = new PluginFamily(typeof (IWidget), "DefaultKey");
+ PluginFamily family = new PluginFamily(typeof(IWidget));
+ family.DefaultInstanceKey = "DefaultKey";
AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget");
family.FindPlugins(graph);
Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-04 01:29:30 UTC (rev 90)
+++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-04 02:28:19 UTC (rev 91)
@@ -44,7 +44,7 @@
family.AddInstance(_memento);
- PluginGraph graph = builder.CreatePluginGraph();
+ PluginGraph graph = builder.PluginGraph;
InstanceManager manager = new InstanceManager(graph);
StubbedGateway gateway = (StubbedGateway) manager.CreateInstance(typeof (IGateway), _memento.InstanceKey);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-05-04 02:59:59
|
Revision: 92
http://structuremap.svn.sourceforge.net/structuremap/?rev=92&view=rev
Author: jeremydmiller
Date: 2008-05-03 19:59:57 -0700 (Sat, 03 May 2008)
Log Message:
-----------
Cleaned up PluginFamilyAttribute
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Graph/AssemblyGraph.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-04 02:28:19 UTC (rev 91)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-04 02:59:57 UTC (rev 92)
@@ -1,8 +1,6 @@
using System;
using StructureMap.Attributes;
using StructureMap.Graph;
-using StructureMap.Interceptors;
-using StructureMap.Source;
namespace StructureMap
{
@@ -60,24 +58,6 @@
set { _scope = value ? InstanceScope.Singleton : InstanceScope.PerRequest; }
}
- public MementoSource CreateSource(Type exportedType)
- {
- if (SourceType != null)
- {
- try
- {
- return (MementoSource) Activator.CreateInstance(SourceType);
- }
- catch (Exception ex)
- {
- throw new StructureMapException(122, ex, SourceType.FullName, exportedType.FullName);
- }
- }
- else
- {
- return new MemoryMementoSource();
- }
- }
/// <summary>
/// Determines if a Type object is marked as a PluginFamily
@@ -91,84 +71,36 @@
return (att != null);
}
- /// <summary>
- /// Gets the default instance key from a Type marked as a PluginFamily
- /// </summary>
- /// <param name="objectType"></param>
- /// <returns></returns>
- public static string GetDefaultKey(Type objectType)
+ public static void ConfigureFamily(IPluginFamily family)
{
PluginFamilyAttribute att =
- GetCustomAttribute(objectType, typeof (PluginFamilyAttribute), false) as PluginFamilyAttribute;
- if (att == null)
- {
- return string.Empty;
- }
- else
- {
- return att.DefaultKey;
- }
- }
-
- /// <summary>
- /// Interrogates the attribute on the pluginType and determines if the PluginFamily is
- /// marked as a Singleton
- /// </summary>
- /// <param name="pluginType"></param>
- /// <returns></returns>
- public static bool IsMarkedAsSingleton(Type pluginType)
- {
- bool returnValue = false;
-
- PluginFamilyAttribute att =
- GetCustomAttribute(
- pluginType,
- typeof (PluginFamilyAttribute), false)
+ GetCustomAttribute(family.PluginType, typeof (PluginFamilyAttribute), false)
as PluginFamilyAttribute;
-
if (att != null)
{
- returnValue = att.IsSingleton;
+ att.Configure(family);
}
-
- return returnValue;
}
- public PluginFamily BuildPluginFamily(Type exportedType)
+ public void Configure(IPluginFamily family)
{
- if (!MarkedAsPluginFamily(exportedType))
+ if (SourceType != null)
{
- return new PluginFamily(exportedType);
+ try
+ {
+ MementoSource source = (MementoSource) Activator.CreateInstance(SourceType);
+ family.AddMementoSource(source);
+ }
+ catch (Exception ex)
+ {
+ throw new StructureMapException(122, ex, SourceType.FullName, family.PluginTypeName);
+ }
}
- MementoSource source = CreateSource(exportedType);
- PluginFamily family = new PluginFamily(exportedType);
- family.DefaultInstanceKey = DefaultKey;
- family.AddMementoSource(source);
- family.SetScopeTo(Scope);
-
- return family;
+ if (!string.IsNullOrEmpty(DefaultKey)) family.DefaultInstanceKey = DefaultKey;
+ if (Scope != InstanceScope.PerRequest) family.SetScopeTo(Scope);
}
-
- public static PluginFamily CreatePluginFamily(Type exportedType)
- {
- PluginFamilyAttribute att = GetAttribute(exportedType);
-
- if (att == null)
- {
- return new PluginFamily(exportedType);
- }
-
- PluginFamily family = att.BuildPluginFamily(exportedType);
-
- return family;
- }
-
- public static PluginFamilyAttribute GetAttribute(Type exportedType)
- {
- return GetCustomAttribute(exportedType, typeof (PluginFamilyAttribute), false) as PluginFamilyAttribute;
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/AssemblyGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2008-05-04 02:28:19 UTC (rev 91)
+++ trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2008-05-04 02:59:57 UTC (rev 92)
@@ -98,7 +98,7 @@
{
if (PluginFamilyAttribute.MarkedAsPluginFamily(exportedType))
{
- PluginFamily family = PluginFamilyAttribute.CreatePluginFamily(exportedType);
+ PluginFamily family = new PluginFamily(exportedType);
list.Add(family);
}
}
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 02:28:19 UTC (rev 91)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 02:59:57 UTC (rev 92)
@@ -13,7 +13,7 @@
/// the system. A PluginFamily defines a CLR Type that StructureMap can build, and all of the possible
/// Plugin\x92s implementing the CLR Type.
/// </summary>
- public class PluginFamily
+ public class PluginFamily : IPluginFamily
{
public const string CONCRETE_KEY = "CONCRETE";
private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>();
@@ -39,13 +39,7 @@
_pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
_plugins = new PluginCollection(this);
- // TODO -- Merge functionality with PluginFamilyAttribute
- PluginFamilyAttribute attribute = PluginFamilyAttribute.GetAttribute(pluginType);
- if (attribute != null)
- {
- SetScopeTo(attribute.Scope);
- }
-
+ PluginFamilyAttribute.ConfigureFamily(this);
}
Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-04 02:28:19 UTC (rev 91)
+++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-04 02:59:57 UTC (rev 92)
@@ -169,7 +169,7 @@
{
if (!_pluginFamilies.Contains(pluginType))
{
- PluginFamily family = PluginFamilyAttribute.CreatePluginFamily(pluginType);
+ PluginFamily family = new PluginFamily(pluginType);
_pluginFamilies.Add(family);
attachImplicitPlugins(family);
}
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2008-05-04 02:28:19 UTC (rev 91)
+++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-04 02:59:57 UTC (rev 92)
@@ -118,6 +118,7 @@
<Compile Include="Configuration\ProfileBuilder.cs" />
<Compile Include="Diagnostics\Tokens.cs" />
<Compile Include="Emitting\ConstructorEmitter.cs" />
+ <Compile Include="Graph\IPluginFamily.cs" />
<Compile Include="InstanceBuilderList.cs" />
<Compile Include="InstanceFamily.cs" />
<Compile Include="Pipeline\BuildStrategies.cs" />
Modified: trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-05-04 02:28:19 UTC (rev 91)
+++ trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-05-04 02:59:57 UTC (rev 92)
@@ -1,5 +1,7 @@
using System;
using NUnit.Framework;
+using Rhino.Mocks;
+using Rhino.Mocks.Constraints;
using StructureMap.Attributes;
using StructureMap.Graph;
using StructureMap.Interceptors;
@@ -16,17 +18,19 @@
PluginFamilyAttribute att = new PluginFamilyAttribute("something");
att.Scope = scope;
- PluginFamily family = att.BuildPluginFamily(typeof (Target1));
+ PluginFamily family = new PluginFamily(typeof(TypeThatDoesNotHaveCustomMementoSource));
+ att.Configure(family);
+
Assert.IsInstanceOfType(interceptorType, family.Policy);
}
[PluginFamily]
- public class Target1
+ public class TypeThatDoesNotHaveCustomMementoSource
{
}
[PluginFamily(SourceType = typeof (CustomMementoSource))]
- public class Target2
+ public class TypeWithDesignatedMementoSource
{
}
@@ -56,36 +60,63 @@
[Test]
public void CreateMemoryMementoSourceWhenTheMementoSourceIsExplicitlyDefinedInAttribute()
{
- PluginFamilyAttribute att = PluginFamilyAttribute.GetAttribute(typeof (Target2));
+ MockRepository mocks = new MockRepository();
+ IPluginFamily family = mocks.DynamicMock<IPluginFamily>();
- MementoSource source = att.CreateSource(typeof (Target2));
- Assert.IsTrue(source is CustomMementoSource);
+ using (mocks.Record())
+ {
+ SetupResult.For(family.PluginType).Return(typeof (TypeWithDesignatedMementoSource));
+
+ family.AddMementoSource(null);
+ LastCall.Constraints(Is.TypeOf<CustomMementoSource>());
+ }
+
+ using (mocks.Playback())
+ {
+ PluginFamilyAttribute.ConfigureFamily(family);
+ }
}
[Test]
- public void CreatesAConfigInstanceMementoSourceByDefault()
+ public void Do_not_add_a_memento_source_if_it_is_not_defined()
{
- PluginFamilyAttribute att = PluginFamilyAttribute.GetAttribute(typeof (Target1));
+ MockRepository mocks = new MockRepository();
+ IPluginFamily family = mocks.DynamicMock<IPluginFamily>();
- MementoSource source = att.CreateSource(typeof (Target1));
- Assert.IsTrue(source is MemoryMementoSource);
+ using (mocks.Record())
+ {
+ SetupResult.For(family.PluginType).Return(typeof(TypeThatDoesNotHaveCustomMementoSource));
+
+ family.AddMementoSource(null);
+ LastCall.Repeat.Never();
+ }
+
+ using (mocks.Playback())
+ {
+ PluginFamilyAttribute.ConfigureFamily(family);
+ }
}
+
[Test]
- public void PerRequestDoesNotHaveAnyInterceptors()
+ public void PerRequest_DoesNot_call_SetScopeTo_on_family()
{
PluginFamilyAttribute att = new PluginFamilyAttribute("something");
att.Scope = InstanceScope.PerRequest;
- PluginFamily family = att.BuildPluginFamily(typeof (Target1));
- Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
- }
+ MockRepository mocks = new MockRepository();
+ IPluginFamily family = mocks.DynamicMock<IPluginFamily>();
- [Test]
- public void ScopeIsPerRequestByDefault()
- {
- PluginFamilyAttribute att = new PluginFamilyAttribute();
- Assert.AreEqual(InstanceScope.PerRequest, att.Scope);
+ using (mocks.Record())
+ {
+ family.SetScopeTo(InstanceScope.PerRequest);
+ LastCall.Repeat.Never();
+ }
+
+ using (mocks.Playback())
+ {
+ att.Configure(family);
+ }
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs 2008-05-04 02:28:19 UTC (rev 91)
+++ trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs 2008-05-04 02:59:57 UTC (rev 92)
@@ -13,16 +13,5 @@
Assert.IsNotNull(gateway);
}
- [Test]
- public void GetTheDefaultInstanceKeyFromType()
- {
- string default1 = PluginFamilyAttribute.GetDefaultKey(typeof (IGateway));
- string default2 = PluginFamilyAttribute.GetDefaultKey(typeof (IService));
- string default3 = PluginFamilyAttribute.GetDefaultKey(typeof (IWorker));
-
- Assert.AreEqual("Default", default1);
- Assert.AreEqual(string.Empty, default2);
- Assert.AreEqual(string.Empty, default3);
- }
}
}
\ 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: <jer...@us...> - 2008-05-06 21:48:23
|
Revision: 94
http://structuremap.svn.sourceforge.net/structuremap/?rev=94&view=rev
Author: jeremydmiller
Date: 2008-05-06 14:48:18 -0700 (Tue, 06 May 2008)
Log Message:
-----------
Cleaning up unnecessary noise in PluggableAttribute and Plugin
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluggableAttribute.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs
trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Graph/PluginCollection.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/TypePath.cs
trunk/Source/StructureMap/InstanceBuilderList.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Source/MemoryMementoSource.cs
trunk/Source/StructureMap/Source/XmlFileMementoSource.cs
trunk/Source/StructureMap.Testing/Container/EmittingTester.cs
trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs
trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs
trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs
trunk/Source/StructureMap.Testing.Widget/IWidget.cs
trunk/Source/StructureMap.Testing.Widget/Rule.cs
trunk/Source/StructureMap.Testing.Widget/WidgetMaker.cs
trunk/Source/StructureMap.Testing.Widget2/DefaultRule.cs
trunk/Source/StructureMap.Testing.Widget2/Rule1.cs
trunk/Source/StructureMap.Testing.Widget3/Gateways.cs
Modified: trunk/Source/StructureMap/Attributes/PluggableAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -9,18 +9,12 @@
public class PluggableAttribute : Attribute
{
private string _concreteKey;
- private string _description;
public PluggableAttribute(string concreteKey)
- : this(concreteKey, string.Empty)
{
+ _concreteKey = concreteKey;
}
- public PluggableAttribute(string TypeName, string Description)
- {
- _concreteKey = TypeName;
- _description = Description;
- }
/// <summary>
/// The ConcreteKey alias of the Type
@@ -32,15 +26,6 @@
}
/// <summary>
- /// Description of the pluggable class type
- /// </summary>
- public string Description
- {
- get { return _description; }
- set { _description = value; }
- }
-
- /// <summary>
/// Gets an instance of PluggableAttribute from a Type object
/// </summary>
/// <param name="objectType"></param>
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -150,7 +150,7 @@
_alterations.Add(
delegate(PluginFamily family)
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (CONCRETETYPE));
+ Plugin plugin = new Plugin(typeof (CONCRETETYPE));
plugin.ConcreteKey = instanceName;
family.Plugins.Add(plugin);
}
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -119,8 +119,7 @@
string context = "creating a Plugin for " + family.PluginTypeName;
_builder.WithType(pluginPath, context, delegate(Type pluggedType)
{
- Plugin plugin =
- Plugin.CreateExplicitPlugin(pluggedType, concreteKey, "");
+ Plugin plugin = new Plugin(pluggedType, concreteKey);
family.Plugins.Add(plugin);
foreach (XmlElement setterElement in pluginElement.ChildNodes)
Modified: trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -9,7 +9,7 @@
[Obsolete("Think this is unnecessary")] public class GenericMemento<T> : MemoryInstanceMemento
{
public GenericMemento(string instanceKey)
- : base(Plugin.CreateImplicitPlugin(typeof (T)).ConcreteKey, instanceKey)
+ : base(new Plugin(typeof (T)).ConcreteKey, instanceKey)
{
}
}
Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -6,7 +6,7 @@
{
public class GenericsPluginGraph
{
- private Dictionary<Type, PluginFamily> _families;
+ private readonly Dictionary<Type, PluginFamily> _families;
public GenericsPluginGraph()
{
@@ -15,12 +15,6 @@
public static bool CanBeCast(Type pluginType, Type pluggedType)
{
- //bool isGenericComparison = pluginType.IsGenericType && pluggedType.IsGenericType;
- //if (!isGenericComparison)
- //{
- // return false;
- //}
-
try
{
return checkGenericType(pluggedType, pluginType);
@@ -68,19 +62,6 @@
return false;
}
- public PluginFamily FindGenericFamily(string pluginTypeName)
- {
- foreach (KeyValuePair<Type, PluginFamily> pair in _families)
- {
- if (new TypePath(pair.Key).Matches(pluginTypeName))
- {
- return pair.Value;
- }
- }
-
- return null;
- }
-
public void AddFamily(PluginFamily family)
{
_families.Add(family.PluginType, family);
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -22,19 +22,7 @@
{
#region static
- public static Plugin CreateAutofilledPlugin(Type concreteType)
- {
- string pluginKey = Guid.NewGuid().ToString();
- Plugin plugin = CreateExplicitPlugin(concreteType, pluginKey, string.Empty);
- if (!plugin.CanBeAutoFilled)
- {
- throw new StructureMapException(231);
- }
- return plugin;
- }
-
-
/// <summary>
/// Determines if the PluggedType is a valid Plugin into the
/// PluginType
@@ -42,7 +30,7 @@
/// <param name="pluginType"></param>
/// <param name="pluggedType"></param>
/// <returns></returns>
- public static bool IsAnExplicitPlugin(Type pluginType, Type pluggedType)
+ public static bool IsExplicitlyMarkedAsPlugin(Type pluginType, Type pluggedType)
{
bool returnValue = false;
@@ -84,38 +72,6 @@
}
- /// <summary>
- /// Creates an Implicit Plugin that discovers its ConcreteKey from a [Pluggable]
- /// attribute on the PluggedType
- /// </summary>
- /// <param name="pluggedType"></param>
- /// <returns></returns>
- public static Plugin CreateImplicitPlugin(Type pluggedType)
- {
- PluggableAttribute att = PluggableAttribute.InstanceOf(pluggedType);
- if (att == null)
- {
- return
- new Plugin(pluggedType, TypePath.GetAssemblyQualifiedName(pluggedType));
- }
- else
- {
- return new Plugin(pluggedType, att.ConcreteKey);
- }
- }
-
- /// <summary>
- /// Creates an Explicit Plugin for the pluggedType with the entered
- /// concreteKey
- /// </summary>
- /// <param name="pluggedType"></param>
- /// <param name="concreteKey"></param>
- /// <param name="description"></param>
- public static Plugin CreateExplicitPlugin(Type pluggedType, string concreteKey, string description)
- {
- return new Plugin(pluggedType, concreteKey);
- }
-
public static ConstructorInfo GetGreediestConstructor(Type pluggedType)
{
ConstructorInfo returnValue = null;
@@ -149,7 +105,7 @@
/// </summary>
/// <param name="pluggedType"></param>
/// <param name="concreteKey"></param>
- private Plugin(Type pluggedType, string concreteKey) : base()
+ public Plugin(Type pluggedType, string concreteKey) : base()
{
if (concreteKey == string.Empty)
{
@@ -161,13 +117,23 @@
_setters = new SetterPropertyCollection(this);
}
+ public Plugin(Type pluggedType)
+ {
+ PluggableAttribute att = PluggableAttribute.InstanceOf(pluggedType);
+ _concreteKey = att == null ? pluggedType.AssemblyQualifiedName : att.ConcreteKey;
+
+ _pluggedType = pluggedType;
+ _setters = new SetterPropertyCollection(this);
+
+ }
+
/// <summary>
/// Troubleshooting constructor used by PluginGraphBuilder to find possible problems
/// with the configured Plugin
/// </summary>
/// <param name="path"></param>
/// <param name="concreteKey"></param>
- public Plugin(TypePath path, string concreteKey) : base()
+ [Obsolete("Get rid of this. All of this should go through NormalGraphBuilder")] public Plugin(TypePath path, string concreteKey) : base()
{
if (concreteKey == string.Empty)
{
Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -75,6 +75,7 @@
}
}
+ [Obsolete("Get rid of this")]
public void Add(TypePath path, string concreteKey)
{
Plugin plugin = new Plugin(path, concreteKey);
@@ -87,9 +88,10 @@
/// <param name="pluggedType"></param>
/// <param name="concreteKey"></param>
// TODO -- not wild about this method.
+ [Obsolete("Get rid of this")]
public void Add(Type pluggedType, string concreteKey)
{
- Plugin plugin = Plugin.CreateExplicitPlugin(pluggedType, concreteKey, string.Empty);
+ Plugin plugin = new Plugin(pluggedType, concreteKey);
Add(plugin);
}
@@ -138,7 +140,7 @@
public Plugin FindOrCreate(Type pluggedType, bool createDefaultInstanceOfType)
{
- Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType);
+ Plugin plugin = new Plugin(pluggedType);
Add(plugin);
return plugin;
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -44,7 +44,7 @@
PluginFamilyAttribute.ConfigureFamily(this);
- _explicitlyMarkedPluginFilter = delegate(Type type) { return Plugin.IsAnExplicitPlugin(PluginType, type); };
+ _explicitlyMarkedPluginFilter = delegate(Type type) { return Plugin.IsExplicitlyMarkedAsPlugin(PluginType, type); };
_implicitPluginFilter = delegate(Type type) { return Plugin.CanBeCast(PluginType, type); };
_pluginFilter = _explicitlyMarkedPluginFilter;
}
@@ -255,7 +255,7 @@
{
if (!HasPlugin(pluggedType))
{
- Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType);
+ Plugin plugin = new Plugin(pluggedType);
_plugins.Add(plugin);
}
}
@@ -270,13 +270,13 @@
{
if (!HasPlugin(pluggedType))
{
- _plugins.Add(Plugin.CreateImplicitPlugin(pluggedType));
+ _plugins.Add(new Plugin(pluggedType));
}
}
public void AddPlugin(Type pluggedType, string key)
{
- Plugin plugin = Plugin.CreateExplicitPlugin(pluggedType, key, string.Empty);
+ Plugin plugin = new Plugin(pluggedType, key);
_plugins.Add(plugin);
}
Modified: trunk/Source/StructureMap/Graph/TypePath.cs
===================================================================
--- trunk/Source/StructureMap/Graph/TypePath.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Graph/TypePath.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -53,16 +53,6 @@
get { return _className; }
}
- public static string GetTypeIdentifier(Type type)
- {
- return new TypePath(type).AssemblyQualifiedName;
- }
-
- public static TypePath TypePathForFullName(string fullname)
- {
- return new TypePath(string.Empty, fullname);
- }
-
public static TypePath CreateFromXmlNode(XmlNode node)
{
string typeName = node.Attributes[XmlConstants.TYPE_ATTRIBUTE].Value;
@@ -96,16 +86,6 @@
}
}
- public bool Matches(string typeName)
- {
- return (AssemblyQualifiedName == typeName || ClassName == typeName);
- }
-
- public bool Matches(Type type)
- {
- return (AssemblyQualifiedName == type.AssemblyQualifiedName || ClassName == type.FullName);
- }
-
public override bool Equals(object obj)
{
TypePath peer = obj as TypePath;
@@ -122,20 +102,6 @@
return AssemblyQualifiedName.GetHashCode();
}
-
- public bool CanFindType()
- {
- try
- {
- Type type = FindType();
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
-
public override string ToString()
{
return AssemblyQualifiedName;
Modified: trunk/Source/StructureMap/InstanceBuilderList.cs
===================================================================
--- trunk/Source/StructureMap/InstanceBuilderList.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/InstanceBuilderList.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -29,7 +29,7 @@
// Add a missing PluggedType if we can
if (Plugin.CanBeCast(_pluginType, pluggedType))
{
- Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType);
+ Plugin plugin = new Plugin(pluggedType);
processPlugins(new Plugin[]{plugin});
return _builders[pluggedType];
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -280,7 +280,7 @@
}
// TODO: Little bit of smelliness here
- Plugin plugin = Plugin.CreateImplicitPlugin(type);
+ Plugin plugin = new Plugin(type);
if (!plugin.CanBeAutoFilled)
{
throw new StructureMapException(230, type.FullName);
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -223,7 +223,7 @@
private string findPropertyName<T>()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType);
+ Plugin plugin = new Plugin(_pluggedType);
string propertyName = plugin.FindFirstConstructorArgumentOfType<T>();
if (string.IsNullOrEmpty(propertyName))
Modified: trunk/Source/StructureMap/Source/MemoryMementoSource.cs
===================================================================
--- trunk/Source/StructureMap/Source/MemoryMementoSource.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Source/MemoryMementoSource.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -5,7 +5,7 @@
/// <summary>
/// An in-memory MementoSource
/// </summary>
- [Pluggable("Default", "")]
+ [Pluggable("Default")]
public class MemoryMementoSource : MementoSource
{
private Hashtable _mementos;
Modified: trunk/Source/StructureMap/Source/XmlFileMementoSource.cs
===================================================================
--- trunk/Source/StructureMap/Source/XmlFileMementoSource.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap/Source/XmlFileMementoSource.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -8,7 +8,7 @@
/// Implementation of XmlMementoSource that reads InstanceMemento's from an external file.
/// Useful to break the StructureMap.config file into smaller pieces.
/// </summary>
- [Pluggable("XmlFile", "")]
+ [Pluggable("XmlFile")]
public class XmlFileMementoSource : XmlMementoSource
{
private string _filePath;
Modified: trunk/Source/StructureMap.Testing/Container/EmittingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -21,7 +21,7 @@
try
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule));
+ Plugin plugin = new Plugin(typeof (ComplexRule));
InstanceBuilderAssembly _InstanceBuilderAssembly =
new InstanceBuilderAssembly("StructureMap.EmittingTesterAssembly", typeof (Rule));
Modified: trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -54,7 +54,7 @@
{
PluginGraph graph = new PluginGraph();
PluginFamily family = graph.FindFamily(typeof (IGridColumn));
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof(EnumGridColumn));
+ Plugin plugin = new Plugin(typeof(EnumGridColumn));
family.Plugins.Add(plugin);
family.AddInstance(_source.GetMemento("Enum"));
@@ -71,7 +71,7 @@
{
PluginGraph graph = new PluginGraph();
PluginFamily family = graph.FindFamily(typeof(IGridColumn));
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof(LongGridColumn));
+ Plugin plugin = new Plugin(typeof(LongGridColumn));
family.Plugins.Add(plugin);
InstanceMemento memento = _source.GetMemento("Long");
@@ -90,7 +90,7 @@
{
PluginGraph graph = new PluginGraph();
PluginFamily family = graph.FindFamily(typeof(IGridColumn));
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof(StringGridColumn));
+ Plugin plugin = new Plugin(typeof(StringGridColumn));
family.Plugins.Add(plugin);
InstanceMemento memento = _source.GetMemento("String");
Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -62,13 +62,13 @@
[Test]
public void CanCreatePluginForGenericTypeWithGenericParameter()
{
- Plugin plugin = Plugin.CreateExplicitPlugin(typeof (GenericService<int>), "key", string.Empty);
+ Plugin plugin = new Plugin(typeof (GenericService<int>), "key");
}
[Test]
public void CanCreatePluginForGenericTypeWithoutGenericParameter()
{
- Plugin plugin = Plugin.CreateExplicitPlugin(typeof (GenericService<>), "key", string.Empty);
+ Plugin plugin = new Plugin(typeof (GenericService<>), "key");
}
[Test, Ignore("Generics with more than 2 parameters")]
Modified: trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -39,7 +39,7 @@
[Test]
public void Plugin_can_service_a_generic_type()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof(SpecificConcept));
+ Plugin plugin = new Plugin(typeof(SpecificConcept));
Assert.IsTrue(plugin.CanBePluggedIntoGenericType(typeof(IConcept<>), typeof(object)));
Assert.IsFalse(plugin.CanBePluggedIntoGenericType(typeof(IConcept<>), typeof(string)));
Assert.IsFalse(plugin.CanBePluggedIntoGenericType(typeof(IConcept<>), typeof(int)));
Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-05-06 20:33:10 UTC (rev 93)
+++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-05-06 21:48:18 UTC (rev 94)
@@ -18,7 +18,7 @@
[SetUp]
public void SetUp()
{
- _plugin = Plugin.CreateImplicitPlugin(typeof (ConfigurationWidget));
+ _plugin = new Plugin(typeof (ConfigurationWidget));
_iwidget = typeof (IWidget);
_widgetmaker = typeof (WidgetMaker);
_colorwidget = typeof (ColorWidget);
@@ -59,9 +59,16 @@
}
[Test]
+ public void Get_concrete_key_from_attribute_if_it_exists()
+ {
+ Plugin plugin = new Plugin(typeof(ColorWidget));
+ Assert.AreEqual("Color", plugin.ConcreteKey);
+ }
+
+ [Test]
public void CanBeAutoFilledIsFalse()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (GrandPrix));
+ Plugin plugin = new Plugin(typeof (GrandPrix));
Assert.IsFalse(plugin.CanBeAutoFilled);
}
@@ -69,7 +76,7 @@
[Test]
public void CanBeAutoFilledIsTrue()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (Mustang));
+ Plugin plugin = new Plugin(typeof (Mustang));
Assert.IsTrue(plugin.CanBeAutoFilled);
}
@@ -94,14 +101,14 @@
[Test]
public void CanMakeObjectInstanceActivator()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (DefaultGateway));
+ Plugin plugin = new Plugin(typeof (DefaultGateway));
Assert.IsTrue(!plugin.HasConstructorArguments(), "DefaultGateway can be just an activator");
}
[Test]
public void CanNotMakeObjectInstanceActivator()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule));
+ Plugin plugin = new Plugin(typeof (ComplexRule));
Assert.IsTrue(plugin.HasConstructorArguments(), "ComplexRule cannot be just an activator");
}
@@ -109,13 +116,13 @@
public void CanNotPluginWithoutAttribute()
{
string msg = "NotPluggableWidget cannot plug into IWidget automatically";
- Assert.AreEqual(false, Plugin.IsAnExplicitPlugin(_iwidget, typeof (NotPluggable)), msg);
+ Assert.AreEqual(false, Plugin.IsExplicitlyMarkedAsPlugin(_iwidget, typeof (NotPluggable)), msg);
}
[Test]
public void CanPluginWithAttribute()
{
- Assert.AreEqual(true, Plugin.IsAnExplicitPlugin(_iwidget, _colorwidget), "ColorWidget plugs into IWidget");
+ Assert.AreEqual(true, Plugin.IsExplicitlyMarkedAsPlugin(_iwidget, _colorwidget), "ColorWidget plugs into IWidget");
}
@@ -144,7 +151,7 @@
[Test]
public void CreateImplicitMementoWithNoConstructorArguments()
{
- Plugin plugin = Plugin.CreateExplicitPlugin(typeof (DefaultGateway), "Default", string.Empty);
+ Plugin plugin = new Plugin(typeof (DefaultGateway), "Default");
InstanceMemento memento = plugin.CreateImplicitMemento();
Assert.IsNotNull(memento);
@@ -155,7 +162,7 @@
[Test]
public void CreateImplicitMementoWithSomeConstructorArgumentsReturnValueIsNull()
{
- Plugin plugin = Plugin.CreateExplicitPlugin(typeof (Strategy), "Default", string.Empty);
+ Plugin plugin = new Plugin(typeof (Strategy), "Default");
InstanceMemento memento = plugin.CreateImplicitMemento();
Assert.IsNull(memento);
}
@@ -175,14 +182,14 @@
[Test]
public void CreatePluginFromTypeThatDoesNotHaveAnAttributeDetermineTheConcreteKey()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(GetType());
- Assert.AreEqual(TypePath.GetAssemblyQualifiedName(GetType()), plugin.ConcreteKey);
+ Plugin plugin = new Plugin(GetType());
+ Assert.AreEqual(GetType().AssemblyQualifiedName, plugin.ConcreteKey);
}
[Test]
public void CreatesAnImplicitMementoForAPluggedTypeThatCanBeAutoFilled()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (Mustang));
+ Plugin plugin = new Plugin(typeof (Mustang));
InstanceMemento memento = plugin.CreateImplicitMemento();
Assert.IsNotNull(memento);
@@ -193,7 +200,7 @@
[Test]
public void DoesNotCreateAnImplicitMementoForAPluggedTypeThatCanBeAutoFilled()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (GrandPrix));
+ Plugin plugin = new Plugin(typeof (GrandPrix));
InstanceMemento memento = plugin.CreateImplicitMemento();
Assert.IsNull(memento);
@@ -202,7 +209,7 @@
[Test]
public void FindFirstConstructorArgumentOfType()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (GrandPrix));
+ Plugin plugin = new Plugin(typeof (GrandPrix));
string expected = "engine";
string actual = plugin.FindFirstConstructorArgumentOfType<IEngine>();
@@ -215,14 +222,14 @@
)]
public void FindFirstConstructorArgumentOfTypeNegativeCase()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (GrandPrix));
+ Plugin plugin = new Plugin(typeof (GrandPrix));
plugin.FindFirstConstructorArgumentOfType<IWidget>();
}
[Test]
public void GetFirstMarkedConstructor()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule));
+ Plugin plugin = new Plugin(typeof (ComplexRule));
ConstructorInfo constructor = plugin.GetConstructor();
Assert.IsNotNull(constructor);
@@ -232,7 +239,7 @@
[Test]
public void GetGreediestConstructor()
{
- Plugin plugin = Plugin.CreateImplicitPlugin(typeof (GreaterThanRule));
+ Plugin plugin = new Plugin(typeof (GreaterThanRule));
ConstructorInfo constructor = plugin.GetConstructor();
Assert.IsNotNull(constructor);
@@ -257,7 +264,7 ...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-09 15:47:42
|
Revision: 95
http://structuremap.svn.sourceforge.net/structuremap/?rev=95&view=rev
Author: jeremydmiller
Date: 2008-05-09 08:47:15 -0700 (Fri, 09 May 2008)
Log Message:
-----------
centralized the Generics stuff to GenericsPluginGraph, cleaned out some other cruft, Plugin/Emitting code cleanup
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Emitting/ClassBuilder.cs
trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs
trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
trunk/Source/StructureMap/Graph/IPluginFamily.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Graph/PluginCollection.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/IInstanceManager.cs
trunk/Source/StructureMap/InstanceBuilder.cs
trunk/Source/StructureMap/InstanceBuilderList.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/InstanceMemento.cs
trunk/Source/StructureMap/MementoSource.cs
trunk/Source/StructureMap/ObjectFactory.cs
trunk/Source/StructureMap/Pipeline/BuildStrategies.cs
trunk/Source/StructureMap/PluginGraphBuilder.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs
trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
trunk/Source/StructureMap.Testing/Container/EmittingTester.cs
trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs
trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
trunk/Source/StructureMap.Testing/ObjectMother.cs
trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs
trunk/Source/StructureMap.Testing.Widget/Decision.cs
trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs
trunk/Source/StructureMap.Testing.Widget/Rule.cs
trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs
trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs
Removed Paths:
-------------
trunk/Source/StructureMap/Configuration/Mementos/
trunk/Source/StructureMap/IPluginGraphSource.cs
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -94,7 +94,7 @@
}
catch (Exception ex)
{
- throw new StructureMapException(122, ex, SourceType.FullName, family.PluginTypeName);
+ throw new StructureMapException(122, ex, SourceType.FullName, family.PluginType.AssemblyQualifiedName);
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -8,14 +8,13 @@
namespace StructureMap.Configuration.DSL.Expressions
{
- public delegate void AlterPluginFamilyDelegate(PluginFamily family);
/// <summary>
/// Represents the parameters for creating instances of a given Type
/// </summary>
public class CreatePluginFamilyExpression<PLUGINTYPE> : IExpression
{
- private readonly List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>();
+ private readonly List<Action<PluginFamily>> _alterations = new List<Action<PluginFamily>>();
private readonly List<IExpression> _children = new List<IExpression>();
private readonly Type _pluginType;
private readonly InstanceScope _scope = InstanceScope.PerRequest;
@@ -37,7 +36,7 @@
child.Configure(graph);
}
- foreach (AlterPluginFamilyDelegate alteration in _alterations)
+ foreach (Action<PluginFamily> alteration in _alterations)
{
alteration(family);
}
@@ -45,6 +44,8 @@
#endregion
+ // TODO: Try alterAndContinue(f => {});
+
/// <summary>
/// Sets the default instance of a Type to the definition represented by builder
/// </summary>
@@ -159,7 +160,7 @@
return this;
}
- public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(IInstanceInterceptor interceptor)
+ public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(IBuildInterceptor interceptor)
{
_alterations.Add(delegate(PluginFamily family)
{
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -116,7 +116,7 @@
TypePath pluginPath = TypePath.CreateFromXmlNode(pluginElement);
string concreteKey = pluginElement.GetAttribute(XmlConstants.CONCRETE_KEY_ATTRIBUTE);
- string context = "creating a Plugin for " + family.PluginTypeName;
+ string context = "creating a Plugin for " + family.PluginType.AssemblyQualifiedName;
_builder.WithType(pluginPath, context, delegate(Type pluggedType)
{
Plugin plugin = new Plugin(pluggedType, concreteKey);
@@ -148,7 +148,7 @@
XmlAttributeInstanceMemento interceptorMemento = new XmlAttributeInstanceMemento(interceptorNode);
- _builder.WithSystemObject<IInstanceInterceptor>(interceptorMemento, context, delegate(IInstanceInterceptor interceptor)
+ _builder.WithSystemObject<IBuildInterceptor>(interceptorMemento, context, delegate(IBuildInterceptor interceptor)
{
family.AddInterceptor(interceptor);
});
Modified: trunk/Source/StructureMap/Emitting/ClassBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -84,28 +84,58 @@
}
- public void AddReadonlyStringProperty(string PropertyName, string Value, bool Override)
+ public void AddReadonlyStringProperty(string propertyName, string propertyValue, bool @override)
{
PropertyBuilder prop =
- _newTypeBuilder.DefineProperty(PropertyName, PropertyAttributes.HasDefault, typeof (string), null);
+ _newTypeBuilder.DefineProperty(propertyName, PropertyAttributes.HasDefault, typeof (string), null);
MethodAttributes atts = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig |
MethodAttributes.Final | MethodAttributes.SpecialName;
- string _GetMethodName = "get_" + PropertyName;
+ string getterMethodName = "get_" + propertyName;
MethodBuilder methodGet =
- _newTypeBuilder.DefineMethod(_GetMethodName, atts, CallingConventions.Standard, typeof (string), null);
+ _newTypeBuilder.DefineMethod(getterMethodName, atts, CallingConventions.Standard, typeof (string), null);
ILGenerator gen = methodGet.GetILGenerator();
LocalBuilder ilReturn = gen.DeclareLocal(typeof (string));
- gen.Emit(OpCodes.Ldstr, Value);
+ gen.Emit(OpCodes.Ldstr, propertyValue);
gen.Emit(OpCodes.Stloc_0);
gen.Emit(OpCodes.Ldloc_0);
gen.Emit(OpCodes.Ret);
prop.SetGetMethod(methodGet);
}
+
+ public void AddPluggedTypeGetter(Type pluggedType)
+ {
+ PropertyBuilder prop =
+ _newTypeBuilder.DefineProperty("PluggedType", PropertyAttributes.HasDefault, typeof(Type), null);
+
+ MethodAttributes atts = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig |
+ MethodAttributes.Final | MethodAttributes.SpecialName;
+
+ string getterMethodName = "get_PluggedType";
+
+ MethodBuilder methodGet =
+ _newTypeBuilder.DefineMethod(getterMethodName, atts, CallingConventions.Standard, typeof(Type), null);
+ ILGenerator gen = methodGet.GetILGenerator();
+
+ LocalBuilder ilReturn = gen.DeclareLocal(typeof(Type));
+
+ gen.Emit(OpCodes.Nop);
+ gen.Emit(OpCodes.Ldtoken, pluggedType);
+
+ MethodInfo method = typeof(Type).GetMethod("GetTypeFromHandle");
+ gen.Emit(OpCodes.Call, method);
+
+ gen.Emit(OpCodes.Stloc_0);
+
+ gen.Emit(OpCodes.Ldloc_0);
+ gen.Emit(OpCodes.Ret);
+
+ prop.SetGetMethod(methodGet);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs
===================================================================
--- trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Reflection;
using StructureMap.Graph;
@@ -9,23 +10,66 @@
/// </summary>
public class InstanceBuilderAssembly
{
- private DynamicAssembly _dynamicAssembly;
- private Type _pluginType;
+ private readonly DynamicAssembly _dynamicAssembly;
+ private readonly Type _pluginType;
+ private readonly List<string> _classNames = new List<string>();
- public InstanceBuilderAssembly(string assemblyName, Type pluginType)
+ public InstanceBuilderAssembly(Type pluginType, IEnumerable<Plugin> plugins)
{
+ string assemblyName = Guid.NewGuid().ToString().Replace(".", "") + "InstanceBuilderAssembly";
_dynamicAssembly = new DynamicAssembly(assemblyName);
_pluginType = pluginType;
+
+ foreach (Plugin plugin in plugins)
+ {
+ processPlugin(plugin);
+ }
}
- public void AddPlugin(Plugin plugin)
+ /// <summary>
+ /// Gets a class name for the InstanceBuilder that will be emitted for this Plugin
+ /// </summary>
+ /// <returns></returns>
+ public static string getInstanceBuilderClassName(Type pluggedType)
{
+ string className = "";
+
+ if (pluggedType.IsGenericType)
+ {
+ className += escapeClassName(pluggedType);
+
+ Type[] args = pluggedType.GetGenericArguments();
+ foreach (Type arg in args)
+ {
+ className += escapeClassName(arg);
+ }
+ }
+ else
+ {
+ className = escapeClassName(pluggedType);
+ }
+
+ return className + "InstanceBuilder";
+ }
+
+ private static string escapeClassName(Type type)
+ {
+ string typeName = type.Namespace + type.Name;
+ string returnValue = typeName.Replace(".", string.Empty);
+ return returnValue.Replace("`", string.Empty);
+ }
+
+ private void processPlugin(Plugin plugin)
+ {
if (Plugin.CanBeCast(_pluginType, plugin.PluggedType))
{
+ string className = getInstanceBuilderClassName(plugin.PluggedType);
ClassBuilder builderClass =
- _dynamicAssembly.AddClass(plugin.GetInstanceBuilderClassName(), typeof (InstanceBuilder));
+ _dynamicAssembly.AddClass(className, typeof (InstanceBuilder));
configureClassBuilder(builderClass, plugin);
+
+ _classNames.Add(className);
}
else
{
@@ -33,15 +77,21 @@
}
}
- public Assembly Compile()
+ public List<InstanceBuilder> Compile()
{
- return _dynamicAssembly.Compile();
+ Assembly assembly = _dynamicAssembly.Compile();
+
+ return _classNames.ConvertAll<InstanceBuilder>(delegate(string typeName)
+ {
+ return (InstanceBuilder) assembly.CreateInstance(typeName);
+ });
}
private void configureClassBuilder(ClassBuilder builderClass, Plugin plugin)
{
builderClass.AddReadonlyStringProperty("ConcreteTypeKey", plugin.ConcreteKey, true);
+ builderClass.AddPluggedTypeGetter(plugin.PluggedType);
BuildInstanceMethod method = new BuildInstanceMethod(plugin);
builderClass.AddMethod(method);
Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -79,12 +79,68 @@
profileManager.CopyDefaults(basicType, templatedType);
- return basicFamily.CreateTemplatedClone(templatedParameterTypes);
+ return CreateTemplatedClone(basicFamily, templatedParameterTypes);
}
else
{
return null;
}
}
+
+ // TODO: This code sucks. What's going on here?
+ public static PluginFamily CreateTemplatedClone(PluginFamily baseFamily, params Type[] templateTypes)
+ {
+ Type templatedType = baseFamily.PluginType.MakeGenericType(templateTypes);
+ PluginFamily templatedFamily = new PluginFamily(templatedType);
+ templatedFamily.DefaultInstanceKey = baseFamily.DefaultInstanceKey;
+ templatedFamily.Parent = baseFamily.Parent;
+ templatedFamily.Policy = baseFamily.Policy.Clone();
+
+ // Add Plugins
+ foreach (Plugin plugin in baseFamily.Plugins)
+ {
+ if (plugin.CanBePluggedIntoGenericType(baseFamily.PluginType, templateTypes))
+ {
+ Plugin templatedPlugin = CreateTemplatedClone(plugin, templateTypes);
+ templatedFamily.Plugins.Add(templatedPlugin);
+ }
+ }
+
+ // TODO -- Got a big problem here. Intances need to be copied over
+ foreach (IDiagnosticInstance instance in baseFamily.GetAllInstances())
+ {
+ if (instance.CanBePartOfPluginFamily(templatedFamily))
+ {
+ templatedFamily.AddInstance((Instance)instance);
+ }
+ }
+
+ // Need to attach the new PluginFamily to the old PluginGraph
+ baseFamily.Parent.PluginFamilies.Add(templatedFamily);
+
+ return templatedFamily;
+ }
+
+
+
+ public static Plugin CreateTemplatedClone(Plugin plugin, params Type[] types)
+ {
+ Type templatedType;
+ if (plugin.PluggedType.IsGenericType)
+ {
+ templatedType = plugin.PluggedType.MakeGenericType(types);
+ }
+ else
+ {
+ templatedType = plugin.PluggedType;
+ }
+ Plugin templatedPlugin = new Plugin(templatedType, plugin.ConcreteKey);
+ foreach (SetterProperty setter in plugin.Setters)
+ {
+ templatedPlugin.Setters.Add(setter.Name);
+ }
+
+ return templatedPlugin;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/IPluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/IPluginFamily.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Graph/IPluginFamily.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -21,12 +21,7 @@
get;
}
- string PluginTypeName
- {
- get;
- }
-
void SetScopeTo(InstanceScope scope);
- void AddInterceptor(IInstanceInterceptor interceptor);
+ void AddInterceptor(IBuildInterceptor interceptor);
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -1,6 +1,5 @@
using System;
using System.Reflection;
-using StructureMap.Configuration.Mementos;
namespace StructureMap.Graph
{
@@ -127,25 +126,6 @@
}
- /// <summary>
- /// Troubleshooting constructor used by PluginGraphBuilder to find possible problems
- /// with the configured Plugin
- /// </summary>
- /// <param name="path"></param>
- /// <param name="concreteKey"></param>
- [Obsolete("Get rid of this. All of this should go through NormalGraphBuilder")] public Plugin(TypePath path, string concreteKey) : base()
- {
- if (concreteKey == string.Empty)
- {
- throw new StructureMapException(112, path.ClassName);
- }
-
- setPluggedType(path, concreteKey);
- _setters = new SetterPropertyCollection(this);
-
- _concreteKey = concreteKey;
- }
-
#endregion
@@ -218,37 +198,7 @@
}
}
- private void setPluggedType(TypePath path, string concreteKey)
- {
- try
- {
- _pluggedType = path.FindType();
- }
- catch (Exception ex)
- {
- throw new StructureMapException(111, ex, path.ClassName, concreteKey);
- }
- }
-
- public Plugin CreateTemplatedClone(params Type[] types)
- {
- Type templatedType;
- if (_pluggedType.IsGenericType)
- {
- templatedType = _pluggedType.MakeGenericType(types);
- }
- else
- {
- templatedType = _pluggedType;
- }
- Plugin templatedPlugin = new Plugin(templatedType, _concreteKey);
- templatedPlugin._setters = _setters;
-
- return templatedPlugin;
- }
-
-
/// <summary>
/// Returns the System.Reflection.ConstructorInfo for the PluggedType. Uses either
/// the "greediest" constructor with the most arguments or the constructor function
@@ -273,40 +223,7 @@
return returnValue;
}
- /// <summary>
- /// Gets a class name for the InstanceBuilder that will be emitted for this Plugin
- /// </summary>
- /// <returns></returns>
- public string GetInstanceBuilderClassName()
- {
- string className = "";
- if (_pluggedType.IsGenericType)
- {
- className += escapeClassName(_pluggedType);
-
- Type[] args = _pluggedType.GetGenericArguments();
- foreach (Type arg in args)
- {
- className += escapeClassName(arg);
- }
- }
- else
- {
- className = escapeClassName(_pluggedType);
- }
-
- return className + "InstanceBuilder";
- }
-
- private string escapeClassName(Type type)
- {
- string typeName = type.Namespace + type.Name;
- string returnValue = typeName.Replace(".", string.Empty);
- return returnValue.Replace("`", string.Empty);
- }
-
-
/// <summary>
/// Boolean flag denoting the presence of any constructor arguments
/// </summary>
@@ -435,6 +352,8 @@
}
}
+ // TODO: Move to Generics. This code is insanely stupid. Just make the templated type and do
+ // IsAssignableFrom. Duh!
public bool CanBePluggedIntoGenericType(Type pluginType, params Type[] templateTypes)
{
bool isValid = true;
Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -75,13 +75,6 @@
}
}
- [Obsolete("Get rid of this")]
- public void Add(TypePath path, string concreteKey)
- {
- Plugin plugin = new Plugin(path, concreteKey);
- Add(plugin);
- }
-
/// <summary>
/// Adds a new Plugin by the PluggedType
/// </summary>
@@ -109,14 +102,14 @@
}
else
{
- throw new StructureMapException(113, plugin.ConcreteKey, _family.PluginTypeName);
+ throw new StructureMapException(113, plugin.ConcreteKey, _family.PluginType.AssemblyQualifiedName);
}
}
// Reject if the PluggedType cannot be upcast to the PluginType
if (!Plugin.CanBeCast(_family.PluginType, plugin.PluggedType))
{
- throw new StructureMapException(114, plugin.PluggedType.FullName, _family.PluginTypeName);
+ throw new StructureMapException(114, plugin.PluggedType.FullName, _family.PluginType.AssemblyQualifiedName);
}
_plugins.Add(plugin.ConcreteKey, plugin);
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -15,20 +15,19 @@
/// </summary>
public class PluginFamily : IPluginFamily
{
- public const string CONCRETE_KEY = "CONCRETE";
private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>();
private readonly PluginCollection _plugins;
private string _defaultKey = string.Empty;
private InstanceInterceptor _instanceInterceptor = new NulloInterceptor();
private PluginGraph _parent;
- private readonly Type _pluginType;
- private readonly string _pluginTypeName;
private readonly List<Instance> _instances = new List<Instance>();
private IBuildPolicy _buildPolicy = new BuildPolicy();
+ private readonly Type _pluginType;
private readonly Predicate<Type> _explicitlyMarkedPluginFilter;
private readonly Predicate<Type> _implicitPluginFilter;
private Predicate<Type> _pluginFilter;
+ private IBuildPolicy _policy;
// TODO: Need to unit test the scope from the attribute
@@ -39,7 +38,6 @@
public PluginFamily(Type pluginType)
{
_pluginType = pluginType;
- _pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
_plugins = new PluginCollection(this);
PluginFamilyAttribute.ConfigureFamily(this);
@@ -62,42 +60,8 @@
set { _instanceInterceptor = value; }
}
- // TODO: This code sucks. What's going on here?
- public PluginFamily CreateTemplatedClone(params Type[] templateTypes)
- {
- Type templatedType = _pluginType.MakeGenericType(templateTypes);
- PluginFamily templatedFamily = new PluginFamily(templatedType);
- templatedFamily._defaultKey = _defaultKey;
- templatedFamily.Parent = Parent;
- templatedFamily._buildPolicy = _buildPolicy.Clone();
- // Add Plugins
- foreach (Plugin plugin in _plugins)
- {
- if (plugin.CanBePluggedIntoGenericType(_pluginType, templateTypes))
- {
- Plugin templatedPlugin = plugin.CreateTemplatedClone(templateTypes);
- templatedFamily.Plugins.Add(templatedPlugin);
- }
- }
- // TODO -- Got a big problem here. Intances need to be copied over
- foreach (IDiagnosticInstance instance in GetAllInstances())
- {
- if (instance.CanBePartOfPluginFamily(templatedFamily))
- {
- templatedFamily.AddInstance((Instance)instance);
- }
- }
-
- // Need to attach the new PluginFamily to the old PluginGraph
- Parent.PluginFamilies.Add(templatedFamily);
-
- return templatedFamily;
- }
-
-
-
public void AddInstance(InstanceMemento memento)
{
_mementoList.Add(memento);
@@ -145,11 +109,6 @@
get { return _plugins; }
}
- public string PluginTypeName
- {
- get { return _pluginTypeName; }
- }
-
public bool IsGenericTemplate
{
get { return _pluginType.IsGenericTypeDefinition; }
@@ -175,6 +134,7 @@
public IBuildPolicy Policy
{
get { return _buildPolicy; }
+ set { _policy = value; }
}
public int PluginCount
@@ -242,7 +202,7 @@
}
}
- public void AddInterceptor(IInstanceInterceptor interceptor)
+ public void AddInterceptor(IBuildInterceptor interceptor)
{
interceptor.InnerPolicy = _buildPolicy;
_buildPolicy = interceptor;
Modified: trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -31,41 +31,6 @@
}
}
-
- public PluginFamily this[int index]
- {
- get
- {
- PluginFamily[] families = new PluginFamily[_pluginFamilies.Count];
- return families[index];
- }
- }
-
- public PluginFamily this[string pluginTypeName]
- {
- get
- {
- Type pluginType = Type.GetType(pluginTypeName);
-
- if (pluginType == null)
- {
- foreach (KeyValuePair<Type, PluginFamily> pair in _pluginFamilies)
- {
- if (pair.Value.PluginType.FullName == pluginTypeName)
- {
- return pair.Value;
- }
- }
-
- throw new ApplicationException("Could not find PluginFamily " + pluginTypeName);
- }
- else
- {
- return this[pluginType];
- }
- }
- }
-
public int Count
{
get { return _pluginFamilies.Count; }
Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-06 21:48:18 UTC (rev 94)
+++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-09 15:47:15 UTC (rev 95)
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
using System.Reflection;
-using StructureMap.Configuration.DSL;
using StructureMap.Diagnostics;
using StructureMap.Interceptors;
using StructureMap.Pipeline;
@@ -106,8 +104,6 @@
_sealed = true;
}
-
-
#endregion
...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-15 16:32:29
|
Revision: 96
http://structuremap.svn.sourceforge.net/structuremap/?rev=96&view=rev
Author: jeremydmiller
Date: 2008-05-15 09:32:20 -0700 (Thu, 15 May 2008)
Log Message:
-----------
A LOT OF REFACTORINGS
PipelineGraph, BuildSession, cleaning up InstanceFactory & InstanceManager, introduced TypeRules to centralize "Type" testing rules, refactored emitting code
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/ConfigurationParser.cs
trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs
trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs
trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs
trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs
trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs
trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs
trunk/Source/StructureMap/Emitting/Parameters/EnumParameterEmitter.cs
trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs
trunk/Source/StructureMap/Emitting/Parameters/PrimitiveParameterEmitter.cs
trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs
trunk/Source/StructureMap/Exceptions/StructureMapException.cs
trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Graph/PluginCollection.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/Graph/SetterProperty.cs
trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs
trunk/Source/StructureMap/Graph/TypePath.cs
trunk/Source/StructureMap/IInstanceFactory.cs
trunk/Source/StructureMap/InstanceBuilder.cs
trunk/Source/StructureMap/InstanceBuilderList.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/InstanceMemento.cs
trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs
trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs
trunk/Source/StructureMap/Interceptors/Interceptors.cs
trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs
trunk/Source/StructureMap/MementoSource.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs
trunk/Source/StructureMap/Pipeline/DefaultInstance.cs
trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/ILocationPolicy.cs
trunk/Source/StructureMap/Pipeline/Instance.cs
trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs
trunk/Source/StructureMap/Pipeline/LiteralInstance.cs
trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs
trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs
trunk/Source/StructureMap/Pipeline/UserControlInstance.cs
trunk/Source/StructureMap/PluginGraphBuilder.cs
trunk/Source/StructureMap/Source/BasicXmlMementoSource.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs
trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs
trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs
trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
trunk/Source/StructureMap.Testing/Container/EmittingTester.cs
trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs
trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs
trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs
trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.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/ImplicitPluginFromPluggedTypeAttributeTester.cs
trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
trunk/Source/StructureMap.Testing/ObjectMother.cs
trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ThreadLocalStoragePolicyTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs
trunk/Source/StructureMap.Testing.Widget/Columns.cs
trunk/Source/StructureMap.Testing.Widget/Decision.cs
trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs
trunk/Source/StructureMap.Testing.Widget/IWidget.cs
trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs
trunk/Source/StructureMap.Testing.Widget3/Gateways.cs
trunk/Source/StructureMap.Testing.Widget4/Strategy.cs
trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs
Added Paths:
-----------
trunk/Source/StructureMap/BuildSession.cs
trunk/Source/StructureMap/Configuration/GraphBuilder.cs
trunk/Source/StructureMap/Emitting/ArgumentEmitter.cs
trunk/Source/StructureMap/Graph/Constructor.cs
trunk/Source/StructureMap/Graph/IArgumentVisitor.cs
trunk/Source/StructureMap/Graph/TypeRules.cs
trunk/Source/StructureMap/MemoryInstanceMemento.cs
trunk/Source/StructureMap/Pipeline/BuildPolicy.cs
trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs
trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs
trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs
trunk/Source/StructureMap/Pipeline/IBuildInterceptor.cs
trunk/Source/StructureMap/Pipeline/IBuildPolicy.cs
trunk/Source/StructureMap/Pipeline/IBuildSession.cs
trunk/Source/StructureMap/PipelineGraph.cs
trunk/Source/StructureMap.Testing/BuildSessionTester.cs
trunk/Source/StructureMap.Testing/MementoTester.cs
trunk/Source/StructureMap.Testing/Pipeline/StubBuildSession.cs
trunk/Source/StructureMap.Testing/Pipeline/TypeRulesTester.cs
Removed Paths:
-------------
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Emitting/ConstructorEmitter.cs
trunk/Source/StructureMap/Pipeline/BuildStrategies.cs
trunk/Source/StructureMap.Testing/Debugging.cs
trunk/Source/StructureMap.Testing/Pipeline/StubInstanceCreator.cs
Added: trunk/Source/StructureMap/BuildSession.cs
===================================================================
--- trunk/Source/StructureMap/BuildSession.cs (rev 0)
+++ trunk/Source/StructureMap/BuildSession.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using StructureMap.Interceptors;
+using StructureMap.Pipeline;
+
+namespace StructureMap
+{
+ public class BuildSession : IBuildSession
+ {
+ private readonly PipelineGraph _pipelineGraph;
+ private readonly InterceptorLibrary _interceptorLibrary;
+
+ public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary)
+ {
+ _pipelineGraph = pipelineGraph;
+ _interceptorLibrary = interceptorLibrary;
+ }
+
+ private IInstanceFactory forType(Type pluginType)
+ {
+ return _pipelineGraph.ForType(pluginType);
+ }
+
+ public object CreateInstance(Type type, string name)
+ {
+ return forType(type).Build(this, name);
+ }
+
+ public object CreateInstance(Type pluginType, Instance instance)
+ {
+ return forType(pluginType).Build(this, instance);
+ }
+
+ public Array CreateInstanceArray(Type pluginType, Instance[] instances)
+ {
+ // TODO -- default to returning all
+ if (instances == null)
+ {
+ throw new StructureMapException(205, pluginType, "UNKNOWN");
+ }
+
+ // TODO: 3.5, move this to an extension method of Array?
+ Array array = Array.CreateInstance(pluginType, instances.Length);
+ for (int i = 0; i < instances.Length; i++)
+ {
+ Instance instance = instances[i];
+
+ object arrayValue = forType(pluginType).Build(this, instance);
+ array.SetValue(arrayValue, i);
+ }
+
+ return array;
+ }
+
+ public object CreateInstance(Type pluginType)
+ {
+ Instance instance = _pipelineGraph.GetDefault(pluginType);
+
+ if (instance == null)
+ {
+ throw new StructureMapException(202, pluginType.FullName);
+ }
+
+ return forType(pluginType).Build(this, instance);
+ }
+
+ public object ApplyInterception(Type pluginType, object actualValue)
+ {
+ return _interceptorLibrary.FindInterceptor(actualValue.GetType()).Process(actualValue);
+ }
+
+ public InstanceBuilder FindBuilderByType(Type pluginType, Type pluggedType)
+ {
+ return forType(pluginType).FindBuilderByType(pluggedType);
+ }
+
+ public InstanceBuilder FindBuilderByConcreteKey(Type pluginType, string concreteKey)
+ {
+ return forType(pluginType).FindBuilderByConcreteKey(concreteKey);
+ }
+ }
+}
Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-09 15:47:15 UTC (rev 95)
+++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -48,12 +48,13 @@
includedPath = Path.Combine(folder, fileName);
includedDoc.Load(includedPath);
- // TODO: get rid of throw, put on PluginGraph here
+
ConfigurationParser parser = new ConfigurationParser(includedDoc.DocumentElement);
list.Add(parser);
}
catch (Exception ex)
{
+ // TODO: get rid of throw, put on PluginGraph here
throw new StructureMapException(150, ex, fileName);
}
}
Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-05-09 15:47:15 UTC (rev 95)
+++ trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -70,6 +70,7 @@
}
catch (Exception ex)
{
+ // TODO -- needs to log to PluginGraph instead
throw new StructureMapException(100, filename, ex);
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2008-05-09 15:47:15 UTC (rev 95)
+++ trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -23,7 +23,7 @@
public void IntoPluginType(Type pluginType)
{
- if (!Plugin.CanBeCast(pluginType, _pluggedType))
+ if (!TypeRules.CanBeCast(pluginType, _pluggedType))
{
throw new StructureMapException(
303,
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-09 15:47:15 UTC (rev 95)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -15,7 +15,7 @@
public class CreatePluginFamilyExpression<PLUGINTYPE> : IExpression
{
private readonly List<Action<PluginFamily>> _alterations = new List<Action<PluginFamily>>();
- private readonly List<IExpression> _children = new List<IExpression>();
+ private readonly List<Action<PluginGraph>> _children = new List<Action<PluginGraph>>();
private readonly Type _pluginType;
private readonly InstanceScope _scope = InstanceScope.PerRequest;
@@ -31,20 +31,14 @@
PluginFamily family = graph.FindFamily(_pluginType);
family.SetScopeTo(_scope);
- foreach (IExpression child in _children)
- {
- child.Configure(graph);
- }
-
- foreach (Action<PluginFamily> alteration in _alterations)
- {
- alteration(family);
- }
+ // TODO: clean up with 3.5
+ _children.ForEach(delegate(Action<PluginGraph> action) { action(graph); });
+ _alterations.ForEach(delegate(Action<PluginFamily> action) { action(family); });
}
#endregion
- // TODO: Try alterAndContinue(f => {});
+ // TODO: 3.5, Try alterAndContinue(f => {});
/// <summary>
/// Sets the default instance of a Type to the definition represented by builder
@@ -122,22 +116,38 @@
}
- public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(StartupHandler<PLUGINTYPE> handler)
+ public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(Action<PLUGINTYPE> handler)
{
- _alterations.Add(
- delegate(PluginFamily family) { family.InstanceInterceptor = new StartupInterceptor<PLUGINTYPE>(handler); });
+ _children.Add(
+ delegate(PluginGraph graph)
+ {
+ InterceptionFunction function = delegate(object target)
+ {
+ handler((PLUGINTYPE) target);
+ return target;
+ };
+ PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), function);
+ graph.InterceptorLibrary.AddInterceptor(interceptor);
+ });
+
return this;
}
public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(EnrichmentHandler<PLUGINTYPE> handler)
{
- _alterations.Add(
- delegate(PluginFamily family)
- {
- family.InstanceInterceptor = new EnrichmentInterceptor<PLUGINTYPE>(handler);
- });
+ _children.Add(
+ delegate(PluginGraph graph)
+ {
+ InterceptionFunction function = delegate(object target)
+ {
+ return handler((PLUGINTYPE)target);
+ };
+ PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), function);
+ graph.InterceptorLibrary.AddInterceptor(interceptor);
+ });
+
return this;
}
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-09 15:47:15 UTC (rev 95)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -7,8 +7,6 @@
namespace StructureMap.Configuration.DSL
{
- public delegate object InterceptionDelegate(object target);
-
public class Registry : IDisposable
{
private readonly List<IExpression> _expressions = new List<IExpression>();
@@ -284,7 +282,7 @@
public class TypeInterceptorExpression : IExpression, TypeInterceptor
{
private readonly Predicate<Type> _match;
- private InterceptionDelegate _interception;
+ private InterceptionFunction _interception;
internal TypeInterceptorExpression(Predicate<Type> match)
{
@@ -314,7 +312,7 @@
#endregion
- public void InterceptWith(InterceptionDelegate interception)
+ public void InterceptWith(InterceptionFunction interception)
{
_interception = interception;
}
Added: trunk/Source/StructureMap/Configuration/GraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/GraphBuilder.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -0,0 +1,131 @@
+using System;
+using System.Reflection;
+using StructureMap.Configuration.DSL;
+using StructureMap.Graph;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Configuration
+{
+ public class GraphBuilder : IGraphBuilder
+ {
+ private readonly PluginGraph _pluginGraph;
+ private readonly PluginGraph _systemGraph;
+ private Profile _profile;
+ private InstanceManager _systemInstanceManager;
+
+
+ public GraphBuilder(Registry[] registries) : this(registries, new PluginGraph())
+ {
+ }
+
+ public GraphBuilder(Registry[] registries, PluginGraph pluginGraph)
+ {
+ _pluginGraph = pluginGraph;
+ foreach (Registry registry in registries)
+ {
+ registry.ConfigurePluginGraph(_pluginGraph);
+ }
+
+ _systemGraph = new PluginGraph(false);
+ _systemGraph.Assemblies.Add(Assembly.GetExecutingAssembly());
+ }
+
+ #region IGraphBuilder Members
+
+ public void FinishFamilies()
+ {
+ _pluginGraph.Seal();
+ }
+
+ public PluginGraph SystemGraph
+ {
+ get { return _systemGraph; }
+ }
+
+ public PluginGraph PluginGraph
+ {
+ get { return _pluginGraph; }
+ }
+
+ public void AddAssembly(string assemblyName)
+ {
+ try
+ {
+ Assembly assembly = AppDomain.CurrentDomain.Load(assemblyName);
+ _pluginGraph.Assemblies.Add(assembly);
+ _systemGraph.Assemblies.Add(assembly);
+ }
+ catch (Exception ex)
+ {
+ _pluginGraph.Log.RegisterError(101, ex, assemblyName);
+ }
+ }
+
+ public void PrepareSystemObjects()
+ {
+ // TODO: is this a problem here?
+ _systemGraph.Seal();
+ }
+
+ public IProfileBuilder GetProfileBuilder()
+ {
+ return new ProfileBuilder(_pluginGraph);
+ }
+
+ public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
+ {
+ try
+ {
+ Type pluginType = pluginTypePath.FindType();
+ PluginFamily family = _pluginGraph.FindFamily(pluginType);
+ action(family);
+ }
+ catch (Exception ex)
+ {
+ _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.ClassName, pluginTypePath.AssemblyName);
+ }
+ }
+
+
+ public void WithSystemObject<T>(InstanceMemento memento, string context, Action<T> action)
+ {
+ try
+ {
+ T systemObject = (T) buildSystemObject(typeof (T), memento);
+ action(systemObject);
+ }
+ catch (Exception ex)
+ {
+ _pluginGraph.Log.RegisterError(130, ex, context);
+ }
+ }
+
+
+ public void WithType(TypePath path, string context, Action<Type> action)
+ {
+ try
+ {
+ Type type = path.FindType();
+ action(type);
+ }
+ catch (Exception ex)
+ {
+ _pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context);
+ }
+ }
+
+ #endregion
+
+ private object buildSystemObject(Type type, InstanceMemento memento)
+ {
+ Instance instance = memento.ReadInstance(_systemGraph, type);
+
+ if (_systemInstanceManager == null)
+ {
+ _systemInstanceManager = new InstanceManager(_systemGraph);
+ }
+
+ return _systemInstanceManager.CreateInstance(type, instance);
+ }
+ }
+}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-09 15:47:15 UTC (rev 95)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -1,131 +0,0 @@
-using System;
-using System.Reflection;
-using StructureMap.Configuration.DSL;
-using StructureMap.Graph;
-using StructureMap.Pipeline;
-
-namespace StructureMap.Configuration
-{
- public class NormalGraphBuilder : IGraphBuilder
- {
- private readonly PluginGraph _pluginGraph;
- private readonly PluginGraph _systemGraph;
- private Profile _profile;
- private InstanceManager _systemInstanceManager;
-
-
- public NormalGraphBuilder(Registry[] registries) : this(registries, new PluginGraph())
- {
- }
-
- public NormalGraphBuilder(Registry[] registries, PluginGraph pluginGraph)
- {
- _pluginGraph = pluginGraph;
- foreach (Registry registry in registries)
- {
- registry.ConfigurePluginGraph(_pluginGraph);
- }
-
- _systemGraph = new PluginGraph(false);
- _systemGraph.Assemblies.Add(Assembly.GetExecutingAssembly());
- }
-
- #region IGraphBuilder Members
-
- public void FinishFamilies()
- {
- _pluginGraph.Seal();
- }
-
- public PluginGraph SystemGraph
- {
- get { return _systemGraph; }
- }
-
- public PluginGraph PluginGraph
- {
- get { return _pluginGraph; }
- }
-
- public void AddAssembly(string assemblyName)
- {
- try
- {
- Assembly assembly = AppDomain.CurrentDomain.Load(assemblyName);
- _pluginGraph.Assemblies.Add(assembly);
- _systemGraph.Assemblies.Add(assembly);
- }
- catch (Exception ex)
- {
- _pluginGraph.Log.RegisterError(101, ex, assemblyName);
- }
- }
-
- public void PrepareSystemObjects()
- {
- // TODO: is this a problem here?
- _systemGraph.Seal();
- }
-
- public IProfileBuilder GetProfileBuilder()
- {
- return new ProfileBuilder(_pluginGraph);
- }
-
- public void ConfigureFamily(TypePath pluginTypePath, Action<PluginFamily> action)
- {
- try
- {
- Type pluginType = pluginTypePath.FindType();
- PluginFamily family = _pluginGraph.FindFamily(pluginType);
- action(family);
- }
- catch (Exception ex)
- {
- _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.ClassName, pluginTypePath.AssemblyName);
- }
- }
-
-
- public void WithSystemObject<T>(InstanceMemento memento, string context, Action<T> action)
- {
- try
- {
- T systemObject = (T) buildSystemObject(typeof (T), memento);
- action(systemObject);
- }
- catch (Exception ex)
- {
- _pluginGraph.Log.RegisterError(130, ex, context);
- }
- }
-
-
- public void WithType(TypePath path, string context, Action<Type> action)
- {
- try
- {
- Type type = path.FindType();
- action(type);
- }
- catch (Exception ex)
- {
- _pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context);
- }
- }
-
- #endregion
-
- private object buildSystemObject(Type type, InstanceMemento memento)
- {
- Instance instance = memento.ReadInstance(_systemGraph, type);
-
- if (_systemInstanceManager == null)
- {
- _systemInstanceManager = new InstanceManager(_systemGraph);
- }
-
- return _systemInstanceManager.CreateInstance(type, instance);
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2008-05-09 15:47:15 UTC (rev 95)
+++ trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -26,6 +26,7 @@
IList<XmlNode> nodes = ConfigurationSettings.GetConfig(XmlConstants.STRUCTUREMAP) as IList<XmlNode>;
if (nodes == null)
{
+ // TODO -- need to get this into PluginGraph instead
throw new StructureMapException(105, XmlConstants.STRUCTUREMAP);
}
return nodes;
Added: trunk/Source/StructureMap/Emitting/ArgumentEmitter.cs
===================================================================
--- trunk/Source/StructureMap/Emitting/ArgumentEmitter.cs (rev 0)
+++ trunk/Source/StructureMap/Emitting/ArgumentEmitter.cs 2008-05-15 16:32:20 UTC (rev 96)
@@ -0,0 +1,77 @@
+using System.Reflection;
+using System.Reflection.Emit;
+using StructureMap.Emitting.Parameters;
+using StructureMap.Graph;
+
+namespace StructureMap.Emitting
+{
+ public class ArgumentEmitter : IArgumentVisitor
+ {
+ private readonly ChildParameterEmitter _child = new ChildParameterEmitter();
+ private readonly ChildArrayParameterEmitter _childArray = new ChildArrayParameterEmitter();
+ private readonly EnumParameterEmitter _enum = new EnumParameterEmitter();
+ private readonly PrimitiveParameterEmitter _primitive = new PrimitiveParameterEmitter();
+ private readonly StringParameterEmitter _string = new StringParameterEmitter();
+ private readonly ILGenerator ilgen;
+
+
+ public ArgumentEmitter(ILGenerator ilgen)
+ {
+ this.ilgen = ilgen;
+ }
+
+ #region IArgumentVisitor Members
+
+ public void PrimitiveSetter(PropertyInfo property)
+ {
+ _primitive.Setter(ilgen, property);
+ }
+
+ public void StringSetter(PropertyInfo property)
+ {
+ _string.Setter(ilgen, property);
+ }
+
+ public void EnumSetter(PropertyInfo property)
+ {
+ _enum.Setter(ilgen, property);
+ }
+
+ public void ChildSetter(PropertyInfo property)
+ {
+ _child.Setter(ilgen, property);
+ }
+
+ public void ChildArraySetter(PropertyInfo property)
+ {
+ _childArray.Setter(ilgen, property);
+ }
+
+ public void PrimitiveParameter(ParameterInfo parameter)
+ {
+ _primitive.Ctor(ilgen, parameter);
+ }
+
+ public void StringParameter(ParameterInfo parameter)
+ {
+ _string.Ctor(ilgen, parameter);
+ }
+
+ public void EnumParameter(ParameterInfo parameter)
+ {
+ _enum.Ctor(ilgen, parameter);
+ }
+
+ public void ChildParameter(ParameterInfo parameter)
+ {
+ _child.Ctor(ilgen, parameter);
+ }
+
+ public void ChildArrayParameter(ParameterInfo parameter)
+ {
+ _childArray.Ctor(ilgen, parameter);
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs
===================================================================
--- trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-05-09 15:47:15 UTC (rev 95)
+++ trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-05-15 ...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-27 16:04:37
|
Revision: 101
http://structuremap.svn.sourceforge.net/structuremap/?rev=101&view=rev
Author: jeremydmiller
Date: 2008-05-27 08:36:33 -0700 (Tue, 27 May 2008)
Log Message:
-----------
adding convenience methods for registering instances
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Delegates.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs
trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs
trunk/Source/StructureMap/StructureMap.csproj
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/Expressions/GenericFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs
trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -109,7 +109,7 @@
_children.Add(
delegate(PluginGraph graph)
{
- InterceptionFunction function = delegate(object target)
+ Func<object, object> function = delegate(object target)
{
handler((PLUGINTYPE) target);
return target;
@@ -127,7 +127,7 @@
_children.Add(
delegate(PluginGraph graph)
{
- InterceptionFunction function = delegate(object target) { return handler((PLUGINTYPE) target); };
+ Func<object, object> function = delegate(object target) { return handler((PLUGINTYPE) target); };
PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function);
graph.InterceptorLibrary.AddInterceptor(interceptor);
@@ -178,5 +178,29 @@
return this;
}
+
+ public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(PLUGINTYPE @object)
+ {
+ return TheDefaultIs(new LiteralInstance(@object));
+ }
+
+ public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(Func<PLUGINTYPE> func)
+ {
+ ConstructorInstance instance = new ConstructorInstance(delegate() { return func(); });
+ return TheDefaultIs(instance);
+ }
+
+ public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(PLUGINTYPE @object)
+ {
+ LiteralInstance instance = new LiteralInstance(@object);
+ return AddInstance(instance);
+ }
+
+ public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(Func<PLUGINTYPE> func)
+ {
+ ConstructorInstance instance = new ConstructorInstance(delegate(){ return func();});
+ return AddInstance(instance);
+ }
+
}
}
\ No newline at end of file
Added: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -0,0 +1,102 @@
+using System;
+using StructureMap.Attributes;
+using StructureMap.Graph;
+using StructureMap.Interceptors;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Configuration.DSL.Expressions
+{
+ public class GenericFamilyExpression
+ {
+ private readonly Type _pluginType;
+ private readonly Registry _registry;
+
+ public GenericFamilyExpression(Type pluginType, Registry registry)
+ {
+ _pluginType = pluginType;
+ _registry = registry;
+ }
+
+ private GenericFamilyExpression alterAndContinue(Action<PluginFamily> action)
+ {
+ _registry.addExpression(delegate(PluginGraph graph)
+ {
+ PluginFamily family = graph.FindFamily(_pluginType);
+ action(family);
+ });
+
+ return this;
+ }
+
+ public GenericFamilyExpression TheDefaultIsConcreteType(Type concreteType)
+ {
+ ConfiguredInstance instance = new ConfiguredInstance(concreteType);
+ return TheDefaultIs(instance);
+ }
+
+ public GenericFamilyExpression TheDefaultIs(Instance instance)
+ {
+ return alterAndContinue(delegate(PluginFamily family)
+ {
+ family.AddInstance(instance);
+ family.DefaultInstanceKey = instance.Name;
+ });
+ }
+
+ public GenericFamilyExpression TheDefaultIs(Func<object> func)
+ {
+ ConstructorInstance instance = new ConstructorInstance(func);
+ return TheDefaultIs(instance);
+ }
+
+ public GenericFamilyExpression AddInstance(Instance instance)
+ {
+ return alterAndContinue(delegate(PluginFamily family) { family.AddInstance(instance); });
+ }
+
+ public GenericFamilyExpression CacheBy(InstanceScope scope)
+ {
+ return alterAndContinue(delegate(PluginFamily family) { family.SetScopeTo(scope); });
+ }
+
+ public GenericFamilyExpression OnCreation(Action<object> action)
+ {
+ Func<object, object> func = delegate(object raw)
+ {
+ action(raw);
+ return raw;
+ };
+ return EnrichWith(func);
+ }
+
+ public GenericFamilyExpression EnrichWith(Func<object, object> func)
+ {
+ _registry.addExpression(delegate(PluginGraph graph)
+ {
+ PluginTypeInterceptor interceptor = new PluginTypeInterceptor(_pluginType, func);
+ graph.InterceptorLibrary.AddInterceptor(interceptor);
+ });
+
+ return this;
+ }
+
+
+ public GenericFamilyExpression InterceptConstructionWith(IBuildInterceptor interceptor)
+ {
+ return alterAndContinue(delegate(PluginFamily family)
+ {
+ family.AddInterceptor(interceptor);
+ });
+ }
+
+ public GenericFamilyExpression AddConcreteType(Type concreteType)
+ {
+ return AddInstance(new ConfiguredInstance(concreteType));
+ }
+
+ public GenericFamilyExpression AddConcreteType(Type concreteType, string instanceName)
+ {
+ return AddInstance(new ConfiguredInstance(concreteType).WithName(instanceName));
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -7,7 +7,7 @@
namespace StructureMap.Configuration.DSL
{
- public class Registry : IDisposable
+ public class Registry : RegistryExpressions, IDisposable
{
private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>();
private readonly PluginGraph _graph;
@@ -67,6 +67,12 @@
return new CreatePluginFamilyExpression<PLUGINTYPE>(this);
}
+
+ public GenericFamilyExpression ForRequestedType(Type pluginType)
+ {
+ return new GenericFamilyExpression(pluginType, this);
+ }
+
/// <summary>
/// Direct StructureMap to build instances of type T, and look for concrete classes
/// marked with the [Pluggable] attribute that implement type T.
@@ -114,41 +120,6 @@
/// <summary>
- /// Convenience method to start the definition of an instance of type T
- /// </summary>
- /// <typeparam name="PLUGGEDTYPE"></typeparam>
- /// <returns></returns>
- public static ConfiguredInstance Instance<PLUGGEDTYPE>()
- {
- ConfiguredInstance instance = new ConfiguredInstance();
- instance.PluggedType = typeof (PLUGGEDTYPE);
-
- return instance;
- }
-
- /// <summary>
- /// Convenience method to register a prototype instance
- /// </summary>
- /// <typeparam name="PLUGINTYPE"></typeparam>
- /// <param name="prototype"></param>
- /// <returns></returns>
- public static PrototypeInstance Prototype<PLUGINTYPE>(PLUGINTYPE prototype)
- {
- return new PrototypeInstance((ICloneable) prototype);
- }
-
- /// <summary>
- /// Convenience method to register a preconfigured instance of type T
- /// </summary>
- /// <typeparam name="PLUGINTYPE"></typeparam>
- /// <param name="instance"></param>
- /// <returns></returns>
- public static LiteralInstance Object<PLUGINTYPE>(PLUGINTYPE instance)
- {
- return new LiteralInstance(instance);
- }
-
- /// <summary>
/// Registers a preconfigured instance
/// </summary>
/// <typeparam name="PLUGINTYPE"></typeparam>
@@ -214,33 +185,6 @@
return (type.GetConstructor(new Type[0]) != null);
}
- /// <summary>
- /// Registers a UserControl as an instance
- /// </summary>
- /// <typeparam name="PLUGINTYPE"></typeparam>
- /// <param name="url"></param>
- /// <returns></returns>
- public UserControlInstance LoadControlFromUrl<PLUGINTYPE>(string url)
- {
- UserControlInstance instance = new UserControlInstance(url);
-
- PluginFamily family = _graph.FindFamily(typeof (PLUGINTYPE));
- family.AddInstance(instance);
-
- return instance;
- }
-
- public static ConstructorInstance ConstructedBy<PLUGINTYPE>
- (Func<PLUGINTYPE> builder)
- {
- return new ConstructorInstance(delegate() { return builder(); });
- }
-
- public static ReferencedInstance Instance(string referencedKey)
- {
- return new ReferencedInstance(referencedKey);
- }
-
public void RegisterInterceptor(TypeInterceptor interceptor)
{
addExpression(
@@ -276,35 +220,4 @@
_actions.Add(delegate(PluginGraph graph) { graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); });
}
}
-
-
- public class MatchedTypeInterceptor : TypeInterceptor
- {
- private readonly Predicate<Type> _match;
- private InterceptionFunction _interception;
-
- internal MatchedTypeInterceptor(Predicate<Type> match)
- {
- _match = match;
- }
-
- #region TypeInterceptor Members
-
- public bool MatchesType(Type type)
- {
- return _match(type);
- }
-
- public object Process(object target)
- {
- return _interception(target);
- }
-
- #endregion
-
- public void InterceptWith(InterceptionFunction interception)
- {
- _interception = interception;
- }
- }
}
\ No newline at end of file
Added: trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -0,0 +1,65 @@
+using System;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Configuration.DSL
+{
+ public class RegistryExpressions
+ {
+ /// <summary>
+ /// Convenience method to start the definition of an instance of type T
+ /// </summary>
+ /// <typeparam name="PLUGGEDTYPE"></typeparam>
+ /// <returns></returns>
+ public static ConfiguredInstance Instance<PLUGGEDTYPE>()
+ {
+ ConfiguredInstance instance = new ConfiguredInstance();
+ instance.PluggedType = typeof (PLUGGEDTYPE);
+
+ return instance;
+ }
+
+ /// <summary>
+ /// Convenience method to register a prototype instance
+ /// </summary>
+ /// <typeparam name="PLUGINTYPE"></typeparam>
+ /// <param name="prototype"></param>
+ /// <returns></returns>
+ public static PrototypeInstance Prototype<PLUGINTYPE>(PLUGINTYPE prototype)
+ {
+ return new PrototypeInstance((ICloneable) prototype);
+ }
+
+ /// <summary>
+ /// Convenience method to register a preconfigured instance of type T
+ /// </summary>
+ /// <typeparam name="PLUGINTYPE"></typeparam>
+ /// <param name="instance"></param>
+ /// <returns></returns>
+ public static LiteralInstance Object<PLUGINTYPE>(PLUGINTYPE instance)
+ {
+ return new LiteralInstance(instance);
+ }
+
+ /// <summary>
+ /// Registers a UserControl as an instance
+ /// </summary>
+ /// <typeparam name="PLUGINTYPE"></typeparam>
+ /// <param name="url"></param>
+ /// <returns></returns>
+ public UserControlInstance LoadControlFromUrl(string url)
+ {
+ return new UserControlInstance(url);
+ }
+
+ public static ConstructorInstance ConstructedBy<PLUGINTYPE>
+ (Func<PLUGINTYPE> builder)
+ {
+ return new ConstructorInstance(delegate() { return builder(); });
+ }
+
+ public static ReferencedInstance Instance(string referencedKey)
+ {
+ return new ReferencedInstance(referencedKey);
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Delegates.cs
===================================================================
--- trunk/Source/StructureMap/Delegates.cs 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap/Delegates.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -8,5 +8,6 @@
public delegate void Action<T>(T t);
public delegate void Action<T, T1>(T t, T1 t1);
public delegate T Func<T>();
+ public delegate T1 Func<T, T1>(T t);
}
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
+using StructureMap.Configuration.DSL;
using StructureMap.Diagnostics;
using StructureMap.Graph;
using StructureMap.Interceptors;
@@ -15,9 +16,17 @@
/// </summary>
public class InstanceManager : TypeRules, IInstanceManager
{
- private readonly InterceptorLibrary _interceptorLibrary;
- private readonly PipelineGraph _pipelineGraph;
+ private InterceptorLibrary _interceptorLibrary;
+ private PipelineGraph _pipelineGraph;
+ public InstanceManager(Action<Registry> action)
+ {
+ Registry registry = new Registry();
+ action(registry);
+
+ construct(registry.Build());
+ }
+
public InstanceManager() : this(new PluginGraph())
{
}
@@ -30,6 +39,11 @@
/// <param name="failOnException">Flags the InstanceManager to fail or trap exceptions</param>
public InstanceManager(PluginGraph pluginGraph)
{
+ construct(pluginGraph);
+ }
+
+ private void construct(PluginGraph pluginGraph)
+ {
_interceptorLibrary = pluginGraph.InterceptorLibrary;
if (!pluginGraph.IsSealed)
Modified: trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -10,10 +10,10 @@
public class PluginTypeInterceptor : TypeInterceptor
{
- private readonly InterceptionFunction _function;
+ private readonly Func<object, object> _function;
private readonly Type _pluginType;
- public PluginTypeInterceptor(Type pluginType, InterceptionFunction function)
+ public PluginTypeInterceptor(Type pluginType, Func<object, object> function)
{
_pluginType = pluginType;
_function = function;
Modified: trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -3,8 +3,6 @@
namespace StructureMap.Interceptors
{
- public delegate object InterceptionFunction(object target);
-
public class InterceptorLibrary
{
public static readonly InterceptorLibrary Empty = new InterceptorLibrary();
Added: trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs (rev 0)
+++ trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace StructureMap.Interceptors
+{
+ public class MatchedTypeInterceptor : TypeInterceptor
+ {
+ private readonly Predicate<Type> _match;
+ private Func<object, object> _interception;
+
+ internal MatchedTypeInterceptor(Predicate<Type> match)
+ {
+ _match = match;
+ }
+
+ #region TypeInterceptor Members
+
+ public bool MatchesType(Type type)
+ {
+ return _match(type);
+ }
+
+ public object Process(object target)
+ {
+ return _interception(target);
+ }
+
+ #endregion
+
+ public void InterceptWith(Func<object, object> interception)
+ {
+ _interception = interception;
+ }
+ }
+}
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 15:36:33 UTC (rev 101)
@@ -116,6 +116,8 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="BuildSession.cs" />
+ <Compile Include="Configuration\DSL\Expressions\GenericFamilyExpression.cs" />
+ <Compile Include="Configuration\DSL\RegistryExpressions.cs" />
<Compile Include="Configuration\ProfileBuilder.cs" />
<Compile Include="Delegates.cs" />
<Compile Include="Diagnostics\BuildError.cs" />
@@ -140,6 +142,7 @@
<Compile Include="InstanceBuilderList.cs" />
<Compile Include="InstanceCache.cs" />
<Compile Include="InstanceFamily.cs" />
+ <Compile Include="Interceptors\MatchedTypeInterceptor.cs" />
<Compile Include="PipelineGraph.cs" />
<Compile Include="Pipeline\BuildPolicy.cs" />
<Compile Include="Pipeline\CacheInterceptor.cs" />
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -213,6 +213,54 @@
Assert.IsInstanceOfType(typeof (DefaultGateway), gateway);
}
+
+ [Test]
+ public void Set_the_default_to_a_built_object()
+ {
+ AWidget aWidget = new AWidget();
+
+ InstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<IWidget>().TheDefaultIs(aWidget);
+ });
+
+ Assert.AreSame(aWidget, manager.CreateInstance<IWidget>());
+ }
+
+ [Test]
+ public void Set_the_default_by_a_lambda()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<IWidget>().TheDefaultIs(delegate() { return new AWidget(); });
+ });
+
+ Assert.IsInstanceOfType(typeof(AWidget), manager.CreateInstance<IWidget>());
+ }
+
+ [Test]
+ public void Add_an_instance_by_literal()
+ {
+ AWidget aWidget = new AWidget();
+
+ InstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<IWidget>().AddInstance(aWidget);
+ });
+
+ Assert.IsInstanceOfType(typeof(AWidget), manager.GetAllInstances<IWidget>()[0]);
+ }
+
+ [Test]
+ public void Add_an_instance_by_lambda()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<IWidget>().AddInstance(delegate() { return new AWidget(); });
+ });
+
+ Assert.IsInstanceOfType(typeof(AWidget), manager.GetAllInstances<IWidget>()[0]);
+ }
}
public class StubbedInstanceFactoryInterceptor : IBuildInterceptor
Added: trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -0,0 +1,189 @@
+using System;
+using NUnit.Framework;
+using StructureMap.Attributes;
+using StructureMap.Configuration.DSL;
+using StructureMap.Graph;
+using StructureMap.Interceptors;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Testing.Configuration.DSL
+{
+ [TestFixture]
+ public class GenericFamilyExpressionTester : RegistryExpressions
+ {
+ public interface ITarget
+ {
+ }
+
+ public class Target1 : ITarget
+ {
+ }
+
+ public class Target2 : ITarget
+ {
+ }
+
+ public class Target3 : ITarget
+ {
+ }
+
+ public class WrappedTarget : ITarget
+ {
+ private readonly ITarget _inner;
+
+ public WrappedTarget(ITarget target)
+ {
+ _inner = target;
+ }
+
+ public ITarget Inner
+ {
+ get { return _inner; }
+ }
+ }
+
+ [Test]
+ public void Add_concrete_type()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry r)
+ {
+ r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target1));
+ });
+
+
+ Assert.IsInstanceOfType(typeof(Target1), manager.GetAllInstances<ITarget>()[0]);
+ }
+
+ [Test]
+ public void Add_concrete_type_with_name()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry r)
+ {
+ r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target1), "1");
+ r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target2), "2");
+ r.ForRequestedType(typeof(ITarget)).AddConcreteType(typeof(Target3), "3");
+ });
+
+
+ Assert.IsInstanceOfType(typeof(Target1), manager.CreateInstance<ITarget>("1"));
+ Assert.IsInstanceOfType(typeof(Target2), manager.CreateInstance<ITarget>("2"));
+ Assert.IsInstanceOfType(typeof(Target3), manager.CreateInstance<ITarget>("3"));
+ }
+
+ [Test]
+ public void Add_default_by_concrete_type()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry r)
+ {
+ r.ForRequestedType(typeof (ITarget)).TheDefaultIsConcreteType(typeof (Target3));
+ });
+
+ Assert.IsInstanceOfType(typeof(Target3), manager.CreateInstance<ITarget>());
+ }
+
+ [Test]
+ public void Add_default_instance()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry r)
+ {
+ r.ForRequestedType(typeof(ITarget)).TheDefaultIs(Instance<Target2>());
+ });
+
+ Assert.IsInstanceOfType(typeof(Target2), manager.CreateInstance<ITarget>());
+ }
+
+ [Test]
+ public void Add_instance_by_lambda()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry r)
+ {
+ r.ForRequestedType(typeof(ITarget)).TheDefaultIs(delegate() { return new Target1(); });
+ });
+
+ Assert.IsInstanceOfType(typeof(Target1), manager.CreateInstance<ITarget>());
+ }
+
+ [Test]
+ public void Add_instance_directly()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry r)
+ {
+ r.ForRequestedType(typeof (ITarget)).AddInstance(Instance<Target2>());
+ });
+
+
+ Assert.IsInstanceOfType(typeof(Target2), manager.GetAllInstances<ITarget>()[0]);
+ }
+
+ [Test]
+ public void Enrichment()
+ {
+ InstanceManager manager = new InstanceManager(delegate(Registry r)
+ {
+ r.ForRequestedType(typeof(ITarget))
+ .TheDefaultIsConcreteType(typeof(Target1))
+ .EnrichWith(delegate(object raw){ return new WrappedTarget((ITarget) raw);});
+ });
+
+ WrappedTarget target = (WrappedTarget) manager.CreateInstance<ITarget>();
+ Assert.IsInstanceOfType(typeof(Target1), target.Inner);
+ }
+
+ [Test]
+ public void Intercept_construction_with()
+ {
+ Registry registry = new Registry();
+ TestingBuildPolicy policy = new TestingBuildPolicy();
+ registry.ForRequestedType(typeof (ITarget)).InterceptConstructionWith(policy);
+ PluginGraph graph = registry.Build();
+
+ Assert.AreSame(policy, graph.FindFamily(typeof(ITarget)).Policy);
+ }
+
+ public class TestingBuildPolicy : IBuildInterceptor
+ {
+ public IBuildPolicy InnerPolicy
+ {
+ get { throw new NotImplementedException(); }
+ set { }
+ }
+
+ public object Build(IBuildSession buildSession, Type pluginType, Instance instance)
+ {
+ throw new NotImplementedException();
+ }
+
+ public IBuildPolicy Clone()
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ [Test]
+ public void On_creation()
+ {
+ ITarget created = null;
+
+ InstanceManager manager = new InstanceManager(delegate(Registry r)
+ {
+ r.ForRequestedType(typeof (ITarget))
+ .TheDefaultIsConcreteType(typeof (Target3))
+ .OnCreation(delegate(object raw) { created = (ITarget) raw; });
+ });
+
+ manager.CreateInstance<ITarget>();
+
+ Assert.IsInstanceOfType(typeof(Target3), created);
+ }
+
+ [Test]
+ public void Set_caching()
+ {
+ Registry registry = new Registry();
+ registry.ForRequestedType(typeof (ITarget)).CacheBy(InstanceScope.ThreadLocal);
+ PluginGraph graph = registry.Build();
+
+ Assert.IsInstanceOfType(typeof(ThreadLocalStoragePolicy), graph.FindFamily(typeof(ITarget)).Policy);
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-27 13:25:28 UTC (rev 100)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-27 15:36:33 UTC (rev 101)
@@ -20,26 +20,6 @@
#endregion
-
- [Test]
- public void LoadControl()
- {
- PluginGraph graph = new PluginGraph();
- Registry registry = new Registry(graph);
-
- string theUrl = "some url";
- string theKey = "the memento";
- registry.LoadControlFromUrl<IGateway>(theUrl).WithName(theKey);
-
- registry.Dispose();
-
- PluginFamily family = graph.FindFamily(typeof (IGateway));
- UserControlInstance instance = (UserControlInstance) family.GetInstance(theKey);
- Assert.IsNotNull(instance);
-
- Assert.AreEqual(theUrl, instance.Url);
- Assert.AreEqual(theKey, instance.Name);
- }
}
public class TestRegistry : Registry
...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-27 17:50:53
|
Revision: 102
http://structuremap.svn.sourceforge.net/structuremap/?rev=102&view=rev
Author: jeremydmiller
Date: 2008-05-27 10:50:51 -0700 (Tue, 27 May 2008)
Log Message:
-----------
killing off TODO's
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/GraphBuilder.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/Pipeline/BuildPolicy.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs
trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/Instance.cs
trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapConfiguration.cs
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs
trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs
trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs
trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
trunk/Source/StructureMap.Testing.Widget/Rule.cs
trunk/Source/StructureMap.Testing.Widget5/OtherGridColumn.cs
Added Paths:
-----------
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Building.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs
trunk/Source/StructureMap/Pipeline/IStructuredInstance.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-05-27 15:36:33 UTC (rev 101)
+++ trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -12,8 +12,7 @@
/// <returns></returns>
public static ConfiguredInstance Instance<PLUGGEDTYPE>()
{
- ConfiguredInstance instance = new ConfiguredInstance();
- instance.PluggedType = typeof (PLUGGEDTYPE);
+ ConfiguredInstance instance = new ConfiguredInstance(typeof (PLUGGEDTYPE));
return instance;
}
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 15:36:33 UTC (rev 101)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -42,24 +42,11 @@
_builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family)
{
- // TODO: there's a little duplication here
InstanceScope scope = findScope(element);
family.SetScopeTo(scope);
- Type pluginType = family.PluginType;
-
- string name = element.GetAttribute(XmlConstants.NAME);
- if (string.IsNullOrEmpty(name))
- {
- name = "DefaultInstanceOf" + pluginTypePath.AssemblyQualifiedName;
- }
-
InstanceMemento memento = _mementoCreator.CreateMemento(element);
- memento.InstanceKey = name;
-
- family.DefaultInstanceKey = name;
-
- family.AddInstance(memento);
+ family.AddDefaultMemento(memento);
});
}
Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-27 15:36:33 UTC (rev 101)
+++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -63,7 +63,6 @@
public void PrepareSystemObjects()
{
- // TODO: is this a problem here?
_systemGraph.Seal();
}
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 15:36:33 UTC (rev 101)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -286,5 +286,16 @@
return plugin;
}
}
+
+ public void AddDefaultMemento(InstanceMemento memento)
+ {
+ if (string.IsNullOrEmpty(memento.InstanceKey))
+ {
+ memento.InstanceKey = "DefaultInstanceOf" + TypePath.GetAssemblyQualifiedName(PluginType);
+ }
+
+ AddInstance(memento);
+ DefaultInstanceKey = memento.InstanceKey;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-05-27 15:36:33 UTC (rev 101)
+++ trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -68,13 +68,11 @@
{
if (property == null)
{
- // TODO -- log this
throw new StructureMapException(240, propertyName, _plugin.PluggedType);
}
if (property.GetSetMethod() == null)
{
- // TODO -- log this
throw new StructureMapException(241, propertyName, _plugin.PluggedType);
}
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 15:36:33 UTC (rev 101)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -96,8 +96,7 @@
public void InjectByName<PLUGINTYPE, CONCRETETYPE>(string instanceKey)
{
- ConfiguredInstance instance = new ConfiguredInstance();
- instance.PluggedType = typeof(CONCRETETYPE);
+ ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE));
instance.Name = instanceKey;
AddInstance<PLUGINTYPE>(instance);
@@ -207,7 +206,6 @@
throw new StructureMapException(230, type.FullName);
}
- // TODO: Little bit of smelliness here
Plugin plugin = new Plugin(type);
if (!plugin.CanBeAutoFilled)
{
Modified: trunk/Source/StructureMap/Pipeline/BuildPolicy.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2008-05-27 15:36:33 UTC (rev 101)
+++ trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -15,8 +15,14 @@
object builtObject = instance.Build(pluginType, buildSession);
- // TODO: error handling around the interception
- return buildSession.ApplyInterception(pluginType, builtObject);
+ try
+ {
+ return buildSession.ApplyInterception(pluginType, builtObject);
+ }
+ catch (Exception e)
+ {
+ throw new StructureMapException(308, e, instance.Name, builtObject.GetType());
+ }
}
public IBuildPolicy Clone()
Added: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Building.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Building.cs (rev 0)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Building.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace StructureMap.Pipeline
+{
+ public partial class ConfiguredInstance
+ {
+ Type IConfiguredInstance.PluggedType
+ {
+ get { return _pluggedType; }
+ }
+
+ Instance[] IConfiguredInstance.GetChildrenArray(string propertyName)
+ {
+ return _arrays.ContainsKey(propertyName) ? _arrays[propertyName] : null;
+ }
+
+ string IConfiguredInstance.GetProperty(string propertyName)
+ {
+ if (!_properties.ContainsKey(propertyName))
+ {
+ throw new StructureMapException(205, propertyName, Name);
+ }
+
+ return _properties[propertyName];
+ }
+
+ object IConfiguredInstance.GetChild(string propertyName, Type pluginType, IBuildSession buildSession)
+ {
+ return getChild(propertyName, pluginType, buildSession);
+ }
+
+ string IConfiguredInstance.ConcreteKey
+ {
+ get { return _concreteKey; }
+ set { _concreteKey = value; }
+ }
+
+
+ // Only open for testing
+ object IConfiguredInstance.Build(Type pluginType, IBuildSession session, InstanceBuilder builder)
+ {
+ if (builder == null)
+ {
+ throw new StructureMapException(
+ 201, _concreteKey, Name, pluginType);
+ }
+
+
+ try
+ {
+ return builder.BuildInstance(this, session);
+ }
+ catch (StructureMapException)
+ {
+ throw;
+ }
+ catch (InvalidCastException ex)
+ {
+ throw new StructureMapException(206, ex, Name);
+ }
+ catch (Exception ex)
+ {
+ throw new StructureMapException(207, ex, Name, pluginType.FullName);
+ }
+ }
+
+ }
+}
Added: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs (rev 0)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -0,0 +1,283 @@
+using System;
+using System.Configuration;
+using StructureMap.Configuration.DSL;
+using StructureMap.Graph;
+
+namespace StructureMap.Pipeline
+{
+ public partial class ConfiguredInstance
+ {
+ /// <summary>
+ /// Use a named Plugin type denoted by a [Pluggable("Key")] attribute
+ /// </summary>
+ /// <param name="concreteKey"></param>
+ /// <returns></returns>
+ public ConfiguredInstance UsingConcreteTypeNamed(string concreteKey)
+ {
+ _concreteKey = concreteKey;
+ return this;
+ }
+
+ /// <summary>
+ /// Use type T for the concrete type of an instance
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns></returns>
+ public ConfiguredInstance UsingConcreteType<T>()
+ {
+ _pluggedType = typeof (T);
+ return this;
+ }
+
+ public ChildArrayExpression ChildArray<PLUGINTYPE>(string propertyName)
+ {
+ validateTypeIsArray<PLUGINTYPE>();
+
+ ChildArrayExpression expression =
+ new ChildArrayExpression(this, propertyName, typeof (PLUGINTYPE));
+
+ return expression;
+ }
+
+ public ChildArrayExpression ChildArray(string propertyName, Type childType)
+ {
+ return new ChildArrayExpression(this, propertyName, childType);
+ }
+
+ public ChildArrayExpression ChildArray<PLUGINTYPE>()
+ {
+ validateTypeIsArray<PLUGINTYPE>();
+
+ string propertyName = findPropertyName<PLUGINTYPE>();
+ return ChildArray<PLUGINTYPE>(propertyName);
+ }
+
+ /// <summary>
+ /// Start the definition of a child instance for type CONSTRUCTORARGUMENTTYPE
+ /// </summary>
+ /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam>
+ /// <returns></returns>
+ public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>()
+ {
+ string propertyName = findPropertyName<CONSTRUCTORARGUMENTTYPE>();
+
+ ChildInstanceExpression child = Child(propertyName);
+ child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE);
+
+ return child;
+ }
+
+ public ChildInstanceExpression Child(string propertyName)
+ {
+ return new ChildInstanceExpression(this, propertyName);
+ }
+
+
+ /// <summary>
+ /// Starts the definition of a child instance specifying the argument name
+ /// in the case of a constructor function that consumes more than one argument
+ /// of type T
+ /// </summary>
+ /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam>
+ /// <param name="propertyName"></param>
+ /// <returns></returns>
+ public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>(string propertyName)
+ {
+ ChildInstanceExpression child = new ChildInstanceExpression(this, propertyName);
+ child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE);
+
+ return child;
+ }
+
+ /// <summary>
+ /// Start the definition of a primitive argument to a constructor argument
+ /// </summary>
+ /// <param name="propertyName"></param>
+ /// <returns></returns>
+ public PropertyExpression WithProperty(string propertyName)
+ {
+ return new PropertyExpression(this, propertyName);
+ }
+
+ public ConfiguredInstance WithConcreteKey(string concreteKey)
+ {
+ replaceNameIfNotAlreadySet(concreteKey);
+ _concreteKey = concreteKey;
+ return this;
+ }
+
+
+ private string findPropertyName<T>()
+ {
+ Plugin plugin = new Plugin(_pluggedType);
+ string propertyName = plugin.FindFirstConstructorArgumentOfType<T>();
+
+ if (string.IsNullOrEmpty(propertyName))
+ {
+ throw new StructureMapException(305, typeof (T));
+ }
+
+ return propertyName;
+ }
+
+ private static void validateTypeIsArray<PLUGINTYPE>()
+ {
+ if (!typeof (PLUGINTYPE).IsArray)
+ {
+ throw new StructureMapException(307);
+ }
+ }
+
+ #region Nested type: ChildArrayExpression
+
+ public class ChildArrayExpression
+ {
+ private readonly Type _childType;
+ private readonly ConfiguredInstance _instance;
+ private readonly string _propertyName;
+
+ public ChildArrayExpression(ConfiguredInstance instance, string propertyName, Type childType)
+ {
+ _instance = instance;
+ _propertyName = propertyName;
+
+ _childType = _childType;
+ }
+
+ public ConfiguredInstance Contains(params Instance[] instances)
+ {
+ _instance.setChildArray(_propertyName, instances);
+
+ return _instance;
+ }
+ }
+
+ #endregion
+
+ #region Nested type: ChildInstanceExpression
+
+ /// <summary>
+ /// Part of the Fluent Interface, represents a nonprimitive argument to a
+ /// constructure function
+ /// </summary>
+ public class ChildInstanceExpression
+ {
+ private readonly ConfiguredInstance _instance;
+ private readonly string _propertyName;
+ private Type _childType;
+
+
+ public ChildInstanceExpression(ConfiguredInstance instance, string propertyName)
+ {
+ _instance = instance;
+ _propertyName = propertyName;
+ }
+
+ public ChildInstanceExpression(ConfiguredInstance instance, string propertyName,
+ Type childType)
+ : this(instance, propertyName)
+ {
+ _childType = childType;
+ }
+
+ internal Type ChildType
+ {
+ set { _childType = value; }
+ }
+
+ /// <summary>
+ /// Use a previously configured and named instance for the child
+ /// </summary>
+ /// <param name="instanceKey"></param>
+ /// <returns></returns>
+ public ConfiguredInstance IsNamedInstance(string instanceKey)
+ {
+ ReferencedInstance instance = new ReferencedInstance(instanceKey);
+ _instance.setChild(_propertyName, instance);
+
+ return _instance;
+ }
+
+ /// <summary>
+ /// Start the definition of a child instance by defining the concrete type
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns></returns>
+ public ConfiguredInstance IsConcreteType<T>()
+ {
+ Type pluggedType = typeof (T);
+ ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType);
+
+ ConfiguredInstance childInstance = new ConfiguredInstance();
+ childInstance._pluggedType = pluggedType;
+ _instance.setChild(_propertyName, childInstance);
+
+ return _instance;
+ }
+
+
+ /// <summary>
+ /// Registers a configured instance to use as the argument to the parent's
+ /// constructor
+ /// </summary>
+ /// <param name="child"></param>
+ /// <returns></returns>
+ public ConfiguredInstance Is(Instance child)
+ {
+ _instance.setChild(_propertyName, child);
+ return _instance;
+ }
+
+ public ConfiguredInstance Is(object value)
+ {
+ LiteralInstance instance = new LiteralInstance(value);
+ return Is(instance);
+ }
+ }
+
+ #endregion
+
+ #region Nested type: PropertyExpression
+
+ /// <summary>
+ /// Defines the value of a primitive argument to a constructur argument
+ /// </summary>
+ public class PropertyExpression
+ {
+ private readonly ConfiguredInstance _instance;
+ private readonly string _propertyName;
+
+ public PropertyExpression(ConfiguredInstance instance, string propertyName)
+ {
+ _instance = instance;
+ _propertyName = propertyName;
+ }
+
+ /// <summary>
+ /// Sets the value of the constructor argument
+ /// </summary>
+ /// <param name="propertyValue"></param>
+ /// <returns></returns>
+ public ConfiguredInstance EqualTo(object propertyValue)
+ {
+ _instance.SetProperty(_propertyName, propertyValue.ToString());
+ return _instance;
+ }
+
+ /// <summary>
+ /// Sets the value of the constructor argument to the key/value in the
+ /// AppSettings
+ /// </summary>
+ /// <param name="appSettingKey"></param>
+ /// <returns></returns>
+ public ConfiguredInstance EqualToAppSetting(string appSettingKey)
+ {
+ string propertyValue = ConfigurationManager.AppSettings[appSettingKey];
+ _instance.SetProperty(_propertyName, propertyValue);
+ return _instance;
+ }
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-27 15:36:33 UTC (rev 101)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-27 17:50:51 UTC (rev 102)
@@ -1,13 +1,11 @@
using System;
using System.Collections.Generic;
-using System.Configuration;
-using StructureMap.Configuration.DSL;
using StructureMap.Graph;
namespace StructureMap.Pipeline
{
- // TODO: Move the FI stuff into a partial class
- public class ConfiguredInstance : ExpressedInstance<ConfiguredInstance>, IConfiguredInstance
+ public partial class ConfiguredInstance : ExpressedInstance<ConfiguredInstance>, IConfiguredInstance,
+ IStructuredInstance
{
private readonly Dictionary<string, Instance> _children = new Dictionary<string, Instance>();
private readonly Dictionary<string, string> _properties = new Dictionary<string, string>();
@@ -23,7 +21,7 @@
public ConfiguredInstance(InstanceMemento memento, PluginGraph graph, Type pluginType)
{
- Read(memento, graph, pluginType);
+ read(memento, graph, pluginType);
}
public ConfiguredInstance(string name)
@@ -37,55 +35,36 @@
_pluggedType = pluggedType;
}
- public Type PluggedType
- {
- get { return _pluggedType; }
- set { _pluggedType = value; }
- }
-
protected override ConfiguredInstance thisInstance
{
get { return this; }
}
- #region IConfiguredInstance Members
+ #region IStructuredInstance Members
- public string ConcreteKey
+ Instance IStructuredInstance.GetChild(string name)
{
- get
- {
- return _concreteKey;
- }
- set { _concreteKey = value; }
+ return _children[name];
}
- Instance[] IConfiguredInstance.GetChildrenArray(string propertyName)
+ Instance[] IStructuredInstance.GetChildArray(string name)
{
- if (_arrays.ContainsKey(propertyName))
- {
- return _arrays[propertyName];
- }
-
- return null;
+ return _arrays[name];
}
- string IConfiguredInstance.GetProperty(string propertyName)
+ void IStructuredInstance.RemoveKey(string name)
{
- if (!_properties.ContainsKey(propertyName))
- {
- throw new StructureMapException(205, propertyName, Name);
- }
-
- return _properties[propertyName];
+ _properties.Remove(name);
}
- object IConfiguredInstance.GetChild(string propertyName, Type pluginType, IBuildSession buildSession)
+ #endregion
+
+ protected void setPluggedType(Type pluggedType)
{
- return getChild(propertyName, pluginType, buildSession);
+ _pluggedType = pluggedType;
}
- #endregion
protected void mergeIntoThis(ConfiguredInstance instance)
{
@@ -114,39 +93,11 @@
protected override object build(Type pluginType, IBuildSession session)
{
InstanceBuilder builder = session.FindBuilderByType(pluginType, _pluggedType) ??
- session.FindBuilderByConcreteKey(pluginType, ConcreteKey);
+ session.FindBuilderByConcreteKey(pluginType, _concreteKey);
- return Build(pluginType, session, builder);
+ return ((IConfiguredInstance) this).Build(pluginType, session, builder);
}
- // Only open for testing
- public object Build(Type pluginType, IBuildSession session, InstanceBuilder builder)
- {
- if (builder == null)
- {
- throw new StructureMapException(
- 201, ConcreteKey, Name, pluginType);
- }
-
-
- try
- {
- return builder.BuildInstance(this, session);
- }
- catch (StructureMapException)
- {
- throw;
- }
- catch (InvalidCastException ex)
- {
- throw new StructureMapException(206, ex, Name);
- }
- catch (Exception ex)
- {
- throw new StructureMapException(207, ex, Name, pluginType.FullName);
- }
- }
-
protected virtual object getChild(string propertyName, Type pluginType, IBuildSession buildSession)
{
Instance childInstance = _children.ContainsKey(propertyName)
@@ -166,9 +117,9 @@
return family.Plugins.HasPlugin(_concreteKey);
}
- if (PluggedType != null)
+ if (_pluggedType != null)
{
- return TypeRules.CanBeCast(family.PluginType, PluggedType);
+ return TypeRules.CanBeCast(family.PluginType, _pluggedType);
}
return false;
@@ -185,12 +136,12 @@
return this;
}
- public void Read(InstanceMemento memento, PluginGraph graph, Type pluginType)
+ private void read(InstanceMemento memento, PluginGraph graph, Type pluginType)
{
PluginFamily family = graph.FindFamily(pluginType);
Plugin plugin = memento.FindPlugin(family);
- PluggedType = plugin.PluggedType;
+ _pluggedType = plugin.PluggedType;
_concreteKey = plugin.ConcreteKey;
InstanceMementoPropertyReader reader = new InstanceMementoPropertyReader(this, memento, graph, pluginType);
@@ -198,286 +149,17 @@
}
- public void SetChild(string name, Instance instance)
+ private void setChild(string name, Instance instance)
{
_children.Add(name, instance);
}
- public Instance GetChild(string name)
+ private void setChildArray(string name, Instance[] array)
{
- return _children[name];
- }
-
- public void SetChildArray(string name, Instance[] array)
- {
_arrays.Add(name, array);
}
- public Instance[] GetChildArray(string name)
- {
- return _arrays[name];
- }
-
- public ConfiguredInstance WithConcreteKey(string concreteKey)
- {
- replaceNameIfNotAlreadySet(concreteKey);
- _concreteKey = concreteKey;
- return this;
- }
-
- public void RemoveKey(string name)
- {
- _properties.Remove(name);
- }
-
- /// <summary>
- /// Start the definition of a primitive argument to a constructor argument
- /// </summary>
- /// <param name="propertyName"></param>
- /// <returns></returns>
- public PropertyExpression WithProperty(string propertyName)
- {
- return new PropertyExpression(this, propertyName);
- }
-
- /// <summary>
- /// Starts the definition of a child instance specifying the argument name
- /// in the case of a constructor function that consumes more than one argument
- /// of type T
- /// </summary>
- /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam>
- /// <param name="propertyName"></param>
- /// <returns></returns>
- public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>(string propertyName)
- {
- ChildInstanceExpression child = new ChildInstanceExpression(this, propertyName);
- child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE);
-
- return child;
- }
-
- /// <summary>
- /// Start the definition of a child instance for type CONSTRUCTORARGUMENTTYPE
- /// </summary>
- /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam>
- /// <returns></returns>
- public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>()
- {
- string propertyName = findPropertyName<CONSTRUCTORARGUMENTTYPE>();
-
- ChildInstanceExpression child = new ChildInstanceExpression(this, propertyName);
- child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE);
- return child;
- }
-
- private string findPropertyName<T>()
- {
- Plugin plugin = new Plugin(_pluggedType);
- string propertyName = plugin.FindFirstConstructorArgumentOfType<T>();
-
- if (string.IsNullOrEmpty(propertyName))
- {
- throw new StructureMapException(305, typeof (T));
- }
-
- return propertyName;
- }
-
- public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>()
- {
- validateTypeIsArray<PLUGINTYPE>();
-
- string propertyName = findPropertyName<PLUGINTYPE>();
- return ChildArray<PLUGINTYPE>(propertyName);
- }
-
- public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>(string propertyName)
- {
- validateTypeIsArray<PLUGINTYPE>();
-
- ChildArrayExpression<PLUGINTYPE> expression =
- new ChildArrayExpression<PLUGINTYPE>(this, propertyName);
-
- return expression;
- }
-
- private static void validateTypeIsArray<PLUGINTYPE>()
- {
- if (!typeof (PLUGINTYPE).IsArray)
- {
- throw new StructureMapException(307);
- }
- }
-
- /// <summary>
- /// Use type T for the concrete type of an instance
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <returns></returns>
- public ConfiguredInstance UsingConcreteType<T>()
- {
- _pluggedType...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-27 22:12:36
|
Revision: 103
http://structuremap.svn.sourceforge.net/structuremap/?rev=103&view=rev
Author: jeremydmiller
Date: 2008-05-27 15:12:33 -0700 (Tue, 27 May 2008)
Log Message:
-----------
little refactoring of ProfileManager and PluginFamily to move misplaced code
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Pipeline/ProfileManager.cs
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 17:50:51 UTC (rev 102)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 22:12:33 UTC (rev 103)
@@ -297,5 +297,21 @@
AddInstance(memento);
DefaultInstanceKey = memento.InstanceKey;
}
+
+ public void FillDefault(Profile profile)
+ {
+ if (string.IsNullOrEmpty(DefaultInstanceKey))
+ {
+ return;
+ }
+
+ Instance defaultInstance = GetInstance(DefaultInstanceKey);
+ if (defaultInstance == null)
+ {
+ Parent.Log.RegisterError(210, DefaultInstanceKey, PluginType);
+ }
+
+ profile.FillTypeInto(PluginType, defaultInstance);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 17:50:51 UTC (rev 102)
+++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 22:12:33 UTC (rev 103)
@@ -133,7 +133,7 @@
{
foreach (PluginFamily family in graph.PluginFamilies)
{
- findDefaultFromPluginFamily(family);
+ family.FillDefault(_default);
}
}
@@ -158,19 +158,6 @@
}
}
- private void findDefaultFromPluginFamily(PluginFamily family)
- {
- // TODO: Sad path here if the default instance key cannot be found
- // TODO: Pull inside of PluginFamily itself
- if (string.IsNullOrEmpty(family.DefaultInstanceKey))
- {
- return;
- }
-
- Instance defaultInstance = family.GetInstance(family.DefaultInstanceKey);
- _default.FillTypeInto(family.PluginType, defaultInstance);
- }
-
public void CopyDefaults(Type basicType, Type templatedType)
{
_default.CopyDefault(basicType, templatedType);
Modified: trunk/Source/StructureMap/StructureMapException.resx
===================================================================
--- trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 17:50:51 UTC (rev 102)
+++ trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 22:12:33 UTC (rev 103)
@@ -256,4 +256,7 @@
<data name="270" xml:space="preserve">
<value>Instance specific interception failed for {0} of PluginType {1}</value>
</data>
+ <data name="210" xml:space="preserve">
+ <value>The designated default instance '{0}' for PluginType {1} cannot be found</value>
+ </data>
</root>
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-27 17:50:51 UTC (rev 102)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-27 22:12:33 UTC (rev 103)
@@ -112,6 +112,32 @@
}
[Test]
+ public void FillDefault_happy_path()
+ {
+ PluginFamily family = new PluginFamily(typeof (IWidget));
+ family.Parent = new PluginGraph();
+ family.AddInstance(new ConfiguredInstance().WithName("Default"));
+ family.DefaultInstanceKey = "Default";
+
+
+ family.FillDefault(new Profile("theProfile"));
+
+ family.Parent.Log.AssertHasNoError(210);
+ }
+
+ [Test]
+ public void FillDefault_sad_path_when_the_default_instance_key_does_not_exist_throws_210()
+ {
+ PluginFamily family = new PluginFamily(typeof (IWidget));
+ family.Parent = new PluginGraph();
+
+ family.DefaultInstanceKey = "something that cannot be found";
+ family.FillDefault(new Profile("theProfile"));
+
+ family.Parent.Log.AssertHasError(210);
+ }
+
+ [Test]
public void If_PluginFamily_only_has_one_instance_make_that_the_default()
{
PluginFamily family = new PluginFamily(typeof (IGateway));
@@ -259,7 +285,7 @@
[Pluggable("Default")]
public class SingletonRepositoryWithAttribute : ISingletonRepository
{
- private Guid _id = Guid.NewGuid();
+ private readonly Guid _id = Guid.NewGuid();
public Guid Id
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-05-27 23:46:17
|
Revision: 104
http://structuremap.svn.sourceforge.net/structuremap/?rev=104&view=rev
Author: jeremydmiller
Date: 2008-05-27 16:46:15 -0700 (Tue, 27 May 2008)
Log Message:
-----------
Killing off the TODO's in the code, lots of defensive programming
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/GraphBuilder.cs
trunk/Source/StructureMap/Configuration/ProfileBuilder.cs
trunk/Source/StructureMap/Diagnostics/Error.cs
trunk/Source/StructureMap/Diagnostics/GraphLog.cs
trunk/Source/StructureMap/Exceptions/StructureMapException.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs
trunk/Source/StructureMap/Pipeline/ProfileManager.cs
trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml
trunk/Source/StructureMap.Testing/TestData/PluggedTypeTest.xml
Added Paths:
-----------
trunk/Source/StructureMap/ErrorMessages.cs
trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -75,7 +75,6 @@
return returnValue;
}
- // TODO: change to many
private void attachMementoSource(PluginFamily family, XmlElement familyElement)
{
XmlNode sourceNode = familyElement[XmlConstants.MEMENTO_SOURCE_NODE];
Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -99,22 +99,9 @@
}
}
-
public void WithType(TypePath path, string context, Action<Type> action)
{
- try
- {
- Type type = path.FindType();
- action(type);
- }
- catch (StructureMapException ex)
- {
- _pluginGraph.Log.RegisterError(ex);
- }
- catch (Exception ex)
- {
- _pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context);
- }
+ _pluginGraph.Log.WithType(path, context, action);
}
#endregion
Modified: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -47,12 +47,11 @@
public void OverrideProfile(TypePath typePath, string instanceKey)
{
- _pluginGraph.Log.Try(delegate()
+ _pluginGraph.Log.WithType(typePath, "while trying to add an override for a Profile", delegate(Type pluginType)
{
ReferencedInstance instance = new ReferencedInstance(instanceKey);
- _pluginGraph.SetDefault(_lastProfile, typePath.FindType(), instance);
-
- }).AndReportErrorAs(107, typePath.AssemblyQualifiedName);
+ _pluginGraph.SetDefault(_lastProfile, pluginType, instance);
+ });
}
public void AddMachine(string machineName, string profileName)
@@ -72,9 +71,13 @@
return;
}
- // TODO: what if the Type cannot be found?
- ReferencedInstance instance = new ReferencedInstance(instanceKey);
- _profileManager.SetMachineDefault(typePath.FindType(), instance);
+ _pluginGraph.Log.WithType(typePath,
+ "trying to configure a Machine Override",
+ delegate(Type pluginType)
+ {
+ ReferencedInstance instance = new ReferencedInstance(instanceKey);
+ _profileManager.SetMachineDefault(pluginType, instance);
+ });
}
public void SetDefaultProfileName(string profileName)
Modified: trunk/Source/StructureMap/Diagnostics/Error.cs
===================================================================
--- trunk/Source/StructureMap/Diagnostics/Error.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Diagnostics/Error.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -22,10 +22,7 @@
public Error(int errorCode, params object[] args)
{
_code = errorCode;
- string template = getMessage(errorCode);
- if (template == null) template = string.Empty;
-
- _message = string.Format(template, args);
+ _message = ErrorMessages.GetMessage(errorCode, args);
}
public Error(int errorCode, Exception ex, params object[] args) : this(errorCode, args)
@@ -62,11 +59,6 @@
#endregion
- private static string getMessage(int errorCode)
- {
- ResourceManager resources = new ResourceManager(typeof (StructureMapException));
- return resources.GetString(errorCode.ToString());
- }
public override bool Equals(object obj)
{
Modified: trunk/Source/StructureMap/Diagnostics/GraphLog.cs
===================================================================
--- trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -127,6 +127,23 @@
}
}
+ public void WithType(TypePath path, string context, Action<Type> action)
+ {
+ try
+ {
+ Type type = path.FindType();
+ action(type);
+ }
+ catch (StructureMapException ex)
+ {
+ RegisterError(ex);
+ }
+ catch (Exception ex)
+ {
+ RegisterError(131, ex, path.AssemblyQualifiedName, context);
+ }
+ }
+
public TryAction Try(Action action)
{
return new TryAction(action, this);
Added: trunk/Source/StructureMap/ErrorMessages.cs
===================================================================
--- trunk/Source/StructureMap/ErrorMessages.cs (rev 0)
+++ trunk/Source/StructureMap/ErrorMessages.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Resources;
+using System.Text;
+
+namespace StructureMap
+{
+ internal static class ErrorMessages
+ {
+ public static string GetMessage(int errorCode, params object[] args)
+ {
+ string msg = "StructureMap Exception Code: " + errorCode + "\n";
+
+ for (int i = 0; i < args.Length; i++)
+ {
+ object arg = args[i];
+ Type type = arg as Type;
+ if (type != null)
+ {
+ args[i] = type.AssemblyQualifiedName;
+ }
+ }
+
+ string errorMsg = getMessage(errorCode);
+ if (errorMsg == null)
+ {
+ errorMsg = string.Empty;
+ }
+
+ return string.Format(errorMsg, args);
+ }
+
+ private static string getMessage(int errorCode)
+ {
+ ResourceManager resources = new ResourceManager(typeof(StructureMapException));
+ return resources.GetString(errorCode.ToString());
+ }
+ }
+}
Modified: trunk/Source/StructureMap/Exceptions/StructureMapException.cs
===================================================================
--- trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -25,13 +25,17 @@
public StructureMapException(int ErrorCode, params object[] args) : base()
{
- initialize(ErrorCode, args);
+ _errorCode = ErrorCode;
+ _msg = string.Format("StructureMap Exception Code: {0}\n", _errorCode);
+ _msg += ErrorMessages.GetMessage(ErrorCode, args);
}
public StructureMapException(int ErrorCode, Exception InnerException, params object[] args)
: base(string.Empty, InnerException)
{
- initialize(ErrorCode, args);
+ _errorCode = ErrorCode;
+ _msg = string.Format("StructureMap Exception Code: {0}\n", _errorCode);
+ _msg += ErrorMessages.GetMessage(ErrorCode, args);
}
public override string Message
@@ -44,38 +48,8 @@
get { return _errorCode; }
}
- // TODO: Centralize this code somewhere so it isn't duplicated
- private void initialize(int errorCode, params object[] args)
- {
- _errorCode = errorCode;
- _msg = "StructureMap Exception Code: " + _errorCode + "\n";
- for (int i = 0; i < args.Length; i++)
- {
- object arg = args[i];
- Type type = arg as Type;
- if (type != null)
- {
- args[i] = type.AssemblyQualifiedName;
- }
- }
- string errorMsg = getMessage(ErrorCode);
- if (errorMsg == null)
- {
- errorMsg = string.Empty;
- }
-
- _msg += string.Format(errorMsg, args);
- }
-
- private string getMessage(int errorCode)
- {
- ResourceManager resources = new ResourceManager(GetType());
-
- return resources.GetString(errorCode.ToString());
- }
-
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("errorCode", _errorCode, typeof (int));
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -24,7 +24,6 @@
{
if (concreteKey == string.Empty)
{
- // TODO: Move into PluginFamily and get the exception logged somewhere
throw new StructureMapException(112, pluggedType.FullName);
}
Modified: trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -26,8 +26,14 @@
protected override object build(Type pluginType, IBuildSession session)
{
- // TODO: specific error message
- return _builder();
+ try
+ {
+ return _builder();
+ }
+ catch (Exception ex)
+ {
+ throw new StructureMapException(207, ex, Name, pluginType);
+ }
}
protected override string getDescription()
Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using StructureMap.Diagnostics;
using StructureMap.Graph;
namespace StructureMap.Pipeline
@@ -36,21 +37,29 @@
get { return _currentProfile.Name; }
set
{
- // TODO: Profile cannot be found
-
if (string.IsNullOrEmpty(value))
{
_currentProfile = _default;
}
else
{
+ validateHasProfile(value);
+
_currentProfile = getProfile(value);
_default.FillAllTypesInto(_currentProfile);
}
}
}
+ private void validateHasProfile(string profileName)
+ {
+ if (!_profiles.ContainsKey(profileName))
+ {
+ throw new StructureMapException(280, profileName);
+ }
+ }
+
public Instance GetDefault(Type pluginType, string profileName)
{
Profile profile = getProfile(profileName);
@@ -98,7 +107,7 @@
{
findMasterInstances(graph);
- setProfileDefaults();
+ setProfileDefaults(graph.Log);
processMachineDefaults(graph);
@@ -117,14 +126,18 @@
}
}
- private void setProfileDefaults()
+ private void setProfileDefaults(GraphLog log)
{
if (string.IsNullOrEmpty(_defaultProfileName))
{
return;
}
- // TODO: What if Profile doesn't exist?
+ if (!_profiles.ContainsKey(_defaultProfileName))
+ {
+ log.RegisterError(280, _defaultProfileName);
+ }
+
Profile profile = getProfile(_defaultProfileName);
profile.FillAllTypesInto(_default);
}
@@ -152,7 +165,10 @@
if (!string.IsNullOrEmpty(_defaultMachineProfileName))
{
- // TODO: Machine profile name cannot be found
+ if (!_profiles.ContainsKey(_defaultMachineProfileName))
+ {
+ graph.Log.RegisterError(280, _defaultMachineProfileName);
+ }
Profile profile = getProfile(_defaultMachineProfileName);
profile.FillAllTypesInto(_default);
}
Modified: trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -5,7 +5,7 @@
{
public class PrototypeInstance : ExpressedInstance<PrototypeInstance>
{
- private ICloneable _prototype;
+ private readonly ICloneable _prototype;
public PrototypeInstance(ICloneable prototype)
@@ -21,7 +21,6 @@
protected override object build(Type pluginType, IBuildSession session)
{
- // TODO: VALIDATION IF IT CAN'T BE CAST
return _prototype.Clone();
}
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 23:46:15 UTC (rev 104)
@@ -373,6 +373,7 @@
<None Include="..\structuremap.snk">
<Link>Properties\structuremap.snk</Link>
</None>
+ <Compile Include="ErrorMessages.cs" />
<Compile Include="Pipeline\ConfiguredInstance.Building.cs" />
<Compile Include="Pipeline\IStructuredInstance.cs" />
</ItemGroup>
Modified: trunk/Source/StructureMap/StructureMapException.resx
===================================================================
--- trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 23:46:15 UTC (rev 104)
@@ -161,7 +161,7 @@
<value>Invalid property value(s), InstanceKey "{0}"</value>
</data>
<data name="207" xml:space="preserve">
- <value>Internal exception in the constructor function of the targeted concrete type. InstanceKey "{0}", PluginFamily {1}</value>
+ <value>Internal exception while creating Instance '{0}' of PluginType {1}. Check the inner exception for more details.</value>
</data>
<data name="104" xml:space="preserve">
<value>Type {0} cannot be plugged into type {1}</value>
@@ -259,4 +259,7 @@
<data name="210" xml:space="preserve">
<value>The designated default instance '{0}' for PluginType {1} cannot be found</value>
</data>
+ <data name="280" xml:space="preserve">
+ <value>Requested Profile {0} cannot be found</value>
+ </data>
</root>
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -63,8 +63,31 @@
Assert.AreEqual(instance, _graph.ProfileManager.GetMachineDefault(this.GetType()));
}
+ [Test]
+ public void Log_131_if_trying_to_register_override_for_a_machine_when_the_PluginType_cannot_be_found()
+ {
+ _builder.AddMachine(THE_MACHINE_NAME, "TheProfile");
+
+ _graph.Log.AssertHasNoError(131);
+
+ _builder.OverrideMachine(new TypePath("not a real type"), "Purple");
+ _graph.Log.AssertHasError(131);
+ }
+
[Test]
+ public void Log_131_if_trying_to_register_override_for_a_profile_when_the_PluginType_cannot_be_found()
+ {
+ _builder.AddProfile("TheProfile");
+
+ _graph.Log.AssertHasNoError(131);
+
+ _builder.OverrideProfile(new TypePath("not a real type"), "Purple");
+
+ _graph.Log.AssertHasError(131);
+ }
+
+ [Test]
public void Do_not_register_a_machine_override_if_it_is_NOT_the_matching_machine()
{
_builder.AddMachine("Some other machine", "TheProfile");
@@ -73,7 +96,24 @@
Assert.IsNull(_graph.ProfileManager.GetMachineDefault(this.GetType()));
}
+
[Test]
+ public void Throw_280_if_requesting_an_invalid_profile()
+ {
+ try
+ {
+ ProfileManager manager = new ProfileManager();
+ manager.CurrentProfile = "some profile that does not exist";
+
+ Assert.Fail("Should have thrown error");
+ }
+ catch (StructureMapException ex)
+ {
+ Assert.AreEqual(280, ex.ErrorCode);
+ }
+ }
+
+ [Test]
public void SetDefaultProfileName()
{
string theProfileName = "some profile name";
@@ -82,17 +122,6 @@
Assert.AreEqual(theProfileName, _graph.ProfileManager.DefaultProfileName);
}
- [Test]
- public void Override_profile_with_a_bad_TypePath_should_log_107()
- {
- PluginGraph graph = new PluginGraph();
- ProfileBuilder builder = new ProfileBuilder(graph);
-
- builder.AddProfile("something");
- builder.OverrideProfile(new TypePath("a type that does not exist"), "key");
-
- graph.Log.AssertHasError(107);
- }
}
}
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using NUnit.Framework;
+using StructureMap.Pipeline;
+using StructureMap.Testing.Widget;
+
+namespace StructureMap.Testing.Pipeline
+{
+ [TestFixture]
+ public class ConstructorInstanceTester
+ {
+ [Test]
+ public void Sad_path_inner_function_throws_exception_207_with_key_and_plugin_type()
+ {
+ ConstructorInstance instance = new ConstructorInstance(delegate()
+ {
+ throw new NotImplementedException();
+ });
+
+ try
+ {
+ instance.Build(typeof (IWidget), null);
+ Assert.Fail("Should have thrown an exception");
+ }
+ catch (StructureMapException ex)
+ {
+ Assert.AreEqual(207, ex.ErrorCode);
+ }
+ }
+ }
+}
Modified: trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs 2008-05-27 23:46:15 UTC (rev 104)
@@ -243,5 +243,30 @@
Assert.AreSame(_manager.GetDefault(typeof(IBuildPolicy), "Profile"), _manager.GetDefault(typeof(ISomething), "Profile"));
Assert.AreSame(_manager.GetDefault(typeof(IBuildPolicy), "Profile2"), _manager.GetDefault(typeof(ISomething), "Profile2"));
}
+
+ [Test]
+ public void Log_280_if_the_default_profile_does_not_exist_upon_call_to_Seal()
+ {
+ ProfileManager manager = new ProfileManager();
+ manager.DefaultProfileName = "something that doesn't exist";
+
+ PluginGraph graph = new PluginGraph();
+ manager.Seal(graph);
+
+ graph.Log.AssertHasError(280);
+
+ }
+
+ [Test]
+ public void Log_280_if_the_machine_default_profile_cannot_be_found()
+ {
+ ProfileManager manager = new ProfileManager();
+ manager.DefaultMachineProfileName = "something that doesn't exist";
+
+ PluginGraph graph = new PluginGraph();
+ manager.Seal(graph);
+
+ graph.Log.AssertHasError(280);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-27 23:46:15 UTC (rev 104)
@@ -326,6 +326,7 @@
<Compile Include="PipelineGraphTester.cs" />
<Compile Include="Pipeline\BuildStrategiesTester.cs" />
<Compile Include="Pipeline\ConfiguredInstanceTester.cs" />
+ <Compile Include="Pipeline\ConstructorInstanceTester.cs" />
<Compile Include="Pipeline\DefaultInstanceTester.cs" />
<Compile Include="Pipeline\InstanceTester.cs" />
<Compile Include="Pipeline\LiteralInstanceTester.cs" />
Modified: trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml
===================================================================
--- trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml 2008-05-27 23:46:15 UTC (rev 104)
@@ -1,5 +1,5 @@
<!--<?xml version="1.0" encoding="utf-8" ?>-->
-<StructureMap DefaultProfile="TheDefaultProfile" MementoStyle="Attribute">
+<StructureMap MementoStyle="Attribute">
<Assembly Name="StructureMap.Testing.Widget"/>
<Assembly Name="StructureMap.Testing.Widget2"/>
<Assembly Name="StructureMap.Testing.Widget3"/>
Modified: trunk/Source/StructureMap.Testing/TestData/PluggedTypeTest.xml
===================================================================
--- trunk/Source/StructureMap.Testing/TestData/PluggedTypeTest.xml 2008-05-27 22:12:33 UTC (rev 103)
+++ trunk/Source/StructureMap.Testing/TestData/PluggedTypeTest.xml 2008-05-27 23:46:15 UTC (rev 104)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
-<StructureMap DefaultProfile="TheDefaultProfile" MementoStyle="Attribute">
+<StructureMap MementoStyle="Attribute">
<PluginFamily Type="StructureMap.Testing.Widget.IWidget" Assembly="StructureMap.Testing.Widget">
<Instance Key="Me" PluggedType="StructureMap.Testing.Widget.NotPluggableWidget,StructureMap.Testing.Widget" name="Jeremy"/>
</PluginFamily>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2008-05-28 03:15:35
|
Revision: 105
http://structuremap.svn.sourceforge.net/structuremap/?rev=105&view=rev
Author: jeremydmiller
Date: 2008-05-27 20:15:34 -0700 (Tue, 27 May 2008)
Log Message:
-----------
Cleaning up Registry code
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/StructureMapConfiguration.cs
trunk/Source/StructureMap.Testing/BuildSessionTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs
trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs
trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -32,7 +32,18 @@
});
}
+ public CreatePluginFamilyExpression<PLUGINTYPE> AddInstances(params Instance[] instances)
+ {
+ return alterAndContinue(delegate(PluginFamily family)
+ {
+ foreach (Instance instance in instances)
+ {
+ family.AddInstance(instance);
+ }
+ });
+ }
+
// TODO: 3.5, Try alterAndContinue(f => {});
private CreatePluginFamilyExpression<PLUGINTYPE> alterAndContinue(Action<PluginFamily> action)
{
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -7,7 +7,7 @@
namespace StructureMap.Configuration.DSL
{
- public class Registry : RegistryExpressions, IDisposable
+ public class Registry : RegistryExpressions
{
private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>();
private readonly PluginGraph _graph;
@@ -23,15 +23,6 @@
configure();
}
- #region IDisposable Members
-
- public void Dispose()
- {
- ConfigurePluginGraph(_graph);
- }
-
- #endregion
-
/// <summary>
/// Implement this method to
/// </summary>
@@ -86,12 +77,6 @@
return new CreatePluginFamilyExpression<PLUGINTYPE>(this);
}
- public IInstanceManager BuildInstanceManager()
- {
- ConfigurePluginGraph(_graph);
- return new InstanceManager(_graph);
- }
-
public PluginGraph Build()
{
ConfigurePluginGraph(_graph);
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -62,12 +62,12 @@
});
}
- private InstanceScope findScope(XmlElement familyElement)
+ private static InstanceScope findScope(XmlElement familyElement)
{
InstanceScope returnValue = InstanceScope.PerRequest;
string scopeString = familyElement.GetAttribute(XmlConstants.SCOPE_ATTRIBUTE);
- if (scopeString != null && scopeString != string.Empty)
+ if (!string.IsNullOrEmpty(scopeString))
{
returnValue = (InstanceScope) Enum.Parse(typeof (InstanceScope), scopeString);
}
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -27,6 +27,10 @@
construct(registry.Build());
}
+ public InstanceManager(Registry registry) : this(registry.Build())
+ {
+ }
+
public InstanceManager() : this(new PluginGraph())
{
}
@@ -283,6 +287,5 @@
return _pipelineGraph.ForType(type);
}
-
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs
===================================================================
--- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -166,7 +166,12 @@
return _registry.AddInstanceOf<T>();
}
+ public static void AddInstanceOf<T>(Instance instance)
+ {
+ _registry.ForRequestedType<T>().AddInstance(instance);
+ }
+
/// <summary>
/// Adds a preconfigured instance of Type T to StructureMap. When this instance is requested,
/// StructureMap will always return the original object.
Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -138,13 +138,13 @@
[Test]
public void If_no_child_array_is_explicitly_defined_return_all_instances()
{
- Registry registry = new Registry();
- registry.AddInstanceOf<IWidget>(new ColorWidget("Red"));
- registry.AddInstanceOf<IWidget>(new ColorWidget("Blue"));
- registry.AddInstanceOf<IWidget>(new ColorWidget("Green"));
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.AddInstanceOf<IWidget>(new ColorWidget("Red"));
+ registry.AddInstanceOf<IWidget>(new ColorWidget("Blue"));
+ registry.AddInstanceOf<IWidget>(new ColorWidget("Green"));
+ });
- IInstanceManager manager = registry.BuildInstanceManager();
-
WidgetHolder holder = manager.CreateInstance<WidgetHolder>();
Assert.AreEqual(3, holder.Widgets.Length);
}
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -15,38 +15,38 @@
[SetUp]
public void SetUp()
{
- pluginGraph = new PluginGraph();
- Registry registry = new Registry(pluginGraph);
- registry.ScanAssemblies().IncludeAssemblyContainingType<ColorWidget>();
+
+ manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ScanAssemblies().IncludeAssemblyContainingType<ColorWidget>();
- // Add an instance with properties
- registry.AddInstanceOf<IWidget>()
- .UsingConcreteType<ColorWidget>()
- .WithName("DarkGreen")
- .WithProperty("Color").EqualTo("DarkGreen");
+ // Add an instance with properties
+ registry.AddInstanceOf<IWidget>()
+ .UsingConcreteType<ColorWidget>()
+ .WithName("DarkGreen")
+ .WithProperty("Color").EqualTo("DarkGreen");
- // Add an instance by specifying the ConcreteKey
- registry.AddInstanceOf<IWidget>()
- .UsingConcreteTypeNamed("Color")
- .WithName("Purple")
- .WithProperty("Color").EqualTo("Purple");
+ // Add an instance by specifying the ConcreteKey
+ registry.AddInstanceOf<IWidget>()
+ .UsingConcreteTypeNamed("Color")
+ .WithName("Purple")
+ .WithProperty("Color").EqualTo("Purple");
- // Pull a property from the App config
- registry.AddInstanceOf<IWidget>()
- .UsingConcreteType<ColorWidget>()
- .WithName("AppSetting")
- .WithProperty("Color").EqualToAppSetting("Color");
+ // Pull a property from the App config
+ registry.AddInstanceOf<IWidget>()
+ .UsingConcreteType<ColorWidget>()
+ .WithName("AppSetting")
+ .WithProperty("Color").EqualToAppSetting("Color");
- registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>();
+ registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>();
- manager = registry.BuildInstanceManager();
+ });
}
#endregion
private IInstanceManager manager;
- private PluginGraph pluginGraph;
[Test]
public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteKey()
@@ -65,14 +65,13 @@
[Test]
public void AddInstanceAndOverrideTheConcreteTypeForADependency()
{
- Registry registry = new Registry();
+ IInstanceManager manager = new InstanceManager(delegate(Registry 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>();
+ });
- // 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);
}
@@ -88,13 +87,12 @@
[Test]
public void SimpleCaseWithNamedInstance()
{
- Registry registry = new Registry();
+ manager = new InstanceManager(delegate(Registry registry)
+ {
+ // Specify a new Instance and override the Name
+ registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance");
+ });
- // 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);
}
@@ -102,25 +100,21 @@
[Test]
public void SpecifyANewInstanceOverrideADependencyWithANamedInstance()
{
- Registry registry = new Registry();
+ manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias");
- //registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>();
+ // Add an instance by specifying the ConcreteKey
+ registry.AddInstanceOf<IWidget>()
+ .UsingConcreteType<ColorWidget>()
+ .WithName("Purple")
+ .WithProperty("Color").EqualTo("Purple");
+ // Specify a new Instance, override a dependency with a named instance
+ registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("RuleThatUsesMyInstance")
+ .Child<IWidget>("widget").IsNamedInstance("Purple");
+ });
- registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias");
-
- // Add an instance by specifying the ConcreteKey
- registry.AddInstanceOf<IWidget>()
- .UsingConcreteType<ColorWidget>()
- .WithName("Purple")
- .WithProperty("Color").EqualTo("Purple");
-
- // Specify a new Instance, override a dependency with a named instance
- registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("RuleThatUsesMyInstance")
- .Child<IWidget>("widget").IsNamedInstance("Purple");
-
- manager = registry.BuildInstanceManager();
-
Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>("Alias"));
WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("RuleThatUsesMyInstance");
@@ -131,21 +125,21 @@
[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")
- );
- IInstanceManager mgr = registry.BuildInstanceManager();
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey)
+ .Child<IWidget>().Is(
+ Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>()
+ .WithProperty("Color").EqualTo("Orange")
+ .WithName("Orange")
+ );
+ });
- WidgetRule rule = (WidgetRule) mgr.CreateInstance<Rule>(instanceKey);
+ WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>(instanceKey);
ColorWidget widget = (ColorWidget) rule.Widget;
Assert.AreEqual("Orange", widget.Color);
}
@@ -153,13 +147,15 @@
[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"
CloneableWidget theWidget = new CloneableWidget("Jeremy");
- registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy");
+
- manager = registry.BuildInstanceManager();
+ manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy");
+ });
CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy");
CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy");
@@ -178,12 +174,13 @@
[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();
+ manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.AddInstanceOf<IWidget>(julia).WithName("Julia");
+ });
CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia");
CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia");
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -30,14 +30,15 @@
[Test]
public void A_concrete_type_is_available_by_name_when_it_is_added_by_the_shorthand_mechanism()
{
- Registry registry = new Registry();
- registry.ForRequestedType<IAddTypes>()
- .AddConcreteType<RedAddTypes>("Red")
- .AddConcreteType<GreenAddTypes>("Green")
- .AddConcreteType<BlueAddTypes>("Blue")
- .AddConcreteType<PurpleAddTypes>();
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<IAddTypes>()
+ .AddConcreteType<RedAddTypes>("Red")
+ .AddConcreteType<GreenAddTypes>("Green")
+ .AddConcreteType<BlueAddTypes>("Blue")
+ .AddConcreteType<PurpleAddTypes>();
+ });
- IInstanceManager manager = registry.BuildInstanceManager();
Assert.IsInstanceOfType(typeof (RedAddTypes), manager.CreateInstance<IAddTypes>("Red"));
Assert.IsInstanceOfType(typeof (GreenAddTypes), manager.CreateInstance<IAddTypes>("Green"));
Assert.IsInstanceOfType(typeof (BlueAddTypes), manager.CreateInstance<IAddTypes>("Blue"));
@@ -46,28 +47,33 @@
[Test]
public void A_concrete_type_is_available_when_it_is_added_by_the_shorthand_mechanism()
{
- Registry registry = new Registry();
- registry.ForRequestedType<IAddTypes>()
- .AddConcreteType<RedAddTypes>()
- .AddConcreteType<GreenAddTypes>()
- .AddConcreteType<BlueAddTypes>()
- .AddConcreteType<PurpleAddTypes>();
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<IAddTypes>()
+ .AddConcreteType<RedAddTypes>()
+ .AddConcreteType<GreenAddTypes>()
+ .AddConcreteType<BlueAddTypes>()
+ .AddConcreteType<PurpleAddTypes>();
+ });
- IList<IAddTypes> instances = registry.BuildInstanceManager().GetAllInstances<IAddTypes>();
+
+ IList<IAddTypes> instances = manager.GetAllInstances<IAddTypes>();
Assert.AreEqual(4, instances.Count);
}
[Test]
public void Make_sure_that_we_dont_double_dip_instances_when_we_register_a_type_with_a_name()
{
- Registry registry = new Registry();
- registry.ForRequestedType<IAddTypes>()
- .AddConcreteType<RedAddTypes>("Red")
- .AddConcreteType<GreenAddTypes>()
- .AddConcreteType<BlueAddTypes>("Blue")
- .AddConcreteType<PurpleAddTypes>();
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<IAddTypes>()
+ .AddConcreteType<RedAddTypes>("Red")
+ .AddConcreteType<GreenAddTypes>()
+ .AddConcreteType<BlueAddTypes>("Blue")
+ .AddConcreteType<PurpleAddTypes>();
+ });
- IList<IAddTypes> instances = registry.BuildInstanceManager().GetAllInstances<IAddTypes>();
+ IList<IAddTypes> instances = manager.GetAllInstances<IAddTypes>();
Assert.AreEqual(4, instances.Count);
}
}
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -31,17 +31,15 @@
Concretion concretion1 = new Concretion();
Concretion concretion2 = new Concretion();
- Registry registry = new Registry();
- registry.ForRequestedType<Abstraction>()
- .AddInstance(
- ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One")
- )
- .AddInstance(
- ConstructedBy<Abstraction>(delegate { return concretion2; }).WithName("Two")
- );
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<Abstraction>()
+ .AddInstances(
+ ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One"),
+ ConstructedBy<Abstraction>(delegate { return concretion2; }).WithName("Two")
+ );
+ });
- IInstanceManager manager = registry.BuildInstanceManager();
-
Assert.AreSame(concretion1, manager.CreateInstance<Abstraction>("One"));
Assert.AreSame(concretion2, manager.CreateInstance<Abstraction>("Two"));
}
@@ -51,12 +49,13 @@
{
Concretion concretion = new Concretion();
- Registry registry = new Registry();
- registry.ForRequestedType<Abstraction>().TheDefaultIs(
- ConstructedBy<Abstraction>(delegate { return concretion; })
- );
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<Abstraction>().TheDefaultIs(
+ ConstructedBy<Abstraction>(delegate { return concretion; })
+ );
+ });
- IInstanceManager manager = registry.BuildInstanceManager();
Assert.AreSame(concretion, manager.CreateInstance<Abstraction>());
}
@@ -66,17 +65,17 @@
Concretion concretion1 = new Concretion();
Concretion concretion2 = new Concretion();
- Registry registry = new Registry();
- registry.ForRequestedType<Abstraction>().AddInstance(
- ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One")
- );
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<Abstraction>().AddInstance(
+ ConstructedBy<Abstraction>(delegate { return concretion1; }).WithName("One")
+ );
- registry.ForRequestedType<Abstraction>().AddInstance(
- ConstructedBy<Abstraction>(delegate { return concretion2; }).WithName("Two")
- );
+ registry.ForRequestedType<Abstraction>().AddInstance(
+ ConstructedBy<Abstraction>(delegate { return concretion2; }).WithName("Two")
+ );
+ });
- IInstanceManager manager = registry.BuildInstanceManager();
-
Assert.AreSame(concretion1, manager.CreateInstance<Abstraction>("One"));
Assert.AreSame(concretion2, manager.CreateInstance<Abstraction>("Two"));
}
@@ -86,14 +85,13 @@
{
Concretion concretion = new Concretion();
- Registry registry = new Registry();
- registry.ForRequestedType<Abstraction>().AddInstance(
- ConstructedBy<Abstraction>(delegate { return concretion; })
- );
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<Abstraction>().AddInstance(
+ ConstructedBy<Abstraction>(delegate { return concretion; })
+ );
+ });
-
- IInstanceManager manager = registry.BuildInstanceManager();
-
Abstraction actual = manager.GetAllInstances<Abstraction>()[0];
Assert.AreSame(concretion, actual);
}
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-27 23:46:15 UTC (rev 104)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-28 03:15:34 UTC (rev 105)
@@ -5,7 +5,6 @@
using StructureMap.Configuration.DSL;
using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
-using StructureMap.Interceptors;
using StructureMap.Pipeline;
using StructureMap.Testing.Widget;
using StructureMap.Testing.Widget3;
@@ -37,14 +36,36 @@
}
[Test]
- public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap()
+ public void Add_an_instance_by_lambda()
{
- Registry registry = new Registry();
- registry.ForRequestedType<Something>().AddInstance(
- Registry.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red")
- );
+ InstanceManager manager =
+ new InstanceManager(
+ delegate(Registry registry) { registry.ForRequestedType<IWidget>().AddInstance(delegate { return new AWidget(); }); });
- IInstanceManager manager = registry.BuildInstanceManager();
+ Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]);
+ }
+
+ [Test]
+ public void Add_an_instance_by_literal()
+ {
+ AWidget aWidget = new AWidget();
+
+ InstanceManager manager =
+ new InstanceManager(
+ delegate(Registry registry) { registry.ForRequestedType<IWidget>().AddInstance(aWidget); });
+
+ Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]);
+ }
+
+ [Test]
+ public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap()
+ {
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.ForRequestedType<Something>().AddInstance(
+ RegistryExpressions.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red")
+ );
+ });
IList<Something> instances = manager.GetAllInstances<Something>();
Assert.AreEqual(1, instances.Count);
}
@@ -52,12 +73,10 @@
[Test]
public void AddInstanceWithNameOnlyAddsOneInstanceToStructureMap()
{
- PluginGraph graph = new PluginGraph();
- Registry registry = new Registry(graph);
- registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red");
-
-
- IInstanceManager manager = registry.BuildInstanceManager();
+ IInstanceManager manager = new InstanceManager(delegate(Registry registry)
+ {
+ registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red");
+ });
IList<Something> instances = manager.GetAllInstances<Something>();
Assert.AreEqual(1, instances.Count);
}
@@ -65,72 +84,64 @@
[Test]
public void AsAnotherScope()
{
- PluginGraph pluginGraph = new PluginGraph();
- using (Registry registry = new Registry(pluginGraph))
- {
- CreatePluginFamilyExpression<IGateway> expression =
- registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal);
- Assert.IsNotNull(expression);
- }
+ Registry registry = new Registry();
+ CreatePluginFamilyExpression<IGateway> expression =
+ registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal);
+ Assert.IsNotNull(expression);
+ PluginGraph pluginGraph = registry.Build();
+
PluginFamily family = pluginGraph.FindFamily(typeof (IGateway));
- Assert.IsInstanceOfType(typeof(ThreadLocalStoragePolicy), family.Policy);
+ Assert.IsInstanceOfType(typeof (ThreadLocalStoragePolicy), family.Policy);
}
[Test]
public void BuildInstancesOfType()
{
- Pl...
[truncated message content] |
|
From: <jer...@us...> - 2008-05-28 03:35:04
|
Revision: 106
http://structuremap.svn.sourceforge.net/structuremap/?rev=106&view=rev
Author: jeremydmiller
Date: 2008-05-27 20:35:02 -0700 (Tue, 27 May 2008)
Log Message:
-----------
minor refactoring of Registry
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-28 03:15:34 UTC (rev 105)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-28 03:35:02 UTC (rev 106)
@@ -10,16 +10,9 @@
public class Registry : RegistryExpressions
{
private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>();
- private readonly PluginGraph _graph;
- public Registry(PluginGraph graph) : this()
- {
- _graph = graph;
- }
-
public Registry()
{
- _graph = new PluginGraph();
configure();
}
@@ -79,10 +72,11 @@
public PluginGraph Build()
{
- ConfigurePluginGraph(_graph);
- _graph.Seal();
+ PluginGraph graph = new PluginGraph();
+ ConfigurePluginGraph(graph);
+ graph.Seal();
- return _graph;
+ return graph;
}
/// <summary>
@@ -95,10 +89,7 @@
ConfiguredInstance instance = new ConfiguredInstance();
addExpression(
- delegate(PluginGraph pluginGraph)
- {
- pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance);
- });
+ delegate(PluginGraph pluginGraph) { pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); });
return instance;
}
@@ -113,7 +104,7 @@
public LiteralInstance AddInstanceOf<PLUGINTYPE>(PLUGINTYPE target)
{
LiteralInstance literal = new LiteralInstance(target);
- _graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal);
+ _actions.Add(delegate(PluginGraph graph) { graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal); });
return literal;
}
@@ -126,10 +117,13 @@
/// <returns></returns>
public PrototypeInstance AddPrototypeInstanceOf<PLUGINTYPE>(PLUGINTYPE prototype)
{
- PrototypeInstance expression = new PrototypeInstance((ICloneable) prototype);
- _graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(expression);
+ PrototypeInstance instance = new PrototypeInstance((ICloneable) prototype);
+ _actions.Add(delegate(PluginGraph graph)
+ {
+ graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance);
+ });
- return expression;
+ return instance;
}
/// <summary>
@@ -138,7 +132,7 @@
/// <typeparam name="PLUGINTYPE"></typeparam>
/// <param name="url"></param>
/// <returns></returns>
- public static UserControlInstance LoadUserControlFrom<PLUGINTYPE>(string url)
+ public static UserControlInstance LoadUserControlFrom(string url)
{
return new UserControlInstance(url);
}
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-28 03:15:34 UTC (rev 105)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-28 03:35:02 UTC (rev 106)
@@ -24,11 +24,6 @@
public class TestRegistry : Registry
{
- public TestRegistry(PluginGraph graph) : base(graph)
- {
- }
-
-
public TestRegistry()
{
}
Modified: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-05-28 03:15:34 UTC (rev 105)
+++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-05-28 03:35:02 UTC (rev 106)
@@ -18,23 +18,20 @@
[SetUp]
public void SetUp()
{
- PluginGraph graph = new PluginGraph();
- Registry registry = new Registry(graph);
+ Registry registry = new Registry();
registry.BuildInstancesOf<Rule>();
registry.ScanAssemblies()
.IncludeAssembly("StructureMap.Testing.Widget")
.IncludeAssembly("StructureMap.Testing.Widget2");
- registry.Build();
+ PluginGraph graph = registry.Build();
PipelineGraph pipelineGraph = new PipelineGraph(graph);
_session = new BuildSession(pipelineGraph, graph.InterceptorLibrary);
- instance = new ConfiguredInstance();
}
#endregion
- private ConfiguredInstance instance;
private IBuildSession _session;
@@ -52,17 +49,7 @@
}
}
- [Test]
- public void TestComplexRule()
- {
- ConfiguredInstance instance = (ConfiguredInstance)ComplexRule.GetInstance();
- Rule rule = (Rule)instance.Build(typeof(Rule), _session);
- Assert.IsNotNull(rule);
- Assert.IsTrue(rule is ComplexRule);
- }
-
-
[Test]
public void AttachDependencies_should_find_the_InstanceBuilder_by_ConcreteKey_if_PluggedType_does_not_exists()
{
@@ -106,7 +93,7 @@
using (mocks.Playback())
{
- object actualObject = ((IConfiguredInstance)instance).Build(GetType(), session, builder);
+ object actualObject = ((IConfiguredInstance) instance).Build(GetType(), session, builder);
Assert.AreSame(theObjectBuilt, actualObject);
}
}
@@ -134,10 +121,10 @@
[Test, ExpectedException(typeof (StructureMapException))]
public void BuildRuleWithAMissingValue()
{
- IStructuredInstance instance = (IStructuredInstance)ComplexRule.GetInstance();
+ IStructuredInstance instance = (IStructuredInstance) ComplexRule.GetInstance();
instance.RemoveKey("String");
- ComplexRule rule = (ComplexRule) ((Instance)instance).Build(typeof (Rule), _session);
+ ComplexRule rule = (ComplexRule) ((Instance) instance).Build(typeof (Rule), _session);
}
[Test]
@@ -225,7 +212,8 @@
[Test]
public void GetProperty_happy_path()
{
- instance.SetProperty("Color", "Red")
+ ConfiguredInstance instance = new ConfiguredInstance()
+ .SetProperty("Color", "Red")
.SetProperty("Age", "34");
IConfiguredInstance configuredInstance = instance;
@@ -242,7 +230,7 @@
{
try
{
- IConfiguredInstance configuredInstance = instance;
+ IConfiguredInstance configuredInstance = new ConfiguredInstance();
configuredInstance.GetProperty("anything");
Assert.Fail("Did not throw exception");
}
@@ -277,6 +265,16 @@
}
[Test]
+ public void TestComplexRule()
+ {
+ ConfiguredInstance instance = (ConfiguredInstance) ComplexRule.GetInstance();
+
+ Rule rule = (Rule) instance.Build(typeof (Rule), _session);
+ Assert.IsNotNull(rule);
+ Assert.IsTrue(rule is ComplexRule);
+ }
+
+ [Test]
public void Trying_to_build_with_an_InvalidCastException_will_throw_error_206()
{
MockRepository mocks = new MockRepository();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|