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