From: <jer...@us...> - 2009-12-26 20:31:38
|
Revision: 302 http://structuremap.svn.sourceforge.net/structuremap/?rev=302&view=rev Author: jeremydmiller Date: 2009-12-26 20:31:30 +0000 (Sat, 26 Dec 2009) Log Message: ----------- Introduced the new IRegistrationConvention, replacing all ITypeScanner classes Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/FamilyAttributeScanner.cs trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs trunk/Source/StructureMap/Graph/FindRegistriesScanner.cs trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap/Graph/ImplementationMap.cs trunk/Source/StructureMap/Graph/PluggableAttributeScanner.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/TypeExtensions.cs trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -225,6 +225,13 @@ /// <typeparam name="U"></typeparam> /// <returns></returns> LambdaInstance<T> Redirect<T, U>() where T : class where U : class; + + /// <summary> + /// Advanced Usage Only! Skips the Registry and goes right to the inner + /// Semantic Model of StructureMap. Use with care + /// </summary> + /// <param name="configure"></param> + void Configure(Action<PluginGraph> configure); } /// <summary> @@ -641,6 +648,16 @@ }); } + /// <summary> + /// Advanced Usage Only! Skips the Registry and goes right to the inner + /// Semantic Model of StructureMap. Use with care + /// </summary> + /// <param name="configure"></param> + public void Configure(Action<PluginGraph> configure) + { + _actions.Add(configure); + } + #region Nested type: BuildWithExpression /// <summary> Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -49,8 +49,8 @@ public AssemblyScanner() { - With<FamilyAttributeScanner>(); - With<PluggableAttributeScanner>(); + Convention<FamilyAttributeScanner>(); + Convention<PluggableAttributeScanner>(); } public int Count { get { return _assemblies.Count; } } @@ -103,7 +103,7 @@ public void LookForRegistries() { - With<FindRegistriesScanner>(); + Convention<FindRegistriesScanner>(); } public void TheCallingAssembly() @@ -141,8 +141,8 @@ public void IgnoreStructureMapAttributes() { - _scanners.RemoveAll(scanner => scanner is FamilyAttributeScanner); - _scanners.RemoveAll(scanner => scanner is PluggableAttributeScanner); + _conventions.RemoveAll(scanner => scanner is FamilyAttributeScanner); + _conventions.RemoveAll(scanner => scanner is PluggableAttributeScanner); } @@ -189,7 +189,7 @@ public void SingleImplementationsOfInterface() { - _scanners.Fill(_implementationMap); + _conventions.Fill(_implementationMap); _postScanningActions.Add(graph => _implementationMap.RegisterSingleImplementations(graph)); } Modified: trunk/Source/StructureMap/Graph/FamilyAttributeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/FamilyAttributeScanner.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Graph/FamilyAttributeScanner.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -1,19 +1,16 @@ using System; +using StructureMap.Configuration.DSL; namespace StructureMap.Graph { - public class FamilyAttributeScanner : ITypeScanner + public class FamilyAttributeScanner : IRegistrationConvention { - #region ITypeScanner Members - - public void Process(Type type, PluginGraph graph) + public void Process(Type type, Registry registry) { if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) { - graph.CreateFamily(type); + registry.Configure(x => x.FindFamily(type)); } } - - #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs =================================================================== --- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -1,9 +1,10 @@ using System; +using StructureMap.Configuration.DSL; using StructureMap.TypeRules; namespace StructureMap.Graph { - public class FindAllTypesFilter : ITypeScanner + public class FindAllTypesFilter : IRegistrationConvention { private readonly Type _pluginType; private Func<Type, string> _getName = type => PluginCache.GetPlugin(type).ConcreteKey; @@ -13,22 +14,18 @@ _pluginType = pluginType; } - #region ITypeScanner Members + public void NameBy(Func<Type, string> getName) + { + _getName = getName; + } - public void Process(Type type, PluginGraph graph) + public void Process(Type type, Registry registry) { if (type.CanBeCastTo(_pluginType) && Constructor.HasConstructors(type)) { string name = _getName(type); - graph.AddType(_pluginType, type, name); + registry.AddType(_pluginType, type, name); } } - - public void NameBy(Func<Type, string> getName) - { - _getName = getName; - } - - #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/FindRegistriesScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/FindRegistriesScanner.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Graph/FindRegistriesScanner.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -3,26 +3,14 @@ namespace StructureMap.Graph { - public class FindRegistriesScanner : ITypeScanner + public class FindRegistriesScanner : IRegistrationConvention { - #region ITypeScanner Members - - public void Process(Type type, PluginGraph graph) + public void Process(Type type, Registry registry) { - if (!Registry.IsPublicRegistry(type)) return; - - foreach (Registry previous in graph.Registries) + if (Registry.IsPublicRegistry(type)) { - if (previous.GetType().Equals(type)) - { - return; - } + registry.Configure(x => x.ImportRegistry(type)); } - - var registry = (Registry) Activator.CreateInstance(type); - registry.ConfigurePluginGraph(graph); } - - #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -36,7 +36,7 @@ } } - public class GenericConnectionScanner : ITypeScanner + public class GenericConnectionScanner : IRegistrationConvention { private readonly Type _openType; @@ -50,12 +50,12 @@ } } - public void Process(Type type, PluginGraph graph) + public void Process(Type type, Registry registry) { Type interfaceType = type.FindInterfaceThatCloses(_openType); if (interfaceType != null) { - graph.AddType(interfaceType, type); + registry.For(interfaceType).Add(type); } } } Modified: trunk/Source/StructureMap/Graph/ImplementationMap.cs =================================================================== --- trunk/Source/StructureMap/Graph/ImplementationMap.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Graph/ImplementationMap.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -1,20 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; +using StructureMap.Configuration.DSL; using StructureMap.TypeRules; using StructureMap.Util; namespace StructureMap.Graph { - public class ImplementationMap : ITypeScanner + public class ImplementationMap : IRegistrationConvention { private readonly Cache<Type, List<Type>> _types = new Cache<Type, List<Type>>(t => new List<Type>()); - public void Process(Type type, PluginGraph graph) - { - RegisterType(type); - } - public void Register(Type interfaceType, Type concreteType) { _types[interfaceType].Add(concreteType); @@ -37,5 +33,10 @@ } }); } + + public void Process(Type type, Registry registry) + { + RegisterType(type); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluggableAttributeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluggableAttributeScanner.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Graph/PluggableAttributeScanner.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -1,19 +1,16 @@ using System; +using StructureMap.Configuration.DSL; namespace StructureMap.Graph { - public class PluggableAttributeScanner : ITypeScanner + public class PluggableAttributeScanner : IRegistrationConvention { - #region ITypeScanner Members - - public void Process(Type type, PluginGraph graph) + public void Process(Type type, Registry registry) { if (PluggableAttribute.MarkedAsPluggable(type)) { - graph.AddType(type); + registry.AddType(type); } } - - #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -5,6 +5,7 @@ using StructureMap.Diagnostics; using StructureMap.Interceptors; using StructureMap.Pipeline; +using System.Linq; namespace StructureMap.Graph { @@ -218,5 +219,13 @@ registry.ConfigurePluginGraph(this); } + + public void ImportRegistry(Type type) + { + if (Registries.Any(x => x.GetType() == type)) return; + + var registry = (Registry)Activator.CreateInstance(type); + registry.ConfigurePluginGraph(this); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/TypeExtensions.cs =================================================================== --- trunk/Source/StructureMap/TypeExtensions.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap/TypeExtensions.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -246,6 +246,8 @@ { return IsChild(type) || IsChildArray(type); } + + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-12-26 19:29:05 UTC (rev 301) +++ trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-12-26 20:31:30 UTC (rev 302) @@ -194,10 +194,19 @@ var scanner = new FamilyAttributeScanner(); var graph = new PluginGraph(); - scanner.Process(typeof (ITypeThatHasAttributeButIsNotInRegistry), graph); + var registry = new Registry(); + + scanner.Process(typeof (ITypeThatHasAttributeButIsNotInRegistry), registry); + registry.ConfigurePluginGraph(graph); + graph.PluginFamilies.Contains(typeof (ITypeThatHasAttributeButIsNotInRegistry)).ShouldBeTrue(); - scanner.Process(GetType(), graph); + graph = new PluginGraph(); + registry = new Registry(); + + scanner.Process(GetType(), registry); + registry.ConfigurePluginGraph(graph); + graph.PluginFamilies.Contains(GetType()).ShouldBeFalse(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |