From: <jer...@us...> - 2009-12-27 16:51:33
|
Revision: 305 http://structuremap.svn.sourceforge.net/structuremap/?rev=305&view=rev Author: jeremydmiller Date: 2009-12-27 16:51:25 +0000 (Sun, 27 Dec 2009) Log Message: ----------- Some refactoring in preparation for redoing the "Model" query system Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/PluginTypeConfiguration.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.DebuggerVisualizers/ContainerVisualizerObjectSource.cs trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs trunk/Source/StructureMap.Testing/ModelQueryTester.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs Added Paths: ----------- trunk/Source/StructureMap/Query/ trunk/Source/StructureMap/Query/IModel.cs trunk/Source/StructureMap/Query/Model.cs Removed Paths: ------------- trunk/Source/StructureMap/IModel.cs trunk/Source/StructureMap/Model.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/Container.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -8,6 +8,7 @@ using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; +using StructureMap.Query; using StructureMap.TypeRules; namespace StructureMap Modified: trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -6,6 +6,7 @@ using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; +using StructureMap.Query; namespace StructureMap.Diagnostics { @@ -14,7 +15,7 @@ private readonly Stack<BuildDependency> _dependencyStack = new Stack<BuildDependency>(); private readonly List<ValidationError> _validationErrors = new List<ValidationError>(); private ErrorCollection _errors; - private List<IInstance> _explicitInstances; + private List<Instance> _explicitInstances; public ValidationBuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) : base(pipelineGraph, interceptorLibrary, new NulloObjectCache()) Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -2,6 +2,7 @@ using System.IO; using System.Text; using StructureMap.Pipeline; +using StructureMap.Query; using StructureMap.TypeRules; namespace StructureMap.Diagnostics Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -3,6 +3,7 @@ using System.Linq; using StructureMap.Attributes; using StructureMap.Pipeline; +using StructureMap.Query; using StructureMap.TypeRules; using StructureMap.Util; @@ -324,6 +325,7 @@ }; } + [Obsolete("replace with Instances")] public void ForInstance(string name, Action<Instance> action) { _instances.WithValue(name, action); @@ -338,7 +340,9 @@ public int InstanceCount { get { return _instances.Count; } } + [Obsolete] public IEnumerable<IInstance> Instances { get { return _instances.GetAll(); } } + public Instance MissingInstance { get; set; } /// <summary> Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/IContainer.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using StructureMap.Pipeline; +using StructureMap.Query; namespace StructureMap { Deleted: trunk/Source/StructureMap/IModel.cs =================================================================== --- trunk/Source/StructureMap/IModel.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/IModel.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using StructureMap.Pipeline; - -namespace StructureMap -{ - /// <summary> - /// Models the state of a Container or ObjectFactory. Can be used to query for the - /// existence of types registered with StructureMap - /// </summary> - public interface IModel - { - /// <summary> - /// Access to all the <seealso cref="PluginTypeConfiguration">Plugin Type</seealso> registrations - /// </summary> - IEnumerable<PluginTypeConfiguration> PluginTypes { get; } - - IEnumerable<IInstance> AllInstances { get; } - - /// <summary> - /// Can StructureMap fulfill a request to ObjectFactory.GetInstance(pluginType) from the - /// current configuration. This does not include concrete classes that could be auto-configured - /// upon demand - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - bool HasDefaultImplementationFor(Type pluginType); - - /// <summary> - /// Can StructureMap fulfill a request to ObjectFactory.GetInstance<T>() from the - /// current configuration. This does not include concrete classes that could be auto-configured - /// upon demand - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - bool HasDefaultImplementationFor<T>(); - - /// <summary> - /// Queryable access to all of the <see cref="IInstance">IInstance</see> for a given PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - IEnumerable<IInstance> InstancesOf(Type pluginType); - - /// <summary> - /// Queryable access to all of the <see cref="IInstance">IInstance</see> for a given PluginType - /// </summary> - /// <returns></returns> - IEnumerable<IInstance> InstancesOf<T>(); - - /// <summary> - /// Does the current container have existing configuration for the "pluginType" - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - bool HasImplementationsFor(Type pluginType); - - /// <summary> - /// Does the current container have existing configuration for the type T - /// </summary> - /// <returns></returns> - bool HasImplementationsFor<T>(); - - /// <summary> - /// Find the concrete type for the default Instance of T. - /// In other words, when I call Container.GetInstance(Type), - /// what do I get? May be indeterminate - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - Type DefaultTypeFor<T>(); - - /// <summary> - /// Find the concrete type for the default Instance of pluginType. - /// In other words, when I call Container.GetInstance(Type), - /// what do I get? May be indeterminate - /// </summary> - /// <returns></returns> - Type DefaultTypeFor(Type pluginType); - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Model.cs =================================================================== --- trunk/Source/StructureMap/Model.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/Model.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -1,85 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using StructureMap.Pipeline; - -namespace StructureMap -{ - public class Model : IModel - { - private readonly PipelineGraph _graph; - private readonly IContainer _container; - - internal Model(PipelineGraph graph, IContainer container) - { - _graph = graph; - _container = container; - } - - #region IModel Members - - public bool HasDefaultImplementationFor(Type pluginType) - { - return findForFamily(pluginType, f => f.Default != null); - } - - private T findForFamily<T>(Type pluginType, Func<PluginTypeConfiguration, T> func) - { - PluginTypeConfiguration family = PluginTypes.FirstOrDefault(x => x.PluginType == pluginType); - return family == null ? default(T) : func(family); - } - - public bool HasDefaultImplementationFor<T>() - { - return HasDefaultImplementationFor(typeof (T)); - } - - public Type DefaultTypeFor<T>() - { - return DefaultTypeFor(typeof (T)); - } - - public Type DefaultTypeFor(Type pluginType) - { - return findForFamily(pluginType, f => f.Default == null ? null : f.Default.ConcreteType); - } - - public IEnumerable<PluginTypeConfiguration> PluginTypes { get { return _graph.PluginTypes; } } - - public IEnumerable<IInstance> InstancesOf(Type pluginType) - { - return _graph.InstancesOf(pluginType); - } - - public IEnumerable<IInstance> InstancesOf<T>() - { - return _graph.InstancesOf(typeof (T)); - } - - public bool HasImplementationsFor(Type pluginType) - { - return _graph.InstancesOf(pluginType).Count() > 0; - } - - public bool HasImplementationsFor<T>() - { - return HasImplementationsFor(typeof (T)); - } - - public IEnumerable<IInstance> AllInstances - { - get - { - foreach (PluginTypeConfiguration pluginType in PluginTypes) - { - foreach (IInstance instance in pluginType.Instances) - { - yield return instance; - } - } - } - } - - #endregion - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/ObjectFactory.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -3,6 +3,7 @@ using System.Collections.Generic; using StructureMap.Graph; using StructureMap.Pipeline; +using StructureMap.Query; namespace StructureMap { Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -2,23 +2,12 @@ using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Interceptors; +using StructureMap.Query; namespace StructureMap.Pipeline { - public interface IInstance - { - string Name { get; } - /// <summary> - /// The actual concrete type of this Instance. Not every type of IInstance - /// can determine the ConcreteType - /// </summary> - Type ConcreteType { get; } - - string Description { get; } - } - public interface IDiagnosticInstance : IInstance { bool CanBePartOfPluginFamily(PluginFamily family); Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/PipelineGraph.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -4,6 +4,7 @@ using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Pipeline; +using StructureMap.Query; namespace StructureMap { @@ -212,6 +213,7 @@ _profileManager.EjectAllInstancesOf<T>(); } + [Obsolete("Move this to PluginTypeConfiguration")] public IEnumerable<IInstance> InstancesOf(Type pluginType) { if (_genericsGraph.HasFamily(pluginType)) @@ -227,16 +229,9 @@ return new IInstance[0]; } - public List<IInstance> GetAllInstances() + public List<Instance> GetAllInstances() { - var list = new List<IInstance>(); - - foreach (var pair in _factories) - { - list.AddRange(pair.Value.AllInstances); - } - - return list; + return _factories.Values.SelectMany(x => x.AllInstances).ToList(); } public bool HasDefaultForPluginType(Type pluginType) Modified: trunk/Source/StructureMap/PluginTypeConfiguration.cs =================================================================== --- trunk/Source/StructureMap/PluginTypeConfiguration.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/PluginTypeConfiguration.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using StructureMap.Pipeline; +using StructureMap.Query; namespace StructureMap { @@ -13,7 +14,7 @@ /// <summary> /// The "instance" that will be used when Container.GetInstance(PluginType) is called. - /// See <see cref="StructureMap.Pipeline.IInstance">IInstance</see> for more information + /// See <see cref="IInstance">IInstance</see> for more information /// </summary> public IInstance Default { get; set; } @@ -23,7 +24,7 @@ public ILifecycle Lifecycle { get; set; } /// <summary> - /// All of the <see cref="StructureMap.Pipeline.IInstance">IInstance</see>'s registered + /// All of the <see cref="IInstance">IInstance</see>'s registered /// for this PluginType /// </summary> public IEnumerable<IInstance> Instances { get; set; } Copied: trunk/Source/StructureMap/Query/IModel.cs (from rev 304, trunk/Source/StructureMap/IModel.cs) =================================================================== --- trunk/Source/StructureMap/Query/IModel.cs (rev 0) +++ trunk/Source/StructureMap/Query/IModel.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using StructureMap.Pipeline; + +namespace StructureMap.Query +{ + + public interface IInstance + { + string Name { get; } + + /// <summary> + /// The actual concrete type of this Instance. Not every type of IInstance + /// can determine the ConcreteType + /// </summary> + Type ConcreteType { get; } + + + string Description { get; } + } + + /// <summary> + /// Models the state of a Container or ObjectFactory. Can be used to query for the + /// existence of types registered with StructureMap + /// </summary> + public interface IModel + { + /// <summary> + /// Access to all the <seealso cref="PluginTypeConfiguration">Plugin Type</seealso> registrations + /// </summary> + IEnumerable<PluginTypeConfiguration> PluginTypes { get; } + + IEnumerable<IInstance> AllInstances { get; } + + /// <summary> + /// Can StructureMap fulfill a request to ObjectFactory.GetInstance(pluginType) from the + /// current configuration. This does not include concrete classes that could be auto-configured + /// upon demand + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + bool HasDefaultImplementationFor(Type pluginType); + + /// <summary> + /// Can StructureMap fulfill a request to ObjectFactory.GetInstance<T>() from the + /// current configuration. This does not include concrete classes that could be auto-configured + /// upon demand + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + bool HasDefaultImplementationFor<T>(); + + /// <summary> + /// Queryable access to all of the <see cref="IInstance">IInstance</see> for a given PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + IEnumerable<IInstance> InstancesOf(Type pluginType); + + /// <summary> + /// Queryable access to all of the <see cref="IInstance">IInstance</see> for a given PluginType + /// </summary> + /// <returns></returns> + IEnumerable<IInstance> InstancesOf<T>(); + + /// <summary> + /// Does the current container have existing configuration for the "pluginType" + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + bool HasImplementationsFor(Type pluginType); + + /// <summary> + /// Does the current container have existing configuration for the type T + /// </summary> + /// <returns></returns> + bool HasImplementationsFor<T>(); + + /// <summary> + /// Find the concrete type for the default Instance of T. + /// In other words, when I call Container.GetInstance(Type), + /// what do I get? May be indeterminate + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + Type DefaultTypeFor<T>(); + + /// <summary> + /// Find the concrete type for the default Instance of pluginType. + /// In other words, when I call Container.GetInstance(Type), + /// what do I get? May be indeterminate + /// </summary> + /// <returns></returns> + Type DefaultTypeFor(Type pluginType); + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Query/Model.cs (from rev 304, trunk/Source/StructureMap/Model.cs) =================================================================== --- trunk/Source/StructureMap/Query/Model.cs (rev 0) +++ trunk/Source/StructureMap/Query/Model.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StructureMap.Pipeline; + +namespace StructureMap.Query +{ + public class Model : IModel + { + private readonly PipelineGraph _graph; + private readonly IContainer _container; + + internal Model(PipelineGraph graph, IContainer container) + { + _graph = graph; + _container = container; + } + + #region IModel Members + + public bool HasDefaultImplementationFor(Type pluginType) + { + return findForFamily(pluginType, f => f.Default != null); + } + + private T findForFamily<T>(Type pluginType, Func<PluginTypeConfiguration, T> func) + { + PluginTypeConfiguration family = PluginTypes.FirstOrDefault(x => x.PluginType == pluginType); + return family == null ? default(T) : func(family); + } + + public bool HasDefaultImplementationFor<T>() + { + return HasDefaultImplementationFor(typeof (T)); + } + + public Type DefaultTypeFor<T>() + { + return DefaultTypeFor(typeof (T)); + } + + public Type DefaultTypeFor(Type pluginType) + { + return findForFamily(pluginType, f => f.Default == null ? null : f.Default.ConcreteType); + } + + public IEnumerable<PluginTypeConfiguration> PluginTypes { get { return _graph.PluginTypes; } } + + public IEnumerable<IInstance> InstancesOf(Type pluginType) + { + return _graph.InstancesOf(pluginType); + } + + public IEnumerable<IInstance> InstancesOf<T>() + { + return _graph.InstancesOf(typeof (T)); + } + + public bool HasImplementationsFor(Type pluginType) + { + return _graph.InstancesOf(pluginType).Count() > 0; + } + + public bool HasImplementationsFor<T>() + { + return HasImplementationsFor(typeof (T)); + } + + public IEnumerable<IInstance> AllInstances + { + get + { + foreach (PluginTypeConfiguration pluginType in PluginTypes) + { + foreach (IInstance instance in pluginType.Instances) + { + yield return instance; + } + } + } + } + + #endregion + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap/StructureMap.csproj 2009-12-27 16:51:25 UTC (rev 305) @@ -367,7 +367,7 @@ <Compile Include="Graph\PluggableAttributeScanner.cs" /> <Compile Include="Graph\PluginCache.cs" /> <Compile Include="IContext.cs" /> - <Compile Include="IModel.cs" /> + <Compile Include="Query\IModel.cs" /> <Compile Include="Pipeline\Arguments.cs" /> <Compile Include="Pipeline\ArrayCoercion.cs" /> <Compile Include="Pipeline\ConditionalInstance.cs" /> @@ -392,7 +392,7 @@ <Compile Include="TypeExtensions.cs" /> <Compile Include="IBootstrapper.cs" /> <Compile Include="InitializationExpression.cs" /> - <Compile Include="Model.cs" /> + <Compile Include="Query\Model.cs" /> <Compile Include="Pipeline\BuildFrame.cs" /> <Compile Include="Pipeline\BuildStack.cs" /> <Compile Include="Pipeline\ConfiguredInstanceBase.cs" /> Modified: trunk/Source/StructureMap.DebuggerVisualizers/ContainerVisualizerObjectSource.cs =================================================================== --- trunk/Source/StructureMap.DebuggerVisualizers/ContainerVisualizerObjectSource.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap.DebuggerVisualizers/ContainerVisualizerObjectSource.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -4,6 +4,7 @@ using System.Linq; using Microsoft.VisualStudio.DebuggerVisualizers; using StructureMap.Pipeline; +using StructureMap.Query; namespace StructureMap.DebuggerVisualizers { Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -6,6 +6,7 @@ using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; +using StructureMap.Query; using StructureMap.Testing.DocumentationExamples; using StructureMap.Testing.Widget; using StructureMap.Testing.Widget3; Modified: trunk/Source/StructureMap.Testing/ModelQueryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ModelQueryTester.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap.Testing/ModelQueryTester.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -3,6 +3,7 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; using StructureMap.Graph; +using StructureMap.Query; using StructureMap.Testing.GenericWidgets; using StructureMap.Testing.Graph; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing/PipelineGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/PipelineGraphTester.cs 2009-12-27 15:59:19 UTC (rev 304) +++ trunk/Source/StructureMap.Testing/PipelineGraphTester.cs 2009-12-27 16:51:25 UTC (rev 305) @@ -4,6 +4,7 @@ using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; +using StructureMap.Query; using StructureMap.Testing.GenericWidgets; using StructureMap.Testing.Graph; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |