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] |