You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
|
Feb
(5) |
Mar
(9) |
Apr
(9) |
May
(4) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
2008 |
Jan
(11) |
Feb
(6) |
Mar
|
Apr
(16) |
May
(28) |
Jun
(13) |
Jul
(3) |
Aug
(19) |
Sep
(11) |
Oct
(37) |
Nov
(1) |
Dec
(17) |
2009 |
Jan
(16) |
Feb
(6) |
Mar
|
Apr
(6) |
May
(1) |
Jun
(10) |
Jul
(4) |
Aug
(4) |
Sep
(4) |
Oct
(8) |
Nov
(3) |
Dec
(45) |
2010 |
Jan
(8) |
Feb
(21) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: <jer...@us...> - 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 Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-27 13:25:28 UTC (rev 100) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-27 15:36:33 UTC (rev 101) @@ -166,6 +166,7 @@ <Compile Include="Configuration\DSL\CreatePluginFamilyTester.cs" /> <Compile Include="Configuration\DSL\CreateProfileTester.cs" /> <Compile Include="Configuration\DSL\DeepInstanceTester.cs" /> + <Compile Include="Configuration\DSL\GenericFamilyExpressionTester.cs" /> <Compile Include="Configuration\DSL\InjectArrayTester.cs" /> <Compile Include="Configuration\DSL\InstanceExpressionTester.cs" /> <Compile Include="Configuration\DSL\InterceptAllInstancesOfPluginTypeTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-27 13:25:34
|
Revision: 100 http://structuremap.svn.sourceforge.net/structuremap/?rev=100&view=rev Author: jeremydmiller Date: 2008-05-27 06:25:28 -0700 (Tue, 27 May 2008) Log Message: ----------- Explicit argument passing cleanup, returning an array of all possibles when not totally defined Modified Paths: -------------- trunk/Source/HTML/HTML.csproj trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Graph/Constructor.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/SetterProperty.cs trunk/Source/StructureMap/Graph/TypeRules.cs trunk/Source/StructureMap/IInstanceManager.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs Added Paths: ----------- trunk/Source/HTML/ExplicitArguments.htm trunk/Source/StructureMap/ExplicitArgsExpression.cs Property Changed: ---------------- trunk/Source/HTML/ Property changes on: trunk/Source/HTML ___________________________________________________________________ Name: svn:ignore + bin obj Added: trunk/Source/HTML/ExplicitArguments.htm =================================================================== --- trunk/Source/HTML/ExplicitArguments.htm (rev 0) +++ trunk/Source/HTML/ExplicitArguments.htm 2008-05-27 13:25:28 UTC (rev 100) @@ -0,0 +1,19 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> + <head> + <title></title> + </head> + <body> + <h1> + Explicit Arguments</h1> + <p> + A new feature in StructureMap 2.5 is the ability to pass in arguments to ObjectFactory.</p> + <p> + </p> + <h4> + Primitive Value</h4> + <p> + </p> + + </body> +</html> \ No newline at end of file Modified: trunk/Source/HTML/HTML.csproj =================================================================== --- trunk/Source/HTML/HTML.csproj 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/HTML/HTML.csproj 2008-05-27 13:25:28 UTC (rev 100) @@ -36,4 +36,7 @@ <Target Name="AfterBuild"> </Target> --> + <ItemGroup> + <Content Include="ExplicitArguments.htm" /> + </ItemGroup> </Project> \ No newline at end of file Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/BuildSession.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using StructureMap.Graph; using StructureMap.Interceptors; @@ -58,20 +59,28 @@ public Array CreateInstanceArray(Type pluginType, Instance[] instances) { - // TODO -- default to returning all + Array array; + if (instances == null) { - throw new StructureMapException(205, pluginType, "UNKNOWN"); + IList list = forType(pluginType).GetAllInstances(this); + array = Array.CreateInstance(pluginType, list.Count); + for (int i = 0; i < list.Count; i++) + { + array.SetValue(list[i], i); + } } - - // 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++) + else { - Instance instance = instances[i]; + // TODO: 3.5, move this to an extension method of 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); + object arrayValue = forType(pluginType).Build(this, instance); + array.SetValue(arrayValue, i); + } } return array; Added: trunk/Source/StructureMap/ExplicitArgsExpression.cs =================================================================== --- trunk/Source/StructureMap/ExplicitArgsExpression.cs (rev 0) +++ trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -0,0 +1,49 @@ +using StructureMap.Pipeline; + +namespace StructureMap +{ + public interface IExplicitProperty + { + ExplicitArgsExpression EqualTo(object value); + } + + public class ExplicitArgsExpression : IExplicitProperty + { + private readonly ExplicitArguments _args = new ExplicitArguments(); + private readonly IInstanceManager _manager; + private string _lastArgName; + + internal ExplicitArgsExpression(IInstanceManager manager) + { + _manager = manager; + } + + #region IExplicitProperty Members + + ExplicitArgsExpression IExplicitProperty.EqualTo(object value) + { + _args.SetArg(_lastArgName, value); + return this; + } + + #endregion + + public ExplicitArgsExpression With<T>(T arg) + { + _args.Set<T>(arg); + return this; + } + + public IExplicitProperty With(string argName) + { + _lastArgName = argName; + return this; + } + + + public T GetInstance<T>() + { + return _manager.CreateInstance<T>(_args); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -66,7 +66,7 @@ { foreach (ParameterInfo parameter in _ctor.GetParameters()) { - if (!IsChild(parameter.ParameterType)) + if (!IsAutoFillable(parameter.ParameterType)) { return false; } Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -140,7 +140,8 @@ _parent.Log.Try(delegate() { diagnosticInstance.Preprocess(this); - }).AndReportErrorAs(104, diagnosticInstance.CreateToken(), _pluginType); + }) + .AndReportErrorAs(104, diagnosticInstance.CreateToken(), _pluginType); if (!diagnosticInstance.CanBePartOfPluginFamily(this)) Modified: trunk/Source/StructureMap/Graph/SetterProperty.cs =================================================================== --- trunk/Source/StructureMap/Graph/SetterProperty.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/Graph/SetterProperty.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -27,7 +27,7 @@ public bool CanBeAutoFilled { - get { return IsChild(_property.PropertyType); } + get { return IsAutoFillable(_property.PropertyType); } } public void Visit(IArgumentVisitor visitor) Modified: trunk/Source/StructureMap/Graph/TypeRules.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypeRules.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/Graph/TypeRules.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -89,5 +89,11 @@ { return !type.IsInterface && !type.IsAbstract; } + + + protected bool IsAutoFillable(Type type) + { + return IsChild(type) || IsChildArray(type); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/IInstanceManager.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -75,6 +75,8 @@ object CreateInstance(Type pluginType, string instanceKey); PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args); - + + ExplicitArgsExpression With<T>(T arg); + IExplicitProperty With(string argName); } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -248,6 +248,16 @@ return writer.GetText(); } + public ExplicitArgsExpression With<T>(T arg) + { + return new ExplicitArgsExpression(this).With<T>(arg); + } + + public IExplicitProperty With(string argName) + { + return new ExplicitArgsExpression(this).With(argName); + } + #endregion private IBuildSession withNewSession() @@ -260,5 +270,7 @@ { return _pipelineGraph.ForType(type); } + + } } \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -238,7 +238,6 @@ #endregion - #region GetInstance /// <summary> /// Returns the default instance of the requested System.Type @@ -347,67 +346,16 @@ public static ExplicitArgsExpression With<T>(T arg) { - return new ExplicitArgsExpression(manager).With<T>(arg); + return manager.With(arg); } public static IExplicitProperty With(string argName) { - return new ExplicitArgsExpression(manager).With(argName); + return manager.With(argName); } - #region Nested type: ExplicitArgsExpression - public class ExplicitArgsExpression : IExplicitProperty - { - private readonly ExplicitArguments _args = new ExplicitArguments(); - private readonly IInstanceManager _manager; - private string _lastArgName; + } - internal ExplicitArgsExpression(IInstanceManager manager) - { - _manager = manager; - } - #region IExplicitProperty Members - - ExplicitArgsExpression IExplicitProperty.EqualTo(object value) - { - _args.SetArg(_lastArgName, value); - return this; - } - - #endregion - - public ExplicitArgsExpression With<T>(T arg) - { - _args.Set<T>(arg); - return this; - } - - public IExplicitProperty With(string argName) - { - _lastArgName = argName; - return this; - } - - - public T GetInstance<T>() - { - return _manager.CreateInstance<T>(_args); - } - } - - #endregion - - #region Nested type: IExplicitProperty - - public interface IExplicitProperty - { - ExplicitArgsExpression EqualTo(object value); - } - - #endregion - - #endregion - } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -62,8 +62,12 @@ Instance[] IConfiguredInstance.GetChildrenArray(string propertyName) { - // TODO: Validate and throw exception if missing - return _arrays[propertyName]; + if (_arrays.ContainsKey(propertyName)) + { + return _arrays[propertyName]; + } + + return null; } string IConfiguredInstance.GetProperty(string propertyName) Modified: trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -5,9 +5,18 @@ { public class ExplicitArguments { - private readonly Dictionary<string, string> _args = new Dictionary<string, string>(); + private readonly Dictionary<string, object> _args; private readonly Dictionary<Type, object> _children = new Dictionary<Type, object>(); + public ExplicitArguments(Dictionary<string, object> args) + { + _args = args; + } + + public ExplicitArguments() : this(new Dictionary<string, object>()) + { + } + public T Get<T>() where T : class { return (T) Get(typeof (T)); @@ -25,19 +34,19 @@ public void SetArg(string key, object argValue) { - _args.Add(key, argValue.ToString()); + _args.Add(key, argValue); } - public string GetArg(string key) + public object GetArg(string key) { return _args.ContainsKey(key) ? _args[key] : null; } public void Configure(ConfiguredInstance instance) { - foreach (KeyValuePair<string, string> arg in _args) + foreach (KeyValuePair<string, object> arg in _args) { - instance.SetProperty(arg.Key, arg.Value); + instance.SetProperty(arg.Key, arg.Value.ToString()); instance.SetChild(arg.Key, new LiteralInstance(arg.Value)); } } Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-27 13:25:28 UTC (rev 100) @@ -131,6 +131,7 @@ <Compile Include="Diagnostics\WhatDoIHaveWriter.cs" /> <Compile Include="Emitting\ArgumentEmitter.cs" /> <Compile Include="Exceptions\StructureMapConfigurationException.cs" /> + <Compile Include="ExplicitArgsExpression.cs" /> <Compile Include="Graph\Constructor.cs" /> <Compile Include="Graph\IArgumentVisitor.cs" /> <Compile Include="Graph\IPluginFamily.cs" /> Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -134,5 +134,34 @@ Assert.AreNotSame(result1, result3); Assert.AreSame(result3, result4); } + + [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 = registry.BuildInstanceManager(); + + WidgetHolder holder = manager.CreateInstance<WidgetHolder>(); + Assert.AreEqual(3, holder.Widgets.Length); + } + + public class WidgetHolder + { + private readonly IWidget[] _widgets; + + public WidgetHolder(IWidget[] widgets) + { + _widgets = widgets; + } + + public IWidget[] Widgets + { + get { return _widgets; } + } + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -1,3 +1,4 @@ +using System.Collections.Generic; using NUnit.Framework; using StructureMap.Configuration.DSL; using StructureMap.Graph; @@ -2,2 +3,3 @@ using StructureMap.Pipeline; +using StructureMap.Testing.Pipeline; @@ -26,38 +28,7 @@ #endregion - public void GetTypedArgumentsFromAnExplicitArgumentsMementoIfThereIsAnExplicitArgument() - { - Assert.Fail("Redo"); - //PluginGraph pluginGraph = new PluginGraph(); - //using (Registry registry = new Registry(pluginGraph)) - //{ - // registry.ForRequestedType<ExplicitTarget>().TheDefaultIs( - // Registry.Instance<ExplicitTarget>() - // .UsingConcreteType<ExplicitTarget>() - // .Child<IProvider>().IsConcreteType<RedProvider>() - // .WithProperty("name").EqualTo("Jeremy") - // ); - //} - - //InstanceMemento inner = pluginGraph.PluginFamilies[typeof (ExplicitTarget)].Source.GetAllMementos()[0]; - //ExplicitArguments args = new ExplicitArguments(); - //ExplicitArgumentMemento memento = new ExplicitArgumentMemento(args, inner); - - //InstanceManager manager = new InstanceManager(pluginGraph); - - //// Get the ExplicitTarget without setting an explicit arg for IProvider - //ExplicitTarget firstTarget = manager.CreateInstance<ExplicitTarget>(memento); - //Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); - - //// Now, set the explicit arg for IProvider - //args.Set<IProvider>(new BlueProvider()); - //ExplicitTarget secondTarget = manager.CreateInstance<ExplicitTarget>(memento); - //Assert.IsInstanceOfType(typeof (BlueProvider), secondTarget.Provider); - } - - public interface IExplicitTarget { } @@ -234,8 +205,62 @@ Assert.AreEqual("Jeremy", args.GetArg("name")); args.SetArg("age", 34); - Assert.AreEqual("34", args.GetArg("age")); + Assert.AreEqual(34, args.GetArg("age")); } + + [Test] + public void Fill_in_argument_by_name() + { + InstanceManager manager = new InstanceManager(); + manager.AddDefaultInstance<IView, View>(); + + Node theNode = new Node(); + Trade theTrade = new Trade(); + + Command command = manager + .With("node").EqualTo(theNode) + .With<Trade>(theTrade) + .GetInstance<Command>(); + + Assert.IsInstanceOfType(typeof(View), command.View); + Assert.AreSame(theNode, command.Node); + Assert.AreSame(theTrade, command.Trade); + } + + [Test] + public void Pass_in_arguments_as_dictionary() + { + InstanceManager manager = new InstanceManager(); + manager.AddDefaultInstance<IView, View>(); + + Node theNode = new Node(); + Trade theTrade = new Trade(); + + ExplicitArguments args = new ExplicitArguments(); + args.Set<Node>(theNode); + args.SetArg("trade", theTrade); + + Command command = manager.CreateInstance<Command>(args); + + Assert.IsInstanceOfType(typeof(View), command.View); + Assert.AreSame(theNode, command.Node); + Assert.AreSame(theTrade, command.Trade); + } + + [Test] + public void ExplicitArguments_can_return_child_by_name() + { + ExplicitArguments args = new ExplicitArguments(); + Node theNode = new Node(); + args.SetArg("node", theNode); + + IConfiguredInstance instance = new ExplicitInstance<Command>(args, null); + + Assert.AreSame(theNode, instance.GetChild("node", typeof(Node), new StubBuildSession())); + } + + + } public class Lump @@ -257,4 +282,42 @@ get { return _lump; } } } + + + public class Trade{} + public class Node{} + public interface IView{} + public class View : IView {} + + public class Command + { + private readonly Trade _trade; + private readonly Node _node; + private readonly IView _view; + + public Command(Trade trade, Node node, IView view) + { + _trade = trade; + _node = node; + _view = view; + } + + public Trade Trade + { + get { return _trade; } + } + + public Node Node + { + get { return _node; } + } + + public IView View + { + get { return _view; } + } + } + + + } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -76,6 +76,41 @@ } [Test] + public void CanBeAutoFilled_with_child_array_in_ctor() + { + Constructor ctor = new Constructor(typeof(CanBeAutoFilledWithArray)); + Assert.IsTrue(ctor.CanBeAutoFilled()); + } + + public class CanBeAutoFilledWithArray + { + public CanBeAutoFilledWithArray(IWidget[] widgets) + { + + } + + [SetterProperty] + public IWidget[] More + { + get + { + return null; + } + set + { + + } + } + } + + [Test] + public void CanBeAutoFilled_with_child_array_in_setter() + { + SetterPropertyCollection setters = new SetterPropertyCollection(new Plugin(typeof(CanBeAutoFilledWithArray))); + Assert.IsTrue(setters.CanBeAutoFilled()); + } + + [Test] public void CanBeAutoFilledIsTrue() { Plugin plugin = new Plugin(typeof (Mustang)); Modified: trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2008-05-26 17:39:08 UTC (rev 99) +++ trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2008-05-27 13:25:28 UTC (rev 100) @@ -5,6 +5,7 @@ using StructureMap.Configuration; using StructureMap.Graph; using StructureMap.Testing.GenericWidgets; +using StructureMap.Testing.TestData; namespace StructureMap.Testing { @@ -16,6 +17,7 @@ [SetUp] public void SetUp() { + DataMother.RestoreStructureMapConfig(); ObjectFactory.ReInitialize(); StructureMapConfiguration.ResetAll(); } @@ -36,6 +38,37 @@ } [Test] + public void StructureMap_functions_without_StructureMapconfig_file_in_the_default_mode() + { + StructureMapConfiguration.ResetAll(); + DataMother.RemoveStructureMapConfig(); + + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); + + } + + [Test] + public void Ignore_the_StructureMap_config_file_even_if_it_exists() + { + StructureMapConfiguration.ResetAll(); + StructureMapConfiguration.IgnoreStructureMapConfig = true; + + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); + + Assert.AreEqual(0, graph.FamilyCount); + } + + [Test] + public void Use_the_StructureMap_config_file_if_it_exists() + { + StructureMapConfiguration.ResetAll(); + DataMother.RestoreStructureMapConfig(); + + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); + Assert.IsTrue(graph.FamilyCount > 0); + } + + [Test] public void BuildPluginGraph() { PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-26 17:39:12
|
Revision: 99 http://structuremap.svn.sourceforge.net/structuremap/?rev=99&view=rev Author: jeremydmiller Date: 2008-05-26 10:39:08 -0700 (Mon, 26 May 2008) Log Message: ----------- cleaning up all the Profile FI and generics problems. Little refactoring to simplify the FI development, validation development, the ValidationBuildSession Modified Paths: -------------- trunk/Source/StructureMap/Attributes/ValidationMethodAttribute.cs trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/ProfileBuilder.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/Graph/TypePath.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/LiteralInstance.cs trunk/Source/StructureMap/Pipeline/Profile.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/DataAccess/CommandFactoryTester.cs trunk/Source/StructureMap.Testing/DataAccess/ExecutionStates/AutoCommitExecutionStateTester.cs trunk/Source/StructureMap.Testing/DataAccess/ExecutionStates/TransactionalExecutionStateTester.cs trunk/Source/StructureMap.Testing/DataAccess/TemplatedCommandTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryTester.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/TestData/DataMother.cs trunk/Source/StructureMap.Testing/TestData/DefaultProfileConfig.xml trunk/Source/StructureMap.Testing/TestData/ObjectMother.config trunk/Source/StructureMap.Testing/TestData/SampleConfig.xml trunk/Source/StructureMap.Testing.GenericWidgets/Widgets.cs trunk/Source/StructureMap.Testing.Widget/IWidget.cs trunk/Source/StructureMap.sln Added Paths: ----------- trunk/Source/HTML/ trunk/Source/HTML/HTML.csproj trunk/Source/StructureMap/Delegates.cs trunk/Source/StructureMap/Diagnostics/BuildError.cs trunk/Source/StructureMap/Diagnostics/Error.cs trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs trunk/Source/StructureMap/Diagnostics/GraphLog.cs trunk/Source/StructureMap/Diagnostics/InstanceToken.cs trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Exceptions/StructureMapConfigurationException.cs trunk/Source/StructureMap.Testing/Diagnostics/IntegrationTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/IExpression.cs trunk/Source/StructureMap/Diagnostics/Tokens.cs Added: trunk/Source/HTML/HTML.csproj =================================================================== --- trunk/Source/HTML/HTML.csproj (rev 0) +++ trunk/Source/HTML/HTML.csproj 2008-05-26 17:39:08 UTC (rev 99) @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>HTML</RootNamespace> + <AssemblyName>HTML</AssemblyName> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file Modified: trunk/Source/StructureMap/Attributes/ValidationMethodAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/ValidationMethodAttribute.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Attributes/ValidationMethodAttribute.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -51,19 +51,5 @@ return returnValue; } - - - /// <summary> - /// Executes the marked validation methods, if any, on an object - /// </summary> - /// <param name="target"></param> - public static void CallValidationMethods(object target) - { - MethodInfo[] methods = GetValidationMethods(target.GetType()); - foreach (MethodInfo method in methods) - { - method.Invoke(target, new object[0]); - } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/BuildSession.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -10,7 +10,7 @@ { private readonly InterceptorLibrary _interceptorLibrary; private readonly PipelineGraph _pipelineGraph; - private InstanceCache _cache = new InstanceCache(); + private readonly InstanceCache _cache = new InstanceCache(); public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) { @@ -24,6 +24,12 @@ } + + protected PipelineGraph pipelineGraph + { + get { return _pipelineGraph; } + } + #region IBuildSession Members public object CreateInstance(Type pluginType, string name) @@ -37,7 +43,7 @@ return CreateInstance(pluginType, instance); } - public object CreateInstance(Type pluginType, Instance instance) + public virtual object CreateInstance(Type pluginType, Instance instance) { object result = _cache.Get(pluginType, instance); Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -31,6 +31,8 @@ #endregion + public string Description = string.Empty; + private readonly XmlMementoCreator _mementoCreator; private readonly XmlNode _structureMapNode; private string _filePath = string.Empty; Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using System.Xml; @@ -8,12 +7,12 @@ { public class ConfigurationParserBuilder { - private readonly List<XmlNode> _nodes = new List<XmlNode>(); + private readonly GraphLog _log; + private readonly List<ConfigurationParser> _parsers = new List<ConfigurationParser>(); private readonly List<string> _otherFiles = new List<string>(); private bool _ignoreDefaultFile = false; - private readonly GraphLog _log; - private bool _useAndEnforceExistenceOfDefaultFile = false; private bool _pullConfigurationFromAppConfig; + private bool _useAndEnforceExistenceOfDefaultFile = false; public ConfigurationParserBuilder(GraphLog log) @@ -37,10 +36,7 @@ public bool PullConfigurationFromAppConfig { get { return _pullConfigurationFromAppConfig; } - set - { - _pullConfigurationFromAppConfig = value; - } + set { _pullConfigurationFromAppConfig = value; } } // TODO: Clean up with 3.5 @@ -53,53 +49,47 @@ if (shouldUseStructureMapConfigFileAt(pathToStructureMapConfig)) { _log.Try(delegate() - { - ConfigurationParser parser = ConfigurationParser.FromFile(pathToStructureMapConfig); - list.Add(parser); - }).AndReportErrorAs(100, pathToStructureMapConfig); + { + ConfigurationParser parser = ConfigurationParser.FromFile(pathToStructureMapConfig); + list.Add(parser); + }).AndReportErrorAs(100, pathToStructureMapConfig); } foreach (string filename in _otherFiles) { _log.Try(delegate() - { - ConfigurationParser parser = ConfigurationParser.FromFile(filename); - list.Add(parser); - }).AndReportErrorAs(160, filename); + { + ConfigurationParser parser = ConfigurationParser.FromFile(filename); + parser.Description = filename; + list.Add(parser); + }).AndReportErrorAs(160, filename); } if (_pullConfigurationFromAppConfig) { _log.Try(delegate() - { - IList<XmlNode> appConfigNodes = StructureMapConfigurationSection.GetStructureMapConfiguration(); - foreach (XmlNode appConfigNode in appConfigNodes) - { - IncludeNode(appConfigNode); - } - }).AndLogAnyErrors(); - + { + IList<XmlNode> appConfigNodes = StructureMapConfigurationSection.GetStructureMapConfiguration(); + foreach (XmlNode appConfigNode in appConfigNodes) + { + IncludeNode(appConfigNode, string.Empty); + } + }).AndLogAnyErrors(); } - // TODO -- some error handling here, or somewhere else. Need to create ConfigurationParser - // as soon as the node is added to try to determine errors - foreach (XmlNode node in _nodes) - { - ConfigurationParser parser = new ConfigurationParser(node); - list.Add(parser); - } + list.AddRange(_parsers); - foreach (ConfigurationParser parser in list.ToArray()) + foreach (ConfigurationParser parser in list.ToArray()) { parser.ForEachFile(_log, delegate(string filename) + { + _log.Try(delegate() { - _log.Try(delegate() - { - ConfigurationParser childParser = ConfigurationParser.FromFile(filename); - list.Add(childParser); - }).AndReportErrorAs(150, filename); - }); + ConfigurationParser childParser = ConfigurationParser.FromFile(filename); + list.Add(childParser); + }).AndReportErrorAs(150, filename); + }); } @@ -109,8 +99,8 @@ private bool shouldUseStructureMapConfigFileAt(string pathToStructureMapConfig) { return - (_useAndEnforceExistenceOfDefaultFile || - File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile; + (_useAndEnforceExistenceOfDefaultFile || + File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile; } @@ -119,15 +109,19 @@ _otherFiles.Add(filename); } - public void IncludeNode(XmlNode node) + + public void IncludeNode(XmlNode node, string description) { - _nodes.Add(node); + ConfigurationParser parser = new ConfigurationParser(node); + parser.Description = description; + + _parsers.Add(parser); } public static ConfigurationParser[] GetParsers(XmlNode node, GraphLog log) { ConfigurationParserBuilder builder = new ConfigurationParserBuilder(log); - builder.IncludeNode(node); + builder.IncludeNode(node, string.Empty); builder.IgnoreDefaultFile = true; return builder.GetParsers(); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -10,31 +10,28 @@ /// <summary> /// Represents the parameters for creating instances of a given Type /// </summary> - public class CreatePluginFamilyExpression<PLUGINTYPE> : IExpression + public class CreatePluginFamilyExpression<PLUGINTYPE> { private readonly List<Action<PluginFamily>> _alterations = new List<Action<PluginFamily>>(); private readonly List<Action<PluginGraph>> _children = new List<Action<PluginGraph>>(); private readonly Type _pluginType; private readonly InstanceScope _scope = InstanceScope.PerRequest; - public CreatePluginFamilyExpression() + public CreatePluginFamilyExpression(Registry registry) { _pluginType = typeof (PLUGINTYPE); - } - #region IExpression Members + registry.addExpression(delegate(PluginGraph graph) + { + PluginFamily family = graph.FindFamily(_pluginType); + family.SetScopeTo(_scope); - void IExpression.Configure(PluginGraph graph) - { - PluginFamily family = graph.FindFamily(_pluginType); - family.SetScopeTo(_scope); - - // TODO: clean up with 3.5 - _children.ForEach(delegate(Action<PluginGraph> action) { action(graph); }); - _alterations.ForEach(delegate(Action<PluginFamily> action) { action(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: 3.5, Try alterAndContinue(f => {}); private CreatePluginFamilyExpression<PLUGINTYPE> alterAndContinue(Action<PluginFamily> action) @@ -51,10 +48,10 @@ public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(Instance instance) { return alterAndContinue(delegate(PluginFamily family) - { - family.AddInstance(instance); - family.DefaultInstanceKey = instance.Name; - }); + { + family.AddInstance(instance); + family.DefaultInstanceKey = instance.Name; + }); } public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(Instance instance) @@ -76,10 +73,10 @@ ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(_pluginType); return alterAndContinue(delegate(PluginFamily family) - { - Plugin plugin = family.Plugins.FindOrCreate(typeof(CONCRETETYPE), true); - family.DefaultInstanceKey = plugin.ConcreteKey; - }); + { + Plugin plugin = family.Plugins.FindOrCreate(typeof (CONCRETETYPE), true); + family.DefaultInstanceKey = plugin.ConcreteKey; + }); return this; } @@ -111,16 +108,16 @@ { _children.Add( delegate(PluginGraph graph) + { + InterceptionFunction function = delegate(object target) { - InterceptionFunction function = delegate(object target) - { - handler((PLUGINTYPE) target); - return target; - }; + handler((PLUGINTYPE) target); + return target; + }; - PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); - graph.InterceptorLibrary.AddInterceptor(interceptor); - }); + PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); + graph.InterceptorLibrary.AddInterceptor(interceptor); + }); return this; } @@ -129,12 +126,12 @@ { _children.Add( delegate(PluginGraph graph) - { - InterceptionFunction function = delegate(object target) { return handler((PLUGINTYPE) target); }; + { + InterceptionFunction function = delegate(object target) { return handler((PLUGINTYPE) target); }; - PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); - graph.InterceptorLibrary.AddInterceptor(interceptor); - }); + PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); + graph.InterceptorLibrary.AddInterceptor(interceptor); + }); return this; } @@ -146,15 +143,15 @@ public CreatePluginFamilyExpression<PLUGINTYPE> AddConcreteType<CONCRETETYPE>(string instanceName) { - ExpressionValidator.ValidatePluggabilityOf(typeof(CONCRETETYPE)).IntoPluginType(typeof(PLUGINTYPE)); + ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(typeof (PLUGINTYPE)); _alterations.Add( delegate(PluginFamily family) - { - Plugin plugin = new Plugin(typeof (CONCRETETYPE)); - plugin.ConcreteKey = instanceName; - family.Plugins.Add(plugin); - } + { + Plugin plugin = new Plugin(typeof (CONCRETETYPE)); + plugin.ConcreteKey = instanceName; + family.Plugins.Add(plugin); + } ); return this; @@ -175,7 +172,7 @@ public CreatePluginFamilyExpression<PLUGINTYPE> AliasConcreteType<PLUGGEDTYPE>(string concreteKey) { - ExpressionValidator.ValidatePluggabilityOf(typeof(PLUGGEDTYPE)).IntoPluginType(typeof(PLUGINTYPE)); + ExpressionValidator.ValidatePluggabilityOf(typeof (PLUGGEDTYPE)).IntoPluginType(typeof (PLUGINTYPE)); _alterations.Add(delegate(PluginFamily family) { family.AddPlugin(typeof (PLUGGEDTYPE), concreteKey); }); Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -1,77 +0,0 @@ -using System; -using StructureMap.Graph; -using StructureMap.Pipeline; - -namespace StructureMap.Configuration.DSL.Expressions -{ - /// <summary> - /// Use to express the instance of a PluginType for the containing Profile - /// </summary> - public class InstanceDefaultExpression - { - private readonly ProfileExpression _parent; - private readonly Type _pluginType; - private Instance _instance; - private string _instanceKey = string.Empty; - - public InstanceDefaultExpression(Type pluginType, ProfileExpression parent) - { - _pluginType = pluginType; - _parent = parent; - } - - /// <summary> - /// Use a named, preconfigured instance as the default instance for this profile - /// </summary> - /// <param name="instanceKey"></param> - /// <returns></returns> - public ProfileExpression UseNamedInstance(string instanceKey) - { - _instanceKey = instanceKey; - return _parent; - } - - internal void Configure(string profileName, PluginGraph pluginGraph) - { - // The profile instance is defined inline - if (_instance != null) - { - _instanceKey = Profile.InstanceKeyForProfile(profileName); - _instance.Name = _instanceKey; - pluginGraph.FindFamily(_pluginType).AddInstance(_instance); - } - - // Using a referenced key for the profile - else if (!string.IsNullOrEmpty(_instanceKey)) - { - _instance = new ReferencedInstance(_instanceKey); - } - - // Set the default instance in the Profile - if (_instance != null) - { - pluginGraph.ProfileManager.SetDefault(profileName, _pluginType, _instance); - } - - // Blow up if the Profile expression is not complete. - else - { - throw new StructureMapException(304, TypePath.GetAssemblyQualifiedName(_pluginType)); - } - } - - /// <summary> - /// Define the default instance of the PluginType for the containing Profile - /// </summary> - /// <param name="mementoBuilder"></param> - /// <returns></returns> - public ProfileExpression Use(Instance instance) - { - // TODO -- validate that the instance can be plugged into the PluginType - - _instance = instance; - - return _parent; - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -1,44 +1,152 @@ -using System.Collections.Generic; +using System; using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Configuration.DSL.Expressions { /// <summary> /// Expression class to help define a runtime Profile /// </summary> - public class ProfileExpression : IExpression + public class ProfileExpression { - private readonly List<InstanceDefaultExpression> _defaults = new List<InstanceDefaultExpression>(); private readonly string _profileName; + private readonly Registry _registry; - public ProfileExpression(string profileName) + public ProfileExpression(string profileName, Registry registry) { _profileName = profileName; + _registry = registry; } - #region IExpression Members - void IExpression.Configure(PluginGraph graph) + /// <summary> + /// Starts the definition of the default instance for the containing Profile + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public InstanceDefaultExpression<T> For<T>() { - foreach (InstanceDefaultExpression expression in _defaults) + return new InstanceDefaultExpression<T>(this); + } + + /// <summary> + /// Use statement to define the Profile defaults for a Generic type + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + public GenericDefaultExpression For(Type pluginType) + { + return new GenericDefaultExpression(this, pluginType); + } + + #region Nested type: InstanceDefaultExpression + + public class InstanceDefaultExpression<T> + { + private readonly ProfileExpression _parent; + private readonly string _profileName; + private readonly Registry _registry; + + public InstanceDefaultExpression(ProfileExpression parent) { - expression.Configure(_profileName, graph); + _parent = parent; + _registry = parent._registry; + _profileName = parent._profileName; } + + /// <summary> + /// Use a named, preconfigured instance as the default instance for this profile + /// </summary> + /// <param name="instanceKey"></param> + /// <returns></returns> + public ProfileExpression UseNamedInstance(string instanceKey) + { + _registry.addExpression(delegate(PluginGraph graph) + { + graph.SetDefault(_profileName, typeof(T), new ReferencedInstance(instanceKey)); + }); + + return _parent; + } + + /// <summary> + /// Define the default instance of the PluginType for the containing Profile + /// </summary> + /// <param name="mementoBuilder"></param> + /// <returns></returns> + public ProfileExpression Use(Instance instance) + { + instance.Name = "Default Instance for Profile " + _profileName; + + _registry.addExpression(delegate (PluginGraph graph) + { + graph.SetDefault(_profileName, typeof(T), instance); + }); + + return _parent; + } + + public ProfileExpression Use(Func<T> func) + { + ConstructorInstance instance = new ConstructorInstance(delegate { return func(); }); + return Use(instance); + } + + public ProfileExpression Use(T t) + { + LiteralInstance instance = new LiteralInstance(t); + return Use(instance); + } + + public ProfileExpression UseConcreteType<CONCRETETYPE>() + { + ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)); + return Use(instance); + } + + public ProfileExpression UsePrototypeOf(T template) + { + PrototypeInstance instance = new PrototypeInstance((ICloneable) template); + return Use(instance); + } } #endregion - /// <summary> - /// Starts the definition of the default instance for the containing Profile - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - public InstanceDefaultExpression For<T>() + public class GenericDefaultExpression { - InstanceDefaultExpression defaultExpression = new InstanceDefaultExpression(typeof (T), this); - _defaults.Add(defaultExpression); + private readonly ProfileExpression _parent; + private readonly Type _pluginType; + private readonly Registry _registry; - return defaultExpression; + internal GenericDefaultExpression(ProfileExpression parent, Type pluginType) + { + _parent = parent; + _registry = parent._registry; + _pluginType = pluginType; + } + + public ProfileExpression UseConcreteType(Type concreteType) + { + ConfiguredInstance instance = new ConfiguredInstance(concreteType); + return Use(instance); + } + + public ProfileExpression Use(Instance instance) + { + _registry.addExpression(delegate(PluginGraph graph) + { + graph.SetDefault(_parent._profileName, _pluginType, instance); + }); + + return _parent; + } + + public ProfileExpression UseNamedInstance(string name) + { + ReferencedInstance instance = new ReferencedInstance(name); + return Use(instance); + } } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -11,7 +11,7 @@ /// Expression that directs StructureMap to scan the named assemblies /// for [PluginFamily] and [Plugin] attributes /// </summary> - public class ScanAssembliesExpression : IExpression + public class ScanAssembliesExpression { private readonly List<Assembly> _assemblies = new List<Assembly>(); private readonly Registry _registry; @@ -19,20 +19,15 @@ public ScanAssembliesExpression(Registry registry) { _registry = registry; - } - - #region IExpression Members - - void IExpression.Configure(PluginGraph graph) - { - foreach (Assembly assembly in _assemblies) + _registry.addExpression(delegate(PluginGraph graph) { - graph.Assemblies.Add(assembly); - } + foreach (Assembly assembly in _assemblies) + { + graph.Assemblies.Add(assembly); + } + }); } - #endregion - public ScanAssembliesExpression IncludeTheCallingAssembly() { Assembly callingAssembly = findTheCallingAssembly(); @@ -74,11 +69,11 @@ public ScanAssembliesExpression AddAllTypesOf<PLUGINTYPE>() { _registry.addExpression(delegate(PluginGraph pluginGraph) - { - PluginFamily family = - pluginGraph.FindFamily(typeof (PLUGINTYPE)); - family.SearchForImplicitPlugins = true; - }); + { + PluginFamily family = + pluginGraph.FindFamily(typeof (PLUGINTYPE)); + family.SearchForImplicitPlugins = true; + }); return this; } Deleted: trunk/Source/StructureMap/Configuration/DSL/IExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -1,9 +0,0 @@ -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - public interface IExpression - { - void Configure(PluginGraph graph); - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -9,7 +9,7 @@ { public class Registry : IDisposable { - private readonly List<IExpression> _expressions = new List<IExpression>(); + private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>(); private readonly PluginGraph _graph; public Registry(PluginGraph graph) : this() @@ -40,21 +40,18 @@ // no-op; } - protected internal void addExpression(IExpression expression) + internal void addExpression(Action<PluginGraph> alteration) { - _expressions.Add(expression); + _actions.Add(alteration); } - internal void addExpression(PluginGraphAlteration alteration) - { - _expressions.Add(new BasicExpression(alteration)); - } - internal void ConfigurePluginGraph(PluginGraph graph) { - foreach (IExpression expression in _expressions) + graph.Log.StartSource("Registry: " + TypePath.GetAssemblyQualifiedName(GetType())); + + foreach (Action<PluginGraph> action in _actions) { - expression.Configure(graph); + action(graph); } } @@ -67,10 +64,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> BuildInstancesOf<PLUGINTYPE>() { - CreatePluginFamilyExpression<PLUGINTYPE> expression = new CreatePluginFamilyExpression<PLUGINTYPE>(); - addExpression(expression); - - return expression; + return new CreatePluginFamilyExpression<PLUGINTYPE>(this); } /// <summary> @@ -83,10 +77,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> ForRequestedType<PLUGINTYPE>() { - CreatePluginFamilyExpression<PLUGINTYPE> expression = new CreatePluginFamilyExpression<PLUGINTYPE>(); - addExpression(expression); - - return expression; + return new CreatePluginFamilyExpression<PLUGINTYPE>(this); } public IInstanceManager BuildInstanceManager() @@ -113,7 +104,10 @@ 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; } @@ -200,8 +194,7 @@ /// <returns></returns> public ProfileExpression CreateProfile(string profileName) { - ProfileExpression expression = new ProfileExpression(profileName); - addExpression(expression); + ProfileExpression expression = new ProfileExpression(profileName, this); return expression; } @@ -254,12 +247,12 @@ delegate(PluginGraph pluginGraph) { pluginGraph.InterceptorLibrary.AddInterceptor(interceptor); }); } - public TypeInterceptorExpression IfTypeMatches(Predicate<Type> match) + public MatchedTypeInterceptor IfTypeMatches(Predicate<Type> match) { - TypeInterceptorExpression expression = new TypeInterceptorExpression(match); - _expressions.Add(expression); + MatchedTypeInterceptor interceptor = new MatchedTypeInterceptor(match); + _actions.Add(delegate(PluginGraph graph) { graph.InterceptorLibrary.AddInterceptor(interceptor); }); - return expression; + return interceptor; } @@ -269,33 +262,32 @@ /// <returns></returns> public ScanAssembliesExpression ScanAssemblies() { - ScanAssembliesExpression expression = new ScanAssembliesExpression(this); - addExpression(expression); + return new ScanAssembliesExpression(this); + } - return expression; + + public void AddInstanceOf(Type pluginType, Instance instance) + { + _actions.Add(delegate(PluginGraph graph) { graph.FindFamily(pluginType).AddInstance(instance); }); } + + public void AddInstanceOf<PLUGINTYPE>(Instance instance) + { + _actions.Add(delegate(PluginGraph graph) { graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); }); + } } - public class TypeInterceptorExpression : IExpression, TypeInterceptor + public class MatchedTypeInterceptor : TypeInterceptor { private readonly Predicate<Type> _match; private InterceptionFunction _interception; - internal TypeInterceptorExpression(Predicate<Type> match) + internal MatchedTypeInterceptor(Predicate<Type> match) { _match = match; } - #region IExpression Members - - void IExpression.Configure(PluginGraph graph) - { - graph.InterceptorLibrary.AddInterceptor(this); - } - - #endregion - #region TypeInterceptor Members public bool MatchesType(Type type) @@ -315,25 +307,4 @@ _interception = interception; } } - - internal delegate void PluginGraphAlteration(PluginGraph pluginGraph); - - internal class BasicExpression : IExpression - { - private readonly PluginGraphAlteration _alteration; - - internal BasicExpression(PluginGraphAlteration alteration) - { - _alteration = alteration; - } - - #region IExpression Members - - public void Configure(PluginGraph graph) - { - _alteration(graph); - } - - #endregion - } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -47,10 +47,12 @@ 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); + _pluginGraph.Log.Try(delegate() + { + ReferencedInstance instance = new ReferencedInstance(instanceKey); + _pluginGraph.SetDefault(_lastProfile, typePath.FindType(), instance); + + }).AndReportErrorAs(107, typePath.AssemblyQualifiedName); } public void AddMachine(string machineName, string profileName) Added: trunk/Source/StructureMap/Delegates.cs =================================================================== --- trunk/Source/StructureMap/Delegates.cs (rev 0) +++ trunk/Source/StructureMap/Delegates.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap +{ + public delegate void Action(); + public delegate void Action<T>(T t); + public delegate void Action<T, T1>(T t, T1 t1); + public delegate T Func<T>(); + +} Added: trunk/Source/StructureMap/Diagnostics/BuildError.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/BuildError.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/BuildError.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using StructureMap.Pipeline; + +namespace StructureMap.Diagnostics +{ + public class BuildDependency : IEquatable<BuildDependency> + { + public Instance Instance; + public Type PluginType; + + + public BuildDependency(Type pluginType, Instance instance) + { + Instance = instance; + PluginType = pluginType; + } + + + public bool Equals(BuildDependency buildDependency) + { + if (buildDependency == null) return false; + return Equals(Instance, buildDependency.Instance) && Equals(PluginType, buildDependency.PluginType); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(this, obj)) return true; + return Equals(obj as BuildDependency); + } + + public override int GetHashCode() + { + return (Instance != null ? Instance.GetHashCode() : 0) + 29*(PluginType != null ? PluginType.GetHashCode() : 0); + } + } + + public class BuildError + { + private readonly Instance _instance; + private readonly Type _pluginType; + private StructureMapException _exception; + private readonly List<BuildDependency> _dependencies = new List<BuildDependency>(); + + public BuildError(Type pluginType, Instance instance) + { + _instance = instance; + _pluginType = pluginType; + } + + public void AddDependency(BuildDependency dependency) + { + if (!_dependencies.Contains(dependency)) + { + _dependencies.Add(dependency); + } + } + + public List<BuildDependency> Dependencies + { + get { return _dependencies; } + } + + public Instance Instance + { + get { return _instance; } + } + + public Type PluginType + { + get { return _pluginType; } + } + + public StructureMapException Exception + { + get { return _exception; } + set { _exception = value; } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Diagnostics/Error.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Error.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/Error.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -0,0 +1,108 @@ +using System; +using System.IO; +using System.Resources; + +namespace StructureMap.Diagnostics +{ + public class Error : IEquatable<Error> + { + private readonly int _code; + private readonly string _message; + private readonly string _stackTrace = string.Empty; + public InstanceToken Instance; + public string 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(int errorCode, Exception ex, params object[] args) : this(errorCode, args) + { + _message += "\n\n" + ex.ToString(); + _stackTrace = ex.StackTrace; + } + + + public Error(StructureMapException exception) + { + _code = exception.ErrorCode; + _message = exception.Message; + _stackTrace = exception.StackTrace; + } + + + public int Code + { + get { return _code; } + } + + #region IEquatable<Error> Members + + 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; + return true; + } + + #endregion + + private static string getMessage(int errorCode) + { + ResourceManager resources = new ResourceManager(typeof (StructureMapException)); + return resources.GetString(errorCode.ToString()); + } + + 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); + 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); + } + + public void Write(StringWriter writer) + { + // TODO: hit with an extension method for 3.5 + writer.WriteLine("Error: " + Code); + if (Instance != null) writer.WriteLine(Instance.ToString()); + writer.WriteLine("Source: " + Source); + + if (!string.IsNullOrEmpty(_message)) writer.WriteLine(_message); + if (!string.IsNullOrEmpty(_stackTrace)) writer.WriteLine(_stackTrace); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using StructureMap.Pipeline; + +namespace StructureMap.Diagnostics +{ + public class ErrorCollection + { + private readonly Dictionary<Instance, BuildError> _buildErrors = new Dictionary<Instance, BuildError>(); + private readonly List<Instance> _brokenInstances = new List<Instance>(); + + + public void LogError( + Instance instance, + Type pluginType, + StructureMapException ex, + IEnumerable<BuildDependency> dependencies) + { + if (_buildErrors.ContainsKey(instance)) + { + BuildError existingError = _buildErrors[instance]; + addDependenciesToError(instance, dependencies, existingError); + } + + if (_brokenInstances.Contains(instance)) + { + return; + } + + InstanceToken token = ((IDiagnosticInstance)instance).CreateToken(); + BuildError error = new BuildError(pluginType, instance); + error.Exception = ex; + + _buildErrors.Add(instance, error); + + addDependenciesToError(instance, dependencies, error); + } + + private void addDependenciesToError(Instance instance, IEnumerable<BuildDependency> dependencies, BuildError error) + { + foreach (BuildDependency dependency in dependencies) + { + if (_brokenInstances.Contains(instance)) + { + continue; + } + + error.AddDependency(dependency); + _brokenInstances.Add(dependency.Instance); + } + } + + public BuildError[] BuildErrors + { + get + { + BuildError[] errors = new BuildError[_buildErrors.Count]; + _buildErrors.Values.CopyTo(errors, 0); + + return errors; + } + } + + public BuildError Find(Type pluginType, string name) + { + foreach (KeyValuePair<Instance, BuildError> pair in _buildErrors) + { + BuildError error = pair.Value; + if (error.PluginType == pluginType && error.Instance.Name == name) + { + return error; + } + } + + return null; + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Diagnostics/GraphLog.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/GraphLog.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using StructureMap.Exceptions; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.Diagnostics +{ + public class GraphLog + { + private string _currentSource; + private readonly List<Error> _errors = new List<Error>(); + + public int ErrorCount + { + get { return _errors.Count; } + } + + public void StartSource(string description) + { + _currentSource = description; + } + + public void RegisterError(IDiagnosticInstance 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); + } + + public void RegisterError(int code, Exception ex, params object[] args) + { + Error error = new Error(code, ex, args); + addError(error); + } + + + + public void RegisterError(StructureMapException ex) + { + Error error = new Error(ex); + addError(error); + } + + private void addError(Error error) + { + error.Source = _currentSource; + _errors.Add(error); + } + + public void AssertFailures() + { + if (_errors.Count == 0) + { + return; + } + + string message = WriteFailures(); + + throw new StructureMapConfigurationException(message); + } + + private string WriteFailures() + { + StringBuilder sb = new StringBuilder(); + StringWriter writer = new StringWriter(sb); + + writer.WriteLine("StructureMap configuration failures:"); + + foreach (Error error in _errors) + { + error.Write(writer); + writer.WriteLine("-----------------------------------------------------------------------------------------------------"); + writer.WriteLine(); + writer.WriteLine(); + } + + return sb.ToString(); + } + + 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 void AssertHasError(int errorCode) + { + string message = "No error with code " + errorCode + "\nHad errors: "; + foreach (Error error in _errors) + { + message += error.Code + ", "; + if (error.Code == errorCode) + { + return; + } + } + + throw new ApplicationException(message); + } + + public void AssertHasNoError(int errorCode) + { + foreach (Error error in _errors) + { + if (error.Code == errorCode) + { + throw new ApplicationException("Has error " + errorCode); + } + } + } + + public TryAction Try(Action action) + { + return new TryAction(action, this); + } + + public class TryAction + { + private readonly Action _action; + private readonly GraphLog _log; + + internal TryAction(Action action, GraphLog log) + { + _action = action; + _log = log; + } + + public void AndReportErrorAs(int code, params object[] args) + { + try + { + _action(); + } + catch (Exception ex) + { + _log.RegisterError(code, ex, args); + } + } + + public void AndLogAnyErrors() + { + try + { + _action(); + } + catch (StructureMapException ex) + { + _log.RegisterError(ex); + } + catch (Exception ex) + { + _log.RegisterError(400, ex); + } + } + } + + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Diagnostics/InstanceToken.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/InstanceToken.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/InstanceToken.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -0,0 +1,57 @@ +using System; + +namespace StructureMap.Diagnostics +{ + public class InstanceToken : IEquatable<InstanceToken> + { + private readonly string _description; + private readonly string _name; + + public InstanceToken(string name, string description) + { + _name = name; + _description = description; + } + + + public string Name + { + get { return _name; } + } + + public string Description + { + get { return _description; } + } + + #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; + 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); + return result; + } + } +} \ No newline at end of file Deleted: trunk/Source/StructureMap/Diagnostics/Tokens.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-17 01:25:16 UTC (rev 98) +++ trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-26 17:39:08 UTC (rev 99) @@ -1,368 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Resources; -using StructureMap.Graph; -using StructureMap.Pipeline; - -namespace StructureMap.Diagnostics -{ - public delegate void Action(); - - public class GraphLog - { - private readonly List<Source> _sources = new List<Source>(); - private Source _currentSource; - private readonly List<Error> _errors = new List<Error>(); - - pu... [truncated message content] |
From: <jer...@us...> - 2008-05-17 01:25:22
|
Revision: 98 http://structuremap.svn.sourceforge.net/structuremap/?rev=98&view=rev Author: jeremydmiller Date: 2008-05-16 18:25:16 -0700 (Fri, 16 May 2008) Log Message: ----------- Putting WhatDoIHave back together, diagnostics fixes, rewrote InlineInstanceDefinitionInProfileAndMachineNodesTester, rewrote unit tests for error handling, made BuildSession cache instances Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Configuration/ConfigurationParser.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/GraphBuilder.cs trunk/Source/StructureMap/Configuration/ProfileBuilder.cs trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs trunk/Source/StructureMap/Diagnostics/Tokens.cs trunk/Source/StructureMap/Graph/Constructor.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.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/IInstanceFactory.cs trunk/Source/StructureMap/IInstanceManager.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/CacheInterceptor.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs trunk/Source/StructureMap/Pipeline/DefaultInstance.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/LiteralInstance.cs trunk/Source/StructureMap/Pipeline/Profile.cs trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs trunk/Source/StructureMap/Pipeline/UserControlInstance.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryTester.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/ProfileManagerTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.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/StructureMapConfigurationTester.cs trunk/Source/StructureMap.Testing/TestData/DataMother.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs trunk/Source/StructureMap/Diagnostics/CharacterWidth.cs trunk/Source/StructureMap/Diagnostics/DividerLine.cs trunk/Source/StructureMap/Diagnostics/Line.cs trunk/Source/StructureMap/Diagnostics/TextLine.cs trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/InstanceCache.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ trunk/Source/StructureMap.Testing/Diagnostics/TextReportWriterSmokeTester.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs trunk/Source/StructureMap.Testing/TestUtility.cs Removed Paths: ------------- trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserCollectionTester.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/ExceptionTestRunner.cs trunk/Source/StructureMap.Testing/TestData/ExceptionHandlingTests.xml trunk/Source/StructureMap.Testing/TestData/InlineInstanceInProfileAndMachine.xml Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/CommonAssemblyInfo.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -1,3 +1,4 @@ +using System; using System.Reflection; using System.Runtime.InteropServices; @@ -11,10 +12,11 @@ // </auto-generated> //------------------------------------------------------------------------------ -[assembly : ComVisible(false)] -[assembly : AssemblyVersion("2.5.0.0000")] -[assembly : AssemblyCopyrightAttribute("Copyright (c) 2007, Jeremy D. Miller")] -[assembly : AssemblyProductAttribute("StructureMap")] -[assembly : AssemblyCompanyAttribute("")] -[assembly : AssemblyConfigurationAttribute("release")] -[assembly : AssemblyInformationalVersionAttribute("2.5.0.0000")] \ No newline at end of file +[assembly: ComVisibleAttribute(false)] +[assembly: AssemblyVersionAttribute("2.5.0.0000")] +[assembly: AssemblyCopyrightAttribute("Copyright (c) 2007, Jeremy D. Miller")] +[assembly: AssemblyProductAttribute("StructureMap")] +[assembly: AssemblyCompanyAttribute("")] +[assembly: AssemblyConfigurationAttribute("release")] +[assembly: AssemblyInformationalVersionAttribute("2.5.0.0000")] + Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/BuildSession.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; @@ -8,6 +10,7 @@ { private readonly InterceptorLibrary _interceptorLibrary; private readonly PipelineGraph _pipelineGraph; + private InstanceCache _cache = new InstanceCache(); public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) { @@ -15,16 +18,36 @@ _interceptorLibrary = interceptorLibrary; } + public BuildSession(PluginGraph graph) + : this(new PipelineGraph(graph), graph.InterceptorLibrary) + { + + } + #region IBuildSession Members - public object CreateInstance(Type type, string name) + public object CreateInstance(Type pluginType, string name) { - return forType(type).Build(this, name); + Instance instance = forType(pluginType).FindInstance(name); + if (instance == null) + { + throw new StructureMapException(200, name, pluginType.FullName); + } + + return CreateInstance(pluginType, instance); } public object CreateInstance(Type pluginType, Instance instance) { - return forType(pluginType).Build(this, instance); + object result = _cache.Get(pluginType, instance); + + if (result == null) + { + result = forType(pluginType).Build(this, instance); + _cache.Set(pluginType, instance, result); + } + + return result; } public Array CreateInstanceArray(Type pluginType, Instance[] instances) @@ -57,7 +80,7 @@ throw new StructureMapException(202, pluginType.FullName); } - return forType(pluginType).Build(this, instance); + return CreateInstance(pluginType, instance); } public object ApplyInterception(Type pluginType, object actualValue) Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Xml; +using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Source; @@ -11,76 +12,28 @@ { #region statics - 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); - - List<ConfigurationParser> list = new List<ConfigurationParser>(); - - list.Add(new ConfigurationParser(node)); - - string includedPath = null; - - try - { - XmlNodeList includeNodes = node.SelectNodes(XmlConstants.INCLUDE_NODE); - foreach (XmlElement includeElement in includeNodes) - { - XmlDocument includedDoc = new XmlDocument(); - string fileName = includeElement.GetAttribute("File"); - - 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"); - } - - try - { - includedPath = Path.Combine(folder, fileName); - includedDoc.Load(includedPath); - - - 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); - } - } - } - catch (Exception ex) - { - // TODO: get rid of throw, put on PluginGraph here - throw new StructureMapException(100, includedPath, ex); - } - - return list.ToArray(); - } - - public static ConfigurationParser FromFile(string filename) { XmlDocument document = new XmlDocument(); document.Load(filename); XmlNode structureMapNode = document.SelectSingleNode("//" + XmlConstants.STRUCTUREMAP); - return new ConfigurationParser(structureMapNode); + if (structureMapNode == null) + { + throw new StructureMapException(155, filename); + } + + ConfigurationParser parser = new ConfigurationParser(structureMapNode); + parser.FilePath = filename; + + return parser; } #endregion private readonly XmlMementoCreator _mementoCreator; private readonly XmlNode _structureMapNode; + private string _filePath = string.Empty; public ConfigurationParser(XmlNode structureMapNode) { @@ -106,6 +59,36 @@ XmlConstants.KEY_ATTRIBUTE); } + public void ForEachFile(GraphLog log, Action<string> action) + { + // TODO: Clean up with 3.5 + string includePath = getIncludePath(); + XmlNodeList includeNodes = _structureMapNode.SelectNodes(XmlConstants.INCLUDE_NODE); + foreach (XmlElement includeElement in includeNodes) + { + string fileName = includeElement.GetAttribute("File"); + if (string.IsNullOrEmpty(fileName)) + { + log.RegisterError(156, _filePath); + } + else + { + string includedFile = Path.Combine(includePath, fileName); + action(includedFile); + } + } + } + + private string getIncludePath() + { + if (string.IsNullOrEmpty(_filePath)) + { + return string.Empty; + } + + return Path.GetDirectoryName(_filePath); + } + public string Id { get @@ -115,6 +98,13 @@ } } + + public string FilePath + { + get { return _filePath; } + set { _filePath = value; } + } + public void ParseAssemblies(IGraphBuilder builder) { parseAssemblies(builder); Added: trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Xml; +using StructureMap.Diagnostics; + +namespace StructureMap.Configuration +{ + public class ConfigurationParserBuilder + { + private readonly List<XmlNode> _nodes = new List<XmlNode>(); + private readonly List<string> _otherFiles = new List<string>(); + private bool _ignoreDefaultFile = false; + private readonly GraphLog _log; + private bool _useAndEnforceExistenceOfDefaultFile = false; + private bool _pullConfigurationFromAppConfig; + + + public ConfigurationParserBuilder(GraphLog log) + { + _log = log; + } + + public bool UseAndEnforceExistenceOfDefaultFile + { + get { return _useAndEnforceExistenceOfDefaultFile; } + set { _useAndEnforceExistenceOfDefaultFile = value; } + } + + + public bool IgnoreDefaultFile + { + get { return _ignoreDefaultFile; } + set { _ignoreDefaultFile = value; } + } + + public bool PullConfigurationFromAppConfig + { + get { return _pullConfigurationFromAppConfig; } + set + { + _pullConfigurationFromAppConfig = value; + } + } + + // TODO: Clean up with 3.5 + public ConfigurationParser[] GetParsers() + { + List<ConfigurationParser> list = new List<ConfigurationParser>(); + + // Pick up the configuration in the default StructureMap.config + string pathToStructureMapConfig = StructureMapConfiguration.GetStructureMapConfigurationPath(); + if (shouldUseStructureMapConfigFileAt(pathToStructureMapConfig)) + { + _log.Try(delegate() + { + ConfigurationParser parser = ConfigurationParser.FromFile(pathToStructureMapConfig); + list.Add(parser); + }).AndReportErrorAs(100, pathToStructureMapConfig); + } + + foreach (string filename in _otherFiles) + { + _log.Try(delegate() + { + ConfigurationParser parser = ConfigurationParser.FromFile(filename); + list.Add(parser); + }).AndReportErrorAs(160, filename); + } + + if (_pullConfigurationFromAppConfig) + { + _log.Try(delegate() + { + IList<XmlNode> appConfigNodes = StructureMapConfigurationSection.GetStructureMapConfiguration(); + foreach (XmlNode appConfigNode in appConfigNodes) + { + IncludeNode(appConfigNode); + } + }).AndLogAnyErrors(); + + } + + // TODO -- some error handling here, or somewhere else. Need to create ConfigurationParser + // as soon as the node is added to try to determine errors + foreach (XmlNode node in _nodes) + { + ConfigurationParser parser = new ConfigurationParser(node); + list.Add(parser); + } + + foreach (ConfigurationParser parser in list.ToArray()) + { + parser.ForEachFile(_log, + delegate(string filename) + { + _log.Try(delegate() + { + ConfigurationParser childParser = ConfigurationParser.FromFile(filename); + list.Add(childParser); + }).AndReportErrorAs(150, filename); + }); + } + + + return list.ToArray(); + } + + private bool shouldUseStructureMapConfigFileAt(string pathToStructureMapConfig) + { + return + (_useAndEnforceExistenceOfDefaultFile || + File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile; + } + + + public void IncludeFile(string filename) + { + _otherFiles.Add(filename); + } + + public void IncludeNode(XmlNode node) + { + _nodes.Add(node); + } + + public static ConfigurationParser[] GetParsers(XmlNode node, GraphLog log) + { + ConfigurationParserBuilder builder = new ConfigurationParserBuilder(log); + builder.IncludeNode(node); + builder.IgnoreDefaultFile = true; + + return builder.GetParsers(); + } + } +} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -1,95 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Xml; - -namespace StructureMap.Configuration -{ - // TODO: 3.5 cleanup here - public delegate XmlNode FetchNodeDelegate(); - - public class ConfigurationParserCollection - { - private readonly List<FetchNodeDelegate> _fetchers = new List<FetchNodeDelegate>(); - private readonly List<string> _otherFiles = new List<string>(); - private bool _ignoreDefaultFile = false; - private bool _useAndEnforceExistenceOfDefaultFile = false; - - public bool UseAndEnforceExistenceOfDefaultFile - { - get { return _useAndEnforceExistenceOfDefaultFile; } - set { _useAndEnforceExistenceOfDefaultFile = value; } - } - - - public bool IgnoreDefaultFile - { - get { return _ignoreDefaultFile; } - set { _ignoreDefaultFile = value; } - } - - public ConfigurationParser[] GetParsers() - { - List<ConfigurationParser> list = new List<ConfigurationParser>(); - - // Pick up the configuration in the default StructureMap.config - string pathToStructureMapConfig = StructureMapConfiguration.GetStructureMapConfigurationPath(); - if (shouldUseStructureMapConfigFile(pathToStructureMapConfig)) - { - addParsersFromFile(pathToStructureMapConfig, list); - } - - foreach (string file in _otherFiles) - { - addParsersFromFile(file, list); - } - - foreach (FetchNodeDelegate fetcher in _fetchers) - { - XmlNode node = fetcher(); - addParsersFromDocument(node, string.Empty, list); - } - - return list.ToArray(); - } - - private bool shouldUseStructureMapConfigFile(string pathToStructureMapConfig) - { - return - (_useAndEnforceExistenceOfDefaultFile || File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile; - } - - private static void addParsersFromFile(string filename, List<ConfigurationParser> list) - { - try - { - XmlDocument doc = new XmlDocument(); - doc.Load(filename); - - string includePath = Path.GetDirectoryName(filename); - addParsersFromDocument(doc.DocumentElement, includePath, list); - } - catch (Exception ex) - { - // TODO -- needs to log to PluginGraph instead - throw new StructureMapException(100, filename, ex); - } - } - - private static void addParsersFromDocument(XmlNode node, string includePath, List<ConfigurationParser> list) - { - ConfigurationParser[] parsers = ConfigurationParser.GetParsers(node, includePath); - list.AddRange(parsers); - } - - public void IncludeFile(string filename) - { - _otherFiles.Add(filename); - } - - public void IncludeNode(FetchNodeDelegate fetcher) - { - _fetchers.Add(fetcher); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -37,6 +37,11 @@ #endregion // TODO: 3.5, Try alterAndContinue(f => {}); + private CreatePluginFamilyExpression<PLUGINTYPE> alterAndContinue(Action<PluginFamily> action) + { + _alterations.Add(action); + return this; + } /// <summary> /// Sets the default instance of a Type to the definition represented by builder @@ -45,21 +50,17 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(Instance instance) { - _alterations.Add(delegate(PluginFamily family) + return alterAndContinue(delegate(PluginFamily family) { family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; }); - - return this; } public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(Instance instance) { - // TODO: Validate pluggability - _alterations.Add(delegate(PluginFamily family) { family.AddInstance(instance); }); - - return this; + return alterAndContinue( + delegate(PluginFamily family) { family.AddInstance(instance); }); } /// <summary> @@ -74,9 +75,9 @@ { ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(_pluginType); - _alterations.Add(delegate(PluginFamily family) + return alterAndContinue(delegate(PluginFamily family) { - Plugin plugin = family.Plugins.FindOrCreate(typeof (CONCRETETYPE), true); + Plugin plugin = family.Plugins.FindOrCreate(typeof(CONCRETETYPE), true); family.DefaultInstanceKey = plugin.ConcreteKey; }); @@ -91,9 +92,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> CacheBy(InstanceScope scope) { - _alterations.Add(delegate(PluginFamily family) { family.SetScopeTo(scope); }); - - return this; + return alterAndContinue(delegate(PluginFamily family) { family.SetScopeTo(scope); }); } /// <summary> @@ -147,6 +146,8 @@ public CreatePluginFamilyExpression<PLUGINTYPE> AddConcreteType<CONCRETETYPE>(string instanceName) { + ExpressionValidator.ValidatePluggabilityOf(typeof(CONCRETETYPE)).IntoPluginType(typeof(PLUGINTYPE)); + _alterations.Add( delegate(PluginFamily family) { @@ -174,6 +175,8 @@ public CreatePluginFamilyExpression<PLUGINTYPE> AliasConcreteType<PLUGGEDTYPE>(string concreteKey) { + ExpressionValidator.ValidatePluggabilityOf(typeof(PLUGGEDTYPE)).IntoPluginType(typeof(PLUGINTYPE)); + _alterations.Add(delegate(PluginFamily family) { family.AddPlugin(typeof (PLUGGEDTYPE), concreteKey); }); return this; Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -33,21 +33,27 @@ internal void Configure(string profileName, PluginGraph pluginGraph) { + // The profile instance is defined inline if (_instance != null) { _instanceKey = Profile.InstanceKeyForProfile(profileName); _instance.Name = _instanceKey; pluginGraph.FindFamily(_pluginType).AddInstance(_instance); } + + // Using a referenced key for the profile else if (!string.IsNullOrEmpty(_instanceKey)) { _instance = new ReferencedInstance(_instanceKey); } + // Set the default instance in the Profile if (_instance != null) { pluginGraph.ProfileManager.SetDefault(profileName, _pluginType, _instance); } + + // Blow up if the Profile expression is not complete. else { throw new StructureMapException(304, TypePath.GetAssemblyQualifiedName(_pluginType)); @@ -61,6 +67,8 @@ /// <returns></returns> public ProfileExpression Use(Instance instance) { + // TODO -- validate that the instance can be plugged into the PluginType + _instance = instance; return _parent; Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -73,7 +73,6 @@ public ScanAssembliesExpression AddAllTypesOf<PLUGINTYPE>() { - // TODO: Do this by adding something to TypeScanner _registry.addExpression(delegate(PluginGraph pluginGraph) { PluginFamily family = Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -238,9 +238,9 @@ } public static ConstructorInstance ConstructedBy<PLUGINTYPE> - (BuildObjectDelegate builder) + (Func<PLUGINTYPE> builder) { - return new ConstructorInstance(builder); + return new ConstructorInstance(delegate() { return builder(); }); } public static ReferencedInstance Instance(string referencedKey) Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -22,17 +22,17 @@ { TypePath typePath = TypePath.CreateFromXmlNode(familyElement); _builder.ConfigureFamily(typePath, delegate(PluginFamily family) - { - family.DefaultInstanceKey = - familyElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE); + { + family.DefaultInstanceKey = + familyElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE); - InstanceScope scope = findScope(familyElement); - family.SetScopeTo(scope); + InstanceScope scope = findScope(familyElement); + family.SetScopeTo(scope); - attachMementoSource(family, familyElement); - attachPlugins(family, familyElement); - attachInterceptors(family, familyElement); - }); + attachMementoSource(family, familyElement); + attachPlugins(family, familyElement); + attachInterceptors(family, familyElement); + }); } public void ParseDefaultElement(XmlElement element) @@ -40,28 +40,27 @@ TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE)); - _builder.ConfigureFamily(pluginTypePath, - delegate(PluginFamily family) - { - // TODO: there's a little duplication here - InstanceScope scope = findScope(element); - family.SetScopeTo(scope); + _builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family) + { + // TODO: there's a little duplication here + InstanceScope scope = findScope(element); + family.SetScopeTo(scope); - Type pluginType = family.PluginType; + Type pluginType = family.PluginType; - string name = element.GetAttribute(XmlConstants.NAME); - if (string.IsNullOrEmpty(name)) - { - name = "DefaultInstanceOf" + pluginTypePath.AssemblyQualifiedName; - } + string name = element.GetAttribute(XmlConstants.NAME); + if (string.IsNullOrEmpty(name)) + { + name = "DefaultInstanceOf" + pluginTypePath.AssemblyQualifiedName; + } - InstanceMemento memento = _mementoCreator.CreateMemento(element); - memento.InstanceKey = name; + InstanceMemento memento = _mementoCreator.CreateMemento(element); + memento.InstanceKey = name; - family.DefaultInstanceKey = name; + family.DefaultInstanceKey = name; - family.AddInstance(memento); - }); + family.AddInstance(memento); + }); } public void ParseInstanceElement(XmlElement element) @@ -69,11 +68,11 @@ TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE)); _builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family) - { - InstanceMemento memento = - _mementoCreator.CreateMemento(element); - family.AddInstance(memento); - }); + { + InstanceMemento memento = + _mementoCreator.CreateMemento(element); + family.AddInstance(memento); + }); } private InstanceScope findScope(XmlElement familyElement) @@ -97,7 +96,8 @@ { InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(sourceNode); - string context = "MementoSource for " + TypePath.GetAssemblyQualifiedName(family.PluginType); + string context = "MementoSource for " + TypePath.GetAssemblyQualifiedName(family.PluginType) + "\n" + + sourceNode.OuterXml; _builder.WithSystemObject<MementoSource>(sourceMemento, context, delegate(MementoSource source) { family.AddMementoSource(source); }); } @@ -109,24 +109,29 @@ 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); + attachPlugin(pluginElement, family); + } + } - string context = "creating a Plugin for " + family.PluginType.AssemblyQualifiedName; - _builder.WithType(pluginPath, context, delegate(Type pluggedType) - { - Plugin plugin = new Plugin(pluggedType, concreteKey); - family.Plugins.Add(plugin); + private void attachPlugin(XmlElement pluginElement, PluginFamily family) + { + TypePath pluginPath = TypePath.CreateFromXmlNode(pluginElement); + string concreteKey = pluginElement.GetAttribute(XmlConstants.CONCRETE_KEY_ATTRIBUTE); - foreach ( - XmlElement setterElement in pluginElement.ChildNodes) - { - string setterName = - setterElement.GetAttribute("Name"); - plugin.Setters.Add(setterName); - } - }); - } + string context = "creating a Plugin for " + family.PluginType.AssemblyQualifiedName; + _builder.WithType(pluginPath, context, delegate(Type pluggedType) + { + Plugin plugin = new Plugin(pluggedType, concreteKey); + family.AddPlugin(plugin); + + foreach ( + XmlElement setterElement in pluginElement.ChildNodes) + { + string setterName = + setterElement.GetAttribute("Name"); + plugin.Setters.Add(setterName); + } + }); } // TODO: 3.5 lambda cleanup @@ -138,13 +143,13 @@ return; } - string context = "Creating an InstanceInterceptor for " + - TypePath.GetAssemblyQualifiedName(family.PluginType); + string contextBase = "creating an InstanceInterceptor for " + + TypePath.GetAssemblyQualifiedName(family.PluginType) + "\n"; foreach (XmlNode interceptorNode in interceptorChainNode.ChildNodes) { XmlAttributeInstanceMemento interceptorMemento = new XmlAttributeInstanceMemento(interceptorNode); - + string context = contextBase + interceptorNode.OuterXml; _builder.WithSystemObject<IBuildInterceptor>(interceptorMemento, context, delegate(IBuildInterceptor interceptor) { family.AddInterceptor(interceptor); }); } Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -82,7 +82,7 @@ } catch (Exception ex) { - _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.ClassName, pluginTypePath.AssemblyName); + _pluginGraph.Log.RegisterError(103, ex, pluginTypePath.AssemblyQualifiedName); } } @@ -108,6 +108,10 @@ Type type = path.FindType(); action(type); } + catch (StructureMapException ex) + { + _pluginGraph.Log.RegisterError(ex); + } catch (Exception ex) { _pluginGraph.Log.RegisterError(131, ex, path.AssemblyQualifiedName, context); Modified: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -6,6 +6,18 @@ { public class ProfileBuilder : IProfileBuilder { + private static string _overriden_machine_name; + + public static void OverrideMachineName(string machineName) + { + _overriden_machine_name = machineName; + } + + public static void ResetMachineName() + { + _overriden_machine_name = string.Empty; + } + private readonly string _machineName; private readonly PluginGraph _pluginGraph; private readonly ProfileManager _profileManager; @@ -72,6 +84,11 @@ public static string GetMachineName() { + if (!string.IsNullOrEmpty(_overriden_machine_name)) + { + return _overriden_machine_name; + } + string machineName = string.Empty; try { Modified: trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -26,7 +26,6 @@ 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/Diagnostics/CharacterWidth.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/CharacterWidth.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/CharacterWidth.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -0,0 +1,39 @@ +namespace StructureMap.Diagnostics +{ + internal class CharacterWidth + { + internal static CharacterWidth[] For(int count) + { + CharacterWidth[] widths = new CharacterWidth[count]; + for (int i = 0; i < widths.Length; i++) + { + widths[i] = new CharacterWidth(); + } + + return widths; + } + + private int _width = 0; + + internal void SetWidth(int width) + { + if (width > _width) + { + _width = width; + } + } + + internal void Add(int add) + { + _width += add; + } + + internal int Width + { + get + { + return _width; + } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Diagnostics/DividerLine.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/DividerLine.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/DividerLine.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -0,0 +1,27 @@ +using System.IO; + +namespace StructureMap.Diagnostics +{ + internal class DividerLine : Line + { + private readonly char _character; + + internal DividerLine(char character) + { + _character = character; + } + + public void OverwriteCounts(CharacterWidth[] widths) + { + // no-op + } + + public void Write(TextWriter writer, CharacterWidth[] widths) + { + foreach (CharacterWidth width in widths) + { + writer.Write(string.Empty.PadRight(width.Width, _character)); + } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Diagnostics/Line.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Line.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/Line.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -0,0 +1,10 @@ +using System.IO; + +namespace StructureMap.Diagnostics +{ + internal interface Line + { + void OverwriteCounts(CharacterWidth[] widths); + void Write(TextWriter writer, CharacterWidth[] widths); + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Diagnostics/TextLine.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/TextLine.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/TextLine.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -0,0 +1,32 @@ +using System.IO; + +namespace StructureMap.Diagnostics +{ + internal class TextLine : Line + { + private readonly string[] _contents; + + internal TextLine(string[] contents) + { + _contents = contents; + } + + public void OverwriteCounts(CharacterWidth[] widths) + { + for (int i = 0; i < widths.Length; i++) + { + CharacterWidth width = widths[i]; + width.SetWidth(_contents[i].Length); + } + } + + public void Write(TextWriter writer, CharacterWidth[] widths) + { + for (int i = 0; i < widths.Length; i++) + { + CharacterWidth width = widths[i]; + writer.Write(_contents[i].PadRight(width.Width)); + } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Text; + +namespace StructureMap.Diagnostics +{ + public class TextReportWriter + { + private readonly int _columnCount; + private List<Line> _lines = new List<Line>(); + + public TextReportWriter(int columnCount) + { + _columnCount = columnCount; + } + + public void AddDivider(char character) + { + _lines.Add(new DividerLine(character)); + } + + public void AddText(params string[] contents) + { + _lines.Add(new TextLine(contents)); + } + + public void Write(StringWriter writer) + { + CharacterWidth[] widths = CharacterWidth.For(_columnCount); + + foreach (Line line in _lines) + { + line.OverwriteCounts(widths); + } + + for (int i = 0; i < widths.Length - 1; i++) + { + CharacterWidth width = widths[i]; + width.Add(5); + } + + foreach (Line line in _lines) + { + writer.WriteLine(); + line.Write(writer, widths); + } + } + + public string Write() + { + StringBuilder sb = new StringBuilder(); + StringWriter writer = new StringWriter(sb); + + Write(writer); + + return sb.ToString(); + } + + public void DumpToConsole() + { + System.Console.WriteLine(Write()); + } + + public void DumpToDebug() + { + Debug.WriteLine(Write()); + } + } +} Modified: trunk/Source/StructureMap/Diagnostics/Tokens.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -6,11 +6,13 @@ namespace StructureMap.Diagnostics { + public delegate void Action(); + public class GraphLog { private readonly List<Source> _sources = new List<Source>(); private Source _currentSource; - private List<Error> _errors = new List<Error>(); + private readonly List<Error> _errors = new List<Error>(); public int ErrorCount { @@ -45,6 +47,13 @@ } + + public void RegisterError(StructureMapException ex) + { + Error error = new Error(ex); + addError(error); + } + private void addError(Error error) { error.Source = _currentSource; @@ -68,16 +77,75 @@ public void AssertHasError(int errorCode) { + string message = "No error with code " + errorCode + "\nHad errors: "; foreach (Error error in _errors) { + message += error.Code + ", "; if (error.Code == errorCode) { return; } } - throw new ApplicationException("No error with code " + errorCode); + throw new ApplicationException(message); } + + public void AssertHasNoError(int errorCode) + { + foreach (Error error in _errors) + { + if (error.Code == errorCode) + { + throw new ApplicationException("Has error " + errorCode); + } + } + } + + public TryAction Try(Action action) + { + return new TryAction(action, this); + } + + public class TryAction + { + private readonly Action _action; + private readonly GraphLog _log; + + internal TryAction(Action action, GraphLog log) + { + _action = action; + _log = log; + } + + public void AndReportErrorAs(int code, params object[] args) + { + try + { + _action(); + } + catch (Exception ex) + { + _log.RegisterError(code, ex, args); + } + } + + public void AndLogAnyErrors() + { + try + { + _action(); + } + catch (StructureMapException ex) + { + _log.RegisterError(ex); + } + catch (Exception ex) + { + _log.RegisterError(400, ex); + } + } + } + } public class Source @@ -154,13 +222,11 @@ { private readonly string _description; private readonly string _name; - private PluginType _pluginType; - public InstanceToken(string name, string description, PluginType pluginType) + public InstanceToken(string name, string description) { _name = name; _description = description; - _pluginType = pluginType; } @@ -174,12 +240,6 @@ get { return _description; } } - - public PluginType PluginType - { - get { return _pluginType; } - } - #region IEquatable<InstanceToken> Members public bool Equals(InstanceToken instanceToken) @@ -187,7 +247,6 @@ 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; } @@ -208,7 +267,6 @@ { 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; } } Added: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs (rev 0) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Text; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.Diagnostics +{ + public class WhatDoIHaveWriter : IPipelineGraphVisitor + { + private readonly PipelineGraph _graph; + private TextReportWriter _writer; + private List<Instance> _instances; + + public WhatDoIHaveWriter(PipelineGraph graph) + { + _graph = graph; + + } + + public string GetText() + { + _writer = new TextReportWriter(3); + _instances = new List<Instance>(); + + _writer.AddDivider('='); + _writer.AddText("PluginType", "Name", "Description"); + + _graph.Visit(this); + + _writer.AddDivider('='); + + return _writer.Write(); + } + + void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance) + { + _writer.AddDivider('-'); + string[] contents = new string[]{TypePath.GetAssemblyQualifiedName(pluginType), string.Empty, string.Empty}; + + if (defaultInstance != null) + { + setContents(contents, defaultInstance); + + } + + _writer.AddText(contents); + } + + private void setContents(string[] contents, Instance instance) + { + InstanceToken token = instance.CreateToken(); + contents[1] = token.Name; + contents[2] = token.Description; + + _instances.Add(instance); + } + + void IPipelineGraphVisitor.Instance(Type pluginType, Instance instance) + { + if (_instances.Contains(instance)) + { + return; + } + + string[] contents = new string[]{string.Empty, string.Empty, string.Empty}; + setContents(contents, instance); + + _writer.AddText(contents); + } + } +} Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -107,5 +107,10 @@ if (IsEnum(parameterType)) visitor.EnumParameter(info); if (IsString(parameterType)) visitor.StringParameter(info); } + + public bool HasArguments() + { + return _ctor.GetParameters().Length > 0; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -91,9 +91,8 @@ public static PluginFamily CreateTemplatedClone(PluginFamily baseFamily, params Type[] templateTypes) { Type templatedType = baseFamily.PluginType.MakeGenericType(templateTypes); - PluginFamily templatedFamily = new PluginFamily(templatedType); + PluginFamily templatedFamily = new PluginFamily(templatedType, baseFamily.Parent); templatedFamily.DefaultInstanceKey = baseFamily.DefaultInstanceKey; - templatedFamily.Parent = baseFamily.Parent; templatedFamily.Policy = baseFamily.Policy.Clone(); // Add Plugins Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -78,18 +78,6 @@ #endregion - /// <summary> - /// Adds a new Plugin by the PluggedType - /// </summary> - /// <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 = new Plugin(pluggedType, concreteKey); - Add(plugin); - } public void Add(Plugin plugin) { @@ -108,9 +96,7 @@ // Reject if the PluggedType cannot be upcast to the PluginType if (!TypeRules.CanBeCast(_family.PluginType, plugin.PluggedType)) { - // TODO -- get this logged - throw new StructureMapException(114, plugin.PluggedType.FullName, - _family.PluginType.AssemblyQualifiedName); + throw new StructureMapException(104, plugin.PluggedType, _family.PluginType); } _plugins.Add(plugin.PluggedType, plugin); Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-15 18:15:44 UTC (rev 97) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-17 01:25:16 UTC (rev 98) @@ -25,7 +25,13 @@ private IBuildPolicy _policy; public PluginFamily(Type pluginType) + : this(pluginType, new PluginGraph()) { + } + + public PluginFamily(Type pluginType, PluginGraph parent) + { + _parent = parent; _pluginType = pluginType; _plugins = new PluginCollection(this); @@ -93,10 +99,15 @@ public void AddInstance(Instance instance) { + IDiagnosticInstance diagnosticInstance = instance; + if (!diagnosticInstance.CanBePartOfPluginFamily(this)) + { + _parent.Log.RegisterError(106, instance.CreateToken(), _pluginType); + } + _instances.Add(instance); } - // TODO -- eliminate this. Move to GraphBuilder, and wrap error handling around it // For testing public InstanceMemento GetMemento(string instanceKey) @@ -108,10 +119,13 @@ public void Seal() { _mementoList.ForEach(delegate(InstanceMemento memento) - { - Instance instance = memento.ReadInstance(Parent, _pluginType); - _instances.Add(instance); - }); + { + _parent.Log.Try(delegate() + { + Instance instance = memento.ReadInstance(Parent, _pluginType); + _instances.Add(instance); + }).AndLogAnyErrors(); + }); discoverImplicitInstances(); @@ -166,20 +180,26 @@ { if (!HasPlugin(pluggedType)) { - _plugins.Add(new Plugin(pluggedType)); + AddPlugin(new Plugin(pluggedType)); } } public Plugin AddPlugin(Type pluggedType, string key) { Plugin plugin = new Plugin(pluggedType, key); - _plugins.Add(plugin); +... [truncated message content] |
From: <jer...@us...> - 2008-05-15 18:15:52
|
Revision: 97 http://structuremap.svn.sourceforge.net/structuremap/?rev=97&view=rev Author: jeremydmiller Date: 2008-05-15 11:15:44 -0700 (Thu, 15 May 2008) Log Message: ----------- Reformatting Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs trunk/Source/StructureMap/BuildSession.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/ProfileExpression.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/ProfileAndMachineParser.cs trunk/Source/StructureMap/Configuration/ProfileBuilder.cs trunk/Source/StructureMap/Configuration/XmlConstants.cs trunk/Source/StructureMap/Diagnostics/Tokens.cs trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs trunk/Source/StructureMap/Emitting/ClassBuilder.cs trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/Constructor.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/SetterPropertyCollection.cs trunk/Source/StructureMap/Graph/TypePath.cs trunk/Source/StructureMap/Graph/TypeRules.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/IInstanceManager.cs trunk/Source/StructureMap/InstanceBuilderList.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceFamily.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/MemoryInstanceMemento.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/BuildPolicy.cs trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/DefaultInstance.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/ILocationPolicy.cs trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs trunk/Source/StructureMap/Pipeline/LiteralInstance.cs trunk/Source/StructureMap/Pipeline/Profile.cs trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs trunk/Source/StructureMap/Pipeline/UserControlInstance.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/Properties/AssemblyInfo.cs trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/CommonAssemblyInfo.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,4 +1,3 @@ -using System; using System.Reflection; using System.Runtime.InteropServices; @@ -12,11 +11,10 @@ // </auto-generated> //------------------------------------------------------------------------------ -[assembly: ComVisibleAttribute(false)] -[assembly: AssemblyVersionAttribute("2.5.0.0000")] -[assembly: AssemblyCopyrightAttribute("Copyright (c) 2007, Jeremy D. Miller")] -[assembly: AssemblyProductAttribute("StructureMap")] -[assembly: AssemblyCompanyAttribute("")] -[assembly: AssemblyConfigurationAttribute("release")] -[assembly: AssemblyInformationalVersionAttribute("2.5.0.0000")] - +[assembly : ComVisible(false)] +[assembly : AssemblyVersion("2.5.0.0000")] +[assembly : AssemblyCopyrightAttribute("Copyright (c) 2007, Jeremy D. Miller")] +[assembly : AssemblyProductAttribute("StructureMap")] +[assembly : AssemblyCompanyAttribute("")] +[assembly : AssemblyConfigurationAttribute("release")] +[assembly : AssemblyInformationalVersionAttribute("2.5.0.0000")] \ No newline at end of file Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -94,7 +94,8 @@ } catch (Exception ex) { - throw new StructureMapException(122, ex, SourceType.FullName, family.PluginType.AssemblyQualifiedName); + throw new StructureMapException(122, ex, SourceType.FullName, + family.PluginType.AssemblyQualifiedName); } } Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/BuildSession.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using StructureMap.Interceptors; using StructureMap.Pipeline; @@ -8,8 +6,8 @@ { public class BuildSession : IBuildSession { + private readonly InterceptorLibrary _interceptorLibrary; private readonly PipelineGraph _pipelineGraph; - private readonly InterceptorLibrary _interceptorLibrary; public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) { @@ -17,10 +15,7 @@ _interceptorLibrary = interceptorLibrary; } - private IInstanceFactory forType(Type pluginType) - { - return _pipelineGraph.ForType(pluginType); - } + #region IBuildSession Members public object CreateInstance(Type type, string name) { @@ -79,5 +74,12 @@ { return forType(pluginType).FindBuilderByConcreteKey(concreteKey); } + + #endregion + + private IInstanceFactory forType(Type pluginType) + { + return _pipelineGraph.ForType(pluginType); + } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Xml; @@ -48,7 +47,7 @@ includedPath = Path.Combine(folder, fileName); includedDoc.Load(includedPath); - + ConfigurationParser parser = new ConfigurationParser(includedDoc.DocumentElement); list.Add(parser); } @@ -86,7 +85,7 @@ public ConfigurationParser(XmlNode structureMapNode) { _structureMapNode = structureMapNode; - + // TODO: 3.5 cleanup with extension method XmlMementoStyle mementoStyle = XmlMementoStyle.NodeNormalized; @@ -128,13 +127,9 @@ foreach (XmlElement familyElement in familyNodes) { TypePath typePath = TypePath.CreateFromXmlNode(familyElement); - - builder.ConfigureFamily(typePath, delegate(PluginFamily family) - { - attachInstances(family, familyElement, builder); - }); - + builder.ConfigureFamily(typePath, + delegate(PluginFamily family) { attachInstances(family, familyElement, builder); }); } } Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -11,8 +11,8 @@ public class ConfigurationParserCollection { private readonly List<FetchNodeDelegate> _fetchers = new List<FetchNodeDelegate>(); + private readonly List<string> _otherFiles = new List<string>(); private bool _ignoreDefaultFile = false; - private readonly List<string> _otherFiles = new List<string>(); private bool _useAndEnforceExistenceOfDefaultFile = false; public bool UseAndEnforceExistenceOfDefaultFile @@ -55,7 +55,8 @@ private bool shouldUseStructureMapConfigFile(string pathToStructureMapConfig) { - return (_useAndEnforceExistenceOfDefaultFile || File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile; + return + (_useAndEnforceExistenceOfDefaultFile || File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile; } private static void addParsersFromFile(string filename, List<ConfigurationParser> list) Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -4,11 +4,9 @@ using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; -using StructureMap.Source; namespace StructureMap.Configuration.DSL.Expressions { - /// <summary> /// Represents the parameters for creating instances of a given Type /// </summary> @@ -59,10 +57,7 @@ public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(Instance instance) { // TODO: Validate pluggability - _alterations.Add(delegate(PluginFamily family) - { - family.AddInstance(instance); - }); + _alterations.Add(delegate(PluginFamily family) { family.AddInstance(instance); }); return this; } @@ -96,10 +91,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> CacheBy(InstanceScope scope) { - _alterations.Add(delegate(PluginFamily family) - { - family.SetScopeTo(scope); - }); + _alterations.Add(delegate(PluginFamily family) { family.SetScopeTo(scope); }); return this; } @@ -127,7 +119,7 @@ return target; }; - PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), function); + PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); graph.InterceptorLibrary.AddInterceptor(interceptor); }); @@ -138,15 +130,12 @@ { _children.Add( delegate(PluginGraph graph) - { - InterceptionFunction function = delegate(object target) - { - return handler((PLUGINTYPE)target); - }; + { + InterceptionFunction function = delegate(object target) { return handler((PLUGINTYPE) target); }; - PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), function); - graph.InterceptorLibrary.AddInterceptor(interceptor); - }); + PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); + graph.InterceptorLibrary.AddInterceptor(interceptor); + }); return this; } @@ -172,29 +161,20 @@ public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(IBuildInterceptor interceptor) { - _alterations.Add(delegate(PluginFamily family) - { - family.AddInterceptor(interceptor); - }); + _alterations.Add(delegate(PluginFamily family) { family.AddInterceptor(interceptor); }); return this; } public CreatePluginFamilyExpression<PLUGINTYPE> AddInstancesFrom(MementoSource source) { - _alterations.Add(delegate(PluginFamily family) - { - family.AddMementoSource(source); - }); + _alterations.Add(delegate(PluginFamily family) { family.AddMementoSource(source); }); return this; } public CreatePluginFamilyExpression<PLUGINTYPE> AliasConcreteType<PLUGGEDTYPE>(string concreteKey) { - _alterations.Add(delegate(PluginFamily family) - { - family.AddPlugin(typeof(PLUGGEDTYPE), concreteKey); - }); + _alterations.Add(delegate(PluginFamily family) { family.AddPlugin(typeof (PLUGGEDTYPE), concreteKey); }); return this; } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -11,8 +11,8 @@ { private readonly ProfileExpression _parent; private readonly Type _pluginType; + private Instance _instance; private string _instanceKey = string.Empty; - private Instance _instance; public InstanceDefaultExpression(Type pluginType, ProfileExpression parent) { @@ -37,7 +37,7 @@ { _instanceKey = Profile.InstanceKeyForProfile(profileName); _instance.Name = _instanceKey; - pluginGraph.FindFamily(_pluginType).AddInstance(_instance); + pluginGraph.FindFamily(_pluginType).AddInstance(_instance); } else if (!string.IsNullOrEmpty(_instanceKey)) { @@ -46,7 +46,7 @@ if (_instance != null) { - pluginGraph.ProfileManager.SetDefault(profileName, _pluginType, _instance); + 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-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using StructureMap.Graph; Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -66,7 +66,7 @@ public ScanAssembliesExpression IncludeAssemblyContainingType<T>() { - _assemblies.Add(typeof(T).Assembly); + _assemblies.Add(typeof (T).Assembly); return this; } Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -112,10 +112,8 @@ { ConfiguredInstance instance = new ConfiguredInstance(); - addExpression(delegate (PluginGraph pluginGraph) - { - pluginGraph.FindFamily(typeof(PLUGINTYPE)).AddInstance(instance); - }); + addExpression( + delegate(PluginGraph pluginGraph) { pluginGraph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance); }); return instance; } @@ -165,7 +163,7 @@ public LiteralInstance AddInstanceOf<PLUGINTYPE>(PLUGINTYPE target) { LiteralInstance literal = new LiteralInstance(target); - _graph.FindFamily(typeof(PLUGINTYPE)).AddInstance(literal); + _graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(literal); return literal; } @@ -179,7 +177,7 @@ public PrototypeInstance AddPrototypeInstanceOf<PLUGINTYPE>(PLUGINTYPE prototype) { PrototypeInstance expression = new PrototypeInstance((ICloneable) prototype); - _graph.FindFamily(typeof(PLUGINTYPE)).AddInstance(expression); + _graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(expression); return expression; } @@ -235,7 +233,7 @@ 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-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -2,7 +2,6 @@ using System.Xml; using StructureMap.Attributes; using StructureMap.Graph; -using StructureMap.Interceptors; using StructureMap.Pipeline; using StructureMap.Source; @@ -68,10 +67,11 @@ public void ParseInstanceElement(XmlElement element) { TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE)); - + _builder.ConfigureFamily(pluginTypePath, delegate(PluginFamily family) { - InstanceMemento memento = _mementoCreator.CreateMemento(element); + InstanceMemento memento = + _mementoCreator.CreateMemento(element); family.AddInstance(memento); }); } @@ -98,12 +98,8 @@ InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(sourceNode); string context = "MementoSource for " + TypePath.GetAssemblyQualifiedName(family.PluginType); - _builder.WithSystemObject<MementoSource>(sourceMemento, context, delegate (MementoSource source) - { - family.AddMementoSource(source); - }); - - + _builder.WithSystemObject<MementoSource>(sourceMemento, context, + delegate(MementoSource source) { family.AddMementoSource(source); }); } } @@ -122,14 +118,14 @@ Plugin plugin = new Plugin(pluggedType, concreteKey); family.Plugins.Add(plugin); - foreach (XmlElement setterElement in pluginElement.ChildNodes) + foreach ( + XmlElement setterElement in pluginElement.ChildNodes) { - string setterName = setterElement.GetAttribute("Name"); + string setterName = + setterElement.GetAttribute("Name"); plugin.Setters.Add(setterName); } }); - - } } @@ -142,17 +138,15 @@ return; } - string context = "Creating an InstanceInterceptor for " + TypePath.GetAssemblyQualifiedName(family.PluginType); + string context = "Creating an InstanceInterceptor for " + + TypePath.GetAssemblyQualifiedName(family.PluginType); foreach (XmlNode interceptorNode in interceptorChainNode.ChildNodes) { XmlAttributeInstanceMemento interceptorMemento = new XmlAttributeInstanceMemento(interceptorNode); - _builder.WithSystemObject<IBuildInterceptor>(interceptorMemento, context, delegate(IBuildInterceptor interceptor) - { - family.AddInterceptor(interceptor); - }); - + _builder.WithSystemObject<IBuildInterceptor>(interceptorMemento, context, + delegate(IBuildInterceptor interceptor) { family.AddInterceptor(interceptor); }); } } } Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,5 +1,4 @@ using System; -using StructureMap.Attributes; using StructureMap.Graph; namespace StructureMap.Configuration @@ -30,5 +29,4 @@ 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/ProfileAndMachineParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,4 +1,3 @@ -using System; using System.Xml; using StructureMap.Graph; using StructureMap.Pipeline; @@ -9,9 +8,9 @@ // TODO: 3.5 cleanup public class ProfileAndMachineParser { - private readonly IProfileBuilder _profileBuilder; - private readonly IGraphBuilder _graphBuilder; private readonly XmlMementoCreator _creator; + private readonly IGraphBuilder _graphBuilder; + private readonly IProfileBuilder _profileBuilder; private readonly XmlNode _structureMapNode; public ProfileAndMachineParser(IGraphBuilder graphBuilder, XmlNode structureMapNode, XmlMementoCreator creator) @@ -91,9 +90,6 @@ family.AddInstance(memento); function(fullName, key); }); - - - } private XmlNodeList findNodes(string nodeName) Modified: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using StructureMap.Graph; using StructureMap.Pipeline; @@ -8,25 +6,11 @@ { public class ProfileBuilder : IProfileBuilder { - public static string GetMachineName() - { - string machineName = string.Empty; - try - { - machineName = Environment.MachineName.ToUpper(); - } - finally - { - } - - return machineName; - } - + private readonly string _machineName; private readonly PluginGraph _pluginGraph; - private readonly string _machineName; + private readonly ProfileManager _profileManager; private string _lastProfile; private bool _useMachineOverrides; - private readonly ProfileManager _profileManager; public ProfileBuilder(PluginGraph pluginGraph, string machineName) @@ -42,6 +26,8 @@ { } + #region IProfileBuilder Members + public void AddProfile(string profileName) { _lastProfile = profileName; @@ -81,5 +67,21 @@ { _profileManager.DefaultProfileName = profileName; } + + #endregion + + public static string GetMachineName() + { + string machineName = string.Empty; + try + { + machineName = Environment.MachineName.ToUpper(); + } + finally + { + } + + return machineName; + } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/XmlConstants.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlConstants.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Configuration/XmlConstants.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,5 +1,3 @@ -using System; - namespace StructureMap.Configuration { /// <summary> Modified: trunk/Source/StructureMap/Diagnostics/Tokens.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -8,9 +8,9 @@ { public class GraphLog { - private List<Error> _errors = new List<Error>(); private readonly List<Source> _sources = new List<Source>(); private Source _currentSource; + private List<Error> _errors = new List<Error>(); public int ErrorCount { @@ -245,11 +245,6 @@ } - public int Code - { - get { return _code; } - } - public Error(StructureMapException exception) { _code = exception.ErrorCode; @@ -257,12 +252,12 @@ _stackTrace = exception.StackTrace; } - private string getMessage(int errorCode) + public int Code { - ResourceManager resources = new ResourceManager(typeof(StructureMapException)); - return resources.GetString(errorCode.ToString()); + get { return _code; } } + #region IEquatable<Error> Members public bool Equals(Error error) { @@ -276,6 +271,14 @@ return true; } + #endregion + + private string getMessage(int errorCode) + { + ResourceManager resources = new ResourceManager(typeof (StructureMapException)); + return resources.GetString(errorCode.ToString()); + } + public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) return true; Modified: trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs =================================================================== --- trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,7 +1,5 @@ using System; -using System.Reflection; using System.Reflection.Emit; -using StructureMap.Emitting.Parameters; using StructureMap.Graph; using StructureMap.Pipeline; @@ -33,7 +31,7 @@ public override Type[] ArgumentList { - get { return new Type[] { typeof(IConfiguredInstance), typeof(StructureMap.Pipeline.IBuildSession) }; } + get { return new Type[] {typeof (IConfiguredInstance), typeof (IBuildSession)}; } } public override string MethodName Modified: trunk/Source/StructureMap/Emitting/ClassBuilder.cs =================================================================== --- trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -111,7 +111,7 @@ public void AddPluggedTypeGetter(Type pluggedType) { PropertyBuilder prop = - _newTypeBuilder.DefineProperty("PluggedType", PropertyAttributes.HasDefault, typeof(Type), null); + _newTypeBuilder.DefineProperty("PluggedType", PropertyAttributes.HasDefault, typeof (Type), null); MethodAttributes atts = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.Final | MethodAttributes.SpecialName; @@ -119,19 +119,19 @@ string getterMethodName = "get_PluggedType"; MethodBuilder methodGet = - _newTypeBuilder.DefineMethod(getterMethodName, atts, CallingConventions.Standard, typeof(Type), null); + _newTypeBuilder.DefineMethod(getterMethodName, atts, CallingConventions.Standard, typeof (Type), null); ILGenerator gen = methodGet.GetILGenerator(); - LocalBuilder ilReturn = gen.DeclareLocal(typeof(Type)); + LocalBuilder ilReturn = gen.DeclareLocal(typeof (Type)); gen.Emit(OpCodes.Nop); gen.Emit(OpCodes.Ldtoken, pluggedType); - MethodInfo method = typeof(Type).GetMethod("GetTypeFromHandle"); + 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); Modified: trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs =================================================================== --- trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -10,9 +10,9 @@ /// </summary> public class InstanceBuilderAssembly { + private readonly List<string> _classNames = new List<string>(); private readonly DynamicAssembly _dynamicAssembly; private readonly Type _pluginType; - private readonly List<string> _classNames = new List<string>(); public InstanceBuilderAssembly(Type pluginType, IEnumerable<Plugin> plugins) { @@ -86,10 +86,9 @@ { Assembly assembly = _dynamicAssembly.Compile(); - return _classNames.ConvertAll<InstanceBuilder>(delegate(string typeName) - { - return (InstanceBuilder) assembly.CreateInstance(typeName); - }); + return + _classNames.ConvertAll<InstanceBuilder>( + delegate(string typeName) { return (InstanceBuilder) assembly.CreateInstance(typeName); }); } Modified: trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Reflection.Emit; +using StructureMap.Pipeline; namespace StructureMap.Emitting.Parameters { @@ -22,18 +23,18 @@ private void putChildArrayFromInstanceMementoOntoStack(ILGenerator ilgen, Type argumentType, string argumentName) { ilgen.Emit(OpCodes.Ldarg_2); - + //ilgen.Emit(OpCodes.Ldstr, argumentType.GetElementType().AssemblyQualifiedName); ilgen.Emit(OpCodes.Ldtoken, argumentType.GetElementType()); - MethodInfo method = typeof(Type).GetMethod("GetTypeFromHandle"); + MethodInfo method = typeof (Type).GetMethod("GetTypeFromHandle"); ilgen.Emit(OpCodes.Call, method); - + ilgen.Emit(OpCodes.Ldarg_1); ilgen.Emit(OpCodes.Ldstr, argumentName); callInstanceMemento(ilgen, "GetChildrenArray"); - MethodInfo methodCreateInstanceArray = (typeof (StructureMap.Pipeline.IBuildSession).GetMethod("CreateInstanceArray")); + MethodInfo methodCreateInstanceArray = (typeof (IBuildSession).GetMethod("CreateInstanceArray")); ilgen.Emit(OpCodes.Callvirt, methodCreateInstanceArray); cast(ilgen, argumentType); } Modified: trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,7 +1,6 @@ using System; using System.Reflection; using System.Reflection.Emit; -using StructureMap.Graph; using StructureMap.Pipeline; namespace StructureMap.Emitting.Parameters @@ -22,6 +21,6 @@ protected void cast(ILGenerator ilgen, Type parameterType) { ilgen.Emit(OpCodes.Castclass, parameterType); - } + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,4 +1,3 @@ -using System; using System.Reflection; using System.Reflection.Emit; Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Reflection; -using System.Text; using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; @@ -13,8 +12,8 @@ // TODO: redo in 3.5 w/ Lambdas public class AssemblyScanner { - private readonly GraphLog _log; private readonly List<Assembly> _assemblies = new List<Assembly>(); + private readonly GraphLog _log; public AssemblyScanner(GraphLog log) { @@ -33,7 +32,7 @@ { if (Registry.IsPublicRegistry(type)) { - Registry registry = (Registry)Activator.CreateInstance(type); + Registry registry = (Registry) Activator.CreateInstance(type); registry.ConfigurePluginGraph(pluginGraph); } }); @@ -45,12 +44,12 @@ private void findFamiliesAndPlugins(PluginGraph pluginGraph) { scanTypes(delegate(Type type) - { - if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) - { - pluginGraph.CreateFamily(type); - } - }); + { + if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) + { + pluginGraph.CreateFamily(type); + } + }); scanTypes(delegate(Type type) { @@ -69,7 +68,7 @@ private void scanTypes(Action<Type> action) { - scanTypes(new Action<Type>[]{action}); + scanTypes(new Action<Type>[] {action}); } private void scanTypes(IEnumerable<Action<Type>> actions) @@ -125,4 +124,4 @@ return false; } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -5,6 +5,20 @@ { public class Constructor : TypeRules { + private readonly Type _pluggedType; + private ConstructorInfo _ctor; + + public Constructor(Type pluggedType) + { + _pluggedType = pluggedType; + _ctor = GetConstructor(pluggedType); + } + + public ConstructorInfo Ctor + { + get { return _ctor; } + } + /// <summary> /// Returns the System.Reflection.ConstructorInfo for the PluggedType. Uses either /// the "greediest" constructor with the most arguments or the constructor function @@ -48,16 +62,6 @@ return returnValue; } - - private readonly Type _pluggedType; - private ConstructorInfo _ctor; - - public Constructor(Type pluggedType) - { - _pluggedType = pluggedType; - _ctor = GetConstructor(pluggedType); - } - public bool CanBeAutoFilled() { foreach (ParameterInfo parameter in _ctor.GetParameters()) @@ -75,7 +79,7 @@ { foreach (ParameterInfo info in _ctor.GetParameters()) { - if (info.ParameterType.Equals(typeof(T))) + if (info.ParameterType.Equals(typeof (T))) { return info.Name; } @@ -85,11 +89,6 @@ } - public ConstructorInfo Ctor - { - get { return _ctor; } - } - public void Visit(IArgumentVisitor visitor) { foreach (ParameterInfo info in _ctor.GetParameters()) @@ -109,4 +108,4 @@ if (IsString(parameterType)) visitor.StringParameter(info); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -111,7 +111,7 @@ { if (instance.CanBePartOfPluginFamily(templatedFamily)) { - templatedFamily.AddInstance((Instance)instance); + templatedFamily.AddInstance((Instance) instance); } } @@ -122,7 +122,6 @@ } - public static Plugin CreateTemplatedClone(Plugin plugin, params Type[] types) { Type templatedType; Modified: trunk/Source/StructureMap/Graph/IPluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/IPluginFamily.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/IPluginFamily.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -6,8 +6,6 @@ { public interface IPluginFamily { - void AddMementoSource(MementoSource source); - /// <summary> /// The InstanceKey of the default instance of the PluginFamily /// </summary> @@ -16,11 +14,10 @@ /// <summary> /// The CLR Type that defines the "Plugin" interface for the PluginFamily /// </summary> - Type PluginType - { - get; - } + Type PluginType { get; } + void AddMementoSource(MementoSource source); + void SetScopeTo(InstanceScope scope); void AddInterceptor(IBuildInterceptor interceptor); } Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,6 +1,5 @@ using System; using System.Reflection; -using StructureMap.Emitting; using StructureMap.Pipeline; namespace StructureMap.Graph @@ -13,11 +12,11 @@ public class Plugin : TypeRules { public static readonly string DEFAULT = "DEFAULT"; + private readonly Constructor _constructor; - private string _concreteKey; private readonly Type _pluggedType; private readonly SetterPropertyCollection _setters; - private readonly Constructor _constructor; + private string _concreteKey; #region constructors @@ -44,7 +43,6 @@ #endregion - /// <summary> /// The ConcreteKey that identifies the Plugin within a PluginFamily /// </summary> @@ -68,18 +66,12 @@ /// </summary> public SetterPropertyCollection Setters { - get - { - return _setters; - } + get { return _setters; } } public bool CanBeAutoFilled { - get - { - return _constructor.CanBeAutoFilled() && _setters.CanBeAutoFilled(); - } + get { return _constructor.CanBeAutoFilled() && _setters.CanBeAutoFilled(); } } public override string ToString() @@ -95,13 +87,13 @@ public string FindFirstConstructorArgumentOfType<T>() { - string returnValue = + string returnValue = _constructor.FindFirstConstructorArgumentOfType<T>() ?? _setters.FindFirstConstructorArgumentOfType<T>(); if (returnValue == null) { - throw new StructureMapException(302, typeof(T).FullName, _pluggedType.FullName); + throw new StructureMapException(302, typeof (T).FullName, _pluggedType.FullName); } return returnValue; @@ -133,5 +125,4 @@ _setters.Visit(arguments); } } - } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -40,10 +40,7 @@ /// <returns></returns> public Plugin this[Type PluggedType] { - get - { - return _plugins[PluggedType]; - } + get { return _plugins[PluggedType]; } } /// <summary> @@ -67,6 +64,20 @@ } } + #region IEnumerable<Plugin> Members + + IEnumerator<Plugin> IEnumerable<Plugin>.GetEnumerator() + { + return _plugins.Values.GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable<Plugin>) this).GetEnumerator(); + } + + #endregion + /// <summary> /// Adds a new Plugin by the PluggedType /// </summary> @@ -98,7 +109,8 @@ if (!TypeRules.CanBeCast(_family.PluginType, plugin.PluggedType)) { // TODO -- get this logged - throw new StructureMapException(114, plugin.PluggedType.FullName, _family.PluginType.AssemblyQualifiedName); + throw new StructureMapException(114, plugin.PluggedType.FullName, + _family.PluginType.AssemblyQualifiedName); } _plugins.Add(plugin.PluggedType, plugin); @@ -129,16 +141,6 @@ return plugin; } - IEnumerator<Plugin> IEnumerable<Plugin>.GetEnumerator() - { - return _plugins.Values.GetEnumerator(); - } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable<Plugin>) this).GetEnumerator(); - } - public List<Plugin> FindAutoFillablePlugins() { List<Plugin> list = new List<Plugin>(); Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,9 +1,6 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Diagnostics; using StructureMap.Attributes; -using StructureMap.Interceptors; using StructureMap.Pipeline; namespace StructureMap.Graph @@ -15,16 +12,15 @@ /// </summary> public class PluginFamily : TypeRules, IPluginFamily { + private readonly Predicate<Type> _explicitlyMarkedPluginFilter; + private readonly Predicate<Type> _implicitPluginFilter; + private readonly List<Instance> _instances = new List<Instance>(); private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>(); private readonly PluginCollection _plugins; + private readonly Type _pluginType; + private IBuildPolicy _buildPolicy = new BuildPolicy(); private string _defaultKey = string.Empty; private PluginGraph _parent; - 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; @@ -35,8 +31,8 @@ PluginFamilyAttribute.ConfigureFamily(this); - _explicitlyMarkedPluginFilter = delegate(Type type) { return TypeRules.IsExplicitlyMarkedAsPlugin(PluginType, type); }; - _implicitPluginFilter = delegate(Type type) { return TypeRules.CanBeCast(PluginType, type); }; + _explicitlyMarkedPluginFilter = delegate(Type type) { return IsExplicitlyMarkedAsPlugin(PluginType, type); }; + _implicitPluginFilter = delegate(Type type) { return CanBeCast(PluginType, type); }; _pluginFilter = _explicitlyMarkedPluginFilter; if (IsConcrete(pluginType)) @@ -53,91 +49,69 @@ set { _parent = value; } } - public void AddInstance(InstanceMemento memento) - { - _mementoList.Add(memento); - } + #region IPluginFamily Members - public void AddInstance(Instance instance) - { - _instances.Add(instance); - } - - // TODO -- eliminate this. Move to GraphBuilder, and wrap error handling around it public void AddMementoSource(MementoSource source) { _mementoList.AddRange(source.GetAllMementos()); } - // For testing - public InstanceMemento GetMemento(string instanceKey) + public void SetScopeTo(InstanceScope scope) { - return _mementoList.Find(delegate(InstanceMemento m) { return m.InstanceKey == instanceKey; }); - } + switch (scope) + { + case InstanceScope.Singleton: + AddInterceptor(new SingletonPolicy()); + break; + case InstanceScope.HttpContext: + AddInterceptor(new HttpContextBuildPolicy()); + break; + case InstanceScope.ThreadLocal: + AddInterceptor(new ThreadLocalStoragePolicy()); + break; - #region properties - - /// <summary> - /// The CLR Type that defines the "Plugin" interface for the PluginFamily - /// </summary> - public Type PluginType - { - get { return _pluginType; } + case InstanceScope.Hybrid: + AddInterceptor(new HybridBuildPolicy()); + break; + } } - /// <summary> - /// The InstanceKey of the default instance of the PluginFamily - /// </summary> - public string DefaultInstanceKey + public void AddInterceptor(IBuildInterceptor interceptor) { - get { return _defaultKey; } - set { _defaultKey = value ?? string.Empty; } + interceptor.InnerPolicy = _buildPolicy; + _buildPolicy = interceptor; } - public PluginCollection Plugins - { - get { return _plugins; } - } + #endregion - public bool IsGenericTemplate + public void AddInstance(InstanceMemento memento) { - get { return _pluginType.IsGenericTypeDefinition; } + _mementoList.Add(memento); } - public bool SearchForImplicitPlugins + public void AddInstance(Instance instance) { - get - { - return ReferenceEquals(_pluginFilter, _implicitPluginFilter); - } - set - { - _pluginFilter = value ? _implicitPluginFilter : _explicitlyMarkedPluginFilter; - } + _instances.Add(instance); } - public IBuildPolicy Policy - { - get { return _buildPolicy; } - set { _policy = value; } - } + // TODO -- eliminate this. Move to GraphBuilder, and wrap error handling around it - public int PluginCount + // For testing + public InstanceMemento GetMemento(string instanceKey) { - get { return _plugins.Count; } + return _mementoList.Find(delegate(InstanceMemento m) { return m.InstanceKey == instanceKey; }); } - #endregion public void Seal() { _mementoList.ForEach(delegate(InstanceMemento memento) - { - Instance instance = memento.ReadInstance(Parent, _pluginType); - _instances.Add(instance); - }); + { + Instance instance = memento.ReadInstance(Parent, _pluginType); + _instances.Add(instance); + }); discoverImplicitInstances(); @@ -151,13 +125,8 @@ { // TODO: Apply some 3.5 lambda magic. Maybe move to PluginCollection List<Plugin> list = _plugins.FindAutoFillablePlugins(); - list.RemoveAll(delegate(Plugin plugin) - { - return _instances.Exists(delegate(Instance instance) - { - return instance.Matches(plugin); - }); - }); + list.RemoveAll( + delegate(Plugin plugin) { return _instances.Exists(delegate(Instance instance) { return instance.Matches(plugin); }); }); foreach (Plugin plugin in list) { @@ -175,35 +144,7 @@ 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(IBuildInterceptor interceptor) - { - interceptor.InnerPolicy = _buildPolicy; - _buildPolicy = interceptor; - } - - public void AnalyzeTypeForPlugin(Type pluggedType) { if (_pluginFilter(pluggedType)) @@ -246,5 +187,53 @@ { return string.IsNullOrEmpty(_defaultKey) ? null : GetInstance(_defaultKey); } + + #region properties + + public PluginCollection Plugins + { + get { return _plugins; } + } + + public bool IsGenericTemplate + { + get { return _pluginType.IsGenericTypeDefinition; } + } + + public bool SearchForImplicitPlugins + { + get { return ReferenceEquals(_pluginFilter, _implicitPluginFilter); } + set { _pluginFilter = value ? _implicitPluginFilter : _explicitlyMarkedPluginFilter; } + } + + public IBuildPolicy Policy + { + get { return _buildPolicy; } + set { _policy = value; } + } + + public int PluginCount + { + get { return _plugins.Count; } + } + + /// <summary> + /// The CLR Type that defines the "Plugin" interface for the PluginFamily + /// </summary> + public Type PluginType + { + get { return _pluginType; } + } + + /// <summary> + /// The InstanceKey of the default instance of the PluginFamily + /// </summary> + public string DefaultInstanceKey + { + get { return _defaultKey; } + set { _defaultKey = value ?? string.Empty; } + } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -9,8 +9,8 @@ /// </summary> public class PluginFamilyCollection : IEnumerable<PluginFamily> { + private readonly Dictionary<Type, PluginFamily> _pluginFamilies; private readonly PluginGraph _pluginGraph; - private readonly Dictionary<Type, PluginFamily> _pluginFamilies; public PluginFamilyCollection(PluginGraph pluginGraph) { @@ -37,7 +37,20 @@ get { return _pluginFamilies.Count; } } + #region IEnumerable<PluginFamily> Members + IEnumerator<PluginFamily> IEnumerable<PluginFamily>.GetEnumerator() + { + return _pluginFamilies.Values.GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable<PluginFamily>) this).GetEnumerator(); + } + + #endregion + public PluginFamily Add(PluginFamily family) { family.Parent = _pluginGraph; @@ -69,17 +82,5 @@ { return Contains(typeof (T)); } - - - - IEnumerator<PluginFamily> IEnumerable<PluginFamily>.GetEnumerator() - { - return _pluginFamilies.Values.GetEnumerator(); - } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable<PluginFamily>) this).GetEnumerator(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-05-15 16:32:20 UTC (rev 96) +++ trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-05-15 18:15:44 UTC (rev 97) @@ -1,7 +1,5 @@ -using System; using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; using System.Reflection; using StructureMap.Attributes; @@ -34,7 +32,7 @@ { SetterProperty[] returnValue = new SetterProperty[_properties.Count]; _properties.Values.CopyTo(returnValue, 0); - + ... [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 16:32:20 UTC (rev 96) @@ -14,26 +14,26 @@ public class BuildInstanceMethod : Method { private readonly Plugin _plugin; - private readonly ConstructorInfo _constructor; - private readonly ParameterEmitter _parameterEmitter; + //private readonly ConstructorInfo _constructor; + //private readonly ParameterEmitter _parameterEmitter; public BuildInstanceMethod(Plugin plugin) : base() { - _constructor = plugin.GetConstructor(); + //_constructor = plugin.GetConstructor(); - _parameterEmitter = new StringParameterEmitter(); + //_parameterEmitter = new StringParameterEmitter(); - _parameterEmitter.AttachNextSibling(new PrimitiveParameterEmitter()); - _parameterEmitter.AttachNextSibling(new EnumParameterEmitter()); - _parameterEmitter.AttachNextSibling(new ChildParameterEmitter()); - _parameterEmitter.AttachNextSibling(new ChildArrayParameterEmitter()); + //_parameterEmitter.AttachNextSibling(new PrimitiveParameterEmitter()); + //_parameterEmitter.AttachNextSibling(new EnumParameterEmitter()); + //_parameterEmitter.AttachNextSibling(new ChildParameterEmitter()); + //_parameterEmitter.AttachNextSibling(new ChildArrayParameterEmitter()); _plugin = plugin; } public override Type[] ArgumentList { - get { return new Type[] { typeof(IConfiguredInstance), typeof(StructureMap.Pipeline.IInstanceCreator) }; } + get { return new Type[] { typeof(IConfiguredInstance), typeof(StructureMap.Pipeline.IBuildSession) }; } } public override string MethodName @@ -51,20 +51,15 @@ protected override void Generate(ILGenerator ilgen) { ilgen.DeclareLocal(typeof (object)); + ArgumentEmitter arguments = new ArgumentEmitter(ilgen); - foreach (ParameterInfo parameter in _constructor.GetParameters()) - { - _parameterEmitter.Generate(ilgen, parameter); - } + _plugin.VisitConstructor(arguments); - ilgen.Emit(OpCodes.Newobj, _constructor); + ilgen.Emit(OpCodes.Newobj, _plugin.GetConstructor()); Label label = ilgen.DefineLabel(); ilgen.Emit(OpCodes.Stloc_0); - foreach (SetterProperty setter in _plugin.Setters) - { - _parameterEmitter.GenerateSetter(ilgen, setter.Property); - } + _plugin.VisitSetters(arguments); ilgen.Emit(OpCodes.Br_S, label); ilgen.MarkLabel(label); Deleted: trunk/Source/StructureMap/Emitting/ConstructorEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/ConstructorEmitter.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Emitting/ConstructorEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Reflection.Emit; -using System.Text; -using StructureMap.Graph; -using StructureMap.Pipeline; - -namespace StructureMap.Emitting -{ - public class ConstructorEmitter : IPluginArgumentVisitor - { - private readonly ILGenerator _ilgen; - - public ConstructorEmitter(ILGenerator ilgen) - { - _ilgen = ilgen; - } - - - public void Primitive(string name) - { - throw new NotImplementedException(); - } - - public void Child(string name, Type childType) - { - throw new NotImplementedException(); - } - - public void ChildArray(string name, Type childType) - { - throw new NotImplementedException(); - } - - protected void callInstanceMemento(ILGenerator ilgen, string methodName) - { - MethodInfo _method = typeof(IConfiguredInstance).GetMethod(methodName); - ilgen.Emit(OpCodes.Callvirt, _method); - } - - protected void cast(ILGenerator ilgen, Type parameterType) - { - ilgen.Emit(OpCodes.Castclass, parameterType); - } - } -} Modified: trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs =================================================================== --- trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -16,7 +16,7 @@ public InstanceBuilderAssembly(Type pluginType, IEnumerable<Plugin> plugins) { - string assemblyName = Guid.NewGuid().ToString().Replace(".", "") + "InstanceBuilderAssembly"; + string assemblyName = guidString() + "InstanceBuilderAssembly"; _dynamicAssembly = new DynamicAssembly(assemblyName); _pluginType = pluginType; @@ -26,6 +26,11 @@ } } + private static string guidString() + { + return Guid.NewGuid().ToString().Replace(".", ""); + } + /// <summary> /// Gets a class name for the InstanceBuilder that will be emitted for this Plugin /// </summary> @@ -49,7 +54,7 @@ className = escapeClassName(pluggedType); } - return className + "InstanceBuilder"; + return className + "InstanceBuilder" + guidString(); } private static string escapeClassName(Type type) @@ -61,7 +66,7 @@ private void processPlugin(Plugin plugin) { - if (Plugin.CanBeCast(_pluginType, plugin.PluggedType)) + if (TypeRules.CanBeCast(_pluginType, plugin.PluggedType)) { string className = getInstanceBuilderClassName(plugin.PluggedType); ClassBuilder builderClass = Modified: trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -10,20 +10,8 @@ /// </summary> public class ChildArrayParameterEmitter : ParameterEmitter { - protected override bool canProcess(Type parameterType) + public void Ctor(ILGenerator ilgen, ParameterInfo parameter) { - bool returnValue = false; - - if (parameterType.IsArray) - { - returnValue = (!parameterType.GetElementType().IsPrimitive); - } - - return returnValue; - } - - protected override void generate(ILGenerator ilgen, ParameterInfo parameter) - { Type parameterType = parameter.ParameterType; string parameterName = parameter.Name; @@ -34,18 +22,23 @@ private void putChildArrayFromInstanceMementoOntoStack(ILGenerator ilgen, Type argumentType, string argumentName) { ilgen.Emit(OpCodes.Ldarg_2); - ilgen.Emit(OpCodes.Ldstr, argumentType.GetElementType().AssemblyQualifiedName); + + //ilgen.Emit(OpCodes.Ldstr, argumentType.GetElementType().AssemblyQualifiedName); + ilgen.Emit(OpCodes.Ldtoken, argumentType.GetElementType()); + MethodInfo method = typeof(Type).GetMethod("GetTypeFromHandle"); + ilgen.Emit(OpCodes.Call, method); + ilgen.Emit(OpCodes.Ldarg_1); ilgen.Emit(OpCodes.Ldstr, argumentName); callInstanceMemento(ilgen, "GetChildrenArray"); - MethodInfo methodCreateInstanceArray = (typeof (StructureMap.Pipeline.IInstanceCreator).GetMethod("CreateInstanceArray")); + MethodInfo methodCreateInstanceArray = (typeof (StructureMap.Pipeline.IBuildSession).GetMethod("CreateInstanceArray")); ilgen.Emit(OpCodes.Callvirt, methodCreateInstanceArray); cast(ilgen, argumentType); } - protected override void generateSetter(ILGenerator ilgen, PropertyInfo property) + public void Setter(ILGenerator ilgen, PropertyInfo property) { ilgen.Emit(OpCodes.Ldloc_0); putChildArrayFromInstanceMementoOntoStack(ilgen, property.PropertyType, property.Name); Modified: trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -10,13 +10,8 @@ /// </summary> public class ChildParameterEmitter : ParameterEmitter { - protected override bool canProcess(Type parameterType) + public void Ctor(ILGenerator ilgen, ParameterInfo parameter) { - return (!parameterType.IsPrimitive && !parameterType.IsArray); - } - - protected override void generate(ILGenerator ilgen, ParameterInfo parameter) - { Type parameterType = parameter.ParameterType; string parameterName = parameter.Name; @@ -39,7 +34,7 @@ cast(ilgen, parameterType); } - protected override void generateSetter(ILGenerator ilgen, PropertyInfo property) + public void Setter(ILGenerator ilgen, PropertyInfo property) { ilgen.Emit(OpCodes.Ldloc_0); Modified: trunk/Source/StructureMap/Emitting/Parameters/EnumParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/EnumParameterEmitter.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Emitting/Parameters/EnumParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -9,13 +9,8 @@ /// </summary> public class EnumParameterEmitter : ParameterEmitter { - protected override bool canProcess(Type parameterType) + public void Ctor(ILGenerator ilgen, ParameterInfo parameter) { - return (parameterType.IsEnum); - } - - protected override void generate(ILGenerator ilgen, ParameterInfo parameter) - { Type parameterType = parameter.ParameterType; string parameterName = parameter.Name; @@ -44,7 +39,7 @@ ilgen.Emit(OpCodes.Ldind_I4); } - protected override void generateSetter(ILGenerator ilgen, PropertyInfo property) + public void Setter(ILGenerator ilgen, PropertyInfo property) { ilgen.Emit(OpCodes.Ldloc_0); putEnumerationValueFromMementoOntoStack(ilgen, property.PropertyType, property.Name); Modified: trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Reflection.Emit; +using StructureMap.Graph; using StructureMap.Pipeline; namespace StructureMap.Emitting.Parameters @@ -12,67 +13,6 @@ /// </summary> public abstract class ParameterEmitter { - private ParameterEmitter _nextSibling; - - protected ParameterEmitter NextSibling - { - set { _nextSibling = value; } - get { return _nextSibling; } - } - - public void Generate(ILGenerator ilgen, ParameterInfo parameter) - { - if (canProcess(parameter.ParameterType)) - { - generate(ilgen, parameter); - } - else if (_nextSibling != null) - { - _nextSibling.Generate(ilgen, parameter); - } - else - { - string msg = - string.Format("Cannot emit constructor injection for type *{0}*", - parameter.ParameterType.AssemblyQualifiedName); - throw new ApplicationException(msg); - } - } - - public void GenerateSetter(ILGenerator ilgen, PropertyInfo property) - { - if (canProcess(property.PropertyType)) - { - generateSetter(ilgen, property); - } - else if (_nextSibling != null) - { - _nextSibling.GenerateSetter(ilgen, property); - } - else - { - string msg = - string.Format("Cannot emit constructor injection for type *{0}*", - property.PropertyType.AssemblyQualifiedName); - throw new ApplicationException(msg); - } - } - - public void AttachNextSibling(ParameterEmitter Sibling) - { - if (NextSibling == null) - { - NextSibling = Sibling; - } - else - { - NextSibling.AttachNextSibling(Sibling); - } - } - - protected abstract bool canProcess(Type parameterType); - protected abstract void generate(ILGenerator ilgen, ParameterInfo parameter); - protected void callInstanceMemento(ILGenerator ilgen, string methodName) { MethodInfo _method = typeof (IConfiguredInstance).GetMethod(methodName); @@ -82,8 +22,6 @@ protected void cast(ILGenerator ilgen, Type parameterType) { ilgen.Emit(OpCodes.Castclass, parameterType); - } - - protected abstract void generateSetter(ILGenerator ilgen, PropertyInfo property); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Emitting/Parameters/PrimitiveParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/PrimitiveParameterEmitter.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Emitting/Parameters/PrimitiveParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -9,13 +9,8 @@ /// </summary> public class PrimitiveParameterEmitter : ParameterEmitter { - protected override bool canProcess(Type parameterType) + public void Ctor(ILGenerator ilgen, ParameterInfo parameter) { - return (parameterType.IsPrimitive && !parameterType.Equals(typeof (string))); - } - - protected override void generate(ILGenerator ilgen, ParameterInfo parameter) - { ilgen.Emit(OpCodes.Ldarg_1); ilgen.Emit(OpCodes.Ldstr, parameter.Name); callInstanceMemento(ilgen, "GetProperty"); @@ -31,7 +26,7 @@ } - protected override void generateSetter(ILGenerator ilgen, PropertyInfo property) + public void Setter(ILGenerator ilgen, PropertyInfo property) { ilgen.Emit(OpCodes.Ldloc_0); ilgen.Emit(OpCodes.Ldarg_1); Modified: trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -9,20 +9,15 @@ /// </summary> public class StringParameterEmitter : ParameterEmitter { - protected override bool canProcess(Type parameterType) + public void Ctor(ILGenerator ilgen, ParameterInfo parameter) { - return (parameterType.Equals(typeof (string))); - } - - protected override void generate(ILGenerator ilgen, ParameterInfo parameter) - { ilgen.Emit(OpCodes.Ldarg_1); ilgen.Emit(OpCodes.Ldstr, parameter.Name); callInstanceMemento(ilgen, "GetProperty"); } - protected override void generateSetter(ILGenerator ilgen, PropertyInfo property) + public void Setter(ILGenerator ilgen, PropertyInfo property) { ilgen.Emit(OpCodes.Ldloc_0); ilgen.Emit(OpCodes.Ldarg_1); Modified: trunk/Source/StructureMap/Exceptions/StructureMapException.cs =================================================================== --- trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -44,11 +44,21 @@ 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) Added: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs (rev 0) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -0,0 +1,112 @@ +using System; +using System.Reflection; + +namespace StructureMap.Graph +{ + public class Constructor : TypeRules + { + /// <summary> + /// Returns the System.Reflection.ConstructorInfo for the PluggedType. Uses either + /// the "greediest" constructor with the most arguments or the constructor function + /// marked with the [DefaultConstructor] + /// </summary> + /// <returns></returns> + public static ConstructorInfo GetConstructor(Type pluggedType) + { + ConstructorInfo returnValue = DefaultConstructorAttribute.GetConstructor(pluggedType); + + // if no constructor is marked as the "ContainerConstructor", find the greediest constructor + if (returnValue == null) + { + returnValue = GetGreediestConstructor(pluggedType); + } + + if (returnValue == null) + { + throw new StructureMapException(180, pluggedType.Name); + } + + return returnValue; + } + + public static ConstructorInfo GetGreediestConstructor(Type pluggedType) + { + ConstructorInfo returnValue = null; + + foreach (ConstructorInfo constructor in pluggedType.GetConstructors()) + { + if (returnValue == null) + { + returnValue = constructor; + } + else if (constructor.GetParameters().Length > returnValue.GetParameters().Length) + { + returnValue = constructor; + } + } + + return returnValue; + } + + + private readonly Type _pluggedType; + private ConstructorInfo _ctor; + + public Constructor(Type pluggedType) + { + _pluggedType = pluggedType; + _ctor = GetConstructor(pluggedType); + } + + public bool CanBeAutoFilled() + { + foreach (ParameterInfo parameter in _ctor.GetParameters()) + { + if (!IsChild(parameter.ParameterType)) + { + return false; + } + } + + return true; + } + + public string FindFirstConstructorArgumentOfType<T>() + { + foreach (ParameterInfo info in _ctor.GetParameters()) + { + if (info.ParameterType.Equals(typeof(T))) + { + return info.Name; + } + } + + return null; + } + + + public ConstructorInfo Ctor + { + get { return _ctor; } + } + + public void Visit(IArgumentVisitor visitor) + { + foreach (ParameterInfo info in _ctor.GetParameters()) + { + Type parameterType = info.ParameterType; + + visitParameter(info, parameterType, visitor); + } + } + + private void visitParameter(ParameterInfo info, Type parameterType, IArgumentVisitor visitor) + { + if (IsPrimitive(parameterType)) visitor.PrimitiveParameter(info); + if (IsChild(parameterType)) visitor.ChildParameter(info); + if (IsChildArray(parameterType)) visitor.ChildArrayParameter(info); + if (IsEnum(parameterType)) visitor.EnumParameter(info); + if (IsString(parameterType)) visitor.StringParameter(info); + } + } +} Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -99,7 +99,7 @@ // Add Plugins foreach (Plugin plugin in baseFamily.Plugins) { - if (plugin.CanBePluggedIntoGenericType(baseFamily.PluginType, templateTypes)) + if (CanBePluggedIntoGenericType(baseFamily.PluginType, plugin.PluggedType, templateTypes)) { Plugin templatedPlugin = CreateTemplatedClone(plugin, templateTypes); templatedFamily.Plugins.Add(templatedPlugin); @@ -142,5 +142,34 @@ return templatedPlugin; } + + + public static bool CanBePluggedIntoGenericType(Type pluginType, Type pluggedType, params Type[] templateTypes) + { + bool isValid = true; + + Type interfaceType = pluggedType.GetInterface(pluginType.Name); + if (interfaceType == null) + { + interfaceType = pluggedType.BaseType; + } + + Type[] pluginArgs = pluginType.GetGenericArguments(); + Type[] pluggableArgs = interfaceType.GetGenericArguments(); + + if (templateTypes.Length != pluginArgs.Length && + pluginArgs.Length != pluggableArgs.Length) + { + return false; + } + + for (int i = 0; i < templateTypes.Length; i++) + { + isValid &= templateTypes[i] == pluggableArgs[i] || + pluginArgs[i].IsGenericParameter && + pluggableArgs[i].IsGenericParameter; + } + return isValid; + } } } \ No newline at end of file Added: trunk/Source/StructureMap/Graph/IArgumentVisitor.cs =================================================================== --- trunk/Source/StructureMap/Graph/IArgumentVisitor.cs (rev 0) +++ trunk/Source/StructureMap/Graph/IArgumentVisitor.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -0,0 +1,19 @@ +using System.Reflection; + +namespace StructureMap.Graph +{ + public interface IArgumentVisitor + { + void PrimitiveSetter(PropertyInfo property); + void StringSetter(PropertyInfo property); + void EnumSetter(PropertyInfo property); + void ChildSetter(PropertyInfo property); + void ChildArraySetter(PropertyInfo property); + + void PrimitiveParameter(ParameterInfo parameter); + void StringParameter(ParameterInfo parameter); + void EnumParameter(ParameterInfo parameter); + void ChildParameter(ParameterInfo parameter); + void ChildArrayParameter(ParameterInfo parameter); + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-09 15:47:15 UTC (rev 95) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-15 16:32:20 UTC (rev 96) @@ -1,119 +1,35 @@ using System; using System.Reflection; +using StructureMap.Emitting; +using StructureMap.Pipeline; namespace StructureMap.Graph { - public interface IPluginArgumentVisitor - { - void Primitive(string name); - void Child(string name, Type childType); - void ChildArray(string name, Type childType); - } - - - /// <summary> /// Represents a concrete class that can be built by StructureMap as an instance of the parent /// PluginFamily\x92s PluginType. The properties of a Plugin are the CLR Type of the concrete class, /// and the human-friendly concrete key that StructureMap will use to identify the Type. /// </summary> - public class Plugin + public class Plugin : TypeRules { - #region static + public static readonly string DEFAULT = "DEFAULT"; - - /// <summary> - /// Determines if the PluggedType is a valid Plugin into the - /// PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="pluggedType"></param> - /// <returns></returns> - public static bool IsExplicitlyMarkedAsPlugin(Type pluginType, Type pluggedType) - { - bool returnValue = false; - - bool markedAsPlugin = PluggableAttribute.MarkedAsPluggable(pluggedType); - if (markedAsPlugin) - { - returnValue = CanBeCast(pluginType, pluggedType); - } - - return returnValue; - } - - - /// <summary> - /// Determines if the pluggedType can be upcast to the pluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="pluggedType"></param> - /// <returns></returns> - public static bool CanBeCast(Type pluginType, Type pluggedType) - { - if (pluggedType.IsInterface || pluggedType.IsAbstract) - { - return false; - } - - if (GenericsPluginGraph.CanBeCast(pluginType, pluggedType)) - { - return true; - } - - ConstructorInfo constructor = GetGreediestConstructor(pluggedType); - if (constructor == null) - { - return false; - } - - return pluginType.IsAssignableFrom(pluggedType); - } - - - public static ConstructorInfo GetGreediestConstructor(Type pluggedType) - { - ConstructorInfo returnValue = null; - - foreach (ConstructorInfo constructor in pluggedType.GetConstructors()) - { - if (returnValue == null) - { - returnValue = constructor; - } - else if (constructor.GetParameters().Length > returnValue.GetParameters().Length) - { - returnValue = constructor; - } - } - - return returnValue; - } - - #endregion - private string _concreteKey; - private Type _pluggedType; - private SetterPropertyCollection _setters; + private readonly Type _pluggedType; + private readonly SetterPropertyCollection _setters; + private readonly Constructor _constructor; #region constructors - /// <summary> - /// Creates an Explicit Plugin for the pluggedType with the entered - /// concreteKey - /// </summary> - /// <param name="pluggedType"></param> - /// <param name="concreteKey"></param> - public Plugin(Type pluggedType, string concreteKey) : base() + public Plugin(Type pluggedType, string concreteKey) : this(pluggedType) { if (concreteKey == string.Empty) { + // TODO: Move into PluginFamily and get the exception logged somewhere throw new StructureMapException(112, pluggedType.FullName); } - _pluggedType = pluggedType; _concreteKey = concreteKey; - _setters = new SetterPropertyCollection(this); } public Plugin(Type pluggedType) @@ -123,7 +39,7 @@ _pluggedType = pluggedType; _setters = new SetterPropertyCollection(this); - + _constructor = new Constructor(pluggedType); } #endregion @@ -148,238 +64,74 @@ } /// <summary> - /// Finds any methods on the PluggedType marked with the [ValidationMethod] - /// attributes - /// </summary> - public MethodInfo[] ValidationMethods - { - get { return ValidationMethodAttribute.GetValidationMethods(_pluggedType); } - } - - /// <summary> /// Property's that will be filled by setter injection /// </summary> public SetterPropertyCollection Setters { get { - if (_setters == null) - { - _setters = new SetterPropertyCollection(this); - } - return _setters; } } - - /// <summary> - /// Determines if the concrete class can be autofilled. - /// </summary> public bool CanBeAutoFilled { get { - bool returnValue = true; - - ConstructorInfo ctor = GetConstructor(); - foreach (ParameterInfo parameter in ctor.GetParameters()) - { - returnValue = returnValue ... [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 public static PluginGraph BuildGraphFromAssembly(Assembly assembly) Modified: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/IInstanceManager.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Pipeline; Deleted: trunk/Source/StructureMap/IPluginGraphSource.cs =================================================================== --- trunk/Source/StructureMap/IPluginGraphSource.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/IPluginGraphSource.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -1,15 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap -{ - [Obsolete] public interface IPluginGraphSource - { - /// <summary> - /// Reads the configuration information and returns the PluginGraph definition of - /// plugin families and plugin's - /// </summary> - /// <returns></returns> - PluginGraph Build(); - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -17,6 +17,8 @@ public abstract string ConcreteTypeKey { get; } + public abstract Type PluggedType { get; } + public abstract object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator); } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceBuilderList.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilderList.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/InstanceBuilderList.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -58,33 +58,17 @@ private void processPlugins(IEnumerable<Plugin> plugins) { - Assembly assembly = createInstanceBuilderAssembly(plugins); - foreach (Plugin plugin in plugins) + List<InstanceBuilder> list = createInstanceBuilders(plugins); + foreach (InstanceBuilder builder in list) { - addPlugin(assembly, plugin); + _builders.Add(builder.PluggedType, builder); } } - private Assembly createInstanceBuilderAssembly(IEnumerable<Plugin> plugins) + private List<InstanceBuilder> createInstanceBuilders(IEnumerable<Plugin> plugins) { - string assemblyName = Guid.NewGuid().ToString().Replace(".", "") + "InstanceBuilderAssembly"; - InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(assemblyName, _pluginType); - - foreach (Plugin plugin in plugins) - { - builderAssembly.AddPlugin(plugin); - } - + InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(_pluginType, plugins); 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 Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -27,7 +27,7 @@ /// </summary> /// <param name="family"></param> /// <param name="failOnException">Toggles error trapping. Set to "true" for diagnostics</param> - public InstanceFactory(PluginFamily family, bool failOnException) + public InstanceFactory(PluginFamily family) { if (family == null) { @@ -53,7 +53,7 @@ } catch (Exception e) { - throw new StructureMapException(115, e, family.PluginTypeName); + throw new StructureMapException(115, e, family.PluginType.AssemblyQualifiedName); } } @@ -68,7 +68,7 @@ return; } - Plugin plugin = new Plugin(new TypePath(concreteType), Guid.NewGuid().ToString()); + Plugin plugin = new Plugin(concreteType, Guid.NewGuid().ToString()); if (plugin.CanBeAutoFilled) { _instanceBuilders = new InstanceBuilderList(_pluginType, new Plugin[] {plugin}); @@ -83,7 +83,7 @@ } } - public static InstanceFactory CreateInstanceFactoryForType(Type concreteType, ProfileManager profileManager) + public static InstanceFactory CreateFactoryForConcreteType(Type concreteType, ProfileManager profileManager) { return new InstanceFactory(concreteType, profileManager); } Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Text; -using StructureMap.Configuration.Mementos; using StructureMap.Exceptions; using StructureMap.Graph; using StructureMap.Interceptors; @@ -353,7 +352,7 @@ private IInstanceFactory registerPluginFamily(PluginFamily family) { - InstanceFactory factory = new InstanceFactory(family, _failOnException); + InstanceFactory factory = new InstanceFactory(family); RegisterType(factory); return factory; @@ -420,10 +419,10 @@ if (pluggedType.IsGenericType) { PluginFamily family = _genericsGraph.CreateTemplatedFamily(pluggedType, _profileManager); - if (family != null) return new InstanceFactory(family, true); + if (family != null) return new InstanceFactory(family); } - return InstanceFactory.CreateInstanceFactoryForType(pluggedType, _profileManager); + return InstanceFactory.CreateFactoryForConcreteType(pluggedType, _profileManager); } #region Nested type: CreateFactoryDelegate Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -44,7 +44,7 @@ return family.Plugins[innerConcreteKey]; } - throw new StructureMapException(201, innerConcreteKey, InstanceKey, family.PluginTypeName); + throw new StructureMapException(201, innerConcreteKey, InstanceKey, family.PluginType.AssemblyQualifiedName); } Modified: trunk/Source/StructureMap/MementoSource.cs =================================================================== --- trunk/Source/StructureMap/MementoSource.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/MementoSource.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -98,7 +98,7 @@ { if (_defaultMemento == null) { - string pluginTypeName = Family == null ? "UNKNOWN" : Family.PluginTypeName; + string pluginTypeName = Family == null ? "UNKNOWN" : Family.PluginType.AssemblyQualifiedName; throw new StructureMapException(202, pluginTypeName); } @@ -110,7 +110,7 @@ if (returnValue == null) { - throw new StructureMapException(200, memento.ReferenceKey, Family.PluginTypeName); + throw new StructureMapException(200, memento.ReferenceKey, Family.PluginType.AssemblyQualifiedName); } } Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Security.Permissions; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Pipeline; Modified: trunk/Source/StructureMap/Pipeline/BuildStrategies.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -27,12 +27,12 @@ } [PluginFamily] - public interface IInstanceInterceptor : IBuildPolicy + public interface IBuildInterceptor : IBuildPolicy { IBuildPolicy InnerPolicy { get; set; } } - public abstract class CacheInterceptor : IInstanceInterceptor + public abstract class CacheInterceptor : IBuildInterceptor { private readonly object _locker = new object(); private IBuildPolicy _innerPolicy = new BuildPolicy(); @@ -80,15 +80,15 @@ protected abstract object retrieveFromCache(string instanceKey, Type pluginType); } - public class HybridBuildPolicy : IInstanceInterceptor + public class HybridBuildPolicy : IBuildInterceptor { - private readonly IInstanceInterceptor _innerInterceptor; + private readonly IBuildInterceptor _innerInterceptor; public HybridBuildPolicy() { _innerInterceptor = HttpContextBuildPolicy.HasContext() - ? (IInstanceInterceptor) new HttpContextBuildPolicy() + ? (IBuildInterceptor) new HttpContextBuildPolicy() : new ThreadLocalStoragePolicy(); } Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -10,7 +10,7 @@ /// Reads configuration XML documents and builds the structures necessary to initialize /// the InstanceManager/IInstanceFactory/InstanceBuilder/ObjectInstanceActivator objects /// </summary> - public class PluginGraphBuilder : IPluginGraphSource + public class PluginGraphBuilder { #region statics @@ -34,7 +34,7 @@ private readonly ConfigurationParser[] _parsers; private readonly Registry[] _registries = new Registry[0]; - private PluginGraph _graph; + private readonly PluginGraph _graph; #region constructors @@ -52,8 +52,6 @@ #endregion - #region IPluginGraphSource Members - /// <summary> /// Reads the configuration information and returns the PluginGraph definition of /// plugin families and plugin's @@ -69,8 +67,6 @@ return _graph; } - #endregion - private void forAllParsers(Action<ConfigurationParser> action) { foreach (ConfigurationParser parser in _parsers) Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-09 15:47:15 UTC (rev 95) @@ -171,10 +171,8 @@ <Compile Include="Configuration\DSL\ExpressionValidator.cs" /> <Compile Include="Configuration\DSL\IExpression.cs" /> <Compile Include="Configuration\DSL\Expressions\InstanceDefaultExpression.cs" /> - <Compile Include="Configuration\Mementos\ExplicitArguments.cs" /> - <Compile Include="Configuration\Mementos\LiteralMemento.cs" /> + <Compile Include="Pipeline\ExplicitArguments.cs" /> <Compile Include="Configuration\DSL\Expressions\ProfileExpression.cs" /> - <Compile Include="Configuration\Mementos\PrototypeMemento.cs" /> <Compile Include="Configuration\DSL\Registry.cs" /> <Compile Include="Configuration\DSL\Expressions\ScanAssembliesExpression.cs" /> <Compile Include="Configuration\FamilyParser.cs"> @@ -188,7 +186,6 @@ </Compile> <Compile Include="Configuration\ProfileAndMachineParser.cs" /> <Compile Include="Configuration\StructureMapConfigurationSection.cs" /> - <Compile Include="Configuration\Mementos\UserControlMemento.cs" /> <Compile Include="Configuration\XmlConstants.cs"> <SubType>Code</SubType> </Compile> @@ -283,11 +280,10 @@ <Compile Include="Interceptors\NulloInterceptor.cs" /> <Compile Include="Interceptors\StartupInterceptor.cs" /> <Compile Include="Interceptors\FilteredInstanceInterceptor.cs" /> - <Compile Include="IPluginGraphSource.cs" /> <Compile Include="MementoSource.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Configuration\Mementos\MemoryInstanceMemento.cs"> + <Compile Include="MemoryInstanceMemento.cs"> <SubType>Code</SubType> </Compile> <Compile Include="ObjectFactory.cs"> Modified: trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -22,7 +22,7 @@ } object service = _locator.Service(pluginType); - InstanceFactory factory = new InstanceFactory(new PluginFamily(pluginType), true); + InstanceFactory factory = new InstanceFactory(new PluginFamily(pluginType)); LiteralInstance instance = new LiteralInstance(service); SetDefault(pluginType, instance); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -215,7 +215,7 @@ } } - public class StubbedInstanceFactoryInterceptor : IInstanceInterceptor + public class StubbedInstanceFactoryInterceptor : IBuildInterceptor { public IBuildPolicy InnerPolicy { Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -2,7 +2,6 @@ using NUnit.Framework; using Rhino.Mocks; using StructureMap.Configuration.DSL; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Pipeline; using StructureMap.Testing.Widget3; Modified: trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -1,6 +1,5 @@ using System.Diagnostics; using NUnit.Framework; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -3,7 +3,6 @@ using Rhino.Mocks; using StructureMap.Configuration; using StructureMap.Configuration.DSL; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Pipeline; using StructureMap.Source; @@ -90,7 +89,7 @@ NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); builder.PrepareSystemObjects(); - builder.WithSystemObject<IInstanceInterceptor>(memento, "singleton", delegate(IInstanceInterceptor policy) + builder.WithSystemObject<IBuildInterceptor>(memento, "singleton", delegate(IBuildInterceptor policy) { Assert.IsInstanceOfType(typeof(SingletonPolicy), policy); iWasCalled = true; Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using NUnit.Framework; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; @@ -205,7 +204,7 @@ } } - public class FakeInstanceFactoryInterceptor : IInstanceInterceptor + public class FakeInstanceFactoryInterceptor : IBuildInterceptor { public IBuildPolicy InnerPolicy { Modified: trunk/Source/StructureMap.Testing/Container/EmittingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using NUnit.Framework; @@ -24,18 +25,11 @@ Plugin plugin = new Plugin(typeof (ComplexRule)); InstanceBuilderAssembly _InstanceBuilderAssembly = - new InstanceBuilderAssembly("StructureMap.EmittingTesterAssembly", typeof (Rule)); + new InstanceBuilderAssembly(typeof (Rule), new Plugin[]{plugin}); - _InstanceBuilderAssembly.AddPlugin(plugin); - assem = _InstanceBuilderAssembly.Compile(); + List<InstanceBuilder> list = _InstanceBuilderAssembly.Compile(); + builder = list[0]; - if (assem != null) - { - string builderName = plugin.GetInstanceBuilderClassName(); - - builder = assem.CreateInstance(builderName) as InstanceBuilder; - } - if (builder != null) { rule = (ComplexRule) builder.BuildInstance(instance, new InstanceManager()); @@ -66,14 +60,7 @@ Assert.AreEqual(true, rule.Bool); } - [Test] - public void BuiltTheAssembly() - { - Assert.IsNotNull(assem); - } - - [Test] public void BuiltTheInstanceBuilder() { Assert.IsNotNull(builder); Modified: trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -1,5 +1,4 @@ using NUnit.Framework; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Source; using StructureMap.Testing.Widget2; @@ -24,7 +23,7 @@ family.Plugins.Add(typeof (Cow), "Default"); - InstanceFactory cowFactory = new InstanceFactory(family, true); + InstanceFactory cowFactory = new InstanceFactory(family); cowFactory.SetInstanceManager(new InstanceManager()); MemoryInstanceMemento memento = new MemoryInstanceMemento("Default", "Angus"); Modified: trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -1,6 +1,5 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Pipeline; Modified: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -1,7 +1,6 @@ using System; using NUnit.Framework; using StructureMap.Configuration.DSL; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -163,7 +163,7 @@ Assert.AreEqual("NotPluggable", plugin.ConcreteKey); // Just for fun, test with InstanceFactory too. - InstanceFactory factory = new InstanceFactory(family, true); + InstanceFactory factory = new InstanceFactory(family); factory.SetInstanceManager(new InstanceManager()); ConfiguredInstance instance = new ConfiguredInstance(); Modified: trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -1,7 +1,6 @@ using System.Collections; using System.Xml; using NUnit.Framework; -using StructureMap.Configuration.Mementos; using StructureMap.Source; using StructureMap.Testing.TestData; using StructureMap.Testing.XmlWriting; Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -77,7 +77,7 @@ PluginFamily family = new PluginFamily(typeof (ITarget2<int, string, bool>)); family.Plugins.Add(typeof (SpecificTarget2<int, string, bool>), "specific"); - InstanceFactory factory = new InstanceFactory(family, true); + InstanceFactory factory = new InstanceFactory(family); } [Test] @@ -86,7 +86,7 @@ PluginFamily family = new PluginFamily(typeof (ITarget<int, string>)); family.Plugins.Add(typeof (SpecificTarget<int, string>), "specific"); - InstanceFactory factory = new InstanceFactory(family, true); + InstanceFactory factory = new InstanceFactory(family); } [Test] Modified: trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -57,7 +57,7 @@ family.Plugins.Add(typeof (SecondGenericService<>), "Second"); family.Plugins.Add(typeof (ThirdGenericService<>), "Third"); - PluginFamily templatedFamily = family.CreateTemplatedClone(typeof (int)); + PluginFamily templatedFamily = GenericsPluginGraph.CreateTemplatedClone(family, typeof(int)); Assert.IsNotNull(templatedFamily); Assert.AreEqual(typeof (IGenericService<int>), templatedFamily.PluginType); @@ -77,12 +77,13 @@ family.Plugins.Add(typeof (SecondGenericService3<,,>), "Second"); family.Plugins.Add(typeof (ThirdGenericService3<,,>), "Third"); - PluginFamily templatedFamily = family.CreateTemplatedClone(typeof (int), typeof (bool), typeof (string)); + PluginFamily templatedFamily = GenericsPluginGraph.CreateTemplatedClone(family, typeof (int), typeof (bool), typeof (string)); Assert.IsNotNull(templatedFamily); Assert.AreEqual(typeof (IGenericService3<int, bool, string>), templatedFamily.PluginType); Assert.AreEqual(3, templatedFamily.Plugins.Count); + Assert.AreEqual(typeof (GenericService3<int, bool, string>), templatedFamily.Plugins["Default"].PluggedType); Assert.AreEqual(typeof (SecondGenericService3<int, bool, string>), templatedFamily.Plugins["Second"].PluggedType); Modified: trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -64,13 +64,11 @@ graph.Assemblies.Add("StructureMap.Testing.Widget"); graph.FindFamily(typeof (IWidget)).DefaultInstanceKey = "Blue"; - TypePath path = - new TypePath("StructureMap.Testing.Widget", "StructureMap.Testing.Widget.NotPluggableWidget"); + - PluginFamily family = graph.FindFamily(typeof (IWidget)); - family.Plugins.Add(path, "NotPluggable"); + family.Plugins.Add(typeof(NotPluggableWidget), "NotPluggable"); graph.Seal(); Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -33,19 +33,7 @@ private Type _colorwidget; private Type _moneywidgetmaker; - [ - Test, - ExpectedException(typeof (StructureMapException), - ExpectedMessage = "StructureMap Exception Code: 112\nMissing a mandatory \"ConcreteKey\" attribute in a <Plugin> node for Type \"StructureMap.Testing.Widget.NotPluggableWidget\"" - )] - public void AddAPluggedTypeWithoutAConcreteKey() - { - TypePath path = new TypePath("StructureMap.Testing.Widget", - "StructureMap.Testing.Widget.NotPluggableWidget"); - Plugin plugin = new Plugin(path, ""); - } - [Test] public void BadPluginToAbstractClass() { @@ -126,28 +114,6 @@ } - [Test, ExpectedException(typeof (StructureMapException))] - public void CreateAPluginWithANonExistentAssembly() - { - TypePath path = new TypePath("IDontExist.Assembly", - "IDontExist.Assembly.NotPluggableWidget"); - - Plugin plugin = new Plugin(path, "default"); - } - - - [ - Test, - ExpectedException(typeof (StructureMapException))] - public void CreateAPluginWithANonExistentClass() - { - TypePath path = new TypePath("StructureMap.Testing.Widget", - "StructureMap.Testing.Widget.NonExistentClass"); - - Plugin plugin = new Plugin(path, "default"); - } - - [Test] public void CreateImplicitMementoWithNoConstructorArguments() { Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-06 21:48:18 UTC (rev 94) +++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-09 15:47:15 UTC (rev 95) @@ -4,7 +4,6 @@ using StructureMap.Attributes; using StructureMap.Configuration; ... [truncated message content] |
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 @@ { try { - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ClassWithNoConstructor)); + Plugin plugin = new Plugin(typeof (ClassWithNoConstructor)); plugin.GetConstructor(); Assert.Fail("Should have thrown a StructureMapException"); } @@ -299,7 +306,7 @@ using (mocks.Playback()) { - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (LotsOfStuff)); + Plugin plugin = new Plugin(typeof (LotsOfStuff)); plugin.VisitArguments(visitor); } } Modified: trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -28,14 +28,14 @@ [Test] public void AutoFillDeterminationWithSetterPropertiesIsFalse() { - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (CannotBeAutoFilledGridColumn)); + Plugin plugin = new Plugin(typeof (CannotBeAutoFilledGridColumn)); Assert.IsFalse(plugin.CanBeAutoFilled); } [Test] public void AutoFillDeterminationWithSetterPropertiesIsTrue() { - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (AutoFilledGridColumn)); + Plugin plugin = new Plugin(typeof (AutoFilledGridColumn)); Assert.IsTrue(plugin.CanBeAutoFilled); } @@ -72,7 +72,7 @@ * WrapLines */ - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (BasicGridColumn)); + Plugin plugin = new Plugin(typeof (BasicGridColumn)); Assert.AreEqual(5, plugin.Setters.Count); Assert.IsTrue(plugin.Setters.Contains("Widget")); @@ -85,21 +85,21 @@ [Test, ExpectedException(typeof (StructureMapException))] public void TryToAddANonExistentSetterProperty() { - Plugin plugin = Plugin.CreateExplicitPlugin(typeof (BasicGridColumn), "Basic", string.Empty); + Plugin plugin = new Plugin(typeof (BasicGridColumn), "Basic"); plugin.Setters.Add("NonExistentPropertyName"); } [Test, ExpectedException(typeof (StructureMapException))] public void TryToAddASetterPropertyThatDoesNotHaveASetter() { - Plugin plugin = Plugin.CreateExplicitPlugin(typeof (BasicGridColumn), "Basic", string.Empty); + Plugin plugin = new Plugin(typeof (BasicGridColumn), "Basic"); plugin.Setters.Add("HeaderText"); } [Test, ExpectedException(typeof (StructureMapException))] public void TryToCreateAnImplicitPluginWithASetterPropertyThatDoesNotHaveASetMethod() { - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (BadSetterClass)); + Plugin plugin = new Plugin(typeof (BadSetterClass)); } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -23,14 +23,6 @@ } [Test] - public void CanFindType() - { - TypePath path = new TypePath(GetType().Assembly.GetName().Name, GetType().FullName); - Assert.IsTrue(path.CanFindType()); - Assert.IsNotNull(path.FindType()); - } - - [Test] public void Define_with_out_assembly_qualified_name_throws_exception() { try Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -26,7 +26,7 @@ values.Add(XmlConstants.PLUGGED_TYPE, TypePath.GetAssemblyQualifiedName(pluggedType)); _memento = new MemoryInstanceMemento(string.Empty, "Frank", values); - _expectedPlugin = Plugin.CreateImplicitPlugin(pluggedType); + _expectedPlugin = new Plugin(pluggedType); } #endregion Modified: trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -174,7 +174,7 @@ public void ReadChildArrayProperty() { PluginGraph graph = new PluginGraph(); - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule)); + Plugin plugin = new Plugin(typeof (ComplexRule)); graph.FindFamily(typeof (Rule)).Plugins.Add(plugin); @@ -207,7 +207,7 @@ public void ReadChildProperty_child_property_is_defined_build_child() { PluginGraph graph = new PluginGraph(); - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule)); + Plugin plugin = new Plugin(typeof (ComplexRule)); graph.FindFamily(typeof (Rule)).Plugins.Add(plugin); @@ -226,7 +226,7 @@ public void ReadChildProperty_child_property_is_not_defined_so_use_default() { PluginGraph graph = new PluginGraph(); - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule)); + Plugin plugin = new Plugin(typeof (ComplexRule)); graph.FindFamily(typeof (Rule)).Plugins.Add(plugin); @@ -241,7 +241,7 @@ public void ReadPrimitivePropertiesHappyPath() { PluginGraph graph = new PluginGraph(); - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule)); + Plugin plugin = new Plugin(typeof (ComplexRule)); graph.FindFamily(typeof (Rule)).Plugins.Add(plugin); Modified: trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -7,7 +7,7 @@ int Count { get; } } - [Pluggable("String", "")] + [Pluggable("String")] public class StringList : IList { public string[] values; @@ -27,7 +27,7 @@ #endregion } - [Pluggable("Integer", "")] + [Pluggable("Integer")] public class IntegerList : IList { public int[] values; Modified: trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -2,7 +2,7 @@ namespace StructureMap.Testing.Widget { - [PluginFamily, Pluggable("Default", "")] + [PluginFamily, Pluggable("Default")] public class GrandChild { private int _BirthYear; @@ -26,7 +26,7 @@ } - [Pluggable("Leftie", "")] + [Pluggable("Leftie")] public class LeftieGrandChild : GrandChild { public LeftieGrandChild(int BirthYear) : base(false, BirthYear) @@ -35,7 +35,7 @@ } - [PluginFamily, Pluggable("Default", "")] + [PluginFamily, Pluggable("Default")] public class Child { private GrandChild _MyGrandChild; @@ -58,7 +58,7 @@ } } - [PluginFamily, Pluggable("Default", "")] + [PluginFamily, Pluggable("Default")] public class Parent { private int _Age; Modified: trunk/Source/StructureMap.Testing.Widget/IWidget.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/IWidget.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing.Widget/IWidget.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -7,7 +7,7 @@ void DoSomething(); } - [Pluggable("Color", "Only for testing")] + [Pluggable("Color")] public class ColorWidget : IWidget, ICloneable { private string _Color; @@ -97,7 +97,7 @@ #endregion } - [Pluggable("Money", "Only for testing")] + [Pluggable("Money")] public class MoneyWidget : IWidget { private double _Amount; @@ -120,7 +120,7 @@ } - [Pluggable("Configuration", "Only for testing")] + [Pluggable("Configuration")] public class ConfigurationWidget : IWidget { private bool _Bool; Modified: trunk/Source/StructureMap.Testing.Widget/Rule.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Rule.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing.Widget/Rule.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -16,7 +16,7 @@ } } - [Pluggable("Complex", "Complex rule for testing")] + [Pluggable("Complex")] public class ComplexRule : Rule { private bool _Bool; @@ -111,7 +111,7 @@ } - [Pluggable("Color", "Color rule for testing")] + [Pluggable("Color")] public class ColorRule : Rule { private string _Color; @@ -130,7 +130,7 @@ } - [Pluggable("GreaterThan", "")] + [Pluggable("GreaterThan")] public class GreaterThanRule : Rule { private string _Attribute; Modified: trunk/Source/StructureMap.Testing.Widget/WidgetMaker.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/WidgetMaker.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing.Widget/WidgetMaker.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -6,7 +6,7 @@ public abstract IWidget MakeWidget(); } - [Pluggable("Color", "Only for testing")] + [Pluggable("Color")] public class ColorWidgetMaker : WidgetMaker { private string _Color; @@ -28,7 +28,7 @@ } } - [Pluggable("Money", "Only for testing")] + [Pluggable("Money")] public class MoneyWidgetMaker : WidgetMaker { private double _Amount; Modified: trunk/Source/StructureMap.Testing.Widget2/DefaultRule.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget2/DefaultRule.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing.Widget2/DefaultRule.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -2,7 +2,7 @@ namespace StructureMap.Testing.Widget2 { - [Pluggable("Default", "")] + [Pluggable("Default")] public class DefaultRule : Rule { public DefaultRule() Modified: trunk/Source/StructureMap.Testing.Widget2/Rule1.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget2/Rule1.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing.Widget2/Rule1.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -3,7 +3,7 @@ namespace StructureMap.Testing.Widget2 { - [Pluggable("Rule1", "")] + [Pluggable("Rule1")] public class Rule1 : Rule { public Rule1() Modified: trunk/Source/StructureMap.Testing.Widget3/Gateways.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget3/Gateways.cs 2008-05-06 20:33:10 UTC (rev 93) +++ trunk/Source/StructureMap.Testing.Widget3/Gateways.cs 2008-05-06 21:48:18 UTC (rev 94) @@ -9,7 +9,7 @@ void DoSomething(); } - [Pluggable("Default", "")] + [Pluggable("Default")] public class DefaultGateway : IGateway { private string _color; @@ -67,7 +67,7 @@ } - [Pluggable("Stubbed", "")] + [Pluggable("Stubbed")] public class StubbedGateway : IGateway { #region IGateway Members This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-05-06 20:33:17
|
Revision: 93 http://structuremap.svn.sourceforge.net/structuremap/?rev=93&view=rev Author: jeremydmiller Date: 2008-05-06 13:33:10 -0700 (Tue, 06 May 2008) Log Message: ----------- Introducing the AssemblyScanner! Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/IGraphBuilder.cs trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs trunk/Source/StructureMap/Diagnostics/Tokens.cs trunk/Source/StructureMap/Graph/PluginCollection.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/Pipeline/BuildStrategies.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/StructureMap.config Added Paths: ----------- trunk/Source/StructureMap/Emitting/ConstructorEmitter.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/IPluginFamily.cs trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Graph/AssemblyGraph.cs trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs trunk/Source/StructureMap.Testing/Container/MockingTester.cs trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -4,6 +4,7 @@ using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; +using StructureMap.Source; namespace StructureMap.Configuration.DSL.Expressions { @@ -40,9 +41,6 @@ { alteration(family); } - - AssemblyGraph assembly = new AssemblyGraph(_pluginType.Assembly); - graph.Assemblies.Add(assembly); } #endregion @@ -169,5 +167,25 @@ }); return this; } + + public CreatePluginFamilyExpression<PLUGINTYPE> AddInstancesFrom(MementoSource source) + { + _alterations.Add(delegate(PluginFamily family) + { + family.AddMementoSource(source); + }); + + return this; + } + + public CreatePluginFamilyExpression<PLUGINTYPE> AliasConcreteType<PLUGGEDTYPE>(string concreteKey) + { + _alterations.Add(delegate(PluginFamily family) + { + family.AddPlugin(typeof(PLUGGEDTYPE), concreteKey); + }); + + return this; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; @@ -12,7 +13,7 @@ /// </summary> public class ScanAssembliesExpression : IExpression { - private readonly List<AssemblyGraph> _assemblies = new List<AssemblyGraph>(); + private readonly List<Assembly> _assemblies = new List<Assembly>(); private readonly Registry _registry; public ScanAssembliesExpression(Registry registry) @@ -24,7 +25,7 @@ void IExpression.Configure(PluginGraph graph) { - foreach (AssemblyGraph assembly in _assemblies) + foreach (Assembly assembly in _assemblies) { graph.Assemblies.Add(assembly); } @@ -38,7 +39,7 @@ if (callingAssembly != null) { - _assemblies.Add(new AssemblyGraph(callingAssembly)); + _assemblies.Add(callingAssembly); } return this; @@ -65,18 +66,19 @@ public ScanAssembliesExpression IncludeAssemblyContainingType<T>() { - _assemblies.Add(AssemblyGraph.ContainingType<T>()); + _assemblies.Add(typeof(T).Assembly); return this; } public ScanAssembliesExpression AddAllTypesOf<PLUGINTYPE>() { + // TODO: Do this by adding something to TypeScanner _registry.addExpression(delegate(PluginGraph pluginGraph) { PluginFamily family = pluginGraph.FindFamily(typeof (PLUGINTYPE)); - family.CanUseUnMarkedPlugins = true; + family.SearchForImplicitPlugins = true; }); return this; @@ -84,7 +86,9 @@ public ScanAssembliesExpression IncludeAssembly(string assemblyName) { - _assemblies.Add(new AssemblyGraph(assemblyName)); + Assembly assembly = AppDomain.CurrentDomain.Load(assemblyName); + _assemblies.Add(assembly); + return this; } } Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -97,6 +97,14 @@ return new InstanceManager(_graph); } + public PluginGraph Build() + { + ConfigurePluginGraph(_graph); + _graph.Seal(); + + return _graph; + } + /// <summary> /// Starts an instance definition of type T /// </summary> Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -20,7 +20,7 @@ PluginGraph PluginGraph { get; } void AddAssembly(string assemblyName); - void StartFamilies(); + void PrepareSystemObjects(); void FinishFamilies(); IProfileBuilder GetProfileBuilder(); Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -49,15 +49,19 @@ public void AddAssembly(string assemblyName) { - AssemblyGraph assemblyGraph = new AssemblyGraph(assemblyName); - _pluginGraph.Assemblies.Add(assemblyGraph); - - AssemblyGraph systemAssemblyGraph = new AssemblyGraph(assemblyName); - systemAssemblyGraph.LookForPluginFamilies = false; - _systemGraph.Assemblies.Add(systemAssemblyGraph); + 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 StartFamilies() + public void PrepareSystemObjects() { // TODO: is this a problem here? _systemGraph.Seal(); Modified: trunk/Source/StructureMap/Diagnostics/Tokens.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Diagnostics/Tokens.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -12,6 +12,11 @@ private readonly List<Source> _sources = new List<Source>(); private Source _currentSource; + public int ErrorCount + { + get { return _errors.Count; } + } + public void StartSource(string description) { Source source = new Source(description); Added: trunk/Source/StructureMap/Emitting/ConstructorEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/ConstructorEmitter.cs (rev 0) +++ trunk/Source/StructureMap/Emitting/ConstructorEmitter.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Reflection.Emit; +using System.Text; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap.Emitting +{ + public class ConstructorEmitter : IPluginArgumentVisitor + { + private readonly ILGenerator _ilgen; + + public ConstructorEmitter(ILGenerator ilgen) + { + _ilgen = ilgen; + } + + + public void Primitive(string name) + { + throw new NotImplementedException(); + } + + public void Child(string name, Type childType) + { + throw new NotImplementedException(); + } + + public void ChildArray(string name, Type childType) + { + throw new NotImplementedException(); + } + + protected void callInstanceMemento(ILGenerator ilgen, string methodName) + { + MethodInfo _method = typeof(IConfiguredInstance).GetMethod(methodName); + ilgen.Emit(OpCodes.Callvirt, _method); + } + + protected void cast(ILGenerator ilgen, Type parameterType) + { + ilgen.Emit(OpCodes.Castclass, parameterType); + } + } +} Deleted: trunk/Source/StructureMap/Graph/AssemblyGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -1,167 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using StructureMap.Configuration.DSL; - -namespace StructureMap.Graph -{ - /// <summary> - /// Models an assembly reference in a PluginGraph - /// </summary> - [Obsolete("Kill!")] - public class AssemblyGraph : IComparable - { - private readonly Assembly _assembly; - private readonly string _assemblyName; - private bool _lookForPluginFamilies = true; - - - /// <summary> - /// Creates an AssemblyGraph, traps exceptions to troubleshoot configuration issues - /// </summary> - /// <param name="assemblyName"></param> - public AssemblyGraph(string assemblyName) - { - _assemblyName = assemblyName; - - try - { - _assembly = AppDomain.CurrentDomain.Load(assemblyName); - } - catch (Exception ex) - { - // TODO: Register error with PluginGraph. Maybe do this at configuration time - throw new StructureMapException(101, ex, assemblyName); - } - } - - public AssemblyGraph(Assembly assembly) - { - _assemblyName = assembly.GetName().Name; - _assembly = assembly; - } - - /// <summary> - /// Short name of the Assembly - /// </summary> - public string AssemblyName - { - get { return _assemblyName; } - } - - - /// <summary> - /// Reference to the System.Reflection.Assembly object - /// </summary> - public Assembly InnerAssembly - { - get { return _assembly; } - } - - /// <summary> - /// Used to control whether or not the assembly should be searched for implicit attributes - /// </summary> - public bool LookForPluginFamilies - { - get { return _lookForPluginFamilies; } - set { _lookForPluginFamilies = value; } - } - - #region IComparable Members - - public int CompareTo(object obj) - { - AssemblyGraph peer = (AssemblyGraph) obj; - return AssemblyName.CompareTo(peer.AssemblyName); - } - - #endregion - - /// <summary> - /// Returns an array of all the CLR Type's in the Assembly that are marked as - /// [PluginFamily] - /// </summary> - /// <returns></returns> - // TODO: Move into the new TypeScanner - public PluginFamily[] FindPluginFamilies() - { - if (_assembly == null || !LookForPluginFamilies) - { - return new PluginFamily[0]; - } - - List<PluginFamily> list = new List<PluginFamily>(); - - Type[] exportedTypes = getExportedTypes(); - - foreach (Type exportedType in exportedTypes) - { - if (PluginFamilyAttribute.MarkedAsPluginFamily(exportedType)) - { - PluginFamily family = new PluginFamily(exportedType); - list.Add(family); - } - } - - return list.ToArray(); - } - - // TODO: Move to TypeScanner - private Type[] getExportedTypes() - { - Type[] exportedTypes; - try - { - exportedTypes = _assembly.GetExportedTypes(); - } - catch (Exception ex) - { - throw new StructureMapException(170, ex, AssemblyName); - } - return exportedTypes; - } - - - public Plugin[] FindPlugins(Predicate<Type> match) - { - Type[] types = FindTypes(match); - return Array.ConvertAll<Type, Plugin>(types, - delegate(Type type) { return Plugin.CreateImplicitPlugin(type); }); - } - - - public static AssemblyGraph ContainingType<T>() - { - return new AssemblyGraph(typeof (T).Assembly); - } - - public Type FindTypeByFullName(string fullName) - { - return _assembly.GetType(fullName, false); - } - - - // TODO: Move into the new TypeScanner - public List<Registry> FindRegistries() - { - Type[] exportedTypes = getExportedTypes(); - List<Registry> returnValue = new List<Registry>(); - - foreach (Type type in exportedTypes) - { - if (Registry.IsPublicRegistry(type)) - { - Registry registry = (Registry) Activator.CreateInstance(type); - returnValue.Add(registry); - } - } - - return returnValue; - } - - public Type[] FindTypes(Predicate<Type> match) - { - return Array.FindAll(getExportedTypes(), match); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -1,87 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; - -namespace StructureMap.Graph -{ - /// <summary> - /// Custom collection for AssemblyGraph's - /// </summary> - [Obsolete("Kill!")] public class AssemblyGraphCollection : IEnumerable<AssemblyGraph> - { - private Dictionary<string, AssemblyGraph> _assemblies; - - public AssemblyGraphCollection(PluginGraph pluginGraph) - { - _assemblies = new Dictionary<string, AssemblyGraph>(); - } - - public AssemblyGraph this[string assemblyName] - { - get { return _assemblies[assemblyName]; } - } - - public AssemblyGraph this[int index] - { - get - { - AssemblyGraph[] array = new AssemblyGraph[_assemblies.Count]; - _assemblies.Values.CopyTo(array, 0); - return array[index]; - } - } - - public int Count - { - get { return _assemblies.Count; } - } - - public AssemblyGraph Add(string assemblyName) - { - AssemblyGraph assemblyGraph = new AssemblyGraph(assemblyName); - return Add(assemblyGraph); - } - - public AssemblyGraph Add(Assembly assembly) - { - return Add(new AssemblyGraph(assembly)); - } - - public AssemblyGraph Add(AssemblyGraph assemblyGraph) - { - if (_assemblies.ContainsKey(assemblyGraph.AssemblyName)) - { - return _assemblies[assemblyGraph.AssemblyName]; - } - - _assemblies.Add(assemblyGraph.AssemblyName, assemblyGraph); - return assemblyGraph; - } - - public void Remove(string assemblyName) - { - _assemblies.Remove(assemblyName); - } - - public void Remove(AssemblyGraph assemblyGraph) - { - Remove(assemblyGraph.AssemblyName); - } - - public bool Contains(string assemblyName) - { - return _assemblies.ContainsKey(assemblyName); - } - - IEnumerator<AssemblyGraph> IEnumerable<AssemblyGraph>.GetEnumerator() - { - return _assemblies.Values.GetEnumerator(); - } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable<AssemblyGraph>) this).GetEnumerator(); - } - } -} \ No newline at end of file Added: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs (rev 0) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using StructureMap.Configuration.DSL; +using StructureMap.Diagnostics; + +namespace StructureMap.Graph +{ + // TODO: dies in 3.5 + public delegate void Action<T, U>(T t, U u); + + // TODO: redo in 3.5 w/ Lambdas + public class AssemblyScanner + { + private readonly GraphLog _log; + private readonly List<Assembly> _assemblies = new List<Assembly>(); + + public AssemblyScanner(GraphLog log) + { + _log = log; + } + + public int Count + { + get { return _assemblies.Count; } + } + + public void ScanForAll(PluginGraph pluginGraph) + { + // Don't do this for SystemScan + scanTypes(delegate(Type type) + { + if (Registry.IsPublicRegistry(type)) + { + Registry registry = (Registry)Activator.CreateInstance(type); + registry.ConfigurePluginGraph(pluginGraph); + } + }); + + + findFamiliesAndPlugins(pluginGraph); + } + + private void findFamiliesAndPlugins(PluginGraph pluginGraph) + { + scanTypes(delegate(Type type) + { + if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) + { + pluginGraph.CreateFamily(type); + } + }); + + scanTypes(delegate(Type type) + { + foreach (PluginFamily family in pluginGraph.PluginFamilies) + { + family.AnalyzeTypeForPlugin(type); + } + }); + } + + + public void ScanForStructureMapObjects(PluginGraph pluginGraph) + { + findFamiliesAndPlugins(pluginGraph); + } + + private void scanTypes(Action<Type> action) + { + scanTypes(new Action<Type>[]{action}); + } + + private void scanTypes(IEnumerable<Action<Type>> actions) + { + foreach (Assembly assembly in _assemblies.ToArray()) + { + scanTypesInAssembly(assembly, actions); + } + } + + private void scanTypesInAssembly(Assembly assembly, IEnumerable<Action<Type>> actions) + { + Type[] exportedTypes; + try + { + foreach (Type type in assembly.GetExportedTypes()) + { + foreach (Action<Type> action in actions) + { + action(type); + } + } + } + catch (Exception ex) + { + _log.RegisterError(170, ex, assembly.FullName); + } + } + + public void Add(Assembly assembly) + { + if (!_assemblies.Contains(assembly)) + { + _assemblies.Add(assembly); + } + } + + public void Add(string assemblyName) + { + Add(AppDomain.CurrentDomain.Load(assemblyName)); + } + + public bool Contains(string assemblyName) + { + foreach (Assembly assembly in _assemblies) + { + if (assembly.GetName().Name == assemblyName) + { + return true; + } + } + + return false; + } + } +} Added: trunk/Source/StructureMap/Graph/IPluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/IPluginFamily.cs (rev 0) +++ trunk/Source/StructureMap/Graph/IPluginFamily.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -0,0 +1,32 @@ +using System; +using StructureMap.Attributes; +using StructureMap.Pipeline; + +namespace StructureMap.Graph +{ + public interface IPluginFamily + { + void AddMementoSource(MementoSource source); + + /// <summary> + /// The InstanceKey of the default instance of the PluginFamily + /// </summary> + string DefaultInstanceKey { get; set; } + + /// <summary> + /// The CLR Type that defines the "Plugin" interface for the PluginFamily + /// </summary> + Type PluginType + { + get; + } + + string PluginTypeName + { + get; + } + + void SetScopeTo(InstanceScope scope); + void AddInterceptor(IInstanceInterceptor interceptor); + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -167,5 +167,18 @@ return list; } + + public bool HasPlugin(Type pluggedType) + { + foreach (KeyValuePair<string, Plugin> pair in _plugins) + { + if (pair.Value.PluggedType == pluggedType) + { + return true; + } + } + + return false; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -18,16 +18,19 @@ public const string CONCRETE_KEY = "CONCRETE"; private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>(); private readonly PluginCollection _plugins; - private bool _canUseUnMarkedPlugins = false; private string _defaultKey = string.Empty; private InstanceInterceptor _instanceInterceptor = new NulloInterceptor(); private PluginGraph _parent; - private Type _pluginType; - private string _pluginTypeName; - private List<Instance> _instances = new List<Instance>(); + private readonly Type _pluginType; + private readonly string _pluginTypeName; + private readonly List<Instance> _instances = new List<Instance>(); private IBuildPolicy _buildPolicy = new BuildPolicy(); + private readonly Predicate<Type> _explicitlyMarkedPluginFilter; + private readonly Predicate<Type> _implicitPluginFilter; + private Predicate<Type> _pluginFilter; + // TODO: Need to unit test the scope from the attribute /// <summary> /// Testing constructor @@ -40,6 +43,10 @@ _plugins = new PluginCollection(this); PluginFamilyAttribute.ConfigureFamily(this); + + _explicitlyMarkedPluginFilter = delegate(Type type) { return Plugin.IsAnExplicitPlugin(PluginType, type); }; + _implicitPluginFilter = delegate(Type type) { return Plugin.CanBeCast(PluginType, type); }; + _pluginFilter = _explicitlyMarkedPluginFilter; } @@ -89,32 +96,8 @@ 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> - [Obsolete] public Plugin[] FindPlugins(AssemblyGraph assembly) - { - Predicate<Type> pluggedTypeFilter = - delegate(Type type) { return Plugin.IsAnExplicitPlugin(PluginType, type); }; - if (_canUseUnMarkedPlugins) - { - pluggedTypeFilter = delegate(Type type) { return Plugin.CanBeCast(PluginType, type); }; - } - Plugin[] plugins = assembly.FindPlugins(pluggedTypeFilter); - - foreach (Plugin plugin in plugins) - { - _plugins.Add(plugin); - } - - return plugins; - } - public void AddInstance(InstanceMemento memento) { _mementoList.Add(memento); @@ -136,21 +119,7 @@ return _mementoList.Find(delegate(InstanceMemento m) { return m.InstanceKey == instanceKey; }); } - // TODO -- Move out into TypeScanner - public void DiscoverImplicitInstances() - { - List<Plugin> list = _plugins.FindAutoFillablePlugins(); - foreach (InstanceMemento memento in _mementoList) - { - Plugin plugin = memento.FindPlugin(this); - list.Remove(plugin); - } - foreach (Plugin plugin in list) - { - AddInstance(plugin.CreateImplicitMemento()); - } - } #region properties @@ -191,11 +160,16 @@ get { return _pluginType.IsGenericType; } } - - public bool CanUseUnMarkedPlugins + public bool SearchForImplicitPlugins { - get { return _canUseUnMarkedPlugins; } - set { _canUseUnMarkedPlugins = value; } + get + { + return ReferenceEquals(_pluginFilter, _implicitPluginFilter); + } + set + { + _pluginFilter = value ? _implicitPluginFilter : _explicitlyMarkedPluginFilter; + } } public IBuildPolicy Policy @@ -203,10 +177,17 @@ get { return _buildPolicy; } } + public int PluginCount + { + get { return _plugins.Count; } + } + #endregion public void Seal() { + discoverImplicitInstances(); + foreach (InstanceMemento memento in _mementoList) { Instance instance = memento.ReadInstance(Parent, _pluginType); @@ -214,6 +195,21 @@ } } + private void discoverImplicitInstances() + { + List<Plugin> list = _plugins.FindAutoFillablePlugins(); + foreach (InstanceMemento memento in _mementoList) + { + Plugin plugin = memento.FindPlugin(this); + list.Remove(plugin); + } + + foreach (Plugin plugin in list) + { + AddInstance(plugin.CreateImplicitMemento()); + } + } + public Instance[] GetAllInstances() { return _instances.ToArray(); @@ -253,5 +249,36 @@ } + public void AnalyzeTypeForPlugin(Type pluggedType) + { + if (_pluginFilter(pluggedType)) + { + if (!HasPlugin(pluggedType)) + { + Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType); + _plugins.Add(plugin); + } + } + } + + public bool HasPlugin(Type pluggedType) + { + return _plugins.HasPlugin(pluggedType); + } + + public void AddPlugin(Type pluggedType) + { + if (!HasPlugin(pluggedType)) + { + _plugins.Add(Plugin.CreateImplicitPlugin(pluggedType)); + } + } + + public void AddPlugin(Type pluggedType, string key) + { + Plugin plugin = Plugin.CreateExplicitPlugin(pluggedType, key, string.Empty); + _plugins.Add(plugin); + + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -16,7 +16,7 @@ [Serializable] public class PluginGraph { - private readonly AssemblyGraphCollection _assemblies; + private readonly AssemblyScanner _assemblies; private readonly InterceptorLibrary _interceptorLibrary = new InterceptorLibrary(); private readonly GraphLog _log = new GraphLog(); private readonly PluginFamilyCollection _pluginFamilies; @@ -29,7 +29,7 @@ /// </summary> public PluginGraph() : base() { - _assemblies = new AssemblyGraphCollection(this); + _assemblies = new AssemblyScanner(_log); _pluginFamilies = new PluginFamilyCollection(this); } @@ -39,7 +39,7 @@ _useExternalRegistries = useExternalRegistries; } - public AssemblyGraphCollection Assemblies + public AssemblyScanner Assemblies { get { return _assemblies; } } @@ -89,22 +89,15 @@ if (_useExternalRegistries) { - searchAssembliesForRegistries(); + _assemblies.ScanForAll(this); } - - foreach (AssemblyGraph assembly in _assemblies) + else { - addImplicitPluginFamilies(assembly); + _assemblies.ScanForStructureMapObjects(this); } foreach (PluginFamily family in _pluginFamilies) { - attachImplicitPlugins(family); - family.DiscoverImplicitInstances(); - } - - foreach (PluginFamily family in _pluginFamilies) - { family.Seal(); } @@ -114,44 +107,7 @@ } - private void searchAssembliesForRegistries() - { - List<Registry> list = new List<Registry>(); - foreach (AssemblyGraph assembly in _assemblies) - { - list.AddRange(assembly.FindRegistries()); - } - foreach (Registry registry in list) - { - registry.ConfigurePluginGraph(this); - } - } - - private void attachImplicitPlugins(PluginFamily family) - { - foreach (AssemblyGraph assembly in _assemblies) - { - family.FindPlugins(assembly); - } - } - - - private void addImplicitPluginFamilies(AssemblyGraph assemblyGraph) - { - PluginFamily[] families = assemblyGraph.FindPluginFamilies(); - - foreach (PluginFamily family in families) - { - if (_pluginFamilies.Contains(family.PluginType)) - { - continue; - } - - _pluginFamilies.Add(family); - } - } - #endregion public static PluginGraph BuildGraphFromAssembly(Assembly assembly) @@ -171,7 +127,6 @@ { PluginFamily family = new PluginFamily(pluginType); _pluginFamilies.Add(family); - attachImplicitPlugins(family); } } @@ -185,5 +140,11 @@ { return _pluginFamilies.Contains(pluginType); } + + public void CreateFamily(Type pluginType) + { + // Just guarantee that this PluginFamily exists + FindFamily(pluginType); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/BuildStrategies.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -2,6 +2,7 @@ namespace StructureMap.Pipeline { + public interface IBuildPolicy { object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance); Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -63,6 +63,9 @@ { NormalGraphBuilder graphBuilder = new NormalGraphBuilder(_registries, _graph); buildPluginGraph(graphBuilder); + + _graph.Seal(); + return _graph; } @@ -80,7 +83,7 @@ { forAllParsers(delegate(ConfigurationParser p) { p.ParseAssemblies(graphBuilder); }); - graphBuilder.StartFamilies(); + graphBuilder.PrepareSystemObjects(); forAllParsers(delegate(ConfigurationParser p) { Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-06 20:33:10 UTC (rev 93) @@ -119,6 +119,7 @@ <Compile Include="Diagnostics\Tokens.cs" /> <Compile Include="Emitting\ConstructorEmitter.cs" /> <Compile Include="Graph\IPluginFamily.cs" /> + <Compile Include="Graph\AssemblyScanner.cs" /> <Compile Include="InstanceBuilderList.cs" /> <Compile Include="InstanceFamily.cs" /> <Compile Include="Pipeline\BuildStrategies.cs" /> @@ -233,12 +234,6 @@ <Compile Include="Exceptions\StructureMapException.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Graph\AssemblyGraph.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Graph\AssemblyGraphCollection.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Graph\GenericsPluginGraph.cs" /> <Compile Include="Graph\Plugin.cs"> <SubType>Code</SubType> Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -203,6 +203,7 @@ using (Registry registry = new Registry(pluginGraph)) { registry.BuildInstancesOf<IGateway>(); + registry.ScanAssemblies().IncludeAssemblyContainingType<IGateway>(); } Assert.IsTrue(pluginGraph.ContainsFamily(typeof(IGateway))); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -57,22 +57,10 @@ [Test] - public void FindRegistries() - { - AssemblyGraph assembly = new AssemblyGraph("StructureMap.Testing.Widget5"); - List<Registry> list = assembly.FindRegistries(); - - Assert.AreEqual(3, list.Count); - Assert.Contains(new RedGreenRegistry(), list); - Assert.Contains(new YellowBlueRegistry(), list); - Assert.Contains(new BrownBlackRegistry(), list); - } - - [Test] public void FindRegistriesWithinPluginGraphSeal() { PluginGraph graph = new PluginGraph(); - graph.Assemblies.Add("StructureMap.Testing.Widget5"); + graph.Assemblies.Add(typeof(RedGreenRegistry).Assembly); graph.Seal(); List<string> colors = new List<string>(); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -34,11 +34,10 @@ .IncludeTheCallingAssembly(); PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>(); - Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); + Assembly assembly = typeof(IGateway).Assembly; + Assert.IsTrue(graph.Assemblies.Contains(assembly.GetName().Name)); - assembly = new AssemblyGraph(Assembly.GetExecutingAssembly()); - Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); + Assert.IsTrue(graph.Assemblies.Contains(Assembly.GetExecutingAssembly().GetName().Name)); } @@ -50,11 +49,10 @@ .IncludeAssemblyContainingType<IGateway>(); PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>(); - Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); + Assembly assembly = typeof(IGateway).Assembly; + Assert.IsTrue(graph.Assemblies.Contains(assembly.GetName().Name)); - assembly = new AssemblyGraph(Assembly.GetExecutingAssembly()); - Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); + Assert.IsTrue(graph.Assemblies.Contains(Assembly.GetExecutingAssembly().GetName().Name)); } [Test] @@ -66,8 +64,8 @@ PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>(); - Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); + Assembly assembly = typeof(IGateway).Assembly; + Assert.IsTrue(graph.Assemblies.Contains(assembly.GetName().Name)); } [Test] @@ -76,8 +74,8 @@ StructureMapConfiguration.ScanAssemblies().IncludeAssemblyContainingType<IGateway>(); PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>(); - Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); + Assembly assembly = typeof(IGateway).Assembly; + Assert.IsTrue(graph.Assemblies.Contains(assembly.GetName().Name)); } [Test] @@ -86,8 +84,7 @@ StructureMapConfiguration.ScanAssemblies().IncludeTheCallingAssembly(); PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - AssemblyGraph assembly = new AssemblyGraph(Assembly.GetExecutingAssembly()); - Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); + Assert.IsTrue(graph.Assemblies.Contains(Assembly.GetExecutingAssembly().GetName().Name)); } } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -0,0 +1,146 @@ +using System; +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Configuration; +using StructureMap.Configuration.DSL; +using StructureMap.Configuration.Mementos; +using StructureMap.Graph; +using StructureMap.Pipeline; +using StructureMap.Source; +using StructureMap.Testing.Widget3; + +namespace StructureMap.Testing.Configuration +{ + [TestFixture] + public class NormalGraphBuilderTester + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void Configure_a_family_that_does_not_exist_and_log_an_error_with_PluginGraph() + { + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + builder.ConfigureFamily(new TypePath("a,a"), delegate (PluginFamily f){}); + + builder.PluginGraph.Log.AssertHasError(103); + } + + [Test] + public void Do_not_call_the_action_on_ConfigureFamily_if_the_type_path_blows_up() + { + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + builder.ConfigureFamily(new TypePath("a,a"), delegate(PluginFamily f) + { + Assert.Fail("Should not be called"); + }); + + } + + [Test] + public void Call_the_action_on_configure_family_if_the_pluginType_is_found() + { + TypePath typePath = new TypePath(typeof(IGateway)); + + bool iWasCalled = false; + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + builder.ConfigureFamily(typePath, delegate(PluginFamily f) + { + Assert.AreEqual(typeof(IGateway), f.PluginType); + iWasCalled = true; + }); + + + Assert.IsTrue(iWasCalled); + } + + [Test] + public void Log_an_error_for_a_requested_system_object_if_it_cannot_be_created() + { + MemoryInstanceMemento memento = new MemoryInstanceMemento(); + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + + builder.WithSystemObject<MementoSource>(memento, "I am going to break here", delegate(MementoSource source){}); + + builder.PluginGraph.Log.AssertHasError(130); + } + + [Test] + public void Do_not_try_to_execute_the_action_when_requested_system_object_if_it_cannot_be_created() + { + MemoryInstanceMemento memento = new MemoryInstanceMemento(); + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + + builder.WithSystemObject<MementoSource>(memento, "I am going to break here", delegate(MementoSource source) + { + Assert.Fail("Wasn't supposed to be called"); + }); + + } + + [Test] + public void Create_system_object_successfully_and_call_the_requested_action() + { + + MemoryInstanceMemento memento = new MemoryInstanceMemento("Singleton", "anything"); + + bool iWasCalled = false; + + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + builder.PrepareSystemObjects(); + builder.WithSystemObject<IInstanceInterceptor>(memento, "singleton", delegate(IInstanceInterceptor policy) + { + Assert.IsInstanceOfType(typeof(SingletonPolicy), policy); + iWasCalled = true; + }); + + Assert.IsTrue(iWasCalled); + } + + [Test] + public void WithType_fails_and_logs_error_with_the_context() + { + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + builder.WithType(new TypePath("a,a"), "creating a Plugin", delegate(Type t){Assert.Fail("Should not be called");}); + + builder.PluginGraph.Log.AssertHasError(131); + } + + [Test] + public void WithType_calls_through_to_the_Action_if_the_type_can_be_found() + { + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + bool iWasCalled = true; + + builder.WithType(new TypePath(this.GetType()), "creating a Plugin", delegate(Type t) + { + iWasCalled = true; + Assert.AreEqual(this.GetType(), t); + }); + + Assert.IsTrue(iWasCalled); + } + + [Test] + public void AddAssembly_HappyPath() + { + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + string assemblyName = this.GetType().Assembly.GetName().Name; + builder.AddAssembly(assemblyName); + + Assert.IsTrue(builder.PluginGraph.Assemblies.Contains(assemblyName)); + Assert.AreEqual(0, builder.PluginGraph.Log.ErrorCount); + } + + [Test] + public void AddAssembly_SadPath() + { + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); + builder.AddAssembly("something"); + + builder.PluginGraph.Log.AssertHasError(101); + } + } +} Modified: trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics; using NUnit.Framework; using StructureMap.Graph; using StructureMap.Pipeline; @@ -31,6 +32,10 @@ _graph.Seal(); Instance[] instances = _graph.FindFamily(typeof (IWidget)).GetAllInstances(); + foreach (Instance instance in instances) + { + Debug.WriteLine(instance.Name + ", " + instance.GetType().FullName); + } Assert.AreEqual(4, instances.Length); } Modified: trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -1,4 +1,6 @@ using NUnit.Framework; +using StructureMap.Configuration; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Source; using StructureMap.Testing.TestData; @@ -22,19 +24,19 @@ [Test] public void BuildDecisionWithRules() { + + DataMother.WriteDocument("FullTesting.XML"); DataMother.WriteDocument("Array.xml"); + DataMother.WriteDocument("ObjectMother.config"); - PluginGraph graph = DataMother.GetPluginGraph("ObjectMother.config"); - + Registry registry = new Registry(); XmlMementoSource source = new XmlFileMementoSource("Array.xml", string.Empty, "Decision"); + registry.ForRequestedType<Decision>().AddInstancesFrom(source).AliasConcreteType<Decision>("Default"); - PluginFamily family = graph.FindFamily(typeof(Decision)); - family.AddMementoSource(source); + PluginGraphBuilder builder = new PluginGraphBuilder(new ConfigurationParser[]{ConfigurationParser.FromFile("ObjectMother.config")}, new Registry[]{registry}); - family.Plugins.Add(typeof (Decision), "Default"); - - graph.Seal(); + PluginGraph graph = builder.Build(); InstanceManager manager = new InstanceManager(graph); Deleted: trunk/Source/StructureMap.Testing/Container/MockingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/MockingTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Container/MockingTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -1,29 +0,0 @@ -using System; -using NUnit.Framework; -using StructureMap.Graph; -using StructureMap.Source; -using StructureMap.Testing.Widget3; - -namespace StructureMap.Testing.Container -{ - [TestFixture] - public class MockingTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - PluginGraph graph = new PluginGraph(); - graph.Assemblies.Add("StructureMap.Testing.Widget3"); - graph.PluginFamilies.Add(gatewayType, string.Empty); - graph.Seal(); - _manager = new InstanceManager(graph); - } - - #endregion - - private InstanceManager _manager; - private Type gatewayType = typeof (IGateway); - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -1,6 +1,7 @@ using System.Xml; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; using StructureMap.Testing.TestData; @@ -141,7 +142,13 @@ [Test] public void GotPluginsThatAreMarkedAsPluggable() { - PluginFamily pluginFamily = graph.FindFamily(typeof (IWidget)); + Registry registry = new Registry(); + registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>(); + registry.BuildInstancesOf<IWidget>(); + PluginGraph pluginGraph = registry.Build(); + + + PluginFamily pluginFamily = pluginGraph.FindFamily(typeof(IWidget)); Plugin plugin = pluginFamily.Plugins[typeof (ColorWidget)]; Assert.IsNotNull(plugin); } Modified: trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -36,16 +36,6 @@ [Test] - public void FindTypes() - { - AssemblyGraph assemblyGraph = new AssemblyGraph(Assembly.GetExecutingAssembly()); - Type[] types = assemblyGraph.FindTypes( - delegate(Type type) { return type.Equals(typeof (BlueType)); }); - - Assert.AreEqual(new Type[] {typeof (BlueType)}, types); - } - - [Test] public void FoundTheRightNumberOfInstancesForATypeWithNoPlugins() { Assert.AreEqual(3, _manager.GetAllInstances<TypeIWantToFind>().Count); Deleted: trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -1,68 +0,0 @@ -using System; -using System.Collections; -using NUnit.Framework; -using StructureMap.Graph; -using StructureMap.Testing.Widget; - -namespace StructureMap.Testing.Graph -{ - [TestFixture] - public class AssemblyGraphTester - { - [Test] - public void CanFindAssembly() - { - AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget"); - Assert.AreEqual("StructureMap.Testing.Widget", graph.AssemblyName); - } - - - [Test] - public void CanFindFamilies() - { - AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget"); - PluginFamily[] families = graph.FindPluginFamilies(); - - Assert.IsNotNull(families); - Assert.AreEqual(4, families.Length); - } - - [Test] - public void CanFindPlugins() - { - AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget"); - PluginFamily family = new PluginFamily(typeof (IWidget)); - Plugin[] plugins = family.FindPlugins(graph); - Assert.IsNotNull(plugins); - Assert.AreEqual(4, plugins.Length); - } - - [Test, - ExpectedException(typeof (StructureMapException), - ExpectedMessage = "StructureMap Exception Code: 101\nAssembly DoesNotExist referenced by an <Assembly> node in StructureMap.config cannot be loaded into the current AppDomain" - )] - public void CannotFindAssembly() - { - AssemblyGraph graph = new AssemblyGraph("DoesNotExist"); - } - - [Test] - public void FindTypeByFullNameReturnsNullIfTypeNotFound() - { - AssemblyGraph assemblyGraph = new AssemblyGraph("StructureMap.Testing.Widget"); - Assert.IsNull(assemblyGraph.FindTypeByFullName("something that does not exist")); - } - - [Test] - public void FindTypeByFullNameSuccess() - { - AssemblyGraph assemblyGraph = new AssemblyGraph("StructureMap.Testing.Widget"); - Type type = typeof (IWidget); - - Type actualType = assemblyGraph.FindTypeByFullName(type.FullName); - - Assert.AreEqual(type, actualType); - } - - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-04 02:59:57 UTC (rev 92) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-06 20:33:10 UTC (rev 93) @@ -32,22 +32,7 @@ } - [Test] - public void GetPlugins() - { - PluginFamily family = new PluginFamily(typeof(IWidget)); - family.DefaultInstanceKey = "DefaultKey"; - AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget"); - family.FindPlugins(graph); - - Assert.AreEqual(4, family.Plugins.Count, "Plugin Count"); - foreach (Plugin plugin in family.Plugins) - { - Assert.IsNotNull(plugin); - } - } - [Test] public void HasANulloInterceptorUponConstruction() { @@ -134,6 +119,72 @@ Assert.IsInstanceOfType(typeof(HybridBuildPolicy), family.Policy); } + + [Test] + public void Analyze_a_type_for_a_plugin_that_does_not_match() + { + PluginFamily family = new PluginFamily(typeof(ISingletonRepository)); + family.AnalyzeTypeForPlugin(typeof (RandomClass)); + + Assert.AreEqual(0, family.PluginCount); + } + + [Test] + public void PluginFamily_only_looks_for_explicit_plugins_by_default() + { + PluginFamily family = new PluginFamily(typeof(ISingletonRepository)); + Assert.IsFalse(family.SearchForImplicitPlugins); + } + + [Test] + public void PluginFamily_adds_an_explicitly_marked_Plugin_when_only_looking_for_Explicit_plugins() + { + PluginFamily family = new PluginFamily(typeof(ISingletonRepository)); + family.SearchForImplicitPlugins = false; + family.AnalyzeTypeForPlugin(typeof(SingletonRepositoryWithAttribute)); + + Assert.AreEqual(1, family.PluginCount); + Assert.IsTrue(family.HasPlugin(typeof(SingletonReposi... [truncated message content] |
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-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 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 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 (IWidget)).DefaultInstanceKey = "Blue"; + graph.FindFamily(typeof (WidgetMaker)); graph.Seal(); @@ -37,7 +37,7 @@ Console.WriteLine(family.PluginType.AssemblyQualifiedName); } - Assert.AreEqual(5, graph.PluginFamilies.Count); + Assert.AreEqual(5, graph.FamilyCount); } [Test] @@ -47,11 +47,11 @@ graph.Assemblies.Add("StructureMap.Testing.Widget"); graph.Assemblies.Add("StructureMap.Testing.Widget2"); - graph.PluginFamilies.Add(typeof (Rule), string.Empty); + graph.FindFamily(typeof (Rule)); graph.Seal(); - PluginFamily family = graph.PluginFamilies[typeof (Rule)]; + PluginFamily family = graph.FindFamily(typeof (Rule)); Assert.IsNotNull(family); Assert.AreEqual(5, family.Plugins.Count, "There are 5 Rule classes in the two assemblies"); } @@ -63,12 +63,12 @@ PluginGraph graph = new PluginGraph(); graph.Assemblies.Add("StructureMap.Testing.Widget"); - graph.PluginFamilies.Add(typeof (IWidget), "Blue"); + graph.FindFamily(typeof (IWidget)).DefaultInstanceKey = "Blue"; TypePath path = new TypePath("StructureMap.Testing.Widget", "StructureMap.Testing.Widget.NotPluggableWidget"); - PluginFamily family = graph.PluginFamilies[typeof (IWidget)]; + PluginFamily family = graph.FindFamily(typeof (IWidget)); family.Plugins.Add(path, "NotPluggable"); graph.Seal(); @@ -88,10 +88,10 @@ PluginGraph graph = new PluginGraph(); graph.Assemblies.Add("StructureMap.Testing.Widget"); - graph.PluginFamilies.Add(typeof (IWidget), "Blue"); + graph.FindFamily(typeof (IWidget)).DefaultInstanceKey = "Blue"; graph.Seal(); - PluginFamily family = graph.PluginFamilies[typeof (IWidget)]; + PluginFamily family = graph.FindFamily(typeof (IWidget)); Assert.IsNotNull(family); Assert.AreEqual("Blue", family.DefaultInstanceKey); Modified: trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-05-03 17:52:03 UTC (rev 88) +++ trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-05-04 01:11:30 UTC (rev 89) @@ -51,7 +51,7 @@ public void CreateSetterPropertyCollectionFromExplicitPlugin() { PluginGraph pluginGraph = getPluginGraph(); - Plugin plugin = pluginGraph.PluginFamilies[typeof (IGridColumn)].Plugins["Other"]; + Plugin plugin = pluginGraph.FindFamily(typeof (IGridColumn)).Plugins["Other"]; Assert.AreEqual(5, plugin.Setters.Count); Assert.IsTrue(plugin.Setters.Contains("Widget")); Modified: trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-05-03 17:52:03 UTC (rev 88) +++ trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs 2008-05-04 01:11:30 UTC (rev 89) @@ -19,10 +19,10 @@ public void SetUp() { _graph = new PluginGraph(); - PluginFamily family = _graph.PluginFamilies.Add(typeof (IService)); + PluginFamily family = _graph.FindFamily(typeof (IService)); family.Plugins.Add(typeof(ColorService), "Color"); - _graph.PluginFamilies.Add(typeof (Rule)); + _graph.FindFamily(typeof (Rule)); } #endregion @@ -176,7 +176,7 @@ PluginGraph graph = new PluginGraph(); Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule)); - graph.PluginFamilies.Add(typeof (Rule)).Plugins.Add(plugin); + graph.FindFamily(typeof (Rule)).Plugins.Add(plugin); MemoryInstanceMemento memento = ComplexRule.GetMemento(); memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName); @@ -209,7 +209,7 @@ PluginGraph graph = new PluginGraph(); Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule)); - graph.PluginFamilies.Add(typeof (Rule)).Plugins.Add(plugin); + graph.FindFamily(typeof (Rule)).Plugins.Add(plugin); MemoryInstanceMemento memento = ComplexRule.GetMemento(); memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName); @@ -228,7 +228,7 @@ PluginGraph graph = new PluginGraph(); Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule)); - graph.PluginFamilies.Add(typeof (Rule)).Plugins.Add(plugin); + graph.FindFamily(typeof (Rule)).Plugins.Add(plugin); MemoryInstanceMemento memento = ComplexRule.GetMemento(); memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName); @@ -243,7 +243,7 @@ PluginGraph graph = new PluginGraph(); Plugin plugin = Plugin.CreateImplicitPlugin(typeof (ComplexRule)); - graph.PluginFamilies.Add(typeof (Rule)).Plugins.Add(plugin); + graph.FindFamily(typeof (Rule)).Plugins.Add(plugin); MemoryInstanceMemento memento = ComplexRule.GetMemento(); memento.SetProperty(XmlConstants.PLUGGED_TYPE, typeof (ComplexRule).AssemblyQualifiedName); Modified: trunk/Source/StructureMap.Testing/ObjectMother.cs =================================================================== --- trunk/Source/StructureMap.Testing/ObjectMother.cs 2008-05-03 17:52:03 UTC (rev 88) +++ trunk/Source/StructureMap.Testing/ObjectMother.cs 2008-05-04 01:11:30 UTC (rev 89) @@ -37,7 +37,7 @@ public static PluginFamily GetPluginFamily(Type pluginType) { - return _pluginGraph.PluginFamilies[pluginType]; + return _pluginGraph.FindFamily(pluginType); } public static Plugin GetPlugin(Type pluginType, string concreteKey) @@ -73,7 +73,7 @@ public static InstanceFactory CreateInstanceFactory(Type pluginType, string[] assemblyNames) { PluginGraph pluginGraph = createPluginGraphFromAssemblyNames(assemblyNames); - pluginGraph.PluginFamilies.Add(pluginType, string.Empty); + pluginGraph.FindFamily(pluginType); pluginGraph.Seal(); InstanceManager manager = new InstanceManager(pluginGraph); Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-03 17:52:03 UTC (rev 88) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-04 01:11:30 UTC (rev 89) @@ -225,9 +225,6 @@ <Compile Include="Container\Interceptors\InterceptorLibraryTester.cs" /> <Compile Include="Container\Interceptors\MockTypeInterceptor.cs" /> <Compile Include="Container\Interceptors\TypeInterceptionTester.cs" /> - <Compile Include="Container\MockingTester.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Container\PluggableAttributeTester.cs"> <SubType>Code</SubType> </Compile> 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-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 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 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-03 03:24:24 UTC (rev 85) @@ -1,8 +1,5 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Diagnostics; -using System.IO; using System.Reflection; using StructureMap.Configuration.DSL; @@ -11,39 +8,9 @@ /// <summary> /// Models an assembly reference in a PluginGraph /// </summary> + [Obsolete("Kill!")] public class AssemblyGraph : IComparable { - #region statics - - /// <summary> - /// Finds a string array of all the assembly files in a path. Used - /// by the UI - /// </summary> - /// <param name="folderPath"></param> - /// <returns></returns> - public static string[] GetAllAssembliesAtPath(string folderPath) - { - ArrayList list = new ArrayList(); - - string[] files = Directory.GetFiles(folderPath, "*dll"); - foreach (string fileName in files) - { - try - { - Assembly assembly = Assembly.LoadFrom(fileName); - list.Add(assembly.GetName().Name); - } - catch (Exception ex) - { - Debug.WriteLine(ex.Message); - } - } - - return (string[]) list.ToArray(typeof (string)); - } - - #endregion - private readonly Assembly _assembly; private readonly string _assemblyName; private bool _lookForPluginFamilies = true; @@ -63,6 +30,7 @@ } catch (Exception ex) { + // TODO: Register error with PluginGraph. Maybe do this at configuration time throw new StructureMapException(101, ex, assemblyName); } } @@ -114,6 +82,7 @@ /// [PluginFamily] /// </summary> /// <returns></returns> + // TODO: Move into the new TypeScanner public PluginFamily[] FindPluginFamilies() { if (_assembly == null || !LookForPluginFamilies) @@ -137,6 +106,7 @@ return list.ToArray(); } + // TODO: Move to TypeScanner private Type[] getExportedTypes() { Type[] exportedTypes; @@ -170,6 +140,8 @@ return _assembly.GetType(fullName, false); } + + // TODO: Move into the new TypeScanner public List<Registry> FindRegistries() { Type[] exportedTypes = getExportedTypes(); Modified: trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -1,3 +1,4 @@ +using System; using System.Collections; using System.Collections.Generic; using System.Reflection; @@ -7,7 +8,7 @@ /// <summary> /// Custom collection for AssemblyGraph's /// </summary> - public class AssemblyGraphCollection : IEnumerable<AssemblyGraph> + [Obsolete("Kill!")] public class AssemblyGraphCollection : IEnumerable<AssemblyGraph> { private Dictionary<string, AssemblyGraph> _assemblies; Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -422,17 +422,26 @@ public void VisitArguments(IPluginArgumentVisitor visitor) { - foreach (ParameterInfo parameter in GetConstructor().GetParameters()) - { - visitMember(parameter.ParameterType, parameter.Name, visitor); - } + VisitConstructorArguments(visitor); + VisitSetterArguments(visitor); + } + private void VisitSetterArguments(IPluginArgumentVisitor visitor) + { foreach (SetterProperty setter in _setters) { visitMember(setter.Property.PropertyType, setter.Property.Name, visitor); } } + private void VisitConstructorArguments(IPluginArgumentVisitor visitor) + { + foreach (ParameterInfo parameter in GetConstructor().GetParameters()) + { + visitMember(parameter.ParameterType, parameter.Name, visitor); + } + } + private static void visitMember(Type type, string name, IPluginArgumentVisitor visitor) { if (TypeIsPrimitive(type)) Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -1,7 +1,5 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Diagnostics; using System.Reflection; using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; @@ -20,11 +18,11 @@ { private readonly AssemblyGraphCollection _assemblies; private readonly InterceptorLibrary _interceptorLibrary = new InterceptorLibrary(); - private readonly PluginFamilyCollection _pluginFamilies; - private bool _sealed = false; - private readonly bool _useExternalRegistries = true; private readonly GraphLog _log = new GraphLog(); + private readonly PluginFamilyCollection _pluginFamilies; private readonly ProfileManager _profileManager = new ProfileManager(); + private readonly bool _useExternalRegistries = true; + private bool _sealed = false; /// <summary> /// Default constructor @@ -171,11 +169,10 @@ } } - public PluginFamily LocateOrCreateFamilyForType(Type pluginType) + public PluginFamily FindFamily(Type pluginType) { buildFamilyIfMissing(pluginType); return PluginFamilies[pluginType]; } - } } \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -20,12 +20,6 @@ private static IInstanceManager _manager; private static string _profile = string.Empty; - - static ObjectFactory() - { - ObjectFactoryCacheCallback callback = new ObjectFactoryCacheCallback(); - } - private static event Notify _notify; /// <summary> Deleted: trunk/Source/StructureMap/ObjectFactoryCacheCallback.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactoryCacheCallback.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/ObjectFactoryCacheCallback.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -1,43 +0,0 @@ -using System; -using StructureMap.Caching; - -namespace StructureMap -{ - internal class ObjectFactoryCacheCallback : IManagedCache - { - public ObjectFactoryCacheCallback() - { - try - { - CacheManager.CurrentManager.WatchFile(StructureMapConfiguration.GetStructureMapConfigurationPath(), this); - } - catch (Exception exception) - { - Console.Write(exception); - } - } - - #region IManagedCache Members - - public string CacheName - { - get { return "ObjectFactory"; } - } - - public void Clear() - { - ObjectFactory.Reset(); - } - - //no-op for interface implementation - public void Prune(DateTime currentTime) - { - } - - public void AddWatches(CacheManager Manager) - { - } - - #endregion - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -136,7 +136,7 @@ public void Read(InstanceMemento memento, PluginGraph graph, Type pluginType) { - PluginFamily family = graph.LocateOrCreateFamilyForType(pluginType); + PluginFamily family = graph.FindFamily(pluginType); Plugin plugin = memento.FindPlugin(family); Modified: trunk/Source/StructureMap/Pipeline/Profile.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Profile.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/Pipeline/Profile.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -64,7 +64,7 @@ foreach (KeyValuePair<Type, Instance> pair in _instances) { - PluginFamily family = graph.LocateOrCreateFamilyForType(pair.Key); + PluginFamily family = graph.FindFamily(pair.Key); Instance masterInstance = ((IDiagnosticInstance) pair.Value).FindMasterInstance(family); master.Add(pair.Key, masterInstance); } Modified: trunk/Source/StructureMap/Source/XmlMementoCreator.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlMementoCreator.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/Source/XmlMementoCreator.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -4,6 +4,7 @@ { public delegate InstanceMemento CreateXmlMementoDelegate(XmlNode node); + // TODO: 3.5, eliminate this with lambdas in ConfigurationParser public class XmlMementoCreator { private readonly string _keyAttribute; Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-05-03 03:24:24 UTC (rev 85) @@ -117,6 +117,7 @@ </Compile> <Compile Include="Configuration\ProfileBuilder.cs" /> <Compile Include="Diagnostics\Tokens.cs" /> + <Compile Include="Emitting\ConstructorEmitter.cs" /> <Compile Include="InstanceBuilderList.cs" /> <Compile Include="InstanceFamily.cs" /> <Compile Include="Pipeline\BuildStrategies.cs" /> @@ -157,69 +158,6 @@ <Compile Include="Attributes\ValidationMethodAttribute.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Caching\CacheItem.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\CacheManager.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\ClearEventDispatcher.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\CloneCacheItem.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\CloneStorageStrategy.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\EagerInstanceCache.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\EventDispatcher.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\Expirations\AbsoluteTimeExpirationPolicy.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\Expirations\SlidingTimeExpirationPolicy.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\FileModificationWatcher.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\ICacheItem.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\IExpirationPolicy.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\IManagedCache.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\IStorageStrategy.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\IValueSource.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\LazyCache.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\PruneEventDispatcher.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\SerializationCacheItem.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\SerializationStorageStrategy.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\SharedCacheItem.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\SharedStorageStrategy.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Configuration\ConfigurationConstants.cs"> <SubType>Code</SubType> </Compile> @@ -246,9 +184,6 @@ <Compile Include="Configuration\NormalGraphBuilder.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Configuration\Problem.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Configuration\ProfileAndMachineParser.cs" /> <Compile Include="Configuration\StructureMapConfigurationSection.cs" /> <Compile Include="Configuration\Mementos\UserControlMemento.cs" /> @@ -362,9 +297,6 @@ <Compile Include="ObjectFactory.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="ObjectFactoryCacheCallback.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="PluginGraphBuilder.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -28,10 +28,9 @@ _document.LoadXml("<PluginFamily />"); _familyElement = _document.DocumentElement; - Type type = typeof (IGateway); - _typePath = new TypePath(type); + thePluginType = typeof (IGateway); - TypePath.WriteTypePathToXmlElement(type, _familyElement); + TypePath.WriteTypePathToXmlElement(thePluginType, _familyElement); } #endregion @@ -40,13 +39,13 @@ private FamilyParser _parser; private XmlDocument _document; private XmlElement _familyElement; - private TypePath _typePath; + private Type thePluginType; [Test] public void ScopeIsBlank() { - _builderMock.Expect("AddPluginFamily", _typePath, string.Empty, InstanceScope.PerRequest); + _builderMock.Expect("AddPluginFamily", thePluginType, string.Empty, InstanceScope.PerRequest); _parser.ParseFamily(_familyElement); @@ -58,7 +57,7 @@ public void ScopeIsBlank2() { _familyElement.SetAttribute(XmlConstants.SCOPE_ATTRIBUTE, ""); - _builderMock.Expect("AddPluginFamily", _typePath, string.Empty, InstanceScope.PerRequest); + _builderMock.Expect("AddPluginFamily", thePluginType, string.Empty, InstanceScope.PerRequest); _parser.ParseFamily(_familyElement); @@ -70,7 +69,7 @@ public void ScopeIsSingleton() { _familyElement.SetAttribute(XmlConstants.SCOPE_ATTRIBUTE, InstanceScope.Singleton.ToString()); - _builderMock.Expect("AddPluginFamily", _typePath, string.Empty, InstanceScope.Singleton); + _builderMock.Expect("AddPluginFamily", thePluginType, string.Empty, InstanceScope.Singleton); _parser.ParseFamily(_familyElement); @@ -82,7 +81,7 @@ public void ScopeIsThreadLocal() { _familyElement.SetAttribute(XmlConstants.SCOPE_ATTRIBUTE, InstanceScope.ThreadLocal.ToString()); - _builderMock.Expect("AddPluginFamily", _typePath, string.Empty, InstanceScope.ThreadLocal); + _builderMock.Expect("AddPluginFamily", thePluginType, string.Empty, InstanceScope.ThreadLocal); _parser.ParseFamily(_familyElement); Modified: trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -24,9 +24,9 @@ MementoSource source2 = new XmlFileMementoSource("IntegratedTest.XML", "Children", "Child"); MementoSource source3 = new XmlFileMementoSource("IntegratedTest.XML", "Parents", "Parent"); - graph.LocateOrCreateFamilyForType(typeof(GrandChild)).AddMementoSource(source1); - graph.LocateOrCreateFamilyForType(typeof(Child)).AddMementoSource(source2); - graph.LocateOrCreateFamilyForType(typeof(Parent)).AddMementoSource(source3); + graph.FindFamily(typeof(GrandChild)).AddMementoSource(source1); + graph.FindFamily(typeof(Child)).AddMementoSource(source2); + graph.FindFamily(typeof(Parent)).AddMementoSource(source3); manager = new InstanceManager(graph); } Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -64,18 +64,5 @@ Assert.AreEqual(type, actualType); } - [Test] - public void GetAllAssembliesAtPath() - { - string[] assemblies = AssemblyGraph.GetAllAssembliesAtPath("."); - ArrayList list = new ArrayList(assemblies); - - Assert.IsTrue(list.Contains("StructureMap.Testing")); - Assert.IsTrue(list.Contains("StructureMap")); - Assert.IsTrue(list.Contains("StructureMap.Testing.Widget")); - Assert.IsTrue(list.Contains("StructureMap.Testing.Widget2")); - Assert.IsTrue(list.Contains("StructureMap.Testing.Widget3")); - Assert.IsTrue(list.Contains("StructureMap.Testing.Widget4")); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -38,10 +38,10 @@ public void CanBuildTheInstance() { NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); - TypePath pluginTypePath = new TypePath(typeof (IGateway)); - builder.AddPluginFamily(pluginTypePath, _memento.InstanceKey, InstanceScope.PerRequest); + Type thePluginType = typeof (IGateway); + builder.AddPluginFamily(thePluginType, _memento.InstanceKey, InstanceScope.PerRequest); - builder.RegisterMemento(pluginTypePath, _memento); + builder.RegisterMemento(thePluginType, _memento); PluginGraph graph = builder.CreatePluginGraph(); InstanceManager manager = new InstanceManager(graph); Modified: trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -3,12 +3,11 @@ using System.Threading; using System.Xml; using NUnit.Framework; -using StructureMap.Caching; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; using IList=System.Collections.IList; -namespace StructureMap.Testing.Caching +namespace StructureMap.Testing { [TestFixture] public class ObjectFactoryTester @@ -19,14 +18,12 @@ public void SetUp() { _event = new ManualResetEvent(false); - _watcher = new FileModificationWatcher("StructureMap.config"); DataMother.WriteDocument("FullTesting.XML"); } #endregion private ManualResetEvent _event; - private FileModificationWatcher _watcher; private void markDone() { Modified: trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -24,7 +24,7 @@ private void addDefaultToPluginFamily<T>(string name) { LiteralInstance instance = new LiteralInstance(null).WithName(name); - PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(typeof (T)); + PluginFamily family = _pluginGraph.FindFamily(typeof (T)); family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; } @@ -32,14 +32,14 @@ private void addDefaultToProfile<T>(string profile, string name) { _manager.SetDefault(profile, typeof (T), new ReferencedInstance(name)); - PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(typeof (T)); + PluginFamily family = _pluginGraph.FindFamily(typeof (T)); family.AddInstance(new LiteralInstance(null).WithName(name)); } private void addDefaultToMachine<T>(string name) { LiteralInstance instance = new LiteralInstance(null).WithName(name); - PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(typeof (T)); + PluginFamily family = _pluginGraph.FindFamily(typeof (T)); family.AddInstance(instance); _manager.SetMachineDefault(typeof (T), new ReferencedInstance(name)); Modified: trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs 2008-05-03 03:24:24 UTC (rev 85) @@ -21,7 +21,7 @@ private void setDefault<T>(string key) { - PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(typeof (T)); + PluginFamily family = _pluginGraph.FindFamily(typeof (T)); family.AddInstance(new LiteralInstance(null).WithName(key)); _profile.SetDefault(typeof(T), new ReferencedInstance(key)); Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-29 04:19:20 UTC (rev 84) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-05-03 03:24:24 UTC (rev 85) @@ -156,18 +156,6 @@ <SubType>Code</SubType> </Compile> <Compile Include="AutoMocking\RhinoAutoMockerTester.cs" /> - <Compile Include="Caching\ExpirationTester.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\FileModificationWatcherTester.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\MockManagedCache.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Caching\StorageAndCacheItemTester.cs"> - <SubType>Code</SubType> - </Compile> <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-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)) - { - return null; - } - - return _profiles[profileName]; - } - - /// <summary> - /// Fetches the named MachineOverride - /// </summary> - /// <param name="machineName"></param> - /// <returns></returns> - public MachineOverride GetMachineOverride(string machineName) - { - if (_machineOverrides.ContainsKey(machineName)) - { - return _machineOverrides[machineName]; - } - else - { - return new MachineOverride(machineName); - } - } - - private Profile findCurrentProfile(string profileName) - { - bool profileNameIsBlank = profileName == string.Empty || profileName == null; - string profileToFind = profileNameIsBlank ? _defaultProfileName : profileName; - - if (_profiles.ContainsKey(profileToFind)) - { - return _profiles[profileToFind]; - } - else - { - return new Profile(profileToFind); - } - } - - /// <summary> - /// Determines the default instance key for each plugin type using machine and/or - /// profile overrides. Used internally by <see cref="ObjectFactory"/> to set instance - /// defaults at runtime - /// </summary> - /// <param name="machineName">The machine (computer) name.</param> - /// <param name="profileName"></param> - /// <returns></returns> - public Profile CalculateDefaults(string machineName, string profileName) - { - Profile answer = new Profile("Defaults"); - MachineOverride machine = GetMachineOverride(machineName); - Profile profile = findCurrentProfile(profileName); - - foreach (InstanceDefault instance in _defaults) - { - answer.AddOverride((InstanceDefault) instance.Clone()); - - // Machine specific override - if (machine.HasOverride(instance.PluginTypeName)) - { - answer.AddOverride(instance.PluginTypeName, machine[instance.PluginTypeName]); - } - - // Profile specific override - if (profile.HasOverride(instance.PluginTypeName)) - { - answer.AddOverride(instance.PluginTypeName, profile[instance.PluginTypeName]); - } - } - - return answer; - } - - public string[] GetMachineNames() - { - string[] names = new string[_machineOverrides.Count]; - int i = 0; - foreach (MachineOverride machine in _machineOverrides.Values) - { - names[i++] = machine.MachineName; - } - - return names; - } - - public string[] GetProfileNames() - { - string[] names = new string[_profiles.Count]; - int i = 0; - foreach (Profile profile in _profiles.Values) - { - names[i++] = profile.ProfileName; - } - - return names; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Graph/MachineOverride.cs =================================================================== --- trunk/Source/StructureMap/Graph/MachineOverride.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/Graph/MachineOverride.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -1,125 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace StructureMap.Graph -{ - /// <summary> - /// Models the machine-level overrides for default instances per plugin type. - /// </summary> - [Serializable] - public class MachineOverride - { - private Dictionary<string, InstanceDefault> _defaults; - private string _machineName; - private Profile _profile = new Profile(string.Empty); - - public MachineOverride(string machineName, Profile profile) - : this(machineName) - { - if (profile != null) - { - _profile = profile; - } - } - - public MachineOverride(string machineName) : base() - { - _machineName = machineName; - _defaults = new Dictionary<string, InstanceDefault>(); - } - - public string MachineName - { - get { return _machineName; } - } - - /// <summary> - /// Finds the default key for a plugin type - /// </summary> - [IndexerName("DefaultKey")] - public string this[string pluginTypeName] - { - get - { - if (_profile.HasOverride(pluginTypeName)) - { - return _profile[pluginTypeName]; - } - else - { - return _defaults[pluginTypeName].DefaultKey; - } - } - } - - /// <summary> - /// If the MachineOverride has a Profile, returns the profile name - /// </summary> - public string ProfileName - { - get { return _profile == null ? string.Empty : _profile.ProfileName; } - } - - - public InstanceDefault[] Defaults - { - get - { - InstanceDefault[] profileDefaults = _profile.Defaults; - Hashtable defaultHash = new Hashtable(); - foreach (InstanceDefault instance in profileDefaults) - { - defaultHash.Add(instance.PluginTypeName, instance); - } - - foreach (InstanceDefault instance in _defaults.Values) - { - if (!defaultHash.ContainsKey(instance.PluginTypeName)) - { - defaultHash.Add(instance.PluginTypeName, instance); - } - } - - InstanceDefault[] returnValue = new InstanceDefault[defaultHash.Count]; - defaultHash.Values.CopyTo(returnValue, 0); - Array.Sort(returnValue); - - return returnValue; - } - } - - - public InstanceDefault[] InnerDefaults - { - get - { - InstanceDefault[] returnValue = new InstanceDefault[_defaults.Count]; - _defaults.Values.CopyTo(returnValue, 0); - return returnValue; - } - } - - /// <summary> - /// Registers an override for the default instance of a certain plugin type. - /// </summary> - /// <param name="pluginTypeName"></param> - /// <param name="defaultKey"></param> - public void AddMachineOverride(string pluginTypeName, string defaultKey) - { - InstanceDefault instanceDefault = new InstanceDefault(pluginTypeName, defaultKey); - _defaults.Add(pluginTypeName, instanceDefault); - } - - /// <summary> - /// Determines if the MachineOverride instance has an overriden default for the plugin type - /// </summary> - /// <param name="pluginTypeName"></param> - /// <returns></returns> - public bool HasOverride(string pluginTypeName) - { - return (_defaults.ContainsKey(pluginTypeName) || _profile.HasOverride(pluginTypeName)); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -267,18 +267,18 @@ #endregion - public Instance[] GetAllInstances() + public void Seal() { - List<Instance> list = new List<Instance>(); foreach (InstanceMemento memento in _mementoList) { Instance instance = memento.ReadInstance(Parent, _pluginType); - list.Add(instance); + _instances.Add(instance); } + } - list.AddRange(_instances); - - return list.ToArray(); + public Instance[] GetAllInstances() + { + return _instances.ToArray(); } public Instance GetInstance(string name) @@ -313,5 +313,7 @@ interceptor.InnerPolicy = _buildPolicy; _buildPolicy = interceptor; } + + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -6,6 +6,7 @@ using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; using StructureMap.Interceptors; +using StructureMap.Pipeline; namespace StructureMap.Graph { @@ -18,12 +19,12 @@ public class PluginGraph { private readonly AssemblyGraphCollection _assemblies; - private readonly InstanceDefaultManager _defaultManager = new InstanceDefaultManager(); private readonly InterceptorLibrary _interceptorLibrary = new InterceptorLibrary(); private readonly PluginFamilyCollection _pluginFamilies; private bool _sealed = false; private readonly bool _useExternalRegistries = true; private readonly GraphLog _log = new GraphLog(); + private readonly ProfileManager _profileManager = new ProfileManager(); /// <summary> /// Default constructor @@ -50,6 +51,10 @@ get { return _pluginFamilies; } } + public ProfileManager ProfileManager + { + get { return _profileManager; } + } public GraphLog Log { @@ -63,11 +68,6 @@ get { return _sealed; } } - public InstanceDefaultManager DefaultManager - { - get { return _defaultManager; } - } - public InterceptorLibrary InterceptorLibrary { get { return _interceptorLibrary; } @@ -100,6 +100,13 @@ family.DiscoverImplicitInstances(); } + foreach (PluginFamily family in _pluginFamilies) + { + family.Seal(); + } + + _profileManager.Seal(this); + _sealed = true; } @@ -154,14 +161,7 @@ return pluginGraph; } - public TypePath LocateOrCreateFamilyForType(string fullName) - { - Type pluginType = findTypeByFullName(fullName); - buildFamilyIfMissing(pluginType); - return new TypePath(pluginType); - } - private void buildFamilyIfMissing(Type pluginType) { if (!_pluginFamilies.Contains(pluginType)) @@ -177,24 +177,5 @@ return PluginFamilies[pluginType]; } - private Type findTypeByFullName(string fullName) - { - foreach (AssemblyGraph assembly in _assemblies) - { - Type type = assembly.FindTypeByFullName(fullName); - if (type != null) - { - return type; - } - } - - throw new StructureMapException(300, fullName); - } - - [Obsolete] - public void ReadDefaults() - { - _defaultManager.ReadDefaultsFromPluginGraph(this); - } } } \ No newline at end of file Deleted: trunk/Source/StructureMap/Graph/Profile.cs =================================================================== --- trunk/Source/StructureMap/Graph/Profile.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/Graph/Profile.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -1,115 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -namespace StructureMap.Graph -{ - /// <summary> - /// A collection of InstanceDefault's overriding the default instances - /// </summary> - [Serializable] - public class Profile - { - private readonly Dictionary<string, InstanceDefault> _defaults; - private string _profileName; - - public Profile(string profileName) - { - _profileName = profileName; - _defaults = new Dictionary<string, InstanceDefault>(); - } - - public string ProfileName - { - get { return _profileName; } - set { _profileName = value; } - } - - [IndexerName("DefaultInstanceKey")] - public string this[string pluginTypeName] - { - get - { - if (_defaults.ContainsKey(pluginTypeName)) - { - return (_defaults[pluginTypeName]).DefaultKey; - } - else - { - return string.Empty; - } - } - } - - public int Count - { - get { return _defaults.Count; } - } - - public InstanceDefault[] Defaults - { - get - { - InstanceDefault[] defaults = getDefaultArray(); - return defaults; - } - } - - - public bool OverridesPluginType(string pluginTypeName) - { - return _defaults.ContainsKey(pluginTypeName); - } - - public void AddOverride(InstanceDefault instanceDefault) - { - if (_defaults.ContainsKey(instanceDefault.PluginTypeName)) - { - _defaults[instanceDefault.PluginTypeName] = instanceDefault; - } - else - { - _defaults.Add(instanceDefault.PluginTypeName, instanceDefault); - } - } - - public void AddOverride(string pluginTypeName, string defaultKey) - { - AddOverride(new InstanceDefault(pluginTypeName, defaultKey)); - } - - public void RemoveOverride(string pluginTypeName) - { - _defaults.Remove(pluginTypeName); - } - - public bool HasOverride(string pluginTypeName) - { - return _defaults.ContainsKey(pluginTypeName); - } - - - private InstanceDefault[] getDefaultArray() - { - InstanceDefault[] defaults = new InstanceDefault[_defaults.Count]; - _defaults.Values.CopyTo(defaults, 0); - return defaults; - } - - public void FilterBlanks() - { - foreach (InstanceDefault instanceDefault in getDefaultArray()) - { - if (instanceDefault.DefaultKey == string.Empty) - { - _defaults.Remove(instanceDefault.PluginTypeName); - } - } - } - - public static string InstanceKeyForProfile(string profileName) - { - return profileName + "-Instance"; - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/TypePath.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypePath.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/Graph/TypePath.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -26,6 +26,18 @@ _assemblyName = type.Assembly.GetName().Name; } + public TypePath(string assemblyQualifiedName) + { + string[] parts = assemblyQualifiedName.Split(','); + if (parts.Length < 2) + { + throw new StructureMapException(107, assemblyQualifiedName); + } + + _className = parts[0].Trim(); + _assemblyName = parts[1].Trim(); + } + public string AssemblyQualifiedName { get { return _className + "," + _assemblyName; } @@ -128,23 +140,5 @@ { return AssemblyQualifiedName; } - - public static TypePath GetTypePath(string name) - { - try - { - Type type = Type.GetType(name); - if (type != null) - { - return new TypePath(type); - } - } - catch (Exception ex) - { - Debug.WriteLine("here!"); - } - - return TypePathForFullName(name); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/IInstanceFactory.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/IInstanceFactory.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -16,11 +16,6 @@ Type PluginType { get; } /// <summary> - /// The InstanceKey of the default instance built by this IInstanceFactory - /// </summary> - string DefaultInstanceKey { get; } - - /// <summary> /// Establishes a reference to the parent InstanceManager /// </summary> /// <param name="instanceManager"></param> @@ -41,25 +36,6 @@ object GetInstance(IConfiguredInstance instance, IInstanceCreator instanceCreator); /// <summary> - /// Creates a new object instance of the default instance memento - /// </summary> - /// <returns></returns> - object GetInstance(); - - /// <summary> - /// Sets the default instance - /// </summary> - /// <param name="InstanceKey"></param> - void SetDefault(string InstanceKey); - - /// <summary> - /// Makes the InstanceMemento the basis of the default instance - /// </summary> - /// <param name="instance"></param> - void SetDefault(Instance instance); - - - /// <summary> /// Returns an IList of all of the configured instances /// </summary> /// <returns></returns> @@ -67,7 +43,8 @@ void AddInstance(Instance instance); Instance AddType<T>(); - Instance GetDefault(); + object ApplyInterception(object rawValue); + object Build(Instance instance); } } \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/IInstanceManager.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -9,7 +9,6 @@ { public interface IInstanceManager { - InstanceDefaultManager DefaultManager { get; } T CreateInstance<T>(string instanceKey); T CreateInstance<T>(); T FillDependencies<T>(); @@ -49,13 +48,6 @@ void SetDefault(Type pluginType, string instanceKey); /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginTypeName"></param> - /// <param name="instanceKey"></param> - void SetDefault(string pluginTypeName, string instanceKey); - - /// <summary> /// Creates a new object instance of the requested type /// </summary> /// <param name="pluginType"></param> Modified: trunk/Source/StructureMap/IPluginGraphSource.cs =================================================================== --- trunk/Source/StructureMap/IPluginGraphSource.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/IPluginGraphSource.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -1,3 +1,4 @@ +using System; using StructureMap.Graph; namespace StructureMap @@ -2,6 +3,4 @@ { - public interface IPluginGraphSource + [Obsolete] public interface IPluginGraphSource { - InstanceDefaultManager DefaultManager { get; } - /// <summary> Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -17,25 +17,9 @@ private readonly Dictionary<string, Instance> _instances = new Dictionary<string, Instance>(); private readonly InstanceInterceptor _interceptor = new NulloInterceptor(); private readonly Type _pluginType; - private Instance _defaultInstance; private InstanceManager _manager = new InstanceManager(); - private IBuildPolicy _policy = new BuildPolicy(); + private readonly IBuildPolicy _policy = new BuildPolicy(); - #region static constructors - - public static InstanceFactory CreateFactoryWithDefault(Type pluginType, object defaultInstance) - { - PluginFamily family = new PluginFamily(pluginType); - InstanceFactory factory = new InstanceFactory(family, true); - - LiteralInstance instance = new LiteralInstance(defaultInstance); - factory.SetDefault(instance); - - return factory; - } - - #endregion - #region constructor functions /// <summary> @@ -62,8 +46,6 @@ { AddInstance(instance); } - - determineDefaultKey(family, failOnException); } catch (StructureMapException) { @@ -75,7 +57,7 @@ } } - private InstanceFactory(Type concreteType) + private InstanceFactory(Type concreteType, ProfileManager profileManager) { _interceptor = new NulloInterceptor(); _pluginType = concreteType; @@ -97,54 +79,16 @@ _instances.Add(instance.Name, instance); - _defaultInstance = instance; + profileManager.SetDefault(concreteType, instance); } } - public static InstanceFactory CreateInstanceFactoryForType(Type concreteType) + public static InstanceFactory CreateInstanceFactoryForType(Type concreteType, ProfileManager profileManager) { - return new InstanceFactory(concreteType); + return new InstanceFactory(concreteType, profileManager); } - private void determineDefaultKey(PluginFamily family, bool failOnException) - { - if (family.DefaultInstanceKey != null && family.DefaultInstanceKey != string.Empty) - { - try - { - SetDefault(family.DefaultInstanceKey); - } - catch (Exception) - { - if (failOnException) - { - throw; - } - } - } - else - { - setDefaultFromAttribute(); - } - } - - private void setDefaultFromAttribute() - { - string defaultKey = PluginFamilyAttribute.GetDefaultKey(PluginType); - if (defaultKey != string.Empty) - { - try - { - SetDefault(defaultKey); - } - catch (Exception ex) - { - throw new StructureMapException(10, ex, defaultKey, PluginType.FullName); - } - } - } - #endregion #region IInstanceFactory Members @@ -181,6 +125,11 @@ Instance instance = _instances[instanceKey]; + return Build(instance); + } + + public object Build(Instance instance) + { return _policy.Build(_manager, PluginType, instance); } @@ -217,61 +166,6 @@ } } - - /// <summary> - /// Builds a new instance of the default instance of the PluginType - /// </summary> - /// <returns></returns> - [Obsolete("Want to remove this eventually")] public object GetInstance() - { - if (_defaultInstance == null) - { - throw new StructureMapException(202, PluginType.FullName); - } - - object builtObject = _policy.Build(_manager, PluginType, _defaultInstance); - return _interceptor.Process(builtObject); - } - - - /// <summary> - /// Sets the default InstanceMemento - /// </summary> - /// <param name="instanceKey"></param> - public void SetDefault(string instanceKey) - { - if (instanceKey == string.Empty || instanceKey == null) - { - _defaultInstance = null; - } - else - { - if (!_instances.ContainsKey(instanceKey)) - { - throw new StructureMapException(215, instanceKey, _pluginType.FullName); - } - - _defaultInstance = _instances[instanceKey]; - } - } - - /// <summary> - /// Sets the default InstanceMemento - /// </summary> - /// <param name="instance"></param> - public void SetDefault(Instance instance) - { - _defaultInstance = instance; - } - - /// <summary> - /// The default instanceKey - /// </summary> - public string DefaultInstanceKey - { - get { return _defaultInstance == null ? string.Empty : _defaultInstance.Name; } - } - public IList GetAllInstances() { IList list = new ArrayList(); @@ -309,17 +203,13 @@ return instance; } - public Instance GetDefault() - { - return _defaultInstance; - } - - public object ApplyInterception(object rawValue) { return _interceptor.Process(rawValue); } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-04-26 01:57:25 UTC (rev 83) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-04-29 04:19:20 UTC (rev 84) @@ -15,11 +15,11 @@ /// </summary> public class InstanceManager : IInstanceManager, IEnumerable, IInstanceCreator { - private readonly InstanceDefaultManager _defaultManager; private readonly Dictionary<Type, IInstanceFactory> _factories; private readonly bool _failOnException = true; private readonly GenericsPluginGraph _genericsGraph; private readonly InterceptorLibrary _interceptorLibrary; + private readonly ProfileManager _profileManager; /// <summary> /// Default constructor @@ -29,6 +29,7 @@ _factories = new Dictionary<Type, IInstanceFactory>(); _genericsGraph = new GenericsPluginGraph(); _interceptorLibrary = new InterceptorLibrary(); + _profileManager = new ProfileManager(); } /// <summary> @@ -50,8 +51,8 @@ public InstanceManager(PluginGraph pluginGraph, bool failOnException) : this() { _failOnException = failOnException; - _defaultManager = pluginGraph.DefaultManager; _interceptorLibrary = pluginGraph.InterceptorLibrary; + _profileManager = pluginGraph.ProfileManager; if (!pluginGraph.IsSealed) { @@ -78,7 +79,7 @@ // Preprocess a GenericType if (pluginType.IsGenericType && !_factories.ContainsKey(pluginType)) { - PluginFamily family = _genericsGraph.CreateTemplatedFamily(pluginType); + PluginFamily family = _genericsGraph.CreateTemplatedFamily(pluginType, _profileManager); return registerPluginFamily(family); } @@ -136,11 +137,6 @@ #region IInstanceManager Members - public InstanceDefaultManager DefaultManager - { - get { return _defaultManager; } - } - public T CreateInstance<T>(string instanceKey) { return (T) CreateInstance(typeof (T), instanceKey); @@ -153,8 +149,9 @@ public PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args) { + // Gotta get the factory first IInstanceFactory factory = getOrCreateFactory(typeof (PLUGINTYPE)); - Instance defaultInstance = factory.GetDefault(); + Instance defaultInstance = _profileManager.GetDefault(typeof (PLUGINTYPE)); ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance); return CreateInstance<PLUGINTYPE>(instance); @@ -196,10 +193,7 @@ public void SetDefaultsToProfile(string profile) { - // The authenticated user may not have required privileges to read from Environment - string machineName = InstanceDefaultManager.GetMachineName(); - Profile defaultProfile = _defaultManager.CalculateDefaults(machineName, profile); - SetDefaults(defaultProfile); + _profileManager.CurrentProfile = profile; } /// <summary> @@ -222,8 +216,17 @@ /// <returns></returns> public object CreateInstance(Type pluginType) { - IInstanceFactory instanceFactory = this[pluginType]; - return instanceFactory.GetInstance(); + // Need to fetch Factory first to make sure that the Type is "known" + IInstanceFactory factory = getOrCreateFactory(pluginType); + + Instance instance = _profileManager.GetDefault(pluginType); + + if (instance == null) + { + throw ... [truncated message content] |
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:57:25 UTC (rev 83) @@ -1,58 +0,0 @@ -using System; -using System.Collections; - -namespace StructureMap.Interceptors -{ - [Pluggable("ThreadLocal")] - public class ThreadLocalStorageInterceptor : CacheInterceptor - { - [ThreadStatic] private static Hashtable _instances = new Hashtable(); - - private static object _lock = new object(); - - public ThreadLocalStorageInterceptor() : base() - { - } - - private void guaranteeHashExists() - { - if (_instances == null) - { - lock (_lock) - { - if (_instances == null) - { - _instances = new Hashtable(); - } - } - } - } - - - private string getKey(string instanceKey) - { - return string.Format("{0}:{1}", InnerInstanceFactory.PluginType.AssemblyQualifiedName, instanceKey); - } - - protected override void cache(string instanceKey, object instance) - { - _instances.Add(getKey(instanceKey), instance); - } - - protected override bool isCached(string instanceKey) - { - guaranteeHashExists(); - return _instances.ContainsKey(getKey(instanceKey)); - } - - protected override object getInstance(string instanceKey) - { - return _instances[getKey(instanceKey)]; - } - - public override object Clone() - { - return MemberwiseClone(); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/BuildStrategies.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -25,6 +25,7 @@ #endregion } + [PluginFamily] public interface IInstanceInterceptor : IBuildPolicy { IBuildPolicy InnerPolicy { get; set; } Modified: trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -3,6 +3,7 @@ namespace StructureMap.Pipeline { + [Pluggable("Singleton")] public class SingletonPolicy : CacheInterceptor { private readonly Dictionary<string, object> _instances = new Dictionary<string, object>(); Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-04-26 01:57:25 UTC (rev 83) @@ -308,9 +308,6 @@ <Compile Include="Graph\InstanceDefaultManager.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Graph\InterceptionChain.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Graph\MachineOverride.cs"> <SubType>Code</SubType> </Compile> @@ -357,37 +354,13 @@ <Compile Include="InstanceMemento.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Interceptors\CacheInterceptor.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Interceptors\CompoundInterceptor.cs" /> <Compile Include="Interceptors\EnrichmentInterceptor.cs" /> - <Compile Include="Interceptors\HttpContextItemInterceptor.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Interceptors\HybridCacheInterceptor.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Interceptors\IInterceptorChainBuilder.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Interceptors\InstanceFactoryInterceptor.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Interceptors\InstanceInterceptor.cs" /> - <Compile Include="Interceptors\InterceptorChainBuilder.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Interceptors\InterceptorLibrary.cs" /> <Compile Include="Interceptors\Interceptors.cs" /> <Compile Include="Interceptors\NulloInterceptor.cs" /> - <Compile Include="Interceptors\SingletonInterceptor.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Interceptors\StartupInterceptor.cs" /> - <Compile Include="Interceptors\ThreadLocalStorageInterceptor.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Interceptors\FilteredInstanceInterceptor.cs" /> <Compile Include="IPluginGraphSource.cs" /> <Compile Include="MementoSource.cs"> Modified: trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -78,7 +78,7 @@ att.Scope = InstanceScope.PerRequest; PluginFamily family = att.BuildPluginFamily(typeof (Target1)); - Assert.AreEqual(0, family.InterceptionChain.Count); + Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy); } [Test] Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -6,6 +6,7 @@ using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Interceptors; +using StructureMap.Pipeline; using StructureMap.Testing.Widget; using StructureMap.Testing.Widget3; @@ -73,7 +74,7 @@ } PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)]; - Assert.IsTrue(family.InterceptionChain.Contains(typeof (ThreadLocalStorageInterceptor))); + Assert.IsInstanceOfType(typeof(ThreadLocalStoragePolicy), family.Policy); } [Test] @@ -101,7 +102,7 @@ } PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)]; - Assert.AreEqual(0, family.InterceptionChain.Count); + Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy); } [Test] @@ -116,7 +117,7 @@ } PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)]; - Assert.IsTrue(family.InterceptionChain.Contains(typeof (SingletonInterceptor))); + Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy); } [Test] @@ -179,9 +180,7 @@ registry.BuildInstancesOf<IGateway>().InterceptConstructionWith(factoryInterceptor); } - InterceptionChain chain = pluginGraph.PluginFamilies[typeof (IGateway)].InterceptionChain; - Assert.AreEqual(1, chain.Count); - Assert.AreSame(factoryInterceptor, chain[0]); + Assert.AreSame(pluginGraph.PluginFamilies[typeof(IGateway)].Policy, factoryInterceptor); } [Test] @@ -215,11 +214,22 @@ } } - public class StubbedInstanceFactoryInterceptor : InstanceFactoryInterceptor + public class StubbedInstanceFactoryInterceptor : IInstanceInterceptor { - public override object Clone() + public IBuildPolicy InnerPolicy { + get { throw new NotImplementedException(); } + set { } + } + + public object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance) + { throw new NotImplementedException(); } + + public IBuildPolicy Clone() + { + throw new NotImplementedException(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -96,27 +96,6 @@ Assert.AreEqual(profileName, defaultManager.Profiles[0].ProfileName); } - [Test] - public void ScopeIsUsedToCreateTheInterceptionChain() - { - InstanceScope theScope = InstanceScope.PerRequest; - InterceptionChain chain = new InterceptionChain(); - DynamicMock builderMock = new DynamicMock(typeof (IInterceptorChainBuilder)); - builderMock.ExpectAndReturn("Build", chain, theScope); - NormalGraphBuilder graphBuilder = - new NormalGraphBuilder((IInterceptorChainBuilder) builderMock.MockInstance, new Registry[0]); - - TypePath typePath = new TypePath(GetType()); - - - graphBuilder.AddPluginFamily(typePath, "something", theScope); - - PluginFamily family = graphBuilder.PluginGraph.PluginFamilies[GetType()]; - - Assert.AreEqual(chain, family.InterceptionChain); - - builderMock.Verify(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -67,21 +67,7 @@ Assert.AreSame(_blue, manager.CreateInstance(typeof (IService), "Blue")); } - [Test] - public void AddInstanceWithInstanceFactoryInterceptor() - { - InstanceFactoryInterceptor interceptor = new FakeInstanceFactoryInterceptor(); - InstanceFactory factory = ObjectMother.Factory<IService>(); - interceptor.InnerInstanceFactory = factory; - - interceptor.AddInstance(new LiteralInstance(_red).WithName("Red")); - interceptor.AddInstance(new LiteralInstance(_blue).WithName("Blue")); - - Assert.AreSame(_red, interceptor.GetInstance("Red")); - Assert.AreSame(_blue, interceptor.GetInstance("Blue")); - } - [Test] public void AddNamedInstanceByType() { @@ -219,12 +205,23 @@ } } - public class FakeInstanceFactoryInterceptor : InstanceFactoryInterceptor + public class FakeInstanceFactoryInterceptor : IInstanceInterceptor { - public override object Clone() + public IBuildPolicy InnerPolicy { + get { throw new NotImplementedException(); } + set { throw new NotImplementedException(); } + } + + public object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance) + { throw new NotImplementedException(); } + + IBuildPolicy IBuildPolicy.Clone() + { + throw new NotImplementedException(); + } } public interface ISomething Modified: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -112,31 +112,9 @@ Assert.AreSame(differentProvider, classThatUsesProvider.Provider); } - [Test] - public void CreatesInterceptionChainOnInstanceFactory() - { - // Create a PluginFamily with one Interceptor in the InterceptionChain of the Family - PluginFamily family = new PluginFamily(typeof (Rule)); - SingletonInterceptor interceptor = new SingletonInterceptor(); - family.InterceptionChain.AddInterceptor(interceptor); - // Create a PluginGraph with the PluginFamily - PluginGraph pluginGraph = new PluginGraph(); - pluginGraph.Assemblies.Add("StructureMap.Testing.Widget"); - pluginGraph.PluginFamilies.Add(family); - pluginGraph.Seal(); - // Create an InstanceManager and examine the InstanceFactory for the PluginFamily - InstanceManager instanceManager = new InstanceManager(pluginGraph); - IInstanceFactory wrappedFactory = instanceManager[typeof (Rule)]; - Assert.AreSame(interceptor, wrappedFactory); - - InstanceFactory factory = (InstanceFactory) interceptor.InnerInstanceFactory; - Assert.AreEqual(typeof (Rule), factory.PluginType); - } - - [Test] public void FindAPluginFamilyForAGenericTypeFromPluginTypeName() { Deleted: trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -1,39 +0,0 @@ -using System; -using NUnit.Framework; -using StructureMap.Attributes; -using StructureMap.Graph; -using StructureMap.Interceptors; - -namespace StructureMap.Testing.Container.Interceptors -{ - [TestFixture] - public class InteceptorChainBuilderTester - { - private InterceptorChainBuilder builder = new InterceptorChainBuilder(); - - private void assertScopeLeadsToInterceptor(InstanceScope scope, Type interceptorType) - { - InterceptionChain chain = builder.Build(scope); - Assert.AreEqual(1, chain.Count); - Type actualType = chain[0].GetType(); - Assert.IsTrue(actualType.Equals(interceptorType)); - } - - [Test] - public void PerInstanceMeansNoInterceptors() - { - InterceptionChain chain = builder.Build(InstanceScope.PerRequest); - Assert.AreEqual(0, chain.Count); - } - - - [Test] - public void ScopeToInterceptorTypes() - { - assertScopeLeadsToInterceptor(InstanceScope.HttpContext, typeof (HttpContextItemInterceptor)); - assertScopeLeadsToInterceptor(InstanceScope.Hybrid, typeof (HybridCacheInterceptor)); - assertScopeLeadsToInterceptor(InstanceScope.Singleton, typeof (SingletonInterceptor)); - assertScopeLeadsToInterceptor(InstanceScope.ThreadLocal, typeof (ThreadLocalStorageInterceptor)); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -1,60 +0,0 @@ -using NUnit.Framework; -using StructureMap.Graph; -using StructureMap.Interceptors; -using StructureMap.Testing.Widget; - -namespace StructureMap.Testing.Container.Interceptors -{ - [TestFixture] - public class SingletonInterceptorTester - { - // "Red", "Blue", "Bigger" are the possible rule choices - - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule)); - InstanceFactory factory = new InstanceFactory(family, true); - factory.SetInstanceManager(new InstanceManager()); - - _interceptor = new SingletonInterceptor(); - _interceptor.InnerInstanceFactory = factory; - } - - #endregion - - private SingletonInterceptor _interceptor; - - [Test] - public void CanSetDefaultAndGetTheDefaultInstance() - { - _interceptor.SetDefault("Red"); - Assert.AreEqual("Red", _interceptor.DefaultInstanceKey); - - ColorRule rule1 = (ColorRule) _interceptor.GetInstance(); - Assert.AreEqual("Red", rule1.Color); - - // Fetch the rule 2 more times. Verify that it is the same object - ColorRule rule2 = (ColorRule) _interceptor.GetInstance(); - ColorRule rule3 = (ColorRule) _interceptor.GetInstance(); - - Assert.AreSame(rule1, rule2); - Assert.AreSame(rule1, rule3); - } - - [Test] - public void GetsTheSameNamedInstance() - { - ColorRule rule1 = (ColorRule) _interceptor.GetInstance("Blue"); - - // Fetch the rule 2 more times. Verify that it is the same object - ColorRule rule2 = (ColorRule) _interceptor.GetInstance("Blue"); - ColorRule rule3 = (ColorRule) _interceptor.GetInstance("Blue"); - - Assert.AreSame(rule1, rule2); - Assert.AreSame(rule1, rule3); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -1,86 +0,0 @@ -using System.Threading; -using NUnit.Framework; -using StructureMap.Graph; -using StructureMap.Interceptors; -using StructureMap.Testing.Widget; - -namespace StructureMap.Testing.Container.Interceptors -{ - [TestFixture] - public class ThreadLocalStorageInterceptorTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule)); - InstanceFactory factory = new InstanceFactory(family, true); - factory.SetInstanceManager(new InstanceManager()); - - _interceptor = new ThreadLocalStorageInterceptor(); - _interceptor.InnerInstanceFactory = factory; - } - - #endregion - - private ThreadLocalStorageInterceptor _interceptor; - private ColorRule _rule1; - private ColorRule _rule2; - private ColorRule _rule3; - - - private void findRule1() - { - _rule1 = (ColorRule) _interceptor.GetInstance(); - - ColorRule rule = (ColorRule) _interceptor.GetInstance(); - Assert.AreSame(_rule1, rule); - } - - private void findRule2() - { - _rule2 = (ColorRule) _interceptor.GetInstance(); - - ColorRule rule = (ColorRule) _interceptor.GetInstance(); - Assert.AreSame(_rule2, rule); - } - - private void findRule3() - { - _rule3 = (ColorRule) _interceptor.GetInstance(); - - ColorRule rule = (ColorRule) _interceptor.GetInstance(); - Assert.AreSame(_rule3, rule); - - rule = (ColorRule) _interceptor.GetInstance(); - Assert.AreSame(_rule3, rule); - - rule = (ColorRule) _interceptor.GetInstance(); - Assert.AreSame(_rule3, rule); - - rule = (ColorRule) _interceptor.GetInstance(); - Assert.AreSame(_rule3, rule); - } - - [Test] - public void FindUniqueInstancePerThread() - { - Thread t1 = new Thread(new ThreadStart(findRule1)); - Thread t2 = new Thread(new ThreadStart(findRule2)); - Thread t3 = new Thread(new ThreadStart(findRule3)); - - t1.Start(); - t2.Start(); - t3.Start(); - - t1.Join(); - t2.Join(); - t3.Join(); - - Assert.IsTrue(_rule1.ID != _rule2.ID); - Assert.IsTrue(_rule1.ID != _rule3.ID); - Assert.IsTrue(_rule2.ID != _rule3.ID); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -45,14 +45,12 @@ PluginGraph pluginGraph = DataMother.GetDiagnosticPluginGraph("SingletonIntercepterTest.xml"); PluginFamily family = pluginGraph.PluginFamilies[typeof (Rule)]; + Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy); - Assert.AreEqual(1, family.InterceptionChain.Count); - Assert.IsTrue(family.InterceptionChain[0] is SingletonInterceptor); - // The PluginFamily for IWidget has no intercepters configured PluginFamily widgetFamily = pluginGraph.PluginFamilies[typeof (IWidget)]; - Assert.AreEqual(0, widgetFamily.InterceptionChain.Count); - } + Assert.IsInstanceOfType(typeof(BuildPolicy), widgetFamily.Policy); + } [Test] public void CanDefinedSourceBuildMemento() @@ -197,21 +195,7 @@ Assert.AreEqual("Green", defaultManager.DefaultProfileName); } - [Test] - public void ReadScopeFromXmlConfiguration() - { - PluginGraph pluginGraph = DataMother.GetDiagnosticPluginGraph("ScopeInFamily.xml"); - PluginFamily family = pluginGraph.PluginFamilies[typeof (Column)]; - Assert.AreEqual(1, family.InterceptionChain.Count); - Assert.IsTrue(family.InterceptionChain[0] is ThreadLocalStorageInterceptor); - - // The PluginFamily for IWidget has no intercepters configured - PluginFamily widgetFamily = pluginGraph.PluginFamilies[typeof (IWidget)]; - Assert.AreEqual(1, widgetFamily.InterceptionChain.Count); - Assert.IsTrue(widgetFamily.InterceptionChain[0] is HttpContextItemInterceptor); - } - [Test] public void SetsTheDefaultInstanceKey() { Deleted: trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -1,80 +0,0 @@ -using NUnit.Framework; -using StructureMap.Graph; -using StructureMap.Interceptors; -using StructureMap.Testing.Widget; - -namespace StructureMap.Testing.Graph -{ - [TestFixture] - public class InterceptionChainTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - _singleton1 = new SingletonInterceptor(); - _singleton2 = new SingletonInterceptor(); - - _chain = new InterceptionChain(); - _chain.AddInterceptor(_singleton1); - _chain.AddInterceptor(_singleton2); - } - - #endregion - - private InterceptionChain _chain; - private SingletonInterceptor _singleton1; - private SingletonInterceptor _singleton2; - - [Test] - public void CreateInterceptionChainWithNoIntercepters() - { - InterceptionChain chain = new InterceptionChain(); - PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule)); - InstanceFactory factory = new InstanceFactory(family, true); - - IInstanceFactory wrappedFactory = chain.WrapInstanceFactory(factory); - - Assert.AreSame(factory, wrappedFactory); - } - - [Test] - public void CreateInterceptionChainWithOneIntercepter() - { - InterceptionChain chain = new InterceptionChain(); - chain.AddInterceptor(_singleton1); - - PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule)); - InstanceFactory factory = new InstanceFactory(family, true); - - IInstanceFactory wrappedFactory = chain.WrapInstanceFactory(factory); - Assert.AreSame(_singleton1, wrappedFactory); - Assert.AreSame(factory, _singleton1.InnerInstanceFactory); - } - - [Test] - public void CreateInterceptionChainWithTwoInterceptors() - { - PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule)); - InstanceFactory factory = new InstanceFactory(family, true); - - IInstanceFactory wrappedFactory = _chain.WrapInstanceFactory(factory); - - Assert.IsNotNull(wrappedFactory); - - // Cast exception if wrappedFactory is not a Singleton - SingletonInterceptor singletonWrapper = (SingletonInterceptor) wrappedFactory; - - Assert.AreSame(_singleton1, singletonWrapper); - Assert.AreSame(_singleton2, _singleton1.InnerInstanceFactory); - Assert.AreSame(factory, _singleton2.InnerInstanceFactory); - } - - [Test] - public void tryIt() - { - ObjectMother.Reset(); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-04-26 01:57:25 UTC (rev 83) @@ -72,13 +72,10 @@ public void ImplicitPluginFamilyCreatesASingletonInterceptorWhenIsSingletonIsTrue() { PluginFamily family = new PluginFamily(typeof (ISingletonRepository)); - Assert.AreEqual(1, family.InterceptionChain.Count); + Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy); - InstanceFactoryInterceptor interceptor = family.InterceptionChain[0]; - Assert.IsTrue(interceptor is SingletonInterceptor); - PluginFamily family2 = new PluginFamily(typeof (IDevice)); - Assert.AreEqual(0, family2.InterceptionChain.Count); + Assert.IsInstanceOfType(typeof(BuildPolicy), family2.Policy); } [Test] Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-25 18:02:44 UTC (rev 82) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-26 01:57:25 UTC (rev 83) @@ -235,17 +235,8 @@ <SubType>Code</SubType> </Compile> <Compile Include="Container\Interceptors\CompoundInterceptorTester.cs" /> - <Compile Include="Container\Interceptors\InteceptorChainBuilderTester.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Container\Interceptors\InterceptorLibraryTester.cs" /> <Compile Include="Container\Interceptors\MockTypeInterceptor.cs" /> - <Compile Include="Container\Interceptors\SingletonInterceptorTester.cs"> - <SubType>Code</SubType> - </Compile> - <Compile Include="Container\Interceptors\ThreadLocalStorageInterceptorTester.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Container\Interceptors\TypeInterceptionTester.cs" /> <Compile Include="Container\MockingTester.cs"> <SubType>Code</SubType> @@ -325,9 +316,6 @@ <Compile Include="Graph\InstanceTarget.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Graph\InterceptionChainTester.cs"> - <SubType>Code</SubType> - </Compile> <Compile Include="Graph\OverrideGraphTester.cs"> <SubType>Code</SubType> </Compile> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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-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(_pluginType, _manager); + object builtObject = _policy.Build(_manager, PluginType, _defaultInstance); return _interceptor.Process(builtObject); } @@ -315,10 +269,7 @@ /// </summary> public string DefaultInstanceKey { - get - { - return _defaultInstance == null ? string.Empty : _defaultInstance.Name; - } + get { return _defaultInstance == null ? string.Empty : _defaultInstance.Name; } } public IList GetAllInstances() @@ -327,7 +278,7 @@ foreach (KeyValuePair<string, Instance> pair in _instances) { - object instance = pair.Value.Build(_pluginType, _manager); + object instance = _policy.Build(_manager, PluginType, pair.Value); list.Add(instance); } @@ -353,8 +304,8 @@ ConfiguredInstance instance = new ConfiguredInstance(); instance.ConcreteKey = builder.ConcreteTypeKey; instance.Name = instance.ConcreteKey; - + return instance; } @@ -370,6 +321,5 @@ } #endregion - } } \ No newline at end of file Added: trunk/Source/StructureMap/InstanceFamily.cs =================================================================== --- trunk/Source/StructureMap/InstanceFamily.cs (rev 0) +++ trunk/Source/StructureMap/InstanceFamily.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap +{ + public class InstanceFamily + { + + } +} Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -27,19 +27,7 @@ get { return innerConcreteKey; } } - [Obsolete] public InstanceBuilder FindBuilder(InstanceBuilderList builders) - { - if (string.IsNullOrEmpty(innerConcreteKey)) - { - string pluggedTypeName = getPluggedType(); - Type pluggedType = TypePath.GetTypePath(pluggedTypeName).FindType(); - return builders.FindByType(pluggedType); - } - - return builders.FindByConcreteKey(innerConcreteKey); - } - public virtual Plugin FindPlugin(PluginFamily family) { if (string.IsNullOrEmpty(innerConcreteKey)) @@ -97,14 +85,6 @@ } /// <summary> - /// Returns the last key/value retrieved for exception tracing - /// </summary> - public string LastKey - { - get { return _lastKey; } - } - - /// <summary> /// Template pattern property specifying whether the InstanceMemento is simply a reference /// to another named instance. Useful for child objects. /// </summary> @@ -216,37 +196,8 @@ //return returnValue; } - private static object buildDefaultChild(string key, StructureMap.Pipeline.IInstanceCreator manager, string typeName) - { - object returnValue; - try - { - returnValue = manager.CreateInstance(typeName); - } - catch (StructureMapException) - { - throw; - } - catch (Exception ex) - { - throw new StructureMapException(209, ex, key, typeName); - } - return returnValue; - } - /// <summary> - /// Not used yet. - /// </summary> - /// <param name="Key"></param> - /// <returns></returns> - public string[] GetStringArray(string Key) - { - string _value = GetProperty(Key); - return _value.Split(new char[] {','}); - } - - /// <summary> /// This method is made public for testing. It is not necessary for normal usage. /// </summary> /// <returns></returns> @@ -276,6 +227,7 @@ { Instance instance = readInstance(pluginGraph, pluginType); instance.Name = InstanceKey; + instance.PluginType = pluginType; return instance; } Modified: trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -1,3 +1,4 @@ +using System; using StructureMap.Attributes; using StructureMap.Graph; @@ -3,6 +4,8 @@ namespace StructureMap.Interceptors { + [Obsolete] public interface IInterceptorChainBuilder { + [Obsolete] InterceptionChain Build(InstanceScope scope); } Modified: trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -1,3 +1,4 @@ +using System; using StructureMap.Attributes; using StructureMap.Graph; @@ -3,4 +4,5 @@ namespace StructureMap.Interceptors { + [Obsolete] public class InterceptorChainBuilder : IInterceptorChainBuilder { @@ -11,6 +13,7 @@ #region IInterceptorChainBuilder Members + [Obsolete] public InterceptionChain Build(InstanceScope scope) { InterceptionChain returnValue = new InterceptionChain(); Added: trunk/Source/StructureMap/Pipeline/BuildStrategies.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildStrategies.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,116 @@ +using System; + +namespace StructureMap.Pipeline +{ + public interface IBuildPolicy + { + object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance); + IBuildPolicy Clone(); + } + + public class BuildPolicy : IBuildPolicy + { + #region IBuildPolicy Members + + public object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance) + { + return instance.Build(pluginType, instanceCreator); + } + + public IBuildPolicy Clone() + { + return this; + } + + #endregion + } + + public interface IInstanceInterceptor : IBuildPolicy + { + IBuildPolicy InnerPolicy { get; set; } + } + + public abstract class CacheInterceptor : IInstanceInterceptor + { + private readonly object _locker = new object(); + private IBuildPolicy _innerPolicy = new BuildPolicy(); + + #region IInstanceInterceptor Members + + public IBuildPolicy InnerPolicy + { + get { return _innerPolicy; } + set { _innerPolicy = value; } + } + + + public object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance) + { + if (!isCached(instance.Name, instance.PluginType)) + { + lock (_locker) + { + if (!isCached(instance.Name, pluginType)) + { + object returnValue = _innerPolicy.Build(instanceCreator, pluginType, instance); + storeInCache(instance.Name, pluginType, returnValue); + } + } + } + + return retrieveFromCache(instance.Name, pluginType); + } + + public IBuildPolicy Clone() + { + CacheInterceptor clonedCache = clone(); + clonedCache.InnerPolicy = _innerPolicy.Clone(); + + return clonedCache; + } + + protected abstract CacheInterceptor clone(); + + #endregion + + protected abstract void storeInCache(string instanceKey, Type pluginType, object instance); + protected abstract bool isCached(string instanceKey, Type pluginType); + protected abstract object retrieveFromCache(string instanceKey, Type pluginType); + } + + public class HybridBuildPolicy : IInstanceInterceptor + { + private readonly IInstanceInterceptor _innerInterceptor; + + + public HybridBuildPolicy() + { + _innerInterceptor = HttpContextBuildPolicy.HasContext() + ? (IInstanceInterceptor) new HttpContextBuildPolicy() + : new ThreadLocalStoragePolicy(); + } + + #region IInstanceInterceptor Members + + public IBuildPolicy InnerPolicy + { + get { return _innerInterceptor.InnerPolicy; } + set { _innerInterceptor.InnerPolicy = value; } + } + + public object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance) + { + return _innerInterceptor.Build(instanceCreator, pluginType, instance); + } + + public IBuildPolicy Clone() + { + HybridBuildPolicy policy = new HybridBuildPolicy(); + policy.InnerPolicy = InnerPolicy.Clone(); + + return policy; + } + + #endregion + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -73,10 +73,8 @@ return _properties[propertyName]; } - object IConfiguredInstance.GetChild(string propertyName, string typeName, IInstanceCreator instanceCreator) + object IConfiguredInstance.GetChild(string propertyName, Type pluginType, IInstanceCreator instanceCreator) { - Type pluginType = Type.GetType(typeName); - return getChild(propertyName, pluginType, instanceCreator); } Added: trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,38 @@ +using System; +using System.Web; + +namespace StructureMap.Pipeline +{ + public class HttpContextBuildPolicy : CacheInterceptor + { + public static bool HasContext() + { + return HttpContext.Current != null; + } + + protected override void storeInCache(string instanceKey, Type pluginType, object instance) + { + HttpContext.Current.Items.Add(getKey(instanceKey, pluginType), instance); + } + + protected override bool isCached(string instanceKey, Type pluginType) + { + return HttpContext.Current.Items.Contains(getKey(instanceKey, pluginType)); + } + + protected override object retrieveFromCache(string instanceKey, Type pluginType) + { + return HttpContext.Current.Items[getKey(instanceKey, pluginType)]; + } + + private static string getKey(string instanceKey, Type pluginType) + { + return string.Format("{0}:{1}", pluginType.AssemblyQualifiedName, instanceKey); + } + + protected override CacheInterceptor clone() + { + return this; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -1,3 +1,5 @@ +using System; + namespace StructureMap.Pipeline { public interface IConfiguredInstance @@ -4,7 +6,7 @@ { Instance[] GetChildrenArray(string propertyName); string GetProperty(string propertyName); - object GetChild(string propertyName, string typeName, IInstanceCreator instanceCreator); + object GetChild(string propertyName, Type pluginType, IInstanceCreator instanceCreator); InstanceBuilder FindBuilder(InstanceBuilderList builders); string ConcreteKey Added: trunk/Source/StructureMap/Pipeline/ILocationPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ILocationPolicy.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ILocationPolicy.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap.Pipeline +{ + public interface ILocationPolicy + { + object Build(IInstanceCreator creator, Instance instance); + } + + //public class DefaultPolicy : ILocationPolicy + //{ + // public object Build(IInstanceCreator creator, Instance instance) + // { + // return instance.Build(creator); + // } + //} +} Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -1,6 +1,7 @@ using System; using System.Data; using System.Web.UI; +using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Interceptors; @@ -26,6 +27,7 @@ { private string _name = Guid.NewGuid().ToString(); private InstanceInterceptor _interceptor = new NulloInterceptor(); + private Type _pluginType = typeof(object); public string Name { @@ -39,6 +41,13 @@ set { _interceptor = value; } } + internal Type PluginType + { + get { return _pluginType; } + set { _pluginType = value; } + } + + // TODO : remove pluginType from signature public virtual object Build(Type pluginType, IInstanceCreator creator) { object rawValue = build(pluginType, creator); @@ -69,6 +78,11 @@ { return true; } + + public InstanceToken CreateToken() + { + throw new NotImplementedException(); + } } public abstract class ExpressedInstance<T> : Instance Added: trunk/Source/StructureMap/Pipeline/Profile.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Profile.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/Profile.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap.Pipeline +{ + //public class Profile + //{ + // private readonly Dictionary<Type, Instance> _instances = new Dictionary<Type, Instance>(); + + + //} +} Added: trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; + +namespace StructureMap.Pipeline +{ + public class SingletonPolicy : CacheInterceptor + { + private readonly Dictionary<string, object> _instances = new Dictionary<string, object>(); + + protected override void storeInCache(string instanceKey, Type pluginType, object instance) + { + _instances.Add(instanceKey, instance); + } + + protected override bool isCached(string instanceKey, Type pluginType) + { + return _instances.ContainsKey(instanceKey); + } + + protected override object retrieveFromCache(string instanceKey, Type pluginType) + { + return _instances[instanceKey]; + } + + protected override CacheInterceptor clone() + { + return new SingletonPolicy(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; + +namespace StructureMap.Pipeline +{ + public class ThreadLocalStoragePolicy : CacheInterceptor + { + [ThreadStatic] + private static Dictionary<string, object> _instances; + private object _locker = new object(); + + private void guaranteeHashExists() + { + if (_instances == null) + { + lock (_locker) + { + if (_instances == null) + { + _instances = new Dictionary<string, object>(); + } + } + } + } + + protected override void storeInCache(string instanceKey, Type pluginType, object instance) + { + _instances.Add(getKey(instanceKey, pluginType), instance); + } + + protected override bool isCached(string instanceKey, Type pluginType) + { + guaranteeHashExists(); + return _instances.ContainsKey(getKey(instanceKey, pluginType)); + } + + protected override object retrieveFromCache(string instanceKey, Type pluginType) + { + return _instances[getKey(instanceKey, pluginType)]; + } + + private string getKey(string instanceKey, Type pluginType) + { + return string.Format("{0}:{1}", pluginType.AssemblyQualifiedName, instanceKey); + } + + protected override CacheInterceptor clone() + { + return this; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-04-25 17:26:13 UTC (rev 81) @@ -115,16 +115,24 @@ <Link>CommonAssemblyInfo.cs</Link> <SubType>Code</SubType> </Compile> + <Compile Include="Diagnostics\Tokens.cs" /> <Compile Include="InstanceBuilderList.cs" /> + <Compile Include="InstanceFamily.cs" /> + <Compile Include="Pipeline\BuildStrategies.cs" /> <Compile Include="Pipeline\ConfiguredInstance.cs" /> <Compile Include="Pipeline\ConstructorInstance.cs" /> <Compile Include="Pipeline\DefaultInstance.cs" /> + <Compile Include="Pipeline\HttpContextBuildPolicy.cs" /> <Compile Include="Pipeline\IConfiguredInstance.cs" /> + <Compile Include="Pipeline\ILocationPolicy.cs" /> <Compile Include="Pipeline\Instance.cs" /> <Compile Include="Pipeline\InstanceMementoPropertyReader.cs" /> <Compile Include="Pipeline\LiteralInstance.cs" /> + <Compile Include="Pipeline\Profile.cs" /> <Compile Include="Pipeline\PrototypeInstance.cs" /> <Compile Include="Pipeline\ReferencedInstance.cs" /> + <Compile Include="Pipeline\SingletonPolicy.cs" /> + <Compile Include="Pipeline\ThreadLocalStoragePolicy.cs" /> <Compile Include="Pipeline\UserControlInstance.cs" /> <Compile Include="Properties\AssemblyInfo.cs"> <SubType>Code</SubType> @@ -443,9 +451,6 @@ <SubType>Code</SubType> </Compile> <Compile Include="StructureMapConfiguration.cs" /> - <Compile Include="XmlMapping\ConfigEditor.cs"> - <SubType>Code</SubType> - </Compile> <EmbeddedResource Include="StructureMapException.resx"> <SubType>Designer</SubType> </EmbeddedResource> Modified: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -71,10 +71,7 @@ Assert.IsEmpty(machine.ProfileName); } - [Test, - ExpectedException(typeof (StructureMapException), - ExpectedMessage = "StructureMap Exception Code: 195\nThe Profile some profile referenced by Machine some machine does not exist" - )] + [Test] public void AddMachineWithProfileThatDoesNotExist() { NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]); @@ -82,6 +79,8 @@ string theProfileName = "some profile"; graphBuilder.AddMachine(theMachineName, theProfileName); + + graphBuilder.CreatePluginGraph().Log.AssertHasError(195, "The Profile some profile referenced by Machine some machine does not exist"); } [Test] Modified: trunk/Source/StructureMap.Testing/Container/EmittingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -128,11 +128,6 @@ } } - [Test] - public void PluginType() - { - Assert.AreEqual("StructureMap.Testing.Widget.Rule,StructureMap.Testing.Widget", builder.PluginType); - } [Test] public void String2Property() Modified: trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs =================================================================== --- trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -1,4 +1,6 @@ +using System; using System.Diagnostics; +using System.Reflection; using NUnit.Framework; using StructureMap.DataAccess; using StructureMap.DataAccess.MSSQL; @@ -24,5 +26,17 @@ Debug.WriteLine(json); } + + [Test] + public void TryingOutTypeMethod() + { + foreach (MethodInfo info in typeof(Type).GetMethods()) + { + Debug.WriteLine(info.Name); + } + + MethodInfo method = typeof(Type).GetMethod("GetTypeFromHandle"); + Assert.IsNotNull(method); + } } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,62 @@ +using NUnit.Framework; +using StructureMap.Pipeline; +using StructureMap.Testing.Widget3; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class BuildStrategiesTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + } + + #endregion + + [Test] + public void Singleton_build_policy() + { + SingletonPolicy policy = new SingletonPolicy(); + ConstructorInstance instance1 = new ConstructorInstance(delegate { return new ColorService("Red"); }).WithName("Red"); + ConstructorInstance instance2 = new ConstructorInstance(delegate { return new ColorService("Green"); }).WithName("Green"); + + ColorService red1 = (ColorService) policy.Build(new StubInstanceCreator(), null, instance1); + ColorService green1 = (ColorService)policy.Build(new StubInstanceCreator(), null, instance2); + ColorService red2 = (ColorService)policy.Build(new StubInstanceCreator(), null, instance1); + ColorService green2 = (ColorService)policy.Build(new StubInstanceCreator(), null, instance2); + ColorService red3 = (ColorService)policy.Build(new StubInstanceCreator(), null, instance1); + ColorService green3 = (ColorService)policy.Build(new StubInstanceCreator(), null, instance2); + + Assert.AreSame(red1, red2); + Assert.AreSame(red1, red3); + Assert.AreSame(green1, green2); + Assert.AreSame(green1, green3); + } + + [Test] + public void CloneSingleton() + { + SingletonPolicy policy = new SingletonPolicy(); + + SingletonPolicy clone = (SingletonPolicy) policy.Clone(); + Assert.AreNotSame(policy, clone); + Assert.IsInstanceOfType(typeof(BuildPolicy), clone.InnerPolicy); + } + + [Test] + public void CloneHybrid() + { + HybridBuildPolicy policy = new HybridBuildPolicy(); + + HybridBuildPolicy clone = (HybridBuildPolicy)policy.Clone(); + Assert.AreNotSame(policy, clone); + Assert.IsInstanceOfType(typeof(BuildPolicy), clone.InnerPolicy); + } + + + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-12 13:45:08 UTC (rev 80) +++ trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -1,6 +1,7 @@ using System; using NUnit.Framework; using Rhino.Mocks; +using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; @@ -43,6 +44,8 @@ Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build(typeof (object), instanceCreator)); } } + + } public class InstanceUnderTest : Instance Added: trunk/Source/StructureMap.Testing/Pipeline/ThreadLocalStoragePolicyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ThreadLocalStoragePolicyTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/ThreadLocalStoragePolicyTester.cs 2008-04-25 17:26:13 UTC (rev 81) @@ -0,0 +1,87 @@ +using System.Threading; +using NUnit.Framework; +using StructureMap.Pipeline; +using StructureMap.Testing.Widget; +using StructureMap.Testing.Widget3; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class ThreadLocalStoragePolicyTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + _policy = new ThreadLocalStoragePolicy(); + _instance = new ConstructorInstance(delegate() { return new ColorRule("Red"); }).WithName("Red"); + + } + + #endregion + + private ThreadLocalStoragePolicy _policy; + private ColorRule _rule1; + private ColorRule _rule2; + private ColorRule _rule3; + private ConstructorInstance _instance; + + + private void findRule1() + { + _rule1 = (ColorRule) _policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + + ColorRule rule = (ColorRule)_policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + Assert.AreSame(_rule1, rule); + } + + private void findRule2() + { + _rule2 = (ColorRule)_policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + + ColorRule rule = (ColorRule)_policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + Assert.AreSame(_rule2, rule); + } + + private void findRule3() + { + _rule3 = (ColorRule)_policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + + ColorRule rule = (ColorRule)_policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + Assert.AreSame(_rule3, rule); + + rule = (ColorRule)_policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + Assert.AreSame(_rule3, rule); + + rule = (ColorRule)_policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + Assert.AreSame(_rule3, rule); + + rule = (ColorRule)_policy.Build(new StubInstanceCreator(), typeof(IService), _instance); + Assert.AreSame(_rule3, rule); + } + + [Test] + public void FindUniqueInstancePerThread() + { + Thread t1 = new Thread(new ThreadStart(findRule1)); + Thread t2 = new Thread(new ThreadStart(findRule2)); + Thread t3 = new Thread(new ThreadStart(findRule3)); + + t1.Start(); + t2.Start(); + t3.Start(); + + t1.Join(); + t2.Join(); + t3.Join(); + + Assert.AreNotSame(_rule1, _rule2); + Assert.AreNotSame(_rule1, _rule3); + Assert.AreNotSame(_rule2, _rule3); + Assert.IsTrue(_rule1.ID != _rule2.ID); + Assert.IsTrue(_rule1.ID != _rule3.ID); + Assert.IsTrue(_rule2.ID != _rule3.ID); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/St... [truncated message content] |
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 - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,45 +0,0 @@ -using System; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Configuration.Mementos; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - public class ReferenceMementoBuilder : IMementoBuilder - { - private InstanceMemento _memento; - - public ReferenceMementoBuilder(string referenceKey) - { - _memento = MemoryInstanceMemento.CreateReferencedInstanceMemento(referenceKey); - } - - #region IMementoBuilder Members - - InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family) - { - return _memento; - } - - InstanceMemento IMementoBuilder.BuildMemento(PluginGraph graph) - { - return _memento; - } - - void IMementoBuilder.SetInstanceName(string instanceKey) - { - } - - void IMementoBuilder.ValidatePluggability(Type pluginType) - { - } - - - void IExpression.Configure(PluginGraph graph) - { - // no-op; - } - - #endregion - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,68 +0,0 @@ -using System; - -namespace StructureMap.Configuration.Mementos -{ - public class ExplicitArgumentMemento : InstanceMemento - { - private readonly ExplicitArguments _args; - private InstanceMemento _inner; - - public ExplicitArgumentMemento(ExplicitArguments args, InstanceMemento inner) - { - _args = args; - _inner = inner; - } - - - protected override string innerConcreteKey - { - get { return _inner.ConcreteKey; } - } - - protected override string innerInstanceKey - { - get { return _inner.InstanceKey; } - } - - public override bool IsReference - { - get { return false; } - } - - public override string ReferenceKey - { - get { return _inner.ReferenceKey; } - } - - protected override object buildInstance(IInstanceCreator creator) - { - if (_inner == null) - { - _inner = creator.DefaultMemento; - } - - return base.buildInstance(creator); - } - - protected override string getPropertyValue(string Key) - { - return _args.GetArg(Key) ?? _inner.GetProperty(Key); - } - - protected override InstanceMemento getChild(string Key) - { - return _inner.GetChildMemento(Key); - } - - public override object GetChild(string key, string typeName, Pipeline.IInstanceCreator instanceCreator) - { - Type type = Type.GetType(typeName, true); - return _args.Get(type) ?? base.GetChild(key, typeName, instanceCreator); - } - - public override InstanceMemento[] GetChildrenArray(string Key) - { - return _inner.GetChildrenArray(Key); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/ConstructorMemento.cs =================================================================== --- trunk/Source/StructureMap/ConstructorMemento.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/ConstructorMemento.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,40 +0,0 @@ -using System; -using StructureMap.Configuration.Mementos; - -namespace StructureMap -{ - public delegate PLUGINTYPE BuildObjectDelegate<PLUGINTYPE>(); - - public class ConstructorMemento<PLUGINTYPE> : MemoryInstanceMemento - { - private BuildObjectDelegate<PLUGINTYPE> _builder; - - - public ConstructorMemento() - { - } - - public ConstructorMemento(string instanceKey, BuildObjectDelegate<PLUGINTYPE> builder) - : base(instanceKey, instanceKey) - { - _builder = builder; - } - - public ConstructorMemento(BuildObjectDelegate<PLUGINTYPE> builder) - : this(Guid.NewGuid().ToString(), builder) - { - } - - - public BuildObjectDelegate<PLUGINTYPE> Builder - { - get { return _builder; } - set { _builder = value; } - } - - protected override object buildInstance(IInstanceCreator creator) - { - return _builder(); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Graph/DefinitionSource.cs =================================================================== --- trunk/Source/StructureMap/Graph/DefinitionSource.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Graph/DefinitionSource.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,12 +0,0 @@ -namespace StructureMap.Graph -{ - /// <summary> - /// Specifies whether a PluginGraphObject is defined Explicitly in the configuration file, - /// or implicitly through the [PluginFamily] or [Pluggable] attributes - /// </summary> - public enum DefinitionSource - { - Implicit, - Explicit - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Graph/Deployable.cs =================================================================== --- trunk/Source/StructureMap/Graph/Deployable.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Graph/Deployable.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,73 +0,0 @@ -using System.Collections.Generic; - -namespace StructureMap.Graph -{ - /// <summary> - /// Base class for PluginGraphObject classes that can be marked for deployment - /// targets. - /// </summary> - public abstract class Deployable - { - public const string ALL = "All"; - - private List<string> _deploymentTargets; - - public Deployable() - { - _deploymentTargets = new List<string>(); - } - - public Deployable(string[] deploymentTargets) : this() - { - DeploymentTargets = deploymentTargets; - } - - /// <summary> - /// A string array of the valid deployment options for the PluginGraphObject. - /// </summary> - public string[] DeploymentTargets - { - get { return _deploymentTargets.ToArray(); } - set - { - _deploymentTargets.Clear(); - _deploymentTargets.AddRange(value); - } - } - - /// <summary> - /// Simple string description of the deployment options for the PluginGraphObject - /// </summary> - public string DeploymentDescription - { - get - { - string[] targets = DeploymentTargets; - if (targets.Length == 0) - { - return "All"; - } - else - { - return string.Join(", ", targets); - } - } - } - - /// <summary> - /// Returns a boolean flag denoting whether or not the PluginGraphObject is deployed - /// for the deploymentTarget - /// </summary> - /// <param name="deploymentTarget"></param> - /// <returns></returns> - public bool IsDeployed(string deploymentTarget) - { - if (_deploymentTargets.Count == 0 || _deploymentTargets.Contains(ALL)) - { - return true; - } - - return _deploymentTargets.Contains(deploymentTarget); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -139,9 +139,12 @@ } // TODO -- Got a big problem here. Intances need to be copied over - foreach (Instance instance in GetAllInstances()) + foreach (IDiagnosticInstance instance in GetAllInstances()) { - throw new NotImplementedException(); + if (instance.CanBePartOfPluginFamily(templatedFamily)) + { + templatedFamily.AddInstance((Instance)instance); + } } // Need to attach the new PluginFamily to the old PluginGraph Deleted: trunk/Source/StructureMap/Graph/PluginGraphObjectCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraphObjectCollection.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Graph/PluginGraphObjectCollection.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,72 +0,0 @@ -using System; -using System.Collections; - -namespace StructureMap.Graph -{ - public abstract class PluginGraphObjectCollection : MarshalByRefObject, ICollection - { - private readonly PluginGraph _pluginGraph; - - public PluginGraphObjectCollection(PluginGraph pluginGraph) : base() - { - _pluginGraph = pluginGraph; - } - - protected abstract ICollection innerCollection { get; } - - #region ICollection Members - - public IEnumerator GetEnumerator() - { - ArrayList list = new ArrayList(innerCollection); - try - { - list.Sort(); - } - catch (Exception) - { - // no-op. Only happens in trouble-shooting instances anyway - } - - return list.GetEnumerator(); - } - - public void CopyTo(Array array, int index) - { - innerCollection.CopyTo(array, index); - } - - public int Count - { - get { return innerCollection.Count; } - } - - public object SyncRoot - { - get { return innerCollection.SyncRoot; } - } - - public bool IsSynchronized - { - get { return innerCollection.IsSynchronized; } - } - - #endregion - - protected void verifySealed() - { - if (!_pluginGraph.IsSealed) - { - throw new InvalidOperationException("This PluginGraph is not Sealed!"); - } - } - - protected void verifyNotSealed() - { - if (_pluginGraph.IsSealed) - { - throw new InvalidOperationException("This PluginGraph is Sealed!"); - } - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/IInstanceCreator.cs =================================================================== --- trunk/Source/StructureMap/IInstanceCreator.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/IInstanceCreator.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,8 +0,0 @@ -namespace StructureMap -{ - public interface IInstanceCreator - { - InstanceMemento DefaultMemento { get; } - object BuildInstance(InstanceMemento memento); - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -92,14 +92,26 @@ InstanceBuilder IConfiguredInstance.FindBuilder(InstanceBuilderList builders) { + if (!string.IsNullOrEmpty(ConcreteKey)) + { + InstanceBuilder builder = builders.FindByConcreteKey(ConcreteKey); + if (builder != null) return builder; + } + if (_pluggedType != null) { return builders.FindByType(_pluggedType); } - return builders.FindByConcreteKey(_concreteKey); + return null; } + + protected override bool canBePartOfPluginFamily(PluginFamily family) + { + return family.Plugins.HasPlugin(ConcreteKey); + } + public ConfiguredInstance SetProperty(string propertyName, string propertyValue) { _properties[propertyName] = propertyValue; @@ -421,6 +433,8 @@ return _instance; } + + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -17,8 +17,12 @@ object ApplyInterception(Type pluginType, object actualValue); } + public interface IDiagnosticInstance + { + bool CanBePartOfPluginFamily(PluginFamily family); + } - public abstract class Instance + public abstract class Instance : IDiagnosticInstance { private string _name = Guid.NewGuid().ToString(); private InstanceInterceptor _interceptor = new NulloInterceptor(); @@ -56,9 +60,15 @@ protected abstract object build(Type pluginType, IInstanceCreator creator); + bool IDiagnosticInstance.CanBePartOfPluginFamily(PluginFamily family) + { + return canBePartOfPluginFamily(family); + } - //public abstract void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) where T : class; - //public abstract void Describe<T>(IInstanceDiagnostics diagnostics) where T : class; + protected virtual bool canBePartOfPluginFamily(PluginFamily family) + { + return true; + } } public abstract class ExpressedInstance<T> : Instance Modified: trunk/Source/StructureMap/Properties/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap/Properties/AssemblyInfo.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap/Properties/AssemblyInfo.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -12,4 +12,4 @@ [assembly : InternalsVisibleTo( "StructureMap.AutoMocking, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d9a2a76e43cd9b1b1944b1f3b489a046b33f0bcd755b25cc5d3ed7b18ded38240d6db7578cd986c72d3feb4f94a7ab26fcfa41e3e4f41cf2c029fba91159db05c44d63f0b2bfac24353a07f4a1230dd3d4240340adafa2275277fa083c75958062cd0e60016701db6af7ae718efdf1e802a840595b49c290964255b3c60c494" - )] \ No newline at end of file + )] Modified: trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -41,7 +41,7 @@ Assert.AreEqual(color, widget.Color); } - [Test, Ignore("Until Generics support is fixed")] + [Test] public void AddNodeDirectly() { string xml = "<StructureMap><Assembly Name=\"StructureMap.Testing.GenericWidgets\"/></StructureMap>"; Deleted: trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,78 +0,0 @@ -using NUnit.Framework; -using StructureMap.Configuration.DSL; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Configuration.Mementos; -using StructureMap.Testing.Widget4; - -namespace StructureMap.Testing.Configuration.DSL -{ - [TestFixture] - public class ChildInstanceExpressionTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - } - - #endregion - - [Test, - ExpectedException(typeof (StructureMapException), - "StructureMap Exception Code: 303\nType System.String,mscorlib is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing" - )] - public void CantCastTheRequestedConcreteType() - { - InstanceExpression instance = new InstanceExpression(typeof (IStrategy)); - MemoryInstanceMemento memento = new MemoryInstanceMemento(); - - ChildInstanceExpression expression = - new ChildInstanceExpression(instance, memento, "a property", typeof (IType)); - expression.IsConcreteType<string>(); - } - - [Test, - ExpectedException(typeof (StructureMapException), - "StructureMap Exception Code: 303\nType StructureMap.Testing.Configuration.DSL.AbstractType,StructureMap.Testing is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing" - )] - public void CantCastTheRequestedConcreteType2() - { - InstanceExpression instance = new InstanceExpression(typeof (IStrategy)); - MemoryInstanceMemento memento = new MemoryInstanceMemento(); - - ChildInstanceExpression expression = - new ChildInstanceExpression(instance, memento, "a property", typeof (IType)); - expression.IsConcreteType<AbstractType>(); - } - - - [Test, - ExpectedException(typeof (StructureMapException), - "StructureMap Exception Code: 303\nType StructureMap.Testing.Configuration.DSL.AbstractType,StructureMap.Testing is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing" - )] - public void CantCastTheRequestedPluggedType3() - { - InstanceExpression instance = new InstanceExpression(typeof (IStrategy)); - MemoryInstanceMemento memento = new MemoryInstanceMemento(); - - ChildInstanceExpression expression = - new ChildInstanceExpression(instance, memento, "a property", typeof (IType)); - InstanceExpression child = Registry.Instance<IType>().UsingConcreteType<AbstractType>(); - - expression.Is(child); - } - } - - public interface IType - { - } - - public abstract class AbstractType : IType - { - } - - public class ConcreteType : AbstractType - { - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,67 +0,0 @@ -using NUnit.Framework; -using StructureMap.Configuration.DSL; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Configuration.Mementos; -using StructureMap.Graph; -using StructureMap.Testing.Widget; - -namespace StructureMap.Testing.Configuration.DSL -{ - [TestFixture] - public class LiteralExpressionTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - } - - #endregion - - [Test] - public void BuildFromInstanceManager() - { - ColorWidget theWidget = new ColorWidget("Red"); - LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); - PluginGraph graph = new PluginGraph(); - ((IExpression) expression).Configure(graph); - - InstanceManager manager = new InstanceManager(graph); - - IWidget actualWidget = manager.CreateInstance<IWidget>(expression.InstanceKey); - Assert.AreSame(theWidget, actualWidget); - } - - [Test] - public void ConfiguresALiteral() - { - ColorWidget theWidget = new ColorWidget("Red"); - LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); - PluginGraph graph = new PluginGraph(); - ((IExpression) expression).Configure(graph); - - PluginFamily family = graph.PluginFamilies[typeof (IWidget)]; - Assert.IsNotNull(family); - - LiteralMemento memento = (LiteralMemento) family.Source.GetMemento(expression.InstanceKey); - Assert.AreSame(theWidget, memento.Build(null)); - } - - [Test] - public void OverrideTheInstanceKey() - { - ColorWidget theWidget = new ColorWidget("Red"); - LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); - expression.WithName("Blue"); - PluginGraph graph = new PluginGraph(); - ((IExpression) expression).Configure(graph); - - PluginFamily family = graph.PluginFamilies[typeof (IWidget)]; - Assert.IsNotNull(family); - - LiteralMemento memento = (LiteralMemento) family.Source.GetMemento(expression.InstanceKey); - Assert.AreSame(theWidget, memento.Build(null)); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,51 +0,0 @@ -using NUnit.Framework; -using StructureMap.Configuration.DSL; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Graph; - -namespace StructureMap.Testing.Configuration.DSL -{ - [TestFixture] - public class ReferenceMementoBuilderTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - } - - #endregion - - public interface Abstraction - { - } - - public class Concretion1 : Abstraction - { - } - - public class Concretion2 : Abstraction - { - } - - [Test] - public void CreateMemento() - { - Registry registry = new Registry(); - registry.AddInstanceOf<Abstraction>().UsingConcreteType<Concretion1>().WithName("One"); - registry.AddInstanceOf<Abstraction>().UsingConcreteType<Concretion2>().WithName("Two"); - - IInstanceManager manager = registry.BuildInstanceManager(); - ReferenceMementoBuilder builder1 = new ReferenceMementoBuilder("One"); - ReferenceMementoBuilder builder2 = new ReferenceMementoBuilder("Two"); - - InstanceMemento memento1 = ((IMementoBuilder) builder1).BuildMemento(new PluginGraph()); - InstanceMemento memento2 = ((IMementoBuilder) builder2).BuildMemento(new PluginGraph()); - - - Assert.IsInstanceOfType(typeof (Concretion1), manager.CreateInstance<Abstraction>(memento1)); - Assert.IsInstanceOfType(typeof (Concretion2), manager.CreateInstance<Abstraction>(memento2)); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,57 +0,0 @@ -using NUnit.Framework; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Configuration.Mementos; -using StructureMap.Graph; - -namespace StructureMap.Testing.Configuration.DSL -{ - [TestFixture] - public class UserControlExpressionTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - } - - #endregion - - [Test] - public void CreateMementoHappyPath() - { - string theUrl = "alskdjf"; - - UserControlExpression expression = new UserControlExpression(typeof (IControl), theUrl); - - UserControlMemento memento = - (UserControlMemento) ((IMementoBuilder) expression).BuildMemento(new PluginGraph()); - Assert.IsNotNull(memento); - - Assert.AreEqual(theUrl, memento.Url); - Assert.IsNotEmpty(memento.InstanceKey); - Assert.IsNotNull(memento.InstanceKey); - } - - [Test] - public void CreateMementoHappyPathWithName() - { - string theUrl = "alskdjf"; - string theName = "the name"; - - UserControlExpression expression = new UserControlExpression(typeof (IControl), theUrl); - expression.WithName(theName); - - UserControlMemento memento = - (UserControlMemento) ((IMementoBuilder) expression).BuildMemento(new PluginGraph()); - Assert.IsNotNull(memento); - - Assert.AreEqual(theUrl, memento.Url); - Assert.AreEqual(theName, memento.InstanceKey); - } - } - - public interface IControl - { - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap.Testing/ConstructorMementoTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ConstructorMementoTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/ConstructorMementoTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -1,26 +0,0 @@ -using NUnit.Framework; - -namespace StructureMap.Testing -{ - [TestFixture] - public class ConstructorMementoTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - } - - #endregion - - [Test] - public void Construct() - { - ConstructorMemento<string> memento = new ConstructorMemento<string>("A", delegate { return "Hello"; }); - Assert.AreEqual("A", memento.InstanceKey); - string actual = (string) memento.Build(null); - Assert.AreEqual("Hello", actual); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -137,7 +137,7 @@ } - [Test, Ignore("Temporarily suspending generics support")] + [Test] public void FindAPluginFamilyForAGenericTypeFromPluginTypeName() { Type serviceType = typeof (IService<string>); Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -8,7 +8,7 @@ namespace StructureMap.Testing { - [TestFixture, Ignore("Temporarily suspending generics support")] + [TestFixture] public class GenericsAcceptanceTester { #region Setup/Teardown Modified: trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -6,7 +6,7 @@ namespace StructureMap.Testing { - [TestFixture, Ignore("Temporarily suspending generics support")] + [TestFixture] public class GenericsIntegrationTester { #region Setup/Teardown Modified: trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-04-11 23:32:28 UTC (rev 79) +++ trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-04-12 13:45:08 UTC (rev 80) @@ -4,7 +4,7 @@ namespace StructureMap.Testing.Graph { - [TestFixture, Ignore("Temporarily suspending generics support")] + [TestFixture] public class GenericsPluginGraphTester { #region Setup/Teardown @@ -36,21 +36,14 @@ family.Plugins.Add(typeof (SecondGenericService<>), "Second"); family.Plugins.Add(typeof (ThirdGenericService<>), "Third"); - PluginFamily intFamily = family.CreateTemplatedClone(typeof (int)); - PluginFamily stringFamily = family.CreateTemplatedClone(typeof (string)); + InstanceManager manager = new InstanceManager(pluginGraph); - InstanceFactory intFactory = new InstanceFactory(intFamil... [truncated message content] |
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-11 23:31:25
|
Revision: 78 http://structuremap.svn.sourceforge.net/structuremap/?rev=78&view=rev Author: jeremydmiller Date: 2008-04-11 16:31:23 -0700 (Fri, 11 Apr 2008) Log Message: ----------- The Great Refactoring of 2008. Generics are temporarily broken however Modified Paths: -------------- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/Configuration/IGraphBuilder.cs trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs trunk/Source/StructureMap/Configuration/Mementos/LiteralMemento.cs trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs trunk/Source/StructureMap/Configuration/Mementos/PrototypeMemento.cs trunk/Source/StructureMap/Configuration/Mementos/UserControlMemento.cs trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs trunk/Source/StructureMap/Configuration/XmlConstants.cs trunk/Source/StructureMap/Graph/AssemblyGraph.cs trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/Graph/InterceptionChain.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/SetterPropertyCollection.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/IInstanceManager.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/DefaultInstance.cs trunk/Source/StructureMap/Pipeline/Instance.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/Source/XmlAttributeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs trunk/Source/StructureMap.Testing/Caching/StorageAndCacheItemTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserCollectionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.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/FamilyParserTester.cs trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.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/EmittingTester.cs trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/ExceptionTestRunner.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.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/MockingTester.cs trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSessionTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.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/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/ReferencedInstanceTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/StructureMap.config trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml trunk/Source/StructureMap.Testing/TestData/ExceptionHandlingTests.xml trunk/Source/StructureMap.Testing/TestData/Master.xml trunk/Source/StructureMap.Testing/TestData/SampleConfig.xml trunk/Source/StructureMap.Testing/TestData/StructureMap.config trunk/Source/StructureMap.Testing.Widget/Rule.cs trunk/Source/StructureMap.Testing.Widget3/IService.cs trunk/StructureMap.config Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -143,7 +143,8 @@ } MementoSource source = CreateSource(exportedType); - PluginFamily family = new PluginFamily(exportedType, DefaultKey, source); + PluginFamily family = new PluginFamily(exportedType, DefaultKey); + family.AddMementoSource(source); InterceptorChainBuilder builder = new InterceptorChainBuilder(); family.InterceptionChain = builder.Build(Scope); @@ -156,8 +157,6 @@ PluginFamilyAttribute att = GetAttribute(exportedType); PluginFamily family = att.BuildPluginFamily(exportedType); - family.DefinitionSource = DefinitionSource.Implicit; - return family; } Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -63,25 +63,7 @@ return (ConfigurationParser[]) list.ToArray(typeof (ConfigurationParser)); } - public static string[] GetDeploymentTargets(XmlNode node) - { - string[] returnValue = new string[0]; - XmlAttribute att = node.Attributes[XmlConstants.DEPLOYMENT_ATTRIBUTE]; - if (att != null) - { - string deployTargetArray = att.Value; - - deployTargetArray = deployTargetArray.Replace(" ,", ","); - deployTargetArray = deployTargetArray.Replace(", ", ","); - - - returnValue = deployTargetArray.Split(','); - } - - return returnValue; - } - public static ConfigurationParser FromFile(string filename) { XmlDocument document = new XmlDocument(); @@ -135,8 +117,6 @@ public void ParseInstances(IGraphBuilder builder) { - parseInstances(builder); - XmlNodeList familyNodes = findNodes(XmlConstants.PLUGIN_FAMILY_NODE); foreach (XmlElement familyElement in familyNodes) { @@ -151,9 +131,8 @@ foreach (XmlNode assemblyNode in assemblyNodes) { string assemblyName = assemblyNode.Attributes[XmlConstants.NAME].Value; - string[] deploymentTargets = GetDeploymentTargets(assemblyNode); - builder.AddAssembly(assemblyName, deploymentTargets); + builder.AddAssembly(assemblyName); } } @@ -201,26 +180,6 @@ } } - private void parseInstances(IGraphBuilder builder) - { - XmlNode instancesNode = _structureMapNode[XmlConstants.INSTANCES_NODE]; - if (instancesNode == null) - { - return; - } - - foreach (XmlNode instanceNode in instancesNode) - { - string pluginTypeName = instanceNode.Name; - TypePath typePath = TypePath.TypePathForFullName(pluginTypeName); - - InstanceMemento memento = _mementoCreator.CreateMemento(instanceNode); - - builder.RegisterMemento(typePath, memento); - } - } - - public void ParseProfilesAndMachines(IGraphBuilder builder) { ProfileAndMachineParser parser = new ProfileAndMachineParser(builder, _structureMapNode, _mementoCreator); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -3,6 +3,7 @@ using StructureMap.Attributes; using StructureMap.Graph; using StructureMap.Interceptors; +using StructureMap.Pipeline; namespace StructureMap.Configuration.DSL.Expressions { @@ -54,30 +55,23 @@ /// </summary> /// <param name="builder"></param> /// <returns></returns> - public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(IMementoBuilder builder) + public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(Instance instance) { - builder.ValidatePluggability(_pluginType); - - _children.Add(builder); _alterations.Add(delegate(PluginFamily family) { - InstanceMemento memento = builder.BuildMemento(family); - family.Source.AddExternalMemento(memento); - family.DefaultInstanceKey = memento.InstanceKey; + family.AddInstance(instance); + family.DefaultInstanceKey = instance.Name; }); return this; } - public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(IMementoBuilder builder) + public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(Instance instance) { - builder.ValidatePluggability(_pluginType); - - _children.Add(builder); + // TODO: Validate pluggability _alterations.Add(delegate(PluginFamily family) { - InstanceMemento memento = builder.BuildMemento(family); - family.Source.AddExternalMemento(memento); + family.AddInstance(instance); }); return this; @@ -144,7 +138,10 @@ public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(EnrichmentHandler<PLUGINTYPE> handler) { _alterations.Add( - delegate(PluginFamily family) { family.InstanceInterceptor = new EnrichmentInterceptor<PLUGINTYPE>(handler); }); + delegate(PluginFamily family) + { + family.InstanceInterceptor = new EnrichmentInterceptor<PLUGINTYPE>(handler); + }); return this; } @@ -161,7 +158,7 @@ { Plugin plugin = Plugin.CreateImplicitPlugin(typeof (CONCRETETYPE)); plugin.ConcreteKey = instanceName; - family.Plugins.Add(plugin, true); + family.Plugins.Add(plugin); } ); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,5 +1,6 @@ using System; using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Configuration.DSL.Expressions { @@ -11,7 +12,7 @@ private readonly ProfileExpression _parent; private readonly Type _pluginType; private string _instanceKey = string.Empty; - private IMementoBuilder _mementoBuilder; + private Instance _instance; public InstanceDefaultExpression(Type pluginType, ProfileExpression parent) { @@ -37,14 +38,13 @@ InstanceDefault instanceDefault = new InstanceDefault(_pluginType, _instanceKey); profile.AddOverride(instanceDefault); } - else if (_mementoBuilder != null) + else if (_instance != null) { string defaultKey = Profile.InstanceKeyForProfile(profile.ProfileName); - InstanceMemento memento = _mementoBuilder.BuildMemento(graph); - memento.InstanceKey = defaultKey; + + _instance.Name = defaultKey; + graph.LocateOrCreateFamilyForType(_pluginType).AddInstance(_instance); - graph.PluginFamilies[_pluginType].AddInstance(memento); - InstanceDefault instanceDefault = new InstanceDefault(_pluginType, defaultKey); profile.AddOverride(instanceDefault); } @@ -59,9 +59,9 @@ /// </summary> /// <param name="mementoBuilder"></param> /// <returns></returns> - public ProfileExpression Use(IMementoBuilder mementoBuilder) + public ProfileExpression Use(Instance instance) { - _mementoBuilder = mementoBuilder; + _instance = instance; return _parent; } Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -3,6 +3,7 @@ using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Interceptors; +using StructureMap.Pipeline; namespace StructureMap.Configuration.DSL { @@ -102,23 +103,30 @@ /// </summary> /// <typeparam name="PLUGINTYPE"></typeparam> /// <returns></returns> - public InstanceExpression.InstanceTypeExpression AddInstanceOf<PLUGINTYPE>() + public ConfiguredInstance AddInstanceOf<PLUGINTYPE>() { - InstanceExpression expression = new InstanceExpression(typeof (PLUGINTYPE)); - addExpression(expression); - return expression.TypeExpression(); + ConfiguredInstance instance = new ConfiguredInstance(); + + addExpression(delegate (PluginGraph pluginGraph) + { + pluginGraph.LocateOrCreateFamilyForType(typeof(PLUGINTYPE)).AddInstance(instance); + }); + + return instance; } /// <summary> /// Convenience method to start the definition of an instance of type T /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> + /// <typeparam name="PLUGGEDTYPE"></typeparam> /// <returns></returns> - public static InstanceExpression.InstanceTypeExpression Instance<PLUGINTYPE>() + public static ConfiguredInstance Instance<PLUGGEDTYPE>() { - InstanceExpression expression = new InstanceExpression(typeof (PLUGINTYPE)); - return expression.TypeExpression(); + ConfiguredInstance instance = new ConfiguredInstance(); + instance.PluggedType = typeof (PLUGGEDTYPE); + + return instance; } /// <summary> @@ -127,9 +135,9 @@ /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="prototype"></param> /// <returns></returns> - public static PrototypeExpression<PLUGINTYPE> Prototype<PLUGINTYPE>(PLUGINTYPE prototype) + public static PrototypeInstance Prototype<PLUGINTYPE>(PLUGINTYPE prototype) { - return new PrototypeExpression<PLUGINTYPE>(prototype); + return new PrototypeInstance((ICloneable) prototype); } /// <summary> @@ -138,9 +146,9 @@ /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="instance"></param> /// <returns></returns> - public static LiteralExpression<PLUGINTYPE> Object<PLUGINTYPE>(PLUGINTYPE instance) + public static LiteralInstance Object<PLUGINTYPE>(PLUGINTYPE instance) { - return new LiteralExpression<PLUGINTYPE>(instance); + return new LiteralInstance(instance); } /// <summary> @@ -149,10 +157,10 @@ /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="target"></param> /// <returns></returns> - public LiteralExpression<PLUGINTYPE> AddInstanceOf<PLUGINTYPE>(PLUGINTYPE target) + public LiteralInstance AddInstanceOf<PLUGINTYPE>(PLUGINTYPE target) { - LiteralExpression<PLUGINTYPE> literal = new LiteralExpression<PLUGINTYPE>(target); - addExpression(literal); + LiteralInstance literal = new LiteralInstance(target); + _graph.LocateOrCreateFamilyForType(typeof(PLUGINTYPE)).AddInstance(literal); return literal; } @@ -163,10 +171,10 @@ /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="prototype"></param> /// <returns></returns> - public PrototypeExpression<PLUGINTYPE> AddPrototypeInstanceOf<PLUGINTYPE>(PLUGINTYPE prototype) + public PrototypeInstance AddPrototypeInstanceOf<PLUGINTYPE>(PLUGINTYPE prototype) { - PrototypeExpression<PLUGINTYPE> expression = new PrototypeExpression<PLUGINTYPE>(prototype); - addExpression(expression); + PrototypeInstance expression = new PrototypeInstance((ICloneable) prototype); + _graph.LocateOrCreateFamilyForType(typeof(PLUGINTYPE)).AddInstance(expression); return expression; } @@ -177,9 +185,9 @@ /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="url"></param> /// <returns></returns> - public static UserControlExpression LoadUserControlFrom<PLUGINTYPE>(string url) + public static UserControlInstance LoadUserControlFrom<PLUGINTYPE>(string url) { - return new UserControlExpression(typeof (PLUGINTYPE), url); + return new UserControlInstance(url); } /// <summary> @@ -216,23 +224,25 @@ /// <typeparam name="PLUGINTYPE"></typeparam> /// <param name="url"></param> /// <returns></returns> - public UserControlExpression LoadControlFromUrl<PLUGINTYPE>(string url) + public UserControlInstance LoadControlFromUrl<PLUGINTYPE>(string url) { - UserControlExpression expression = new UserControlExpression(typeof (PLUGINTYPE), url); - addExpression(expression); + UserControlInstance instance = new UserControlInstance(url); - return expression; + PluginFamily family = _graph.LocateOrCreateFamilyForType(typeof (PLUGINTYPE)); + family.AddInstance(instance); + + return instance; } - public static ConstructorExpression<PLUGINTYPE> ConstructedBy<PLUGINTYPE> - (BuildObjectDelegate<PLUGINTYPE> builder) + public static ConstructorInstance ConstructedBy<PLUGINTYPE> + (BuildObjectDelegate builder) { - return new ConstructorExpression<PLUGINTYPE>(builder); + return new ConstructorInstance(builder); } - public static ReferenceMementoBuilder Instance(string referencedKey) + public static ReferencedInstance Instance(string referencedKey) { - return new ReferenceMementoBuilder(referencedKey); + return new ReferencedInstance(referencedKey); } public void RegisterInterceptor(TypeInterceptor interceptor) Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -21,12 +21,11 @@ { TypePath typePath = TypePath.CreateFromXmlNode(familyElement); string defaultKey = familyElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE); - string[] deploymentTargets = ConfigurationParser.GetDeploymentTargets(familyElement); InstanceScope scope = findScope(familyElement); - _builder.AddPluginFamily(typePath, defaultKey, deploymentTargets, scope); + _builder.AddPluginFamily(typePath, defaultKey, scope); attachMementoSource(familyElement, typePath); attachPlugins(typePath, familyElement); @@ -46,7 +45,7 @@ InstanceMemento memento = _mementoCreator.CreateMemento(element); memento.InstanceKey = name; - _builder.AddPluginFamily(pluginTypePath, name, new string[0], scope); + _builder.AddPluginFamily(pluginTypePath, name, scope); _builder.RegisterMemento(pluginTypePath, memento); } @@ -57,7 +56,6 @@ InstanceMemento memento = _mementoCreator.CreateMemento(element); - _builder.AddPluginFamily(pluginTypePath, null, new string[0], scope); _builder.RegisterMemento(pluginTypePath, memento); } Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -8,11 +8,11 @@ PluginGraph SystemGraph { get; } InstanceDefaultManager DefaultManager { get; } PluginGraph PluginGraph { get; } - void AddAssembly(string assemblyName, string[] deployableTargets); + void AddAssembly(string assemblyName); void StartFamilies(); - void AddPluginFamily(TypePath typePath, string defaultKey, string[] deploymentTargets, InstanceScope scope); + 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); Modified: trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using StructureMap.Pipeline; namespace StructureMap.Configuration.Mementos { @@ -32,5 +33,62 @@ { return _args.ContainsKey(key) ? _args[key] : null; } + + public void Configure(ConfiguredInstance instance) + { + foreach (KeyValuePair<string, string> arg in _args) + { + instance.SetProperty(arg.Key, arg.Value); + instance.SetChild(arg.Key, new LiteralInstance(arg.Value)); + } + } + + public bool Has(Type type) + { + return _children.ContainsKey(type); + } + + public bool Has(string propertyName) + { + return _args.ContainsKey(propertyName); + } } + + public class ExplicitInstance<PLUGINTYPE> : ConfiguredInstance + { + private readonly ExplicitArguments _args; + + public ExplicitInstance(ExplicitArguments args, Instance defaultInstance) + { + args.Configure(this); + _args = args; + + ConfiguredInstance defaultConfiguration = defaultInstance as ConfiguredInstance; + if (defaultConfiguration != null) + { + merge(defaultConfiguration); + PluggedType = defaultConfiguration.PluggedType; + } + else + { + PluggedType = typeof(PLUGINTYPE); + } + } + + + protected override object getChild(string propertyName, Type pluginType, IInstanceCreator instanceCreator) + { + if (_args.Has(pluginType)) + { + return _args.Get(pluginType); + } + + if (_args.Has(propertyName)) + { + return _args.GetArg(propertyName); + } + + return base.getChild(propertyName, pluginType, instanceCreator); + } + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/Mementos/LiteralMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/LiteralMemento.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/Mementos/LiteralMemento.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,7 +1,10 @@ using System; +using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Configuration.Mementos { + [Obsolete("Eliminate!")] public class LiteralMemento : InstanceMemento { private object _instance; @@ -59,9 +62,16 @@ throw new NotImplementedException(); } - protected override object buildInstance(IInstanceCreator creator) + + protected override Instance readInstance(PluginGraph pluginGraph, Type pluginType) { - return _instance; + return new LiteralInstance(_instance); } + + + public override Plugin FindPlugin(PluginFamily family) + { + return null; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,10 +1,12 @@ +using System; using System.Collections; using System.Collections.Specialized; using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Configuration.Mementos { - public class GenericMemento<T> : MemoryInstanceMemento + [Obsolete("Think this is unnecessary")] public class GenericMemento<T> : MemoryInstanceMemento { public GenericMemento(string instanceKey) : base(Plugin.CreateImplicitPlugin(typeof (T)).ConcreteKey, instanceKey) @@ -51,7 +53,7 @@ #endregion private readonly Hashtable _children = new Hashtable(); - private readonly string _concreteKey; + private string _concreteKey; private readonly NameValueCollection _properties = new NameValueCollection(); private string _instanceKey; private bool _isReference; @@ -95,6 +97,12 @@ get { return _concreteKey; } } + [Obsolete("Temporary")] + public void SetConcreteKey(string concreteKey) + { + _concreteKey = concreteKey; + } + /// <summary> /// See <cref>InstanceMemento</cref> /// </summary> Modified: trunk/Source/StructureMap/Configuration/Mementos/PrototypeMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/PrototypeMemento.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/Mementos/PrototypeMemento.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,7 +1,10 @@ using System; +using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Configuration.Mementos { + [Obsolete("Eliminate!")] public class PrototypeMemento : InstanceMemento { private readonly string _instanceKey; @@ -13,6 +16,10 @@ _prototype = prototype; } + public override Plugin FindPlugin(PluginFamily family) + { + return null; + } public ICloneable Prototype { @@ -40,10 +47,6 @@ get { throw new NotImplementedException(); } } - protected override object buildInstance(IInstanceCreator creator) - { - return _prototype.Clone(); - } protected override string getPropertyValue(string Key) { @@ -59,5 +62,11 @@ { throw new NotImplementedException(); } + + + protected override Instance readInstance(PluginGraph pluginGraph, Type pluginType) + { + return new PrototypeInstance(_prototype); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/Mementos/UserControlMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/UserControlMemento.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/Mementos/UserControlMemento.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,8 +1,10 @@ using System; using System.Web.UI; +using StructureMap.Pipeline; namespace StructureMap.Configuration.Mementos { + [Obsolete("Eliminate")] public class UserControlMemento : InstanceMemento { private readonly string _instanceKey; @@ -45,11 +47,6 @@ get { throw new NotImplementedException(); } } - protected override object buildInstance(IInstanceCreator creator) - { - return new Page().LoadControl(_url); - } - protected override string getPropertyValue(string Key) { throw new NotImplementedException(); Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,9 +1,11 @@ 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 { @@ -101,10 +103,9 @@ return _pluginGraph.LocateOrCreateFamilyForType(fullName); } - public void AddAssembly(string assemblyName, string[] deployableTargets) + public void AddAssembly(string assemblyName) { AssemblyGraph assemblyGraph = new AssemblyGraph(assemblyName); - assemblyGraph.DeploymentTargets = deployableTargets; _pluginGraph.Assemblies.Add(assemblyGraph); AssemblyGraph systemAssemblyGraph = new AssemblyGraph(assemblyName); @@ -118,13 +119,25 @@ _systemInstanceManager = new InstanceManager(_systemGraph); } - public void AddPluginFamily(TypePath typePath, string defaultKey, string[] deploymentTargets, - InstanceScope scope) + public void AddPluginFamily(TypePath typePath, string defaultKey, InstanceScope scope) { - PluginFamily family = new PluginFamily(typePath, defaultKey); - family.DefinitionSource = DefinitionSource.Explicit; - family.InterceptionChain = _builder.Build(scope); - _pluginGraph.PluginFamilies.Add(family); + Type pluginType; + try + { + pluginType = typePath.FindType(); + } + catch (Exception ex) + { + throw new StructureMapException(103, ex, typePath.ClassName, typePath.AssemblyName); + } + + + PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(pluginType); + + // Xml configuration wins + family.DefaultInstanceKey = defaultKey; + InterceptionChain interceptionChain = _builder.Build(scope); + family.AddInterceptionChain(interceptionChain); } public virtual void AttachSource(TypePath pluginTypePath, InstanceMemento sourceMemento) @@ -143,7 +156,7 @@ public void AttachSource(TypePath pluginTypePath, MementoSource source) { PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath]; - family.Source = source; + family.AddMementoSource(source); } public Plugin AddPlugin(TypePath pluginTypePath, TypePath pluginPath, string concreteKey) @@ -157,8 +170,7 @@ } Plugin plugin = new Plugin(pluginPath, concreteKey); - plugin.DefinitionSource = DefinitionSource.Explicit; - family.Plugins.Add(plugin, true); + family.Plugins.Add(plugin); return plugin; } @@ -194,22 +206,16 @@ public void RegisterMemento(TypePath pluginTypePath, InstanceMemento memento) { - PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath]; - - Plugin inferredPlugin = memento.CreateInferredPlugin(); - if (inferredPlugin != null) - { - family.Plugins.Add(inferredPlugin, true); - } - - family.Source.AddExternalMemento(memento); + PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(pluginTypePath.FindType()); + family.AddInstance(memento); } #endregion private object buildSystemObject(Type type, InstanceMemento memento) { - return _systemInstanceManager.CreateInstance(type, memento); + Instance instance = memento.ReadInstance(_systemGraph, type); + return _systemInstanceManager.CreateInstance(type, instance); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/XmlConstants.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlConstants.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Configuration/XmlConstants.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,3 +1,5 @@ +using System; + namespace StructureMap.Configuration { /// <summary> @@ -16,7 +18,6 @@ public const string DEPLOYMENT_ATTRIBUTE = "Deploy"; public const string INCLUDE_NODE = "Include"; public const string INSTANCE_NODE = "Instance"; - public const string INSTANCES_NODE = "Instances"; public const string INTERCEPTORS_NODE = "Interceptors"; public const string KEY_ATTRIBUTE = "Key"; public const string MACHINE_NODE = "Machine"; Modified: trunk/Source/StructureMap/Graph/AssemblyGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -11,7 +11,7 @@ /// <summary> /// Models an assembly reference in a PluginGraph /// </summary> - public class AssemblyGraph : Deployable, IComparable + public class AssemblyGraph : IComparable { #region statics Modified: trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -7,20 +7,15 @@ /// <summary> /// Custom collection for AssemblyGraph's /// </summary> - public class AssemblyGraphCollection : PluginGraphObjectCollection + public class AssemblyGraphCollection : IEnumerable<AssemblyGraph> { private Dictionary<string, AssemblyGraph> _assemblies; - public AssemblyGraphCollection(PluginGraph pluginGraph) : base(pluginGraph) + public AssemblyGraphCollection(PluginGraph pluginGraph) { _assemblies = new Dictionary<string, AssemblyGraph>(); } - protected override ICollection innerCollection - { - get { return _assemblies.Values; } - } - public AssemblyGraph this[string assemblyName] { get { return _assemblies[assemblyName]; } @@ -36,6 +31,11 @@ } } + public int Count + { + get { return _assemblies.Count; } + } + public AssemblyGraph Add(string assemblyName) { AssemblyGraph assemblyGraph = new AssemblyGraph(assemblyName); @@ -49,8 +49,6 @@ public AssemblyGraph Add(AssemblyGraph assemblyGraph) { - verifyNotSealed(); - if (_assemblies.ContainsKey(assemblyGraph.AssemblyName)) { return _assemblies[assemblyGraph.AssemblyName]; @@ -62,7 +60,6 @@ public void Remove(string assemblyName) { - verifyNotSealed(); _assemblies.Remove(assemblyName); } @@ -75,5 +72,15 @@ { return _assemblies.ContainsKey(assemblyName); } + + IEnumerator<AssemblyGraph> IEnumerable<AssemblyGraph>.GetEnumerator() + { + return _assemblies.Values.GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable<AssemblyGraph>) this).GetEnumerator(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -99,13 +99,7 @@ } else { - string configuredTypes = ""; - foreach (KeyValuePair<Type, PluginFamily> pair in _families) - { - configuredTypes += "\n" + pair.Value.PluginTypeName + ";"; - } - - throw new StructureMapException(190, templatedType.FullName, basicType.FullName, configuredTypes); + return null; } } Modified: trunk/Source/StructureMap/Graph/InterceptionChain.cs =================================================================== --- trunk/Source/StructureMap/Graph/InterceptionChain.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Graph/InterceptionChain.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -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> + public class InterceptionChain : IEnumerable<InstanceFactoryInterceptor>, IEquatable<InterceptionChain> { private List<InstanceFactoryInterceptor> _interceptorList; @@ -73,5 +73,32 @@ 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/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -4,6 +4,15 @@ namespace StructureMap.Graph { + public interface IPluginArgumentVisitor + { + void Primitive(string name); + void Child(string name, Type childType); + void ChildArray(string name, Type childType); + } + + + /// <summary> /// Represents a concrete class that can be built by StructureMap as an instance of the parent /// PluginFamily\x92s PluginType. The properties of a Plugin are the CLR Type of the concrete class, @@ -87,11 +96,11 @@ if (att == null) { return - new Plugin(pluggedType, TypePath.GetAssemblyQualifiedName(pluggedType), DefinitionSource.Implicit); + new Plugin(pluggedType, TypePath.GetAssemblyQualifiedName(pluggedType)); } else { - return new Plugin(pluggedType, att.ConcreteKey, DefinitionSource.Implicit); + return new Plugin(pluggedType, att.ConcreteKey); } } @@ -104,7 +113,7 @@ /// <param name="description"></param> public static Plugin CreateExplicitPlugin(Type pluggedType, string concreteKey, string description) { - return new Plugin(pluggedType, concreteKey, DefinitionSource.Explicit); + return new Plugin(pluggedType, concreteKey); } public static ConstructorInfo GetGreediestConstructor(Type pluggedType) @@ -129,10 +138,10 @@ #endregion private string _concreteKey; - private DefinitionSource _definitionSource; private Type _pluggedType; private SetterPropertyCollection _setters; + #region constructors /// <summary> /// Creates an Explicit Plugin for the pluggedType with the entered @@ -140,7 +149,7 @@ /// </summary> /// <param name="pluggedType"></param> /// <param name="concreteKey"></param> - private Plugin(Type pluggedType, string concreteKey, DefinitionSource definitionSource) : base() + private Plugin(Type pluggedType, string concreteKey) : base() { if (concreteKey == string.Empty) { @@ -149,7 +158,6 @@ _pluggedType = pluggedType; _concreteKey = concreteKey; - _definitionSource = definitionSource; _setters = new SetterPropertyCollection(this); } @@ -170,10 +178,11 @@ _setters = new SetterPropertyCollection(this); _concreteKey = concreteKey; - _definitionSource = DefinitionSource.Explicit; } + #endregion + /// <summary> /// The ConcreteKey that identifies the Plugin within a PluginFamily /// </summary> @@ -217,16 +226,6 @@ } } - /// <summary> - /// Denotes the source or the definition for this Plugin. Implicit means the - /// Plugin is defined by a [Pluggable] attribute on the PluggedType. Explicit - /// means the Plugin was defined in the StructureMap.config file. - /// </summary> - public DefinitionSource DefinitionSource - { - get { return _definitionSource; } - set { _definitionSource = value; } - } /// <summary> /// Determines if the concrete class can be autofilled. @@ -277,7 +276,7 @@ { templatedType = _pluggedType; } - Plugin templatedPlugin = new Plugin(templatedType, _concreteKey, _definitionSource); + Plugin templatedPlugin = new Plugin(templatedType, _concreteKey); templatedPlugin._setters = _setters; return templatedPlugin; @@ -369,8 +368,6 @@ if (CanBeAutoFilled) { MemoryInstanceMemento memento = new MemoryInstanceMemento(ConcreteKey, ConcreteKey); - memento.DefinitionSource = DefinitionSource.Implicit; - returnValue = memento; } @@ -423,13 +420,72 @@ throw new StructureMapException(302, typeof (T).FullName, _pluggedType.FullName); } - public void AddToSource(MementoSource source) + public void VisitArguments(IPluginArgumentVisitor visitor) { - InstanceMemento memento = CreateImplicitMemento(); - if (memento != null) + foreach (ParameterInfo parameter in GetConstructor().GetParameters()) { - source.AddExternalMemento(memento); + visitMember(parameter.ParameterType, parameter.Name, visitor); } + + foreach (SetterProperty setter in _setters) + { + visitMember(setter.Property.PropertyType, setter.Property.Name, visitor); + } } + + private static void visitMember(Type type, string name, IPluginArgumentVisitor visitor) + { + if (TypeIsPrimitive(type)) + { + visitor.Primitive(name); + } + else if (type.IsArray) + { + visitor.ChildArray(name, type.GetElementType()); + } + else + { + visitor.Child(name, type); + } + } + + public void MergeSetters(Plugin plugin) + { + foreach (SetterProperty setter in plugin.Setters) + { + if (!_setters.Contains(setter.Name)) + { + _setters.Add(setter.Name); + } + } + } + + public bool CanBePluggedIntoGenericType(Type pluginType, params Type[] templateTypes) + { + bool isValid = true; + + Type interfaceType = PluggedType.GetInterface(pluginType.Name); + if (interfaceType == null) + { + interfaceType = PluggedType.BaseType; + } + + Type[] pluginArgs = pluginType.GetGenericArguments(); + Type[] pluggableArgs = interfaceType.GetGenericArguments(); + + if (templateTypes.Length != pluginArgs.Length && + pluginArgs.Length != pluggableArgs.Length) + { + return false; + } + + for (int i = 0; i < templateTypes.Length; i++) + { + isValid &= templateTypes[i] == pluggableArgs[i] || + pluginArgs[i].IsGenericParameter && + pluggableArgs[i].IsGenericParameter; + } + return isValid; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -7,21 +7,16 @@ /// <summary> /// Custom collection for Plugin objects /// </summary> - public class PluginCollection : PluginGraphObjectCollection + public class PluginCollection : IEnumerable<Plugin> { private readonly PluginFamily _family; - private Dictionary<string, Plugin> _plugins = new Dictionary<string, Plugin>(); + private readonly Dictionary<string, Plugin> _plugins = new Dictionary<string, Plugin>(); - public PluginCollection(PluginFamily family) : base(null) + public PluginCollection(PluginFamily family) { _family = family; } - protected override ICollection innerCollection - { - get { return _plugins.Values; } - } - public Plugin[] All { get @@ -33,6 +28,11 @@ } } + public int Count + { + get { return _plugins.Count; } + } + /// <summary> /// Gets a Plugin by its PluggedType /// </summary> @@ -57,16 +57,6 @@ } } - public Plugin this[int index] - { - get - { - ArrayList list = new ArrayList(this); - return (Plugin) list[index]; - } - } - - /// <summary> /// Retrieves a Plugin by its ConcreteKey /// </summary> @@ -81,19 +71,14 @@ return _plugins[concreteKey] as Plugin; } - string msg = string.Format( - "Plugin *{0}* for PluginFamily *{1}* does not exist", - concreteKey, - _family.PluginTypeName); - - throw new ApplicationException(msg); + return null; } } public void Add(TypePath path, string concreteKey) { Plugin plugin = new Plugin(path, concreteKey); - Add(plugin, true); + Add(plugin); } /// <summary> @@ -105,22 +90,25 @@ public void Add(Type pluggedType, string concreteKey) { Plugin plugin = Plugin.CreateExplicitPlugin(pluggedType, concreteKey, string.Empty); - Add(plugin, true); + Add(plugin); } - public void Add(Plugin plugin, bool addInstanceOfTypeIfPossible) + public void Add(Plugin plugin) { // Reject if a duplicate ConcreteKey if (_plugins.ContainsKey(plugin.ConcreteKey)) { - // Don't duplicate + // Don't duplicate, but merge setters Plugin peer = this[plugin.ConcreteKey]; if (peer.PluggedType == plugin.PluggedType) { + peer.MergeSetters(plugin); return; } - - throw new StructureMapException(113, plugin.ConcreteKey, _family.PluginTypeName); + else + { + throw new StructureMapException(113, plugin.ConcreteKey, _family.PluginTypeName); + } } // Reject if the PluggedType cannot be upcast to the PluginType @@ -130,11 +118,6 @@ } _plugins.Add(plugin.ConcreteKey, plugin); - - if (addInstanceOfTypeIfPossible) - { - plugin.AddToSource(_family.Source); - } } /// <summary> @@ -153,23 +136,36 @@ _plugins.Remove(concreteKey); } - public void RemoveImplicitChildren() + public Plugin FindOrCreate(Type pluggedType, bool createDefaultInstanceOfType) { - foreach (Plugin plugin in this) + Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType); + Add(plugin); + + return plugin; + } + + IEnumerator<Plugin> IEnumerable<Plugin>.GetEnumerator() + { + return _plugins.Values.GetEnumerator(); + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable<Plugin>) this).GetEnumerator(); + } + + public List<Plugin> FindAutoFillablePlugins() + { + List<Plugin> list = new List<Plugin>(); + foreach (Plugin plugin in _plugins.Values) { - if (plugin.DefinitionSource == DefinitionSource.Implicit) + if (plugin.CanBeAutoFilled) { - Remove(plugin.ConcreteKey); + list.Add(plugin); } } - } - public Plugin FindOrCreate(Type pluggedType, bool createDefaultInstanceOfType) - { - Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType); - Add(plugin, createDefaultInstanceOfType); - - return plugin; + return list; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-07 15:00:00 UTC (rev 77) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-11 23:31:23 UTC (rev 78) @@ -1,6 +1,9 @@ using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; using StructureMap.Interceptors; -using StructureMap.Source; +using StructureMap.Pipeline; namespace StructureMap.Graph { @@ -9,18 +12,18 @@ /// 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 : Deployable + public class PluginFamily { #region statics + [Obsolete] public static PluginFamily CreateAutoFilledPluginFamily(Type pluginType) { Plugin plugin = Plugin.CreateAutofilledPlugin(pluginType); PluginFamily family = new PluginFamily(pluginType); - family.DefinitionSource = DefinitionSource.Implicit; - family.Plugins.Add(plugin, true); + family.Plugins.Add(plugin); family.DefaultInstanceKey = plugin.ConcreteKey; return family; @@ -29,15 +32,16 @@ #endregion public const string CONCRETE_KEY = "CONCRETE"; + private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>(); private readonly PluginCollection _plugins; private bool _canUseUnMarkedPlugins = false; private string _defaultKey = string.Empty; - private DefinitionSource _definitionSource = DefinitionSource.Implicit; private InstanceInterceptor _instanceInterceptor = new NulloInterceptor(); private InterceptionChain _interceptionChain; + private PluginGraph _parent; private Type _pluginType; private string _pluginTypeName; - private MementoSource _source; + private List<Instance> _instances = new List<Instance>(); #region constructors @@ -49,17 +53,8 @@ _plugins = new PluginCollection(this); _interceptionChain = new InterceptionChain(); - - Source = new MemoryMementoSource(); } - public PluginFamily(Type pluginType, string defaultInstanceKey, MementoSource source) - : this(pluginType, defaultInstanceKey) - { - Source = source; - _definitionSource = DefinitionSource.Explicit; - _pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType); - } /// <summary> /// Testing constructor @@ -87,11 +82,15 @@ _pluginTypeName = path.AssemblyQualifiedName; _interceptionChain = new InterceptionChain(); initializeExplicit(path, defaultKey); + } - Source = new MemoryMementoSource(); + + public PluginGraph Parent + { + get { return _parent; } + set { _parent = value; } } - private void initializeExplicit(TypePath path, string defaultKey) { try @@ -115,14 +114,13 @@ set { _instanceInterceptor = value; } } - // This code sucks. What's going on here? + // 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._source = new MemoryMementoSource(); - templatedFamily._definitionSource = _definitionSource; + templatedFamily.Parent = Parent; foreach (InstanceFactoryInterceptor interceptor in _interceptionChain) { @@ -130,51 +128,26 @@ templatedFamily.InterceptionChain.AddInterceptor(clonedInterceptor); } + // Add Plugins foreach (Plugin plugin in _plugins) { - if (isOfCorrectGenericType(plugin, templateTypes)) + if (plugin.CanBePluggedIntoGenericType(_pluginType, templateTypes)) { Plugin templatedPlugin = plugin.CreateTemplatedClone(templateTypes); - templatedFamily.Plugins.Add(templatedPlugin, true); - foreach (InstanceMemento memento in _source.GetAllMementos()) - { - if (memento.ConcreteKey == plugin.ConcreteKey) - { - templatedFamily._source.AddExternalMemento(memento); - } - } + ... [truncated message content] |
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. |