From: <jer...@us...> - 2007-02-25 19:29:52
|
Revision: 24 http://structuremap.svn.sourceforge.net/structuremap/?rev=24&view=rev Author: jeremydmiller Date: 2007-02-25 11:29:51 -0800 (Sun, 25 Feb 2007) Log Message: ----------- Working on the Fluent Interface configuration for adding instances Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/IExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/Graph/PluginCollection.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/MemoryInstanceMemento.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.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/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing.Widget/IWidget.cs trunk/Source/StructureMap.Testing.Widget/Rule.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs trunk/Source/StructureMap/IInstanceCreator.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config Added: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Text; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + public class ChildInstanceExpression : IExpression + { + private readonly InstanceExpression _instance; + private readonly MemoryInstanceMemento _memento; + private readonly string _propertyName; + private Plugin _plugin; + private Type _childType; + private List<IExpression> _children = new List<IExpression>(); + + + public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName) + { + _instance = instance; + _memento = memento; + _propertyName = propertyName; + } + + + + public InstanceExpression IsNamedInstance(string instanceKey) + { + MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey); + _memento.AddChild(_propertyName, child); + + return _instance; + } + + // TODO -- negative case if the concrete type cannot be an implicit instance + public InstanceExpression IsConcreteType<T>() + { + _plugin = Plugin.CreateImplicitPlugin(typeof(T)); + MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(_plugin.ConcreteKey); + _memento.AddChild(_propertyName, child); + + return _instance; + } + + + void IExpression.Configure(PluginGraph graph) + { + if (_plugin == null || _childType == null) + { + return; + } + + PluginFamily family = graph.LocateOrCreateFamilyForType(_childType); + family.Plugins.FindOrCreate(_plugin.PluggedType); + } + + + IExpression[] IExpression.ChildExpressions + { + get { return _children.ToArray(); } + } + + internal Type ChildType + { + set { _childType = value; } + } + + public InstanceExpression Is(InstanceExpression child) + { + _children.Add(child); + MemoryInstanceMemento childMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey); + _memento.AddChild(_propertyName, childMemento); + + return _instance; + } + } +} Modified: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -39,6 +39,11 @@ graph.Assemblies.Add(assembly); } + IExpression[] IExpression.ChildExpressions + { + get { return new IExpression[0]; } + } + public CreatePluginFamilyExpression WithDefaultConcreteType<T>() { Plugin plugin = addPlugin<T>(); @@ -87,5 +92,10 @@ _scope = scope; return this; } + + public void AndTheDefaultIs(InstanceExpression expression) + { + throw new NotImplementedException(); + } } } Modified: trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -17,5 +17,10 @@ { _configure(graph); } + + IExpression[] IExpression.ChildExpressions + { + get { return new IExpression[0]; } + } } } Modified: trunk/Source/StructureMap/Configuration/DSL/IExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -8,5 +8,6 @@ public interface IExpression { void Configure(PluginGraph graph); + IExpression[] ChildExpressions { get;} } } Added: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Configuration; +using System.Reflection; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + public class InstanceExpression : IExpression + { + private readonly Type _pluginType; + private Type _pluggedType; + private string _propertyName; + private MemoryInstanceMemento _memento; + private List<IExpression> _children = new List<IExpression>(); + + + + public InstanceExpression(Type pluginType) + { + _pluginType = pluginType; + _memento = new MemoryInstanceMemento(); + _memento.InstanceKey = Guid.NewGuid().ToString(); + } + + void IExpression.Configure(PluginGraph graph) + { + if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey)) + { + throw new StructureMapException(301, _memento.InstanceKey, TypePath.GetAssemblyQualifiedName(_pluginType)); + } + + PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); + Plugin plugin = _pluggedType == null + ? family.Plugins[_memento.ConcreteKey] + : family.Plugins.FindOrCreate(_pluggedType); + + _memento.ConcreteKey = plugin.ConcreteKey; + + + + family.Source.AddExternalMemento(_memento); + } + + + public IExpression[] ChildExpressions + { + get { return _children.ToArray(); } + } + + + public InstanceExpression WithName(string instanceKey) + { + _memento.InstanceKey = instanceKey; + return this; + } + + + public string InstanceKey + { + get { return _memento.InstanceKey; } + set { _memento.InstanceKey = value; } + } + + internal Type PluginType + { + get { return _pluginType; } + } + + public InstanceExpression UsingConcreteType<T>() + { + _pluggedType = typeof (T); + return this; + } + + public PropertyExpression WithProperty(string propertyName) + { + return new PropertyExpression(this, _memento, propertyName); + } + + + + + public void UsePrototype(ICloneable cloneable) + { + + } + + + + public InstanceExpression UsingConcreteTypeNamed(string concreteKey) + { + _memento.ConcreteKey = concreteKey; + return this; + } + + public ChildInstanceExpression Child(string propertyName) + { + ChildInstanceExpression child = new ChildInstanceExpression(this,_memento, propertyName); + _children.Add(child); + + return child; + } + + public ChildInstanceExpression Child<T>() + { + // TODO -- what if the property can't be found + string propertyName = findPropertyName<T>(); + ChildInstanceExpression child = Child(propertyName); + child.ChildType = typeof (T); + return child; + } + + private string findPropertyName<T>() + { + Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType); + return plugin.FindFirstConstructorArgumentOfType<T>(); + } + + + + } +} Added: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,18 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + public class ProfileExpression : IExpression + { + public void Configure(PluginGraph graph) + { + throw new NotImplementedException(); + } + + public IExpression[] ChildExpressions + { + get { throw new NotImplementedException(); } + } + } +} Added: trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Text; + +namespace StructureMap.Configuration.DSL +{ + public class PropertyExpression + { + private readonly InstanceExpression _instance; + private readonly MemoryInstanceMemento _memento; + private readonly string _propertyName; + + public PropertyExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName) + { + _instance = instance; + _memento = memento; + _propertyName = propertyName; + } + + public InstanceExpression EqualTo(object propertyValue) + { + _memento.SetProperty(_propertyName, propertyValue.ToString()); + return _instance; + } + + public InstanceExpression EqualToAppSetting(string appSettingKey) + { + string propertyValue = ConfigurationManager.AppSettings[appSettingKey]; + _memento.SetProperty(_propertyName, propertyValue); + return _instance; + } + } +} Added: trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + public class PrototypeExpression : IExpression + { + public void Configure(PluginGraph graph) + { + throw new NotImplementedException(); + } + + public IExpression[] ChildExpressions + { + get { return new IExpression[0]; } + } + + public void WithName(string instanceKey) + { + + } + } +} Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -7,7 +7,7 @@ public class Registry : IDisposable { private List<IExpression> _expressions = new List<IExpression>(); - private readonly PluginGraph _graph; + private PluginGraph _graph; public Registry(PluginGraph graph) { @@ -16,7 +16,17 @@ public Registry() { + _graph = new PluginGraph(); + } + + + /// <summary> + /// Implement this method to + /// </summary> + protected virtual void configure() + { + // no-op; } protected void addExpression(IExpression expression) @@ -24,17 +34,26 @@ _expressions.Add(expression); } - public void Configure(PluginGraph graph) + private void configurePluginGraph(PluginGraph graph) { foreach (IExpression expression in _expressions) { - expression.Configure(graph); + configureExpression(expression, graph); } } + private static void configureExpression(IExpression expression, PluginGraph graph) + { + expression.Configure(graph); + foreach (IExpression childExpression in expression.ChildExpressions) + { + configureExpression(childExpression, graph); + } + } + public void Dispose() { - Configure(_graph); + configurePluginGraph(_graph); } public ScanAssembliesExpression ScanAssemblies() @@ -56,8 +75,25 @@ public InstanceManager BuildInstanceManager() { PluginGraph graph = new PluginGraph(); - Configure(graph); + configurePluginGraph(graph); return new InstanceManager(graph); } + + public InstanceExpression AddInstanceOf<T>() + { + InstanceExpression expression = new InstanceExpression(typeof(T)); + addExpression(expression); + return expression; + } + + public static InstanceExpression Instance<T>() + { + return new InstanceExpression(typeof(T)); + } + + public PrototypeExpression AddInstanceOf<T>(T prototype) + { + return new PrototypeExpression(); + } } } Modified: trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -20,6 +20,11 @@ } } + public IExpression[] ChildExpressions + { + get { return new IExpression[0]; } + } + public ScanAssembliesExpression IncludeTheCallingAssembly() { Assembly callingAssembly = findTheCallingAssembly(); Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -398,5 +398,19 @@ { return (_pluggedType != null ? _pluggedType.GetHashCode() : 0) + 29*(_concreteKey != null ? _concreteKey.GetHashCode() : 0); } + + public string FindFirstConstructorArgumentOfType<T>() + { + ConstructorInfo ctor = this.GetConstructor(); + foreach (ParameterInfo info in ctor.GetParameters()) + { + if (info.ParameterType.Equals(typeof(T))) + { + return info.Name; + } + } + + throw new StructureMapException(302, typeof (T).FullName, _pluggedType.FullName); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCollection.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -153,5 +153,13 @@ } } } + + public Plugin FindOrCreate(Type pluggedType) + { + Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType); + Add(plugin); + + return plugin; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -143,13 +143,24 @@ public TypePath LocateOrCreateFamilyForType(string fullName) { Type pluginType = findTypeByFullName(fullName); + buildFamilyIfMissing(pluginType); + + return new TypePath(pluginType); + } + + private void buildFamilyIfMissing(Type pluginType) + { if (!_pluginFamilies.Contains(pluginType)) { PluginFamily family = _pluginFamilies.Add(pluginType, string.Empty); attachImplicitPlugins(family); } + } - return new TypePath(pluginType); + public PluginFamily LocateOrCreateFamilyForType(Type pluginType) + { + buildFamilyIfMissing(pluginType); + return this.PluginFamilies[pluginType]; } private Type findTypeByFullName(string fullName) @@ -170,5 +181,7 @@ { _defaultManager.ReadDefaultsFromPluginGraph(this); } + + } } \ No newline at end of file Added: trunk/Source/StructureMap/IInstanceCreator.cs =================================================================== --- trunk/Source/StructureMap/IInstanceCreator.cs (rev 0) +++ trunk/Source/StructureMap/IInstanceCreator.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,7 @@ +namespace StructureMap +{ + public interface IInstanceCreator + { + object BuildInstance(InstanceMemento memento); + } +} Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/InstanceFactory.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -12,7 +12,7 @@ /// <summary> /// Default implementation of IInstanceFactory /// </summary> - public class InstanceFactory : IInstanceFactory + public class InstanceFactory : IInstanceFactory, IInstanceCreator { private Type _pluginType; private string _assemblyName; @@ -204,11 +204,13 @@ { // Let the MementoSource fill in Templates, resolve references, etc. InstanceMemento resolvedMemento = _source.ResolveMemento(memento); - return buildFromInstanceBuilder(resolvedMemento); + + + return resolvedMemento.Build(this); } - private object buildFromInstanceBuilder(InstanceMemento memento) + public object BuildInstance(InstanceMemento memento) { if (!_instanceBuilders.Contains(memento.ConcreteKey)) { Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/InstanceManager.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -156,16 +156,9 @@ return instanceFactory.GetInstance(instanceKey); } - /// <summary> - /// Creates the named instance of the PluginTypeName - /// </summary> - /// <param name="pluginTypeName">Fully qualified name of the CLR Type to create</param> - /// <param name="instanceKey"></param> - /// <returns></returns> - public object CreateInstance(string pluginTypeName, string instanceKey) + public T CreateInstance<T>(string instanceKey) { - IInstanceFactory instanceFactory = this[pluginTypeName]; - return instanceFactory.GetInstance(instanceKey); + return (T) CreateInstance(typeof (T), instanceKey); } /// <summary> @@ -179,6 +172,11 @@ return instanceFactory.GetInstance(); } + public T CreateInstance<T>() + { + return (T)CreateInstance(typeof(T)); + } + /// <summary> /// Creates a new object instance of the requested type /// </summary> @@ -203,6 +201,8 @@ return instanceFactory.GetInstance(instanceMemento); } + + /// <summary> /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other /// classes to link children members @@ -331,6 +331,11 @@ return factory.GetInstance(); } + public T FillDependencies<T>() + { + return (T) FillDependencies(typeof (T)); + } + private InstanceFactory getFilledTypeFactory(Type type) { if (!_filledTypeFactories.Contains(type)) Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/InstanceMemento.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -41,6 +41,7 @@ return _concreteKey; } + set { _concreteKey = value; } } protected abstract string innerConcreteKey { get; } @@ -260,5 +261,10 @@ return Plugin.CreateImplicitPlugin(pluggedType); } } + + public virtual object Build(IInstanceCreator creator) + { + return creator.BuildInstance(this); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/MemoryInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/MemoryInstanceMemento.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/MemoryInstanceMemento.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -75,7 +75,7 @@ } - private MemoryInstanceMemento() + public MemoryInstanceMemento() { } @@ -114,7 +114,13 @@ _children.Add(name, Memento); } + public void ReferenceChild(string name, string instanceKey) + { + InstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey); + AddChild(name, child); + } + /// <summary> /// Links an array of InstanceMemento's to a named array property /// </summary> Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/StructureMap.csproj 2007-02-25 19:29:51 UTC (rev 24) @@ -103,6 +103,7 @@ <Reference Include="System"> <Name>System</Name> </Reference> + <Reference Include="System.configuration" /> <Reference Include="System.Data"> <Name>System.Data</Name> </Reference> @@ -212,9 +213,14 @@ <Compile Include="Configuration\DiagnosticGraphBuilder.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Configuration\DSL\ChildInstanceExpression.cs" /> <Compile Include="Configuration\DSL\CreatePluginFamilyExpression.cs" /> <Compile Include="Configuration\DSL\DefaultExpression.cs" /> <Compile Include="Configuration\DSL\IExpression.cs" /> + <Compile Include="Configuration\DSL\InstanceExpression.cs" /> + <Compile Include="Configuration\DSL\ProfileExpression.cs" /> + <Compile Include="Configuration\DSL\PropertyExpression.cs" /> + <Compile Include="Configuration\DSL\PrototypeExpression.cs" /> <Compile Include="Configuration\DSL\Registry.cs" /> <Compile Include="Configuration\DSL\ScanAssembliesExpression.cs" /> <Compile Include="Configuration\FamilyParser.cs"> @@ -435,6 +441,7 @@ <Compile Include="Graph\TypePath.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="IInstanceCreator.cs" /> <Compile Include="IInstanceFactory.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap/StructureMapException.resx 2007-02-25 19:29:51 UTC (rev 24) @@ -231,4 +231,10 @@ <data name="300" xml:space="preserve"> <value>The implied PluginType {0} cannot be found in any of the configured assemblies </value> </data> + <data name="301" xml:space="preserve"> + <value>No concrete type or concrete key is specified for instance {0} for PluginType {1}</value> + </data> + <data name="302" xml:space="preserve"> + <value>There is no argument of type {0} for concrete type {1}</value> + </data> </root> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,234 @@ +using System; +using System.Configuration; +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Testing.Widget; +using IList=System.Collections.IList; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class AddInstanceTester + { + private InstanceManager manager; + private PluginGraph pluginGraph; + + [SetUp] + public void SetUp() + { + pluginGraph = new PluginGraph(); + Registry registry = new Registry(pluginGraph); + + // Add an instance with properties + registry.AddInstanceOf<IWidget>() + .WithName("DarkGreen") + .UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualTo("DarkGreen"); + + // Add an instance by specifying the ConcreteKey + registry.AddInstanceOf<IWidget>() + .WithName("Purple") + .UsingConcreteTypeNamed("Color") + .WithProperty("Color").EqualTo("Purple"); + + // Pull a property from the App config + registry.AddInstanceOf<IWidget>() + .WithName("AppSetting") + .UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualToAppSetting("Color"); + + + + + registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>(); + + + + + + /* + + + + // Build an instance for IWidget, then setup StructureMap to return cloned instances of the + // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy" + registry.AddInstanceOf<IWidget>().WithName("Jeremy").UsePrototype(new CloneableWidget("Jeremy")); + + // Return the specific instance when an IWidget named "Julia" is requested + registry.AddInstanceOf<IWidget>( new CloneableWidget("Julia") ).WithName("Julia"); + */ + manager = registry.BuildInstanceManager(); + } + + + + + [Test] + public void SpecifyANewInstanceWithADependency() + { + Registry registry = new Registry(); + + // Specify a new Instance, create an instance for a dependency on the fly + string instanceKey = "OrangeWidgetRule"; + registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey) + .Child<IWidget>().Is( + Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualTo("Orange") + .WithName("Orange") + ); + + InstanceManager mgr = registry.BuildInstanceManager(); + + ColorWidget orange = (ColorWidget) mgr.CreateInstance<IWidget>("Orange"); + Assert.IsNotNull(orange); + + WidgetRule rule = (WidgetRule)mgr.CreateInstance<Rule>(instanceKey); + ColorWidget widget = (ColorWidget) rule.Widget; + Assert.AreEqual("Orange", widget.Color); + } + + + [Test] + public void AddInstanceAndOverrideTheConcreteTypeForADependency() + { + Registry registry = new Registry(); + + // Specify a new Instance that specifies the concrete type used for a dependency + registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("AWidgetRule") + .Child<IWidget>().IsConcreteType<AWidget>(); + + manager = registry.BuildInstanceManager(); + + WidgetRule rule = (WidgetRule)manager.CreateInstance<Rule>("AWidgetRule"); + Assert.IsInstanceOfType(typeof(AWidget), rule.Widget); + } + + [Test] + public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteType() + { + ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("DarkGreen"); + Assert.AreEqual("DarkGreen", widget.Color); + } + + [Test] + public void AddAnInstanceWithANameAndAPropertySpecifyingConcreteKey() + { + ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("Purple"); + Assert.AreEqual("Purple", widget.Color); + } + + [Test] + public void CreateAnInstancePullAPropertyFromTheApplicationConfig() + { + Assert.AreEqual("Blue", ConfigurationManager.AppSettings["Color"]); + ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>("AppSetting"); + Assert.AreEqual("Blue", widget.Color); + } + + [Test] + public void SimpleCaseWithNamedInstance() + { + Registry registry = new Registry(); + + // Specify a new Instance and override the Name + registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>().WithName("MyInstance"); + + manager = registry.BuildInstanceManager(); + + AWidget widget = (AWidget) manager.CreateInstance<IWidget>("MyInstance"); + Assert.IsNotNull(widget); + } + + [Test] + public void SimpleCaseByPluginName() + { + AWidget widget = (AWidget) manager.CreateInstance<IWidget>("AWidget"); + Assert.IsNotNull(widget); + } + + [Test] + public void SpecifyANewInstanceOverrideADependencyWithANamedInstance() + { + Registry registry = new Registry(); + + registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>(); + + registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias"); + + // Add an instance by specifying the ConcreteKey + registry.AddInstanceOf<IWidget>() + .WithName("Purple") + .UsingConcreteTypeNamed("Color") + .WithProperty("Color").EqualTo("Purple"); + + // Specify a new Instance, override a dependency with a named instance + registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("RuleThatUsesMyInstance") + .Child("widget").IsNamedInstance("Purple"); + + manager = registry.BuildInstanceManager(); + + Assert.IsInstanceOfType(typeof(ARule), manager.CreateInstance<Rule>("Alias")); + + WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("RuleThatUsesMyInstance"); + ColorWidget widget = (ColorWidget) rule.Widget; + Assert.AreEqual("Purple", widget.Color); + } + } + + + public class WidgetRule : Rule + { + private readonly IWidget _widget; + + public WidgetRule(IWidget widget) + { + _widget = widget; + } + + + public IWidget Widget + { + get { return _widget; } + } + } + + public class WidgetThing : IWidget + { + public void DoSomething() + { + throw new NotImplementedException(); + } + } + + public class CloneableWidget : IWidget, ICloneable + { + private string _name; + + + public CloneableWidget(string name) + { + _name = name; + } + + public string Name + { + get { return _name; } + } + + public void DoSomething() + { + throw new NotImplementedException(); + } + + public object Clone() + { + return MemberwiseClone(); + } + } + + public class ARule : Rule + { + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -4,16 +4,29 @@ using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Interceptors; +using StructureMap.Testing.Widget; using StructureMap.Testing.Widget3; namespace StructureMap.Testing.Configuration.DSL { - [TestFixture] + [TestFixture, Explicit] public class CreatePluginFamilyTester { [SetUp] public void SetUp() { + PluginGraph pluginGraph = new PluginGraph(); + using (Registry registry = new Registry(pluginGraph)) + { + // Define the default instance of IWidget + registry.BuildInstancesOfType<IWidget>().AndTheDefaultIs( + Registry.Instance<IWidget>() + .UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualTo("Red") + ); + + + } } [Test] @@ -51,6 +64,7 @@ PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { + // Specify the default implementation for an interface registry.BuildInstancesOfType<IGateway>().WithDefaultConcreteType<StubbedGateway>(); } Added: trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,42 @@ +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Testing.GenericWidgets; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class CreateProfileTester + { + private InstanceManager manager; + private PluginGraph pluginGraph; + + [SetUp] + public void SetUp() + { + /* + pluginGraph = new PluginGraph(); + Registry registry = new Registry(pluginGraph); + registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>(); + registry.AddInstanceOf<IWidget> + .Called("DarkGreen").OfConcreteType<ColorWidget>.WithProperty("Color").EqualTo("DarkGreen"); + + + + registry.CreateProfile("Green") + .UseConcreteType<SimpleThing<string>>().For<ISimpleThing<string>>() + + .UseInstanceNamed("Green").For<Rule>(); + + manager = registry.BuildInstanceManager(); + */ + } + + [Test] + public void CreateProfile() + { + + } + } +} Added: trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,25 @@ +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class InstanceExpressionTester + { + [SetUp] + public void SetUp() + { + } + + [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 301\nNo concrete type or concrete key is specified for instance TheInstanceKey for PluginType StructureMap.Testing.Widget.IWidget,StructureMap.Testing.Widget")] + public void BlowUpIfNoConcreteKeyOrTypeDefinied() + { + InstanceExpression expression = new InstanceExpression(typeof(IWidget)); + expression.InstanceKey = "TheInstanceKey"; + PluginGraph pluginGraph = new PluginGraph(); + ((IExpression)expression).Configure(pluginGraph); + } + } +} Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -23,6 +23,10 @@ IExpression expression1 = mocks.CreateMock<IExpression>(); IExpression expression2 = mocks.CreateMock<IExpression>(); IExpression expression3 = mocks.CreateMock<IExpression>(); + + Expect.Call(expression1.ChildExpressions).Return(new IExpression[0]); + Expect.Call(expression2.ChildExpressions).Return(new IExpression[0]); + Expect.Call(expression3.ChildExpressions).Return(new IExpression[0]); PluginGraph graph = new PluginGraph(); expression1.Configure(graph); @@ -31,12 +35,12 @@ mocks.ReplayAll(); - TestRegistry registry = new TestRegistry(); + TestRegistry registry = new TestRegistry(graph); registry.AddExpression(expression1); registry.AddExpression(expression2); registry.AddExpression(expression3); - registry.Configure(graph); + registry.Dispose(); mocks.VerifyAll(); } @@ -48,7 +52,11 @@ IExpression expression1 = mocks.CreateMock<IExpression>(); IExpression expression2 = mocks.CreateMock<IExpression>(); IExpression expression3 = mocks.CreateMock<IExpression>(); - + + Expect.Call(expression1.ChildExpressions).Return(new IExpression[0]); + Expect.Call(expression2.ChildExpressions).Return(new IExpression[0]); + Expect.Call(expression3.ChildExpressions).Return(new IExpression[0]); + PluginGraph graph = new PluginGraph(); expression1.Configure(graph); expression2.Configure(graph); Modified: trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -203,7 +203,7 @@ IList list = manager.GetAllInstances(typeof (IWidget)); - Assert.AreEqual(6, list.Count); + Assert.AreEqual(7, list.Count); foreach (object target in list) { Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -163,7 +163,7 @@ public void GotRightNumberOfPluginsForIWidget() { PluginFamily pluginFamily = graph.PluginFamilies[typeof (IWidget)]; - Assert.AreEqual(4, pluginFamily.Plugins.Count, "Should be 4 total"); + Assert.AreEqual(5, pluginFamily.Plugins.Count, "Should be 5 total"); } Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -44,7 +44,7 @@ AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget"); Plugin[] plugins = graph.FindPlugins(typeof (IWidget)); Assert.IsNotNull(plugins); - Assert.AreEqual(3, plugins.Length); + Assert.AreEqual(4, plugins.Length); Assert.AreEqual(DefinitionSource.Implicit, plugins[0].DefinitionSource); } Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -19,7 +19,7 @@ AssemblyGraph graph = new AssemblyGraph("StructureMap.Testing.Widget"); family.SearchAssemblyGraph(graph); - Assert.AreEqual(3, family.Plugins.Count, "Plugin Count"); + Assert.AreEqual(4, family.Plugins.Count, "Plugin Count"); foreach (Plugin plugin in family.Plugins) { Assert.IsNotNull(plugin); Modified: trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -66,7 +66,7 @@ Assert.AreEqual("Blue", family.DefaultInstanceKey); - Assert.AreEqual(3, family.Plugins.Count, "3 different IWidget classes are marked as Pluggable"); + Assert.AreEqual(4, family.Plugins.Count, "3 different IWidget classes are marked as Pluggable"); } [Test] @@ -89,9 +89,9 @@ Assert.IsNotNull(family); Assert.AreEqual( - 4, + 5, family.Plugins.Count, - "4 different IWidget classes are marked as Pluggable, + the manual add"); + "5 different IWidget classes are marked as Pluggable, + the manual add"); } [Test] Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -75,7 +75,7 @@ Plugin[] plugs = Plugin.GetPlugins(assem, typeof (IWidget)); Assert.IsNotNull(plugs); - Assert.AreEqual(3, plugs.Length); + Assert.AreEqual(4, plugs.Length); } @@ -294,6 +294,23 @@ Plugin plugin = Plugin.CreateImplicitPlugin(this.GetType()); Assert.AreEqual(TypePath.GetAssemblyQualifiedName(this.GetType()), plugin.ConcreteKey); } + + [Test] + public void FindFirstConstructorArgumentOfType() + { + Plugin plugin = Plugin.CreateImplicitPlugin(typeof (GrandPrix)); + string expected = "engine"; + + string actual = plugin.FindFirstConstructorArgumentOfType<IEngine>(); + Assert.AreEqual(expected, actual); + } + + [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 302\nThere is no argument of type StructureMap.Testing.Widget.IWidget for concrete type StructureMap.Testing.Graph.GrandPrix")] + public void FindFirstConstructorArgumentOfTypeNegativeCase() + { + Plugin plugin = Plugin.CreateImplicitPlugin(typeof(GrandPrix)); + plugin.FindFirstConstructorArgumentOfType<IWidget>(); + } } [PluginFamily("Pushrod")] Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-02-25 19:29:51 UTC (rev 24) @@ -89,6 +89,7 @@ <Reference Include="System"> <Name>System</Name> </Reference> + <Reference Include="System.configuration" /> <Reference Include="System.Data"> <Name>System.Data</Name> </Reference> @@ -183,7 +184,10 @@ <Compile Include="Configuration\DiagnosticGraphBuilderTester.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Configuration\DSL\AddInstanceTester.cs" /> <Compile Include="Configuration\DSL\CreatePluginFamilyTester.cs" /> + <Compile Include="Configuration\DSL\CreateProfileTester.cs" /> + <Compile Include="Configuration\DSL\InstanceExpressionTester.cs" /> <Compile Include="Configuration\DSL\RegistryTester.cs" /> <Compile Include="Configuration\DSL\ScanAssembliesTester.cs" /> <Compile Include="Configuration\FamilyParserTester.cs"> @@ -422,6 +426,9 @@ <SubType>Code</SubType> </Compile> <None Include="StructureMap.config" /> + <None Include="StructureMap.Testing.dll.config"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </None> <EmbeddedResource Include="Container\Source\EmbeddedMementoFile.xml" /> <EmbeddedResource Include="Container\Source\Mementos\Instance1.xml" /> <EmbeddedResource Include="Container\Source\Mementos\Instance2.xml" /> Added: trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config (rev 0) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config 2007-02-25 19:29:51 UTC (rev 24) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <appSettings> + <add key="Color" value="Blue"/> + <add key="Day" value="Monday"/> + </appSettings> +</configuration> \ No newline at end of file Modified: trunk/Source/StructureMap.Testing.Widget/IWidget.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/IWidget.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing.Widget/IWidget.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -33,6 +33,20 @@ #endregion } + [Pluggable("AWidget")] + public class AWidget : IWidget + { + public AWidget() + { + } + + + public void DoSomething() + { + throw new NotImplementedException(); + } + } + public class NotPluggableWidget : IWidget { private readonly string _name; @@ -42,6 +56,12 @@ _name = name; } + + public string Name + { + get { return _name; } + } + #region IWidget Members public void DoSomething() Modified: trunk/Source/StructureMap.Testing.Widget/Rule.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Rule.cs 2007-02-20 23:09:00 UTC (rev 23) +++ trunk/Source/StructureMap.Testing.Widget/Rule.cs 2007-02-25 19:29:51 UTC (rev 24) @@ -152,4 +152,6 @@ get { return _Value; } } } + + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2007-02-26 03:09:24
|
Revision: 25 http://structuremap.svn.sourceforge.net/structuremap/?rev=25&view=rev Author: jeremydmiller Date: 2007-02-25 19:09:23 -0800 (Sun, 25 Feb 2007) Log Message: ----------- Adding the "Prototype" option to the Fluent Interface configuration Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-02-25 19:29:51 UTC (rev 24) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-02-26 03:09:23 UTC (rev 25) @@ -14,7 +14,7 @@ private string _propertyName; private MemoryInstanceMemento _memento; private List<IExpression> _children = new List<IExpression>(); - + private PrototypeMemento _prototypeMemento; public InstanceExpression(Type pluginType) @@ -26,21 +26,29 @@ void IExpression.Configure(PluginGraph graph) { - if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey)) + if (_prototypeMemento == null && _pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey)) { throw new StructureMapException(301, _memento.InstanceKey, TypePath.GetAssemblyQualifiedName(_pluginType)); } PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); - Plugin plugin = _pluggedType == null - ? family.Plugins[_memento.ConcreteKey] - : family.Plugins.FindOrCreate(_pluggedType); - _memento.ConcreteKey = plugin.ConcreteKey; + if (_prototypeMemento == null) + { + Plugin plugin = _pluggedType == null + ? family.Plugins[_memento.ConcreteKey] + : family.Plugins.FindOrCreate(_pluggedType); - - - family.Source.AddExternalMemento(_memento); + _memento.ConcreteKey = plugin.ConcreteKey; + family.Source.AddExternalMemento(_memento); + } + else + { + _prototypeMemento.InstanceKey = _memento.InstanceKey; + family.Source.AddExternalMemento(_prototypeMemento); + } + + } @@ -84,11 +92,10 @@ public void UsePrototype(ICloneable cloneable) { - + _prototypeMemento = new PrototypeMemento(_memento.InstanceKey, cloneable); } - public InstanceExpression UsingConcreteTypeNamed(string concreteKey) { _memento.ConcreteKey = concreteKey; Added: trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs 2007-02-26 03:09:23 UTC (rev 25) @@ -0,0 +1,57 @@ +using System; + +namespace StructureMap.Configuration.DSL +{ + public class PrototypeMemento : InstanceMemento + { + private readonly string _instanceKey; + private readonly ICloneable _prototype; + + public PrototypeMemento(string instanceKey, ICloneable prototype) + { + _instanceKey = instanceKey; + _prototype = prototype; + } + + + public override object Build(IInstanceCreator creator) + { + return _prototype.Clone(); + } + + protected override string innerConcreteKey + { + get { return string.Empty; } + } + + protected override string innerInstanceKey + { + get { return _instanceKey; } + } + + protected override string getPropertyValue(string Key) + { + throw new NotImplementedException(); + } + + protected override InstanceMemento getChild(string Key) + { + throw new NotImplementedException(); + } + + public override InstanceMemento[] GetChildrenArray(string Key) + { + throw new NotImplementedException(); + } + + public override bool IsReference + { + get { return false; } + } + + public override string ReferenceKey + { + get { throw new NotImplementedException(); } + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-02-25 19:29:51 UTC (rev 24) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-02-26 03:09:23 UTC (rev 25) @@ -51,19 +51,37 @@ - // Build an instance for IWidget, then setup StructureMap to return cloned instances of the - // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy" - registry.AddInstanceOf<IWidget>().WithName("Jeremy").UsePrototype(new CloneableWidget("Jeremy")); - + // Return the specific instance when an IWidget named "Julia" is requested registry.AddInstanceOf<IWidget>( new CloneableWidget("Julia") ).WithName("Julia"); */ manager = registry.BuildInstanceManager(); } + [Test] + public void UseAPreBuiltObjectForAnInstanceAsAPrototype() + { + Registry registry = new Registry(); + // Build an instance for IWidget, then setup StructureMap to return cloned instances of the + // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy" + registry.AddInstanceOf<IWidget>().WithName("Jeremy").UsePrototype(new CloneableWidget("Jeremy")); + manager = registry.BuildInstanceManager(); + CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); + CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); + CloneableWidget widget3 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); + + Assert.AreEqual("Jeremy", widget1.Name); + Assert.AreEqual("Jeremy", widget2.Name); + Assert.AreEqual("Jeremy", widget3.Name); + Assert.AreNotSame(widget1, widget2); + Assert.AreNotSame(widget1, widget3); + Assert.AreNotSame(widget2, widget3); + } + + [Test] public void SpecifyANewInstanceWithADependency() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2007-03-08 11:51:51
|
Revision: 26 http://structuremap.svn.sourceforge.net/structuremap/?rev=26&view=rev Author: jeremydmiller Date: 2007-03-08 03:51:48 -0800 (Thu, 08 Mar 2007) Log Message: ----------- More work on the DSL for configuring instances Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/IExpression.cs trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; using StructureMap.Graph; namespace StructureMap.Configuration.DSL @@ -10,9 +9,9 @@ private readonly InstanceExpression _instance; private readonly MemoryInstanceMemento _memento; private readonly string _propertyName; - private Plugin _plugin; private Type _childType; private List<IExpression> _children = new List<IExpression>(); + private IMementoBuilder _builder; public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName) @@ -23,7 +22,6 @@ } - public InstanceExpression IsNamedInstance(string instanceKey) { MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey); @@ -35,29 +33,34 @@ // TODO -- negative case if the concrete type cannot be an implicit instance public InstanceExpression IsConcreteType<T>() { - _plugin = Plugin.CreateImplicitPlugin(typeof(T)); - MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(_plugin.ConcreteKey); - _memento.AddChild(_propertyName, child); + InstanceExpression child = new InstanceExpression(_childType); + child.UsingConcreteType<T>(); + _children.Add(child); + _builder = child; + return _instance; } void IExpression.Configure(PluginGraph graph) { - if (_plugin == null || _childType == null) + if (_childType == null) { return; } PluginFamily family = graph.LocateOrCreateFamilyForType(_childType); - family.Plugins.FindOrCreate(_plugin.PluggedType); - } + if (_builder != null) + { + InstanceMemento childMemento = _builder.BuildMemento(family); + _memento.AddChild(_propertyName, childMemento); + } - - IExpression[] IExpression.ChildExpressions - { - get { return _children.ToArray(); } + foreach (IExpression child in _children) + { + child.Configure(graph); + } } internal Type ChildType @@ -68,10 +71,11 @@ public InstanceExpression Is(InstanceExpression child) { _children.Add(child); - MemoryInstanceMemento childMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey); + MemoryInstanceMemento childMemento = + MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey); _memento.AddChild(_propertyName, childMemento); return _instance; } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -12,7 +12,6 @@ { private Type _pluginType; private List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>(); - private Plugin _lastPlugin; private InstanceScope _scope = InstanceScope.PerRequest; public CreatePluginFamilyExpression(Type pluginType) @@ -20,11 +19,9 @@ _pluginType = pluginType; } - - public void Configure(PluginGraph graph) { - PluginFamily family = PluginFamilyAttribute.CreatePluginFamily(_pluginType); + PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); InterceptorChainBuilder builder = new InterceptorChainBuilder(); family.InterceptionChain = builder.Build(_scope); @@ -32,26 +29,18 @@ { alteration(family); } - + graph.PluginFamilies.Add(family); AssemblyGraph assembly = new AssemblyGraph(_pluginType.Assembly); graph.Assemblies.Add(assembly); } - IExpression[] IExpression.ChildExpressions - { - get { return new IExpression[0]; } - } - public CreatePluginFamilyExpression WithDefaultConcreteType<T>() { Plugin plugin = addPlugin<T>(); - _alterations.Add(delegate (PluginFamily family) - { - family.DefaultInstanceKey = plugin.ConcreteKey; - }); + _alterations.Add(delegate(PluginFamily family) { family.DefaultInstanceKey = plugin.ConcreteKey; }); return this; } @@ -60,42 +49,50 @@ { Plugin plugin = Plugin.CreateImplicitPlugin(typeof (T)); - _alterations.Add(delegate (PluginFamily family) - { - family.Plugins.Add(plugin); - }); + _alterations.Add(delegate(PluginFamily family) { family.Plugins.Add(plugin); }); return plugin; } - public CreatePluginFamilyExpression PluginConcreteType<T>() + public CreatePluginFamilyExpression TheDefaultIs(IMementoBuilder builder) { - _lastPlugin = addPlugin<T>(); + _alterations.Add(delegate(PluginFamily family) + { + InstanceMemento memento = builder.BuildMemento(family); + family.Source.AddExternalMemento(memento); + family.DefaultInstanceKey = memento.InstanceKey; + }); return this; } - public CreatePluginFamilyExpression AliasedAs(string concreteKey) + public CreatePluginFamilyExpression TheDefaultIsConcreteType<T>() { - _lastPlugin.ConcreteKey = concreteKey; + _alterations.Add(delegate(PluginFamily family) + { + Plugin plugin = family.Plugins.FindOrCreate(typeof (T)); + family.DefaultInstanceKey = plugin.ConcreteKey; + }); + return this; } - public CreatePluginFamilyExpression AsASingleton() + public CreatePluginFamilyExpression CacheBy(InstanceScope scope) { - _scope = InstanceScope.Singleton; + _alterations.Add(delegate(PluginFamily family) + { + InterceptorChainBuilder builder = new InterceptorChainBuilder(); + family.InterceptionChain = builder.Build(scope); + }); + return this; } - public CreatePluginFamilyExpression CacheInstanceAtScope(InstanceScope scope) + public CreatePluginFamilyExpression AsSingletons() { - _scope = scope; + _alterations.Add( + delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(new SingletonInterceptor()); }); return this; } - - public void AndTheDefaultIs(InstanceExpression expression) - { - throw new NotImplementedException(); - } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -17,10 +17,5 @@ { _configure(graph); } - - IExpression[] IExpression.ChildExpressions - { - get { return new IExpression[0]; } - } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/IExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/IExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -1,6 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; using StructureMap.Graph; namespace StructureMap.Configuration.DSL @@ -8,6 +5,5 @@ public interface IExpression { void Configure(PluginGraph graph); - IExpression[] ChildExpressions { get;} } -} +} \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -0,0 +1,9 @@ +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + public interface IMementoBuilder + { + InstanceMemento BuildMemento(PluginFamily family); + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -1,81 +1,52 @@ using System; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Configuration; -using System.Reflection; using StructureMap.Graph; namespace StructureMap.Configuration.DSL { - public class InstanceExpression : IExpression + public class InstanceExpression : MementoBuilder<InstanceExpression> { - private readonly Type _pluginType; private Type _pluggedType; - private string _propertyName; private MemoryInstanceMemento _memento; - private List<IExpression> _children = new List<IExpression>(); - private PrototypeMemento _prototypeMemento; - - public InstanceExpression(Type pluginType) + public InstanceExpression(Type pluginType) : base(pluginType) { - _pluginType = pluginType; - _memento = new MemoryInstanceMemento(); - _memento.InstanceKey = Guid.NewGuid().ToString(); } - void IExpression.Configure(PluginGraph graph) + protected override void buildMemento() { - if (_prototypeMemento == null && _pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey)) - { - throw new StructureMapException(301, _memento.InstanceKey, TypePath.GetAssemblyQualifiedName(_pluginType)); - } - - PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); - - if (_prototypeMemento == null) - { - Plugin plugin = _pluggedType == null - ? family.Plugins[_memento.ConcreteKey] - : family.Plugins.FindOrCreate(_pluggedType); - - _memento.ConcreteKey = plugin.ConcreteKey; - family.Source.AddExternalMemento(_memento); - } - else - { - _prototypeMemento.InstanceKey = _memento.InstanceKey; - family.Source.AddExternalMemento(_prototypeMemento); - } - - + _memento = new MemoryInstanceMemento(); } - public IExpression[] ChildExpressions + protected override InstanceMemento memento { - get { return _children.ToArray(); } + get { return _memento; } } - - public InstanceExpression WithName(string instanceKey) + protected override InstanceExpression thisInstance { - _memento.InstanceKey = instanceKey; - return this; + get { return this; } } - - public string InstanceKey + protected override void configureMemento(PluginFamily family) { - get { return _memento.InstanceKey; } - set { _memento.InstanceKey = value; } + Plugin plugin = _pluggedType == null + ? family.Plugins[_memento.ConcreteKey] + : family.Plugins.FindOrCreate(_pluggedType); + + _memento.ConcreteKey = plugin.ConcreteKey; } - internal Type PluginType + protected override void validate() { - get { return _pluginType; } + if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey)) + { + throw new StructureMapException(301, _memento.InstanceKey, + TypePath.GetAssemblyQualifiedName(_pluginType)); + } } + public InstanceExpression UsingConcreteType<T>() { _pluggedType = typeof (T); @@ -87,25 +58,17 @@ return new PropertyExpression(this, _memento, propertyName); } - - - - public void UsePrototype(ICloneable cloneable) - { - _prototypeMemento = new PrototypeMemento(_memento.InstanceKey, cloneable); - } - - public InstanceExpression UsingConcreteTypeNamed(string concreteKey) { _memento.ConcreteKey = concreteKey; return this; } - public ChildInstanceExpression Child(string propertyName) + public ChildInstanceExpression Child<T>(string propertyName) { - ChildInstanceExpression child = new ChildInstanceExpression(this,_memento, propertyName); - _children.Add(child); + ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName); + addChildExpression(child); + child.ChildType = typeof (T); return child; } @@ -114,7 +77,8 @@ { // TODO -- what if the property can't be found string propertyName = findPropertyName<T>(); - ChildInstanceExpression child = Child(propertyName); + ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName); + addChildExpression(child); child.ChildType = typeof (T); return child; } @@ -124,8 +88,5 @@ Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType); return plugin.FindFirstConstructorArgumentOfType<T>(); } - - - } -} +} \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -0,0 +1,40 @@ +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + public class LiteralExpression<T> : MementoBuilder<LiteralExpression<T>> + { + private readonly T _target; + private LiteralMemento _memento; + + public LiteralExpression(T target) : base(typeof (T)) + { + _target = target; + } + + + protected override InstanceMemento memento + { + get { return _memento; } + } + + protected override LiteralExpression<T> thisInstance + { + get { return this; } + } + + protected override void configureMemento(PluginFamily family) + { + _memento.Instance = _target; + } + + protected override void validate() + { + } + + protected override void buildMemento() + { + _memento = new LiteralMemento(null); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -0,0 +1,61 @@ +using System; + +namespace StructureMap.Configuration.DSL +{ + public class LiteralMemento : InstanceMemento + { + private object _instance; + + public LiteralMemento(object instance) + { + _instance = instance; + } + + + public object Instance + { + get { return _instance; } + set { _instance = value; } + } + + protected override string innerConcreteKey + { + get { throw new NotImplementedException(); } + } + + protected override string innerInstanceKey + { + get { throw new NotImplementedException(); } + } + + protected override string getPropertyValue(string Key) + { + throw new NotImplementedException(); + } + + protected override InstanceMemento getChild(string Key) + { + throw new NotImplementedException(); + } + + public override InstanceMemento[] GetChildrenArray(string Key) + { + throw new NotImplementedException(); + } + + public override bool IsReference + { + get { return false; } + } + + public override string ReferenceKey + { + get { throw new NotImplementedException(); } + } + + public override object Build(IInstanceCreator creator) + { + return _instance; + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + // TODO -- T must be constrained to be MementoBuilder + public abstract class MementoBuilder<T> : IExpression, IMementoBuilder + { + protected readonly Type _pluginType; + protected List<IExpression> _children = new List<IExpression>(); + + public MementoBuilder(Type pluginType) + { + _pluginType = pluginType; + buildMemento(); + memento.InstanceKey = Guid.NewGuid().ToString(); + } + + void IExpression.Configure(PluginGraph graph) + { + validate(); + PluginFamily family = graph.LocateOrCreateFamilyForType((Type) _pluginType); + configureMemento(family); + family.Source.AddExternalMemento(memento); + + foreach (IExpression child in _children) + { + child.Configure(graph); + } + } + + protected abstract InstanceMemento memento { get; } + + protected abstract T thisInstance { get; } + + protected abstract void configureMemento(PluginFamily family); + + protected abstract void validate(); + + public T WithName(string instanceKey) + { + memento.InstanceKey = instanceKey; + return thisInstance; + } + + public string InstanceKey + { + get { return memento.InstanceKey; } + set { memento.InstanceKey = value; } + } + + internal Type PluginType + { + get { return _pluginType; } + } + + protected abstract void buildMemento(); + + InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family) + { + validate(); + configureMemento(family); + return memento; + } + + protected void addChildExpression(IExpression expression) + { + _children.Add(expression); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -9,10 +9,5 @@ { throw new NotImplementedException(); } - - public IExpression[] ChildExpressions - { - get { throw new NotImplementedException(); } - } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; using System.Configuration; -using System.Text; namespace StructureMap.Configuration.DSL { @@ -31,4 +28,4 @@ return _instance; } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -1,25 +1,41 @@ using System; -using System.Collections.Generic; -using System.Text; using StructureMap.Graph; namespace StructureMap.Configuration.DSL { - public class PrototypeExpression : IExpression + public class PrototypeExpression<T> : MementoBuilder<PrototypeExpression<T>> { - public void Configure(PluginGraph graph) + private readonly T _prototype; + private PrototypeMemento _memento; + + public PrototypeExpression(T prototype) : base(typeof (T)) { - throw new NotImplementedException(); + _prototype = prototype; } - public IExpression[] ChildExpressions + protected override InstanceMemento memento { - get { return new IExpression[0]; } + get { return _memento; } } - public void WithName(string instanceKey) + protected override PrototypeExpression<T> thisInstance { - + get { return this; } } + + protected override void configureMemento(PluginFamily family) + { + _memento.Prototype = (ICloneable) _prototype; + } + + protected override void validate() + { + // TODO + } + + protected override void buildMemento() + { + _memento = new PrototypeMemento(string.Empty, (ICloneable) _prototype); + } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -5,7 +5,7 @@ public class PrototypeMemento : InstanceMemento { private readonly string _instanceKey; - private readonly ICloneable _prototype; + private ICloneable _prototype; public PrototypeMemento(string instanceKey, ICloneable prototype) { @@ -14,6 +14,12 @@ } + public ICloneable Prototype + { + get { return _prototype; } + set { _prototype = value; } + } + public override object Build(IInstanceCreator creator) { return _prototype.Clone(); Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -20,7 +20,6 @@ } - /// <summary> /// Implement this method to /// </summary> @@ -38,18 +37,10 @@ { foreach (IExpression expression in _expressions) { - configureExpression(expression, graph); + expression.Configure(graph); } } - private static void configureExpression(IExpression expression, PluginGraph graph) - { - expression.Configure(graph); - foreach (IExpression childExpression in expression.ChildExpressions) - { - configureExpression(childExpression, graph); - } - } public void Dispose() { @@ -64,9 +55,9 @@ return expression; } - public CreatePluginFamilyExpression BuildInstancesOfType<T>() + public CreatePluginFamilyExpression BuildInstancesOf<T>() { - CreatePluginFamilyExpression expression = new CreatePluginFamilyExpression(typeof(T)); + CreatePluginFamilyExpression expression = new CreatePluginFamilyExpression(typeof (T)); addExpression(expression); return expression; @@ -81,19 +72,30 @@ public InstanceExpression AddInstanceOf<T>() { - InstanceExpression expression = new InstanceExpression(typeof(T)); + InstanceExpression expression = new InstanceExpression(typeof (T)); addExpression(expression); return expression; } public static InstanceExpression Instance<T>() { - return new InstanceExpression(typeof(T)); + return new InstanceExpression(typeof (T)); } - public PrototypeExpression AddInstanceOf<T>(T prototype) + public LiteralExpression<T> AddInstanceOf<T>(T target) { - return new PrototypeExpression(); + LiteralExpression<T> literal = new LiteralExpression<T>(target); + addExpression(literal); + + return literal; } + + public PrototypeExpression<T> AddPrototypeInstanceOf<T>(T prototype) + { + PrototypeExpression<T> expression = new PrototypeExpression<T>(prototype); + addExpression(expression); + + return expression; + } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -1,8 +1,6 @@ -using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; -using System.Text; using System.Threading; using StructureMap.Graph; @@ -63,4 +61,4 @@ return this; } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -158,5 +158,14 @@ { return Contains(typeof (T)); } + + public PluginFamily Add(Type pluginType) + { + PluginFamilyAttribute att = PluginFamilyAttribute.GetAttribute(pluginType); + PluginFamily family = att == null ? new PluginFamily(pluginType) : att.BuildPluginFamily(pluginType); + _pluginFamilies.Add(pluginType, family); + + return family; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -152,7 +152,7 @@ { if (!_pluginFamilies.Contains(pluginType)) { - PluginFamily family = _pluginFamilies.Add(pluginType, string.Empty); + PluginFamily family = _pluginFamilies.Add(pluginType); attachImplicitPlugins(family); } } Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap/StructureMap.csproj 2007-03-08 11:51:48 UTC (rev 26) @@ -217,10 +217,15 @@ <Compile Include="Configuration\DSL\CreatePluginFamilyExpression.cs" /> <Compile Include="Configuration\DSL\DefaultExpression.cs" /> <Compile Include="Configuration\DSL\IExpression.cs" /> + <Compile Include="Configuration\DSL\IMementoBuilder.cs" /> <Compile Include="Configuration\DSL\InstanceExpression.cs" /> + <Compile Include="Configuration\DSL\LiteralExpression.cs" /> + <Compile Include="Configuration\DSL\LiteralMemento.cs" /> + <Compile Include="Configuration\DSL\MementoBuilder.cs" /> <Compile Include="Configuration\DSL\ProfileExpression.cs" /> <Compile Include="Configuration\DSL\PropertyExpression.cs" /> <Compile Include="Configuration\DSL\PrototypeExpression.cs" /> + <Compile Include="Configuration\DSL\PrototypeMemento.cs" /> <Compile Include="Configuration\DSL\Registry.cs" /> <Compile Include="Configuration\DSL\ScanAssembliesExpression.cs" /> <Compile Include="Configuration\FamilyParser.cs"> Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -4,7 +4,6 @@ using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.Widget; -using IList=System.Collections.IList; namespace StructureMap.Testing.Configuration.DSL { @@ -43,18 +42,6 @@ registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>(); - - - - - /* - - - - - // Return the specific instance when an IWidget named "Julia" is requested - registry.AddInstanceOf<IWidget>( new CloneableWidget("Julia") ).WithName("Julia"); - */ manager = registry.BuildInstanceManager(); } @@ -64,7 +51,8 @@ Registry registry = new Registry(); // Build an instance for IWidget, then setup StructureMap to return cloned instances of the // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy" - registry.AddInstanceOf<IWidget>().WithName("Jeremy").UsePrototype(new CloneableWidget("Jeremy")); + CloneableWidget theWidget = new CloneableWidget("Jeremy"); + registry.AddPrototypeInstanceOf<IWidget>(theWidget).WithName("Jeremy"); manager = registry.BuildInstanceManager(); @@ -83,6 +71,26 @@ [Test] + public void UseAPreBuiltObjectWithAName() + { + Registry registry = new Registry(); + // Return the specific instance when an IWidget named "Julia" is requested + CloneableWidget julia = new CloneableWidget("Julia"); + registry.AddInstanceOf<IWidget>(julia).WithName("Julia"); + + manager = registry.BuildInstanceManager(); + + CloneableWidget widget1 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia"); + CloneableWidget widget2 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia"); + CloneableWidget widget3 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia"); + + Assert.AreSame(julia, widget1); + Assert.AreSame(julia, widget2); + Assert.AreSame(julia, widget3); + } + + + [Test] public void SpecifyANewInstanceWithADependency() { Registry registry = new Registry(); @@ -182,7 +190,7 @@ // Specify a new Instance, override a dependency with a named instance registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName("RuleThatUsesMyInstance") - .Child("widget").IsNamedInstance("Purple"); + .Child<IWidget>("widget").IsNamedInstance("Purple"); manager = registry.BuildInstanceManager(); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -1,5 +1,4 @@ using NUnit.Framework; -using Rhino.Mocks; using StructureMap.Attributes; using StructureMap.Configuration.DSL; using StructureMap.Graph; @@ -9,33 +8,35 @@ namespace StructureMap.Testing.Configuration.DSL { - [TestFixture, Explicit] + [TestFixture] public class CreatePluginFamilyTester { [SetUp] public void SetUp() { - PluginGraph pluginGraph = new PluginGraph(); - using (Registry registry = new Registry(pluginGraph)) - { - // Define the default instance of IWidget - registry.BuildInstancesOfType<IWidget>().AndTheDefaultIs( - Registry.Instance<IWidget>() - .UsingConcreteType<ColorWidget>() - .WithProperty("Color").EqualTo("Red") - ); - - } } [Test] + public void TheDefaultInstanceIsConcreteType() + { + Registry registry = new Registry(); + + // Needs to blow up if the concrete type can't be used + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>(); + + InstanceManager manager = registry.BuildInstanceManager(); + + Assert.IsInstanceOfType(typeof(ARule), manager.CreateInstance<Rule>()); + } + + [Test] public void BuildInstancesOfType() { PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { - registry.BuildInstancesOfType<IGateway>(); + registry.BuildInstancesOf<IGateway>(); } Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); @@ -47,7 +48,7 @@ PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { - registry.BuildInstancesOfType<IGateway>(); + registry.BuildInstancesOf<IGateway>(); } Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); @@ -65,7 +66,7 @@ using (Registry registry = new Registry(pluginGraph)) { // Specify the default implementation for an interface - registry.BuildInstancesOfType<IGateway>().WithDefaultConcreteType<StubbedGateway>(); + registry.BuildInstancesOf<IGateway>().WithDefaultConcreteType<StubbedGateway>(); } Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); @@ -77,13 +78,28 @@ } [Test] + public void CreatePluginFamilyWithADefault() + { + Registry registry = new Registry(); + registry.BuildInstancesOf<IWidget>().TheDefaultIs( + Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Red") + ); + + InstanceManager manager = registry.BuildInstanceManager(); + + ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); + Assert.AreEqual("Red", widget.Color); + } + + + [Test] public void BuildPluginFamilyAsPerRequest() { PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { CreatePluginFamilyExpression expression = - registry.BuildInstancesOfType<IGateway>(); + registry.BuildInstancesOf<IGateway>(); Assert.IsNotNull(expression); } @@ -97,8 +113,7 @@ PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { - CreatePluginFamilyExpression expression = - registry.BuildInstancesOfType<IGateway>().CacheInstanceAtScope(InstanceScope.ThreadLocal); + CreatePluginFamilyExpression expression = registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal); Assert.IsNotNull(expression); } @@ -113,7 +128,7 @@ using (Registry registry = new Registry(pluginGraph)) { CreatePluginFamilyExpression expression = - registry.BuildInstancesOfType<IGateway>().AsASingleton(); + registry.BuildInstancesOf<IGateway>().AsSingletons(); Assert.IsNotNull(expression); } @@ -127,7 +142,7 @@ PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { - registry.BuildInstancesOfType<IGateway>().WithDefaultConcreteType<FakeGateway>(); + registry.BuildInstancesOf<IGateway>().WithDefaultConcreteType<FakeGateway>(); } Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); @@ -138,24 +153,5 @@ Assert.IsInstanceOfType(typeof(FakeGateway), gateway); } - [Test] - public void CanAddAdditionalConcreteTypes() - { - Registry registry = new Registry(); - - registry.BuildInstancesOfType<IGateway>() - .PluginConcreteType<FakeGateway>().AliasedAs("Fake") - .PluginConcreteType<Fake2Gateway>() - .PluginConcreteType<StubbedGateway>() - .PluginConcreteType<Fake3Gateway>().AliasedAs("Fake3"); - - InstanceManager manager = registry.BuildInstanceManager(); - IGateway gateway = (IGateway)manager.CreateInstance(typeof(IGateway), "Fake"); - - Assert.IsInstanceOfType(typeof(FakeGateway), gateway); - Assert.IsInstanceOfType(typeof(Fake3Gateway), manager.CreateInstance(typeof(IGateway), "Fake3")); - Assert.IsInstanceOfType(typeof(StubbedGateway), manager.CreateInstance(typeof(IGateway), "Stubbed")); - Assert.IsInstanceOfType(typeof(Fake2Gateway), manager.CreateInstance(typeof(IGateway), TypePath.GetAssemblyQualifiedName(typeof(Fake2Gateway)))); - } } } Added: trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -0,0 +1,63 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class LiteralExpressionTester + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void ConfiguresALiteral() + { + ColorWidget theWidget = new ColorWidget("Red"); + LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); + PluginGraph graph = new PluginGraph(); + ((IExpression)expression).Configure(graph); + + PluginFamily family = graph.PluginFamilies[typeof (IWidget)]; + Assert.IsNotNull(family); + + LiteralMemento memento = (LiteralMemento) family.Source.GetMemento(expression.InstanceKey); + Assert.AreSame(theWidget, memento.Build(null)); + + } + + [Test] + public void BuildFromInstanceManager() + { + ColorWidget theWidget = new ColorWidget("Red"); + LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); + PluginGraph graph = new PluginGraph(); + ((IExpression)expression).Configure(graph); + + InstanceManager manager = new InstanceManager(graph); + + IWidget actualWidget = manager.CreateInstance<IWidget>(expression.InstanceKey); + Assert.AreSame(theWidget, actualWidget); + } + + [Test] + public void OverrideTheInstanceKey() + { + ColorWidget theWidget = new ColorWidget("Red"); + LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); + expression.WithName("Blue"); + PluginGraph graph = new PluginGraph(); + ((IExpression)expression).Configure(graph); + + PluginFamily family = graph.PluginFamilies[typeof(IWidget)]; + Assert.IsNotNull(family); + + LiteralMemento memento = (LiteralMemento)family.Source.GetMemento(expression.InstanceKey); + Assert.AreSame(theWidget, memento.Build(null)); + } + } +} Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-03-08 11:51:48 UTC (rev 26) @@ -24,10 +24,6 @@ IExpression expression2 = mocks.CreateMock<IExpression>(); IExpression expression3 = mocks.CreateMock<IExpression>(); - Expect.Call(expression1.ChildExpressions).Return(new IExpression[0]); - Expect.Call(expression2.ChildExpressions).Return(new IExpression[0]); - Expect.Call(expression3.ChildExpressions).Return(new IExpression[0]); - PluginGraph graph = new PluginGraph(); expression1.Configure(graph); expression2.Configure(graph); @@ -53,10 +49,6 @@ IExpression expression2 = mocks.CreateMock<IExpression>(); IExpression expression3 = mocks.CreateMock<IExpression>(); - Expect.Call(expression1.ChildExpressions).Return(new IExpression[0]); - Expect.Call(expression2.ChildExpressions).Return(new IExpression[0]); - Expect.Call(expression3.ChildExpressions).Return(new IExpression[0]); - PluginGraph graph = new PluginGraph(); expression1.Configure(graph); expression2.Configure(graph); Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-02-26 03:09:23 UTC (rev 25) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-03-08 11:51:48 UTC (rev 26) @@ -188,6 +188,7 @@ <Compile Include="Configuration\DSL\CreatePluginFamilyTester.cs" /> <Compile Include="Configuration\DSL\CreateProfileTester.cs" /> <Compile Include="Configuration\DSL\InstanceExpressionTester.cs" /> + <Compile Include="Configuration\DSL\LiteralExpressionTester.cs" /> <Compile Include="Configuration\DSL\RegistryTester.cs" /> <Compile Include="Configuration\DSL\ScanAssembliesTester.cs" /> <Compile Include="Configuration\FamilyParserTester.cs"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2007-03-25 02:43:21
|
Revision: 27 http://structuremap.svn.sourceforge.net/structuremap/?rev=27&view=rev Author: jeremydmiller Date: 2007-03-24 19:43:09 -0700 (Sat, 24 Mar 2007) Log Message: ----------- 2.0 ifying, finishing up the Profile DSL support Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs trunk/Source/StructureMap/Graph/Deployable.cs trunk/Source/StructureMap/Graph/InstanceDefault.cs trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs trunk/Source/StructureMap/Graph/MachineOverride.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/Profile.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Sample.xml Removed Paths: ------------- trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs Deleted: trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Configuration/DSL/DefaultExpression.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -1,21 +0,0 @@ -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - public delegate void ConfigurePluginGraph(PluginGraph graph); - - public class DefaultExpression : IExpression - { - private readonly ConfigurePluginGraph _configure; - - public DefaultExpression(ConfigurePluginGraph configure) - { - _configure = configure; - } - - public void Configure(PluginGraph graph) - { - _configure(graph); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -5,5 +5,7 @@ public interface IMementoBuilder { InstanceMemento BuildMemento(PluginFamily family); + InstanceMemento BuildMemento(PluginGraph graph); + void SetInstanceName(string instanceKey); } } \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -0,0 +1,56 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + public class InstanceDefaultExpression + { + private readonly Type _pluginType; + private readonly ProfileExpression _parent; + private string _instanceKey = string.Empty; + private IMementoBuilder _mementoBuilder; + + public InstanceDefaultExpression(Type pluginType, ProfileExpression parent) + { + _pluginType = pluginType; + _parent = parent; + } + + public ProfileExpression UseNamedInstance(string instanceKey) + { + _instanceKey = instanceKey; + return _parent; + } + + public void Configure(Profile profile, PluginGraph graph) + { + if (!string.IsNullOrEmpty(_instanceKey)) + { + InstanceDefault instanceDefault = new InstanceDefault(_pluginType, _instanceKey); + profile.AddOverride(instanceDefault); + } + else if (_mementoBuilder != null) + { + string defaultKey = Profile.InstanceKeyForProfile(profile.ProfileName); + InstanceMemento memento = _mementoBuilder.BuildMemento(graph); + memento.InstanceKey = defaultKey; + + graph.PluginFamilies[_pluginType].AddInstance(memento); + + InstanceDefault instanceDefault = new InstanceDefault(_pluginType, defaultKey); + profile.AddOverride(instanceDefault); + } + + // TODO throw up!!! + } + + public ProfileExpression Use(IMementoBuilder mementoBuilder) + { + _mementoBuilder = mementoBuilder; + + return _parent; + } + + + } +} Modified: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -9,6 +9,7 @@ { protected readonly Type _pluginType; protected List<IExpression> _children = new List<IExpression>(); + private string _instanceKey = null; public MementoBuilder(Type pluginType) { @@ -22,6 +23,12 @@ validate(); PluginFamily family = graph.LocateOrCreateFamilyForType((Type) _pluginType); configureMemento(family); + + if (!string.IsNullOrEmpty(_instanceKey)) + { + memento.InstanceKey = _instanceKey; + } + family.Source.AddExternalMemento(memento); foreach (IExpression child in _children) @@ -59,11 +66,28 @@ InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family) { + return buildMementoFromFamily(family); + } + + private InstanceMemento buildMementoFromFamily(PluginFamily family) + { validate(); configureMemento(family); return memento; } + + InstanceMemento IMementoBuilder.BuildMemento(PluginGraph graph) + { + PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); + return buildMementoFromFamily(family); + } + + public void SetInstanceName(string instanceKey) + { + _instanceKey = instanceKey; + } + protected void addChildExpression(IExpression expression) { _children.Add(expression); Modified: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -1,13 +1,40 @@ using System; +using System.Collections.Generic; using StructureMap.Graph; namespace StructureMap.Configuration.DSL { public class ProfileExpression : IExpression { - public void Configure(PluginGraph graph) + private readonly string _profileName; + private List<InstanceDefaultExpression> _defaults = new List<InstanceDefaultExpression>(); + + public ProfileExpression(string profileName) { - throw new NotImplementedException(); + _profileName = profileName; } + + void IExpression.Configure(PluginGraph graph) + { + Profile profile = graph.DefaultManager.GetProfile(_profileName); + if (profile == null) + { + profile = new Profile(_profileName); + graph.DefaultManager.AddProfile(profile); + } + + foreach (InstanceDefaultExpression expression in _defaults) + { + expression.Configure(profile, graph); + } + } + + public InstanceDefaultExpression For<T>() + { + InstanceDefaultExpression defaultExpression = new InstanceDefaultExpression(typeof(T), this); + _defaults.Add(defaultExpression); + + return defaultExpression; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -65,9 +65,9 @@ public InstanceManager BuildInstanceManager() { - PluginGraph graph = new PluginGraph(); - configurePluginGraph(graph); - return new InstanceManager(graph); + configurePluginGraph(_graph); + _graph.ReadDefaults(); + return new InstanceManager(_graph); } public InstanceExpression AddInstanceOf<T>() @@ -82,6 +82,11 @@ return new InstanceExpression(typeof (T)); } + public static PrototypeExpression<T> Prototype<T>(T prototype) + { + return new PrototypeExpression<T>(prototype); + } + public LiteralExpression<T> AddInstanceOf<T>(T target) { LiteralExpression<T> literal = new LiteralExpression<T>(target); @@ -97,5 +102,13 @@ return expression; } + + public ProfileExpression CreateProfile(string profileName) + { + ProfileExpression expression = new ProfileExpression(profileName); + addExpression(expression); + + return expression; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -10,7 +10,7 @@ { private List<AssemblyGraph> _assemblies = new List<AssemblyGraph>(); - public void Configure(PluginGraph graph) + void IExpression.Configure(PluginGraph graph) { foreach (AssemblyGraph assembly in _assemblies) { @@ -18,11 +18,6 @@ } } - public IExpression[] ChildExpressions - { - get { return new IExpression[0]; } - } - public ScanAssembliesExpression IncludeTheCallingAssembly() { Assembly callingAssembly = findTheCallingAssembly(); Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -77,7 +77,7 @@ private void createOverrideInstance(string fullName, XmlElement instanceElement, WriteOverride function, string profileName) { - string key = profileName + "-Instance"; + string key = Profile.InstanceKeyForProfile(profileName); InstanceMemento memento = _creator.CreateMemento(instanceElement); memento.InstanceKey = key; Modified: trunk/Source/StructureMap/Graph/Deployable.cs =================================================================== --- trunk/Source/StructureMap/Graph/Deployable.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Graph/Deployable.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections.Generic; namespace StructureMap.Graph { @@ -10,11 +10,11 @@ { public const string ALL = "All"; - private ArrayList _deploymentTargets; + private List<string> _deploymentTargets; public Deployable() { - _deploymentTargets = new ArrayList(); + _deploymentTargets = new List<string>(); } public Deployable(string[] deploymentTargets) : this() @@ -27,7 +27,7 @@ /// </summary> public string[] DeploymentTargets { - get { return (string[]) _deploymentTargets.ToArray(typeof (string)); } + get { return _deploymentTargets.ToArray(); } set { _deploymentTargets.Clear(); Modified: trunk/Source/StructureMap/Graph/InstanceDefault.cs =================================================================== --- trunk/Source/StructureMap/Graph/InstanceDefault.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Graph/InstanceDefault.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -19,6 +19,10 @@ _defaultKey = defaultKey; } + public InstanceDefault(Type pluginType, string defaultKey) : this(pluginType.FullName, defaultKey) + { + } + public string PluginTypeName { get { return _pluginTypeName; } Modified: trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs =================================================================== --- trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using StructureMap.Configuration; namespace StructureMap.Graph @@ -25,16 +25,16 @@ return machineName; } - private ArrayList _defaults; - private Hashtable _machineOverrides; - private Hashtable _profiles; + private List<InstanceDefault> _defaults; + private Dictionary<string, MachineOverride> _machineOverrides; + private Dictionary<string, Profile> _profiles; private string _defaultProfileName = string.Empty; public InstanceDefaultManager() : base() { - _defaults = new ArrayList(); - _machineOverrides = new Hashtable(); - _profiles = new Hashtable(); + _defaults = new List<InstanceDefault>(); + _machineOverrides = new Dictionary<string, MachineOverride>(); + _profiles = new Dictionary<string, Profile>(); } /// <summary> @@ -49,9 +49,12 @@ public void ReadDefaultsFromPluginGraph(PluginGraph graph) { + _defaults = new List<InstanceDefault>(); + foreach (PluginFamily family in graph.PluginFamilies) { - AddPluginFamilyDefault(family.PluginType.FullName, family.DefaultInstanceKey); + InstanceDefault instanceDefault = new InstanceDefault(family.PluginType, family.DefaultInstanceKey); + _defaults.Add(instanceDefault); } } @@ -106,7 +109,12 @@ /// <returns></returns> public Profile GetProfile(string profileName) { - return _profiles[profileName] as Profile; + if (!_profiles.ContainsKey(profileName)) + { + return null; + } + + return _profiles[profileName]; } /// <summary> @@ -118,7 +126,7 @@ { if (_machineOverrides.ContainsKey(machineName)) { - return (MachineOverride) _machineOverrides[machineName]; + return _machineOverrides[machineName]; } else { @@ -133,7 +141,7 @@ if (_profiles.ContainsKey(profileToFind)) { - return (Profile) _profiles[profileToFind]; + return _profiles[profileToFind]; } else { Modified: trunk/Source/StructureMap/Graph/MachineOverride.cs =================================================================== --- trunk/Source/StructureMap/Graph/MachineOverride.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Graph/MachineOverride.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Runtime.CompilerServices; using StructureMap.Configuration; using StructureMap.Configuration.Tokens; @@ -14,7 +15,7 @@ { private string _machineName; private Profile _profile = new Profile(string.Empty); - private Hashtable _defaults; + private Dictionary<string, InstanceDefault> _defaults; public MachineOverride(string machineName, Profile profile) : this(machineName) @@ -28,7 +29,7 @@ public MachineOverride(string machineName) : base() { _machineName = machineName; - _defaults = new Hashtable(); + _defaults = new Dictionary<string, InstanceDefault>(); } public string MachineName @@ -71,7 +72,7 @@ } else { - return ((InstanceDefault) _defaults[pluginTypeName]).DefaultKey; + return _defaults[pluginTypeName].DefaultKey; } } } Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -230,5 +230,10 @@ { _plugins.RemoveImplicitChildren(); } + + public void AddInstance(InstanceMemento memento) + { + _source.AddExternalMemento(memento); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/Profile.cs =================================================================== --- trunk/Source/StructureMap/Graph/Profile.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Graph/Profile.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -1,5 +1,5 @@ using System; -using System.Collections; +using System.Collections.Generic; using System.Runtime.CompilerServices; using StructureMap.Configuration; using StructureMap.Configuration.Tokens; @@ -13,12 +13,12 @@ public class Profile : GraphObject { private string _profileName; - private Hashtable _defaults; + private Dictionary<string, InstanceDefault> _defaults; - public Profile(string profileName) : base() + public Profile(string profileName) { _profileName = profileName; - _defaults = new Hashtable(); + _defaults = new Dictionary<string, InstanceDefault>(); } public string ProfileName @@ -34,7 +34,7 @@ { if (_defaults.ContainsKey(pluginTypeName)) { - return ((InstanceDefault) _defaults[pluginTypeName]).DefaultKey; + return (_defaults[pluginTypeName]).DefaultKey; } else { @@ -129,5 +129,10 @@ { get { return ProfileName; } } + + public static string InstanceKeyForProfile(string profileName) + { + return profileName + "-Instance"; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/InstanceManager.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -485,6 +485,18 @@ return this[type].GetAllInstances(); } + public IList<T> GetAllInstances<T>() + { + List<T> list = new List<T>(); + + foreach (T instance in this[typeof(T)].GetAllInstances()) + { + list.Add(instance); + } + + return list; + } + public void SetDefaultsToProfile(string profile) { // The authenticated user may not have required privileges to read from Environment Modified: trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -12,6 +12,7 @@ public HttpContextItemInterceptor() : base() { + } private string getKey(string instanceKey) Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap/StructureMap.csproj 2007-03-25 02:43:09 UTC (rev 27) @@ -215,9 +215,9 @@ </Compile> <Compile Include="Configuration\DSL\ChildInstanceExpression.cs" /> <Compile Include="Configuration\DSL\CreatePluginFamilyExpression.cs" /> - <Compile Include="Configuration\DSL\DefaultExpression.cs" /> <Compile Include="Configuration\DSL\IExpression.cs" /> <Compile Include="Configuration\DSL\IMementoBuilder.cs" /> + <Compile Include="Configuration\DSL\InstanceDefaultExpression.cs" /> <Compile Include="Configuration\DSL\InstanceExpression.cs" /> <Compile Include="Configuration\DSL\LiteralExpression.cs" /> <Compile Include="Configuration\DSL\LiteralMemento.cs" /> Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -1,3 +1,4 @@ +using System; using System.Xml; using NUnit.Framework; using StructureMap.Configuration; @@ -102,7 +103,8 @@ public void GotAllMachines() { string[] names = _defaults.GetMachineNames(); - Assert.AreEqual(new string[] {"SERVER", "GREEN-BOX"}, names); + Array.Sort(names); + Assert.AreEqual(new string[] {"GREEN-BOX", "SERVER" }, names); } [Test] Added: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2007-03-25 02:43:09 UTC (rev 27) @@ -0,0 +1,62 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class ProfileExpressionTester + { + [SetUp] + public void SetUp() + { + + } + + [Test] + public void AddAProfileWithANamedDefault() + { + string theProfileName = "TheProfile"; + string theDefaultName = "TheDefaultName"; + + ProfileExpression expression = new ProfileExpression(theProfileName); + + ProfileExpression expression2 = expression.For<IWidget>().UseNamedInstance(theDefaultName); + Assert.AreSame(expression, expression2); + + PluginGraph graph = new PluginGraph(); + ((IExpression)expression).Configure(graph); + + Profile profile = graph.DefaultManager.GetProfile(theProfileName); + Assert.IsNotNull(profile); + Assert.AreEqual(new InstanceDefault[] { new InstanceDefault(typeof(IWidget), theDefaultName) }, profile.Defaults); + } + + [Test] + public void AddAProfileWithInlineInstanceDefinition() + { + string theProfileName = "TheProfile"; + + PluginGraph graph = new PluginGraph(); + Registry registry = new Registry(graph); + registry.CreateProfile(theProfileName) + .For<IWidget>().Use( + Registry.Instance<IWidget>().UsingConcreteType<AWidget>() + ); + + InstanceManager manager = registry.BuildInstanceManager(); + + + + Profile profile = manager.DefaultManager.GetProfile(theProfileName); + InstanceDefault instanceDefault = profile.Defaults[0]; + Assert.AreEqual(Profile.InstanceKeyForProfile(theProfileName), instanceDefault.DefaultKey); + + manager.SetDefaultsToProfile(theProfileName); + AWidget widget = (AWidget) manager.CreateInstance<IWidget>(); + Assert.IsNotNull(widget); + } + } +} Added: trunk/Source/StructureMap.Testing/Sample.xml =================================================================== --- trunk/Source/StructureMap.Testing/Sample.xml (rev 0) +++ trunk/Source/StructureMap.Testing/Sample.xml 2007-03-25 02:43:09 UTC (rev 27) @@ -0,0 +1,36 @@ +<StructureMap MementoStyle="Attribute" DefaultProfile="Development"> + <Assembly Name="SomeAssembly"/> + + <Profile Name="Production"> + <Override Type="SomeAssembly.IService" DefaultKey="Production"/> + </Profile> + + <Profile Name="Testing"> + <Override Type="SomeAssembly.IService" DefaultKey="Testing"/> + </Profile> + + <Profile Name="Development"> + <Override Type="SomeAssembly.IService" DefaultKey="Development"/> + </Profile> + + + <PluginFamily Type="SomeAssembly.IService" Assembly="SomeAssembly"> + <Plugin Type="SomeAssembly.ConcreteService" Assembly="SomeAssembly" ConcreteKey="Concrete"/> + + <Instance Type="Concrete" Key="Production"> + <Property Name="host" Value="PROD-SERVER"/> + <Property Name="port" Value="5050"/> + </Instance> + + <Instance Type="Concrete" Key="Testing"> + <Property Name="host" Value="TEST-SERVER"/> + <Property Name="port" Value="5050"/> + </Instance> + + <Instance Type="Concrete" Key="Development"> + <Property Name="host" Value="localhost"/> + <Property Name="port" Value="2000"/> + </Instance> + </PluginFamily> + +</StructureMap> Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-03-08 11:51:48 UTC (rev 26) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-03-25 02:43:09 UTC (rev 27) @@ -189,6 +189,7 @@ <Compile Include="Configuration\DSL\CreateProfileTester.cs" /> <Compile Include="Configuration\DSL\InstanceExpressionTester.cs" /> <Compile Include="Configuration\DSL\LiteralExpressionTester.cs" /> + <Compile Include="Configuration\DSL\ProfileExpressionTester.cs" /> <Compile Include="Configuration\DSL\RegistryTester.cs" /> <Compile Include="Configuration\DSL\ScanAssembliesTester.cs" /> <Compile Include="Configuration\FamilyParserTester.cs"> @@ -483,6 +484,9 @@ <ItemGroup> <EmbeddedResource Include="TestData\InlineInstanceInProfileAndMachine.xml" /> </ItemGroup> + <ItemGroup> + <Content Include="Sample.xml" /> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <PropertyGroup> <PreBuildEvent> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2007-03-26 01:52:42
|
Revision: 29 http://structuremap.svn.sourceforge.net/structuremap/?rev=29&view=rev Author: jeremydmiller Date: 2007-03-25 18:52:39 -0700 (Sun, 25 Mar 2007) Log Message: ----------- Adding some defensive programming to the Fluent Interface API Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -21,7 +21,13 @@ _propertyName = propertyName; } + public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName, Type childType) + : this(instance, memento, propertyName) + { + _childType = childType; + } + public InstanceExpression IsNamedInstance(string instanceKey) { MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey); @@ -30,9 +36,11 @@ return _instance; } - // TODO -- negative case if the concrete type cannot be an implicit instance public InstanceExpression IsConcreteType<T>() { + Type pluggedType = typeof (T); + ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType); + InstanceExpression child = new InstanceExpression(_childType); child.UsingConcreteType<T>(); _children.Add(child); @@ -70,6 +78,11 @@ public InstanceExpression Is(InstanceExpression child) { + if (child.PluggedType != null && _childType != null) + { + ExpressionValidator.ValidatePluggabilityOf(child.PluggedType).IntoPluginType(_childType); + } + _children.Add(child); MemoryInstanceMemento childMemento = MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey); Modified: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -19,7 +19,7 @@ _pluginType = pluginType; } - public void Configure(PluginGraph graph) + void IExpression.Configure(PluginGraph graph) { PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); InterceptorChainBuilder builder = new InterceptorChainBuilder(); @@ -36,26 +36,10 @@ graph.Assemblies.Add(assembly); } - public CreatePluginFamilyExpression WithDefaultConcreteType<T>() - { - Plugin plugin = addPlugin<T>(); - - _alterations.Add(delegate(PluginFamily family) { family.DefaultInstanceKey = plugin.ConcreteKey; }); - - return this; - } - - private Plugin addPlugin<T>() - { - Plugin plugin = Plugin.CreateImplicitPlugin(typeof (T)); - - _alterations.Add(delegate(PluginFamily family) { family.Plugins.Add(plugin); }); - - return plugin; - } - public CreatePluginFamilyExpression TheDefaultIs(IMementoBuilder builder) { + builder.ValidatePluggability(_pluginType); + _alterations.Add(delegate(PluginFamily family) { InstanceMemento memento = builder.BuildMemento(family); @@ -68,6 +52,8 @@ public CreatePluginFamilyExpression TheDefaultIsConcreteType<T>() { + ExpressionValidator.ValidatePluggabilityOf(typeof(T)).IntoPluginType(_pluginType); + _alterations.Add(delegate(PluginFamily family) { Plugin plugin = family.Plugins.FindOrCreate(typeof (T)); Added: trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -0,0 +1,35 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL +{ + public static class ExpressionValidator + { + public static ValidateExpression ValidatePluggabilityOf(Type pluggedType) + { + return new ValidateExpression(pluggedType); + } + + + public class ValidateExpression + { + private readonly Type _pluggedType; + + public ValidateExpression(Type pluggedType) + { + _pluggedType = pluggedType; + } + + public void IntoPluginType(Type pluginType) + { + if (!Plugin.CanBeCast(pluginType, _pluggedType)) + { + throw new StructureMapException( + 303, + TypePath.GetAssemblyQualifiedName(_pluggedType), + TypePath.GetAssemblyQualifiedName(pluginType)); + } + } + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -1,3 +1,4 @@ +using System; using StructureMap.Graph; namespace StructureMap.Configuration.DSL @@ -7,5 +8,7 @@ InstanceMemento BuildMemento(PluginFamily family); InstanceMemento BuildMemento(PluginGraph graph); void SetInstanceName(string instanceKey); + + void ValidatePluggability(Type pluginType); } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -22,7 +22,7 @@ return _parent; } - public void Configure(Profile profile, PluginGraph graph) + internal void Configure(Profile profile, PluginGraph graph) { if (!string.IsNullOrEmpty(_instanceKey)) { @@ -40,8 +40,10 @@ InstanceDefault instanceDefault = new InstanceDefault(_pluginType, defaultKey); profile.AddOverride(instanceDefault); } - - // TODO throw up!!! + else + { + throw new StructureMapException(304, TypePath.GetAssemblyQualifiedName(_pluginType)); + } } public ProfileExpression Use(IMementoBuilder mementoBuilder) Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -12,6 +12,12 @@ { } + + internal Type PluggedType + { + get { return _pluggedType; } + } + protected override void buildMemento() { _memento = new MemoryInstanceMemento(); @@ -75,8 +81,13 @@ public ChildInstanceExpression Child<T>() { - // TODO -- what if the property can't be found string propertyName = findPropertyName<T>(); + + if (string.IsNullOrEmpty(propertyName)) + { + throw new StructureMapException(305, TypePath.GetAssemblyQualifiedName(typeof (T))); + } + ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName); addChildExpression(child); child.ChildType = typeof (T); @@ -88,5 +99,15 @@ Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType); return plugin.FindFirstConstructorArgumentOfType<T>(); } + + public override void ValidatePluggability(Type pluginType) + { + if (_pluggedType == null) + { + return; + } + + ExpressionValidator.ValidatePluggabilityOf(_pluggedType).IntoPluginType(pluginType); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -1,3 +1,4 @@ +using System; using StructureMap.Graph; namespace StructureMap.Configuration.DSL @@ -36,5 +37,10 @@ { _memento = new LiteralMemento(null); } + + public override void ValidatePluggability(Type pluginType) + { + ExpressionValidator.ValidatePluggabilityOf(_target.GetType()).IntoPluginType(pluginType); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -88,6 +88,8 @@ _instanceKey = instanceKey; } + public abstract void ValidatePluggability(Type pluginType); + protected void addChildExpression(IExpression expression) { _children.Add(expression); Modified: trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -37,5 +37,10 @@ { _memento = new PrototypeMemento(string.Empty, (ICloneable) _prototype); } + + public override void ValidatePluggability(Type pluginType) + { + ExpressionValidator.ValidatePluggabilityOf(_prototype.GetType()).IntoPluginType(pluginType); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -82,6 +82,11 @@ /// <returns></returns> public static bool CanBeCast(Type pluginType, Type pluggedType) { + if (pluggedType.IsInterface || pluggedType.IsAbstract) + { + return false; + } + if (GenericsPluginGraph.CanBeCast(pluginType, pluggedType)) { return true; Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap/StructureMapException.resx 2007-03-26 01:52:39 UTC (rev 29) @@ -237,4 +237,13 @@ <data name="302" xml:space="preserve"> <value>There is no argument of type {0} for concrete type {1}</value> </data> + <data name="303" xml:space="preserve"> + <value>Type {0} is either abstract or cannot be plugged into Type {1}</value> + </data> + <data name="304" xml:space="preserve"> + <value>Profile or Machine default for {0} not completely specified</value> + </data> + <data name="305" xml:space="preserve"> + <value>There is no constructor property found of type {0}</value> + </data> </root> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -0,0 +1,60 @@ +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Testing.Widget4; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class ChildInstanceExpressionTester + { + [SetUp] + public void SetUp() + { + } + + [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 303\nType System.String,mscorlib is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing")] + public void CantCastTheRequestedConcreteType() + { + InstanceExpression instance = new InstanceExpression(typeof(IStrategy)); + MemoryInstanceMemento memento = new MemoryInstanceMemento(); + + ChildInstanceExpression expression = new ChildInstanceExpression(instance, memento, "a property", typeof(IType)); + expression.IsConcreteType<string>(); + } + + [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 303\nType StructureMap.Testing.Configuration.DSL.AbstractType,StructureMap.Testing is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing")] + public void CantCastTheRequestedConcreteType2() + { + InstanceExpression instance = new InstanceExpression(typeof(IStrategy)); + MemoryInstanceMemento memento = new MemoryInstanceMemento(); + + ChildInstanceExpression expression = new ChildInstanceExpression(instance, memento, "a property", typeof(IType)); + expression.IsConcreteType<AbstractType>(); + } + + + [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 303\nType StructureMap.Testing.Configuration.DSL.AbstractType,StructureMap.Testing is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing")] + public void CantCastTheRequestedPluggedType3() + { + InstanceExpression instance = new InstanceExpression(typeof(IStrategy)); + MemoryInstanceMemento memento = new MemoryInstanceMemento(); + + ChildInstanceExpression expression = new ChildInstanceExpression(instance, memento, "a property", typeof(IType)); + InstanceExpression child = new InstanceExpression(typeof(IType)).UsingConcreteType<AbstractType>(); + expression.Is(child); + } + } + + public interface IType + { + } + + public abstract class AbstractType : IType + { + } + + public class ConcreteType : AbstractType + { + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -17,6 +17,13 @@ } + [Test, ExpectedException(typeof(StructureMapException))] + public void TheConceteTypeDoesNotCase() + { + Registry registry = new Registry(); + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<IWidget>(); + } + [Test] public void TheDefaultInstanceIsConcreteType() { @@ -66,7 +73,7 @@ using (Registry registry = new Registry(pluginGraph)) { // Specify the default implementation for an interface - registry.BuildInstancesOf<IGateway>().WithDefaultConcreteType<StubbedGateway>(); + registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<StubbedGateway>(); } Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); @@ -142,7 +149,7 @@ PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { - registry.BuildInstancesOf<IGateway>().WithDefaultConcreteType<FakeGateway>(); + registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<FakeGateway>(); } Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2007-03-25 02:56:13 UTC (rev 28) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2007-03-26 01:52:39 UTC (rev 29) @@ -21,5 +21,13 @@ PluginGraph pluginGraph = new PluginGraph(); ((IExpression)expression).Configure(pluginGraph); } + + [Test, ExpectedException(typeof(StructureMapException))] + public void BlowUpIfNoPropertyIsFoundForType() + { + InstanceExpression expression = new InstanceExpression(typeof(IWidget)); + expression.UsingConcreteType<AWidget>(); + expression.Child<Rule>(); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2007-03-26 15:33:17
|
Revision: 30 http://structuremap.svn.sourceforge.net/structuremap/?rev=30&view=rev Author: jeremydmiller Date: 2007-03-26 07:31:28 -0700 (Mon, 26 Mar 2007) Log Message: ----------- Deep testing on the Fluent Interface API Modified Paths: -------------- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/MementoSource.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing.Widget/IWidget.cs Added Paths: ----------- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs Modified: trunk/Source/StructureMap/Attributes/PluggableAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -47,7 +47,7 @@ /// <returns></returns> public static PluggableAttribute InstanceOf(Type objectType) { - return (PluggableAttribute) GetCustomAttribute(objectType, typeof (PluggableAttribute), false); + return GetCustomAttribute(objectType, typeof (PluggableAttribute), false) as PluggableAttribute; } /// <summary> Modified: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -41,8 +41,9 @@ Type pluggedType = typeof (T); ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType); + InstanceExpression child = new InstanceExpression(_childType); - child.UsingConcreteType<T>(); + child.TypeExpression().UsingConcreteType<T>(); _children.Add(child); _builder = child; Modified: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -13,6 +13,7 @@ private Type _pluginType; private List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>(); private InstanceScope _scope = InstanceScope.PerRequest; + private List<IExpression> _children = new List<IExpression>(); public CreatePluginFamilyExpression(Type pluginType) { @@ -25,6 +26,11 @@ InterceptorChainBuilder builder = new InterceptorChainBuilder(); family.InterceptionChain = builder.Build(_scope); + foreach (IExpression child in _children) + { + child.Configure(graph); + } + foreach (AlterPluginFamilyDelegate alteration in _alterations) { alteration(family); @@ -40,6 +46,7 @@ { builder.ValidatePluggability(_pluginType); + _children.Add(builder); _alterations.Add(delegate(PluginFamily family) { InstanceMemento memento = builder.BuildMemento(family); Modified: trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -3,7 +3,7 @@ namespace StructureMap.Configuration.DSL { - public interface IMementoBuilder + public interface IMementoBuilder : IExpression { InstanceMemento BuildMemento(PluginFamily family); InstanceMemento BuildMemento(PluginGraph graph); Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -53,22 +53,13 @@ } - public InstanceExpression UsingConcreteType<T>() - { - _pluggedType = typeof (T); - return this; - } + public PropertyExpression WithProperty(string propertyName) { return new PropertyExpression(this, _memento, propertyName); } - public InstanceExpression UsingConcreteTypeNamed(string concreteKey) - { - _memento.ConcreteKey = concreteKey; - return this; - } public ChildInstanceExpression Child<T>(string propertyName) { @@ -109,5 +100,34 @@ ExpressionValidator.ValidatePluggabilityOf(_pluggedType).IntoPluginType(pluginType); } + + internal InstanceTypeExpression TypeExpression() + { + return new InstanceTypeExpression(this); + } + + + public class InstanceTypeExpression + { + private readonly InstanceExpression _parent; + + internal InstanceTypeExpression(InstanceExpression parent) + { + _parent = parent; + } + + public InstanceExpression UsingConcreteType<T>() + { + _parent._pluggedType = typeof(T); + return _parent; + } + + public InstanceExpression UsingConcreteTypeNamed(string concreteKey) + { + _parent._memento.ConcreteKey = concreteKey; + return _parent; + } + + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -70,16 +70,17 @@ return new InstanceManager(_graph); } - public InstanceExpression AddInstanceOf<T>() + public InstanceExpression.InstanceTypeExpression AddInstanceOf<T>() { InstanceExpression expression = new InstanceExpression(typeof (T)); addExpression(expression); - return expression; + return expression.TypeExpression(); } - public static InstanceExpression Instance<T>() + public static InstanceExpression.InstanceTypeExpression Instance<T>() { - return new InstanceExpression(typeof (T)); + InstanceExpression expression = new InstanceExpression(typeof (T)); + return expression.TypeExpression(); } public static PrototypeExpression<T> Prototype<T>(T prototype) @@ -87,6 +88,11 @@ return new PrototypeExpression<T>(prototype); } + public static LiteralExpression<T> Object<T>(T instance) + { + return new LiteralExpression<T>(instance); + } + public LiteralExpression<T> AddInstanceOf<T>(T target) { LiteralExpression<T> literal = new LiteralExpression<T>(target); Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -35,7 +35,7 @@ private string _defaultKey = string.Empty; private Type _pluginType; - private MementoSource _source = new MemoryMementoSource(); + private MementoSource _source; private DefinitionSource _definitionSource = DefinitionSource.Implicit; private string _pluginTypeName; private InterceptionChain _interceptionChain; @@ -53,6 +53,8 @@ _plugins = new PluginCollection(this); _interceptionChain = new InterceptionChain(); + + Source = new MemoryMementoSource(); } public PluginFamily(Type pluginType, string defaultInstanceKey, MementoSource source) @@ -89,6 +91,8 @@ _pluginTypeName = path.AssemblyQualifiedName; _interceptionChain = new InterceptionChain(); initializeExplicit(path, defaultKey); + + Source = new MemoryMementoSource(); } Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/InstanceMemento.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -164,18 +164,7 @@ if (memento == null) { - try - { - returnValue = manager.CreateInstance(typeName); - } - catch (StructureMapException) - { - throw; - } - catch (Exception ex) - { - throw new StructureMapException(209, ex, key, typeName); - } + returnValue = buildDefaultChild(key, manager, typeName); } else { @@ -186,7 +175,25 @@ return returnValue; } + private static object buildDefaultChild(string key, InstanceManager manager, string typeName) + { + object returnValue; + try + { + returnValue = manager.CreateInstance(typeName); + } + catch (StructureMapException) + { + throw; + } + catch (Exception ex) + { + throw new StructureMapException(209, ex, key, typeName); + } + return returnValue; + } + /// <summary> /// Not used yet. /// </summary> Modified: trunk/Source/StructureMap/MementoSource.cs =================================================================== --- trunk/Source/StructureMap/MementoSource.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/MementoSource.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using StructureMap.Configuration.Tokens; using StructureMap.Graph; using StructureMap.Source; @@ -15,7 +16,7 @@ { private PluginFamily _family; private InstanceMemento _defaultMemento; - private Hashtable _externalMementos = new Hashtable(); + private Dictionary<string, InstanceMemento> _externalMementos = new Dictionary<string, InstanceMemento>(); protected MementoSource() : base() { @@ -32,7 +33,7 @@ if (_externalMementos.ContainsKey(instanceKey)) { - returnValue = (InstanceMemento) _externalMementos[instanceKey]; + returnValue = _externalMementos[instanceKey]; } else if (containsKey(instanceKey)) { @@ -88,6 +89,11 @@ else if (memento.IsReference) { returnValue = GetMemento(memento.ReferenceKey); + + if (returnValue == null) + { + throw new StructureMapException(200, memento.ReferenceKey, Family.PluginTypeName); + } } return returnValue; Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap/StructureMap.csproj 2007-03-26 14:31:28 UTC (rev 30) @@ -215,6 +215,7 @@ </Compile> <Compile Include="Configuration\DSL\ChildInstanceExpression.cs" /> <Compile Include="Configuration\DSL\CreatePluginFamilyExpression.cs" /> + <Compile Include="Configuration\DSL\ExpressionValidator.cs" /> <Compile Include="Configuration\DSL\IExpression.cs" /> <Compile Include="Configuration\DSL\IMementoBuilder.cs" /> <Compile Include="Configuration\DSL\InstanceDefaultExpression.cs" /> Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -21,20 +21,20 @@ // Add an instance with properties registry.AddInstanceOf<IWidget>() + .UsingConcreteType<ColorWidget>() .WithName("DarkGreen") - .UsingConcreteType<ColorWidget>() .WithProperty("Color").EqualTo("DarkGreen"); // Add an instance by specifying the ConcreteKey registry.AddInstanceOf<IWidget>() + .UsingConcreteTypeNamed("Color") .WithName("Purple") - .UsingConcreteTypeNamed("Color") .WithProperty("Color").EqualTo("Purple"); // Pull a property from the App config registry.AddInstanceOf<IWidget>() + .UsingConcreteType<ColorWidget>() .WithName("AppSetting") - .UsingConcreteType<ColorWidget>() .WithProperty("Color").EqualToAppSetting("Color"); @@ -184,8 +184,8 @@ // Add an instance by specifying the ConcreteKey registry.AddInstanceOf<IWidget>() + .UsingConcreteTypeNamed("Color") .WithName("Purple") - .UsingConcreteTypeNamed("Color") .WithProperty("Color").EqualTo("Purple"); // Specify a new Instance, override a dependency with a named instance @@ -217,6 +217,20 @@ { get { return _widget; } } + + + public override bool Equals(object obj) + { + if (this == obj) return true; + WidgetRule widgetRule = obj as WidgetRule; + if (widgetRule == null) return false; + return Equals(_widget, widgetRule._widget); + } + + public override int GetHashCode() + { + return _widget != null ? _widget.GetHashCode() : 0; + } } public class WidgetThing : IWidget Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -40,7 +40,8 @@ MemoryInstanceMemento memento = new MemoryInstanceMemento(); ChildInstanceExpression expression = new ChildInstanceExpression(instance, memento, "a property", typeof(IType)); - InstanceExpression child = new InstanceExpression(typeof(IType)).UsingConcreteType<AbstractType>(); + InstanceExpression child = Registry.Instance<IType>().UsingConcreteType<AbstractType>(); + expression.Is(child); } } Added: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -0,0 +1,180 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Configuration.DSL; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class DeepInstanceTester + { + private Thing _prototype = new Thing(4, "Jeremy", .333, new WidgetRule(new ColorWidget("yellow"))); + + private void assertThingMatches(Registry registry) + { + IInstanceManager manager = registry.BuildInstanceManager(); + Thing actual = manager.CreateInstance<Thing>(); + Assert.AreEqual(_prototype, actual); + } + + [Test] + public void DeepInstanceTest1() + { + Registry registry = new Registry(); + InstanceExpression widgetExpression = Registry.Instance<IWidget>() + .UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualTo("yellow"); + + InstanceExpression ruleExpression = Registry.Instance<Rule>() + .UsingConcreteType<WidgetRule>() + .Child<IWidget>().Is(widgetExpression); + + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Registry.Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + .WithProperty("average").EqualTo(.333) + .Child<Rule>().Is( + ruleExpression + ) + ); + + assertThingMatches(registry); + } + + [Test] + public void DeepInstance2() + { + Registry registry = new Registry(); + registry.BuildInstancesOf<IWidget>().TheDefaultIs( + Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualTo("yellow") + ); + + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Registry.Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + ); + + assertThingMatches(registry); + } + + [Test] + public void DeepInstance3() + { + Registry registry = new Registry(); + registry.BuildInstancesOf<IWidget>().TheDefaultIs( + Registry.Object(new ColorWidget("yellow")) + ); + + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Registry.Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + ); + + assertThingMatches(registry); + } + + + [Test] + public void DeepInstance4() + { + Registry registry = new Registry(); + registry.BuildInstancesOf<IWidget>().TheDefaultIs( + Registry.Prototype(new ColorWidget("yellow")) + ); + + registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Registry.Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + ); + + assertThingMatches(registry); + } + + + + [Test] + public void DeepInstance5() + { + Registry registry = new Registry(); + + registry.AddInstanceOf<IWidget>() + .UsingConcreteType<ColorWidget>() + .WithName("Yellow") + .WithProperty("Color").EqualTo("yellow"); + + registry.AddInstanceOf<Rule>() + .UsingConcreteType<WidgetRule>() + .WithName("TheWidgetRule") + .Child<IWidget>().IsNamedInstance("Yellow"); + + registry.BuildInstancesOf<Thing>().TheDefaultIs( + Registry.Instance<Thing>() + .UsingConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + .Child<Rule>().IsNamedInstance("TheWidgetRule") + ); + + assertThingMatches(registry); + } + + } + + public class Thing + { + private int _count; + private string _name; + private double _average; + private Rule _rule; + + + public Thing(int count, string name, double average, Rule rule) + { + _count = count; + _name = name; + _average = average; + _rule = rule; + } + + + public override bool Equals(object obj) + { + if (this == obj) return true; + Thing thing = obj as Thing; + if (thing == null) return false; + if (_count != thing._count) return false; + if (!Equals(_name, thing._name)) return false; + if (_average != thing._average) return false; + if (!Equals(_rule, thing._rule)) return false; + return true; + } + + public override int GetHashCode() + { + int result = _count; + result = 29*result + (_name != null ? _name.GetHashCode() : 0); + result = 29*result + _average.GetHashCode(); + result = 29*result + (_rule != null ? _rule.GetHashCode() : 0); + return result; + } + } +} Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -25,9 +25,7 @@ [Test, ExpectedException(typeof(StructureMapException))] public void BlowUpIfNoPropertyIsFoundForType() { - InstanceExpression expression = new InstanceExpression(typeof(IWidget)); - expression.UsingConcreteType<AWidget>(); - expression.Child<Rule>(); + Registry.Instance<IWidget>().UsingConcreteType<AWidget>().Child<Rule>(); } } } Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-03-26 14:31:28 UTC (rev 30) @@ -185,8 +185,10 @@ <SubType>Code</SubType> </Compile> <Compile Include="Configuration\DSL\AddInstanceTester.cs" /> + <Compile Include="Configuration\DSL\ChildInstanceExpressionTester.cs" /> <Compile Include="Configuration\DSL\CreatePluginFamilyTester.cs" /> <Compile Include="Configuration\DSL\CreateProfileTester.cs" /> + <Compile Include="Configuration\DSL\DeepInstanceTester.cs" /> <Compile Include="Configuration\DSL\InstanceExpressionTester.cs" /> <Compile Include="Configuration\DSL\LiteralExpressionTester.cs" /> <Compile Include="Configuration\DSL\ProfileExpressionTester.cs" /> Modified: trunk/Source/StructureMap.Testing.Widget/IWidget.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/IWidget.cs 2007-03-26 01:52:39 UTC (rev 29) +++ trunk/Source/StructureMap.Testing.Widget/IWidget.cs 2007-03-26 14:31:28 UTC (rev 30) @@ -8,7 +8,7 @@ } [Pluggable("Color", "Only for testing")] - public class ColorWidget : IWidget + public class ColorWidget : IWidget, ICloneable { private string _Color; @@ -31,6 +31,24 @@ } #endregion + + public override bool Equals(object obj) + { + if (this == obj) return true; + ColorWidget colorWidget = obj as ColorWidget; + if (colorWidget == null) return false; + return Equals(_Color, colorWidget._Color); + } + + public override int GetHashCode() + { + return _Color != null ? _Color.GetHashCode() : 0; + } + + public object Clone() + { + return this.MemberwiseClone(); + } } [Pluggable("AWidget")] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2007-03-27 11:18:51
|
Revision: 31 http://structuremap.svn.sourceforge.net/structuremap/?rev=31&view=rev Author: jeremydmiller Date: 2007-03-27 04:18:48 -0700 (Tue, 27 Mar 2007) Log Message: ----------- Integrated Registry into ObjectFactory Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs trunk/Source/StructureMap/Graph/AssemblyGraph.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs Added Paths: ----------- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -9,7 +9,7 @@ private List<IExpression> _expressions = new List<IExpression>(); private PluginGraph _graph; - public Registry(PluginGraph graph) + public Registry(PluginGraph graph) : this() { _graph = graph; } @@ -17,6 +17,7 @@ public Registry() { _graph = new PluginGraph(); + configure(); } @@ -28,12 +29,12 @@ // no-op; } - protected void addExpression(IExpression expression) + protected internal void addExpression(IExpression expression) { _expressions.Add(expression); } - private void configurePluginGraph(PluginGraph graph) + internal void ConfigurePluginGraph(PluginGraph graph) { foreach (IExpression expression in _expressions) { @@ -44,17 +45,10 @@ public void Dispose() { - configurePluginGraph(_graph); + ConfigurePluginGraph(_graph); } - public ScanAssembliesExpression ScanAssemblies() - { - ScanAssembliesExpression expression = new ScanAssembliesExpression(); - addExpression(expression); - return expression; - } - public CreatePluginFamilyExpression BuildInstancesOf<T>() { CreatePluginFamilyExpression expression = new CreatePluginFamilyExpression(typeof (T)); @@ -65,7 +59,7 @@ public IInstanceManager BuildInstanceManager() { - configurePluginGraph(_graph); + ConfigurePluginGraph(_graph); _graph.ReadDefaults(); return new InstanceManager(_graph); } @@ -116,5 +110,20 @@ return expression; } + + public static bool IsPublicRegistry(Type type) + { + if (!typeof(Registry).IsAssignableFrom(type)) + { + return false; + } + + if (type.IsInterface || type.IsAbstract || type.IsGenericType) + { + return false; + } + + return (type.GetConstructor(new Type[0]) != null); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -1,5 +1,6 @@ using System; using StructureMap.Attributes; +using StructureMap.Configuration.DSL; using StructureMap.Configuration.Tokens; using StructureMap.Graph; using StructureMap.Graph.Configuration; @@ -14,9 +15,9 @@ private PluginGraphReport _systemReport; private PluginGraphReport _report; - public DiagnosticGraphBuilder() + public DiagnosticGraphBuilder(Registry[] registries) { - _innerBuilder = new NormalGraphBuilder(); + _innerBuilder = new NormalGraphBuilder(registries); _systemReport = new PluginGraphReport(); _report = _innerBuilder.PluginGraph.Report; } Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -1,6 +1,7 @@ using System; using System.Reflection; using StructureMap.Attributes; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Graph.Configuration; using StructureMap.Interceptors; @@ -17,14 +18,20 @@ private MachineOverride _machine; - public NormalGraphBuilder() : this(new InterceptorChainBuilder()) + public NormalGraphBuilder(Registry[] registries) : this(new InterceptorChainBuilder(), registries) { } - public NormalGraphBuilder(IInterceptorChainBuilder builder) + public NormalGraphBuilder(IInterceptorChainBuilder builder, Registry[] registries) { _builder = builder; + _pluginGraph = new PluginGraph(); + foreach (Registry registry in registries) + { + registry.ConfigurePluginGraph(_pluginGraph); + } + _systemGraph = new PluginGraph(); _systemGraph.Assemblies.Add(Assembly.GetExecutingAssembly()); } Modified: trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -16,11 +16,14 @@ PluginFamilyAttribute att = PluginFamilyAttribute.GetAttribute(family.PluginType); - if (att.Scope != InstanceScope.PerRequest) + if (att != null) { - token.Scope = att.Scope; - InterceptorInstanceToken interceptor = new InterceptorInstanceToken(att.Scope); - token.AddInterceptor(interceptor); + if (att.Scope != InstanceScope.PerRequest) + { + token.Scope = att.Scope; + InterceptorInstanceToken interceptor = new InterceptorInstanceToken(att.Scope); + token.AddInterceptor(interceptor); + } } return token; Modified: trunk/Source/StructureMap/Graph/AssemblyGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -1,8 +1,10 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; +using StructureMap.Configuration.DSL; namespace StructureMap.Graph { @@ -91,17 +93,9 @@ return new PluginFamily[0]; } - ArrayList list = new ArrayList(); + List<PluginFamily> list = new List<PluginFamily>(); - Type[] exportedTypes = null; - try - { - exportedTypes = _assembly.GetExportedTypes(); - } - catch (Exception ex) - { - throw new StructureMapException(170, ex, AssemblyName); - } + Type[] exportedTypes = getExportedTypes(); foreach (Type exportedType in exportedTypes) { @@ -112,9 +106,24 @@ } } - return (PluginFamily[]) list.ToArray(typeof (PluginFamily)); + return list.ToArray(); } + private Type[] getExportedTypes() + { + Type[] exportedTypes = null; + try + { + exportedTypes = _assembly.GetExportedTypes(); + } + catch (Exception ex) + { + throw new StructureMapException(170, ex, AssemblyName); + } + return exportedTypes; + } + + /// <summary> /// Returns an array of possible Plugin's from the Assembly that match /// the requested type @@ -165,5 +174,23 @@ { return _assembly.GetType(fullName, false); } + + 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; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -1,7 +1,9 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Reflection; using StructureMap.Configuration; +using StructureMap.Configuration.DSL; namespace StructureMap.Graph { @@ -54,6 +56,8 @@ return; } + searchAssembliesForRegistries(); + foreach (AssemblyGraph assembly in _assemblies) { addImplicitPluginFamilies(assembly); @@ -67,6 +71,20 @@ _sealed = true; } + 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) Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -1,6 +1,7 @@ using System; using System.Xml; using StructureMap.Configuration; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Graph.Configuration; @@ -17,7 +18,7 @@ public static PluginGraph BuildFromXml(XmlDocument document) { ConfigurationParser[] parsers = ConfigurationParser.GetParsers(document, ""); - PluginGraphBuilder builder = new PluginGraphBuilder(parsers); + PluginGraphBuilder builder = new PluginGraphBuilder(parsers, new Registry[0]); return builder.BuildDiagnosticPluginGraph(); } @@ -49,21 +50,22 @@ private PluginGraph _graph; private PluginGraphReport _report; private ConfigurationParser[] _parsers; + private readonly Registry[] _registries = new Registry[0]; #region constructors public PluginGraphBuilder(ConfigurationParser parser) - : this(new ConfigurationParser[] {parser}) + : this(new ConfigurationParser[] {parser}, new Registry[0]) { } - public PluginGraphBuilder(ConfigurationParser[] parsers) + public PluginGraphBuilder(ConfigurationParser[] parsers, Registry[] registries) { _parsers = parsers; + _registries = registries; } - /// <summary> /// Creates a PluginGraphBuilder that reads configuration from the filePath /// </summary> @@ -102,7 +104,7 @@ /// <returns></returns> public PluginGraph Build() { - NormalGraphBuilder graphBuilder = new NormalGraphBuilder(); + NormalGraphBuilder graphBuilder = new NormalGraphBuilder(_registries); PluginGraph pluginGraph = buildPluginGraph(graphBuilder); return pluginGraph; } @@ -162,7 +164,7 @@ /// <returns></returns> public PluginGraph BuildDiagnosticPluginGraph() { - DiagnosticGraphBuilder graphBuilder = new DiagnosticGraphBuilder(); + DiagnosticGraphBuilder graphBuilder = new DiagnosticGraphBuilder(_registries); buildPluginGraph(graphBuilder); _report = graphBuilder.Report; Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.IO; using System.Xml; using StructureMap.Configuration; +using StructureMap.Configuration.DSL; using StructureMap.Graph; namespace StructureMap @@ -10,7 +12,15 @@ { private const string CONFIG_FILE_NAME = "StructureMap.config"; private static ConfigurationParserCollection _collection = new ConfigurationParserCollection(); + private static Registry _registry = new Registry(); + private static List<Registry> _registries = new List<Registry>(); + static StructureMapConfiguration() + { + ResetAll(); + } + + /// <summary> /// Returns the path to the StructureMap.config file /// </summary> @@ -38,6 +48,9 @@ public static void ResetAll() { _collection = new ConfigurationParserCollection(); + _registry = new Registry(); + _registries = new List<Registry>(); + _registries.Add(_registry); } public static PluginGraph GetPluginGraph() @@ -49,7 +62,7 @@ private static PluginGraphBuilder createBuilder() { ConfigurationParser[] parsers = _collection.GetParsers(); - return new PluginGraphBuilder(parsers); + return new PluginGraphBuilder(parsers, _registries.ToArray()); } public static PluginGraph GetDiagnosticPluginGraph() @@ -80,5 +93,58 @@ get { return _collection.UseDefaultFile; } set { _collection.UseDefaultFile = value; } } + + public static ScanAssembliesExpression ScanAssemblies() + { + ScanAssembliesExpression expression = new ScanAssembliesExpression(); + _registry.addExpression(expression); + + return expression; + } + + public static CreatePluginFamilyExpression BuildInstancesOf<T>() + { + return _registry.BuildInstancesOf<T>(); + } + + public static InstanceExpression.InstanceTypeExpression AddInstanceOf<T>() + { + return _registry.AddInstanceOf<T>(); + } + + public static InstanceExpression.InstanceTypeExpression Instance<T>() + { + return Registry.Instance<T>(); + } + + public static PrototypeExpression<T> Prototype<T>(T prototype) + { + return new PrototypeExpression<T>(prototype); + } + + public static LiteralExpression<T> Object<T>(T instance) + { + return new LiteralExpression<T>(instance); + } + + public static LiteralExpression<T> AddInstanceOf<T>(T target) + { + return _registry.AddInstanceOf(target); + } + + public static PrototypeExpression<T> AddPrototypeInstanceOf<T>(T prototype) + { + return _registry.AddPrototypeInstanceOf(prototype); + } + + public static ProfileExpression CreateProfile(string profileName) + { + return _registry.CreateProfile(profileName); + } + + public static void AddRegistry(Registry registry) + { + _registries.Add(registry); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -2,6 +2,7 @@ using System.Xml; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Source; using StructureMap.Testing.TestData; @@ -45,7 +46,7 @@ ConfigurationParser parser = new ConfigurationParser(doc.DocumentElement); - NormalGraphBuilder builder = new NormalGraphBuilder(); + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); parser.ParseProfilesAndMachines(builder); _defaults = builder.DefaultManager; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -178,13 +178,15 @@ { Registry registry = new Registry(); - registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>(); + //registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>(); + + registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias"); // Add an instance by specifying the ConcreteKey registry.AddInstanceOf<IWidget>() - .UsingConcreteTypeNamed("Color") + .UsingConcreteType<ColorWidget>() .WithName("Purple") .WithProperty("Color").EqualTo("Purple"); Added: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -0,0 +1,86 @@ +using System.Collections.Generic; +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Testing.Widget; +using StructureMap.Testing.Widget5; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class RegistryIntegratedTester + { + [SetUp] + public void SetUp() + { + } + + [TearDown] + public void TearDown() + { + StructureMapConfiguration.ResetAll(); + ObjectFactory.Reset(); + } + + + [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.Seal(); + + List<string> colors = new List<string>(); + foreach (InstanceMemento memento in graph.PluginFamilies[typeof(IWidget)].Source.GetAllMementos() ) + { + colors.Add(memento.InstanceKey); + } + + Assert.Contains("Red", colors); + Assert.Contains("Green", colors); + Assert.Contains("Yellow", colors); + Assert.Contains("Blue", colors); + Assert.Contains("Brown", colors); + Assert.Contains("Black", colors); + } + + [Test] + public void AutomaticallyFindRegistryFromAssembly() + { + StructureMapConfiguration.ResetAll(); + StructureMapConfiguration.ScanAssemblies().IncludeAssemblyContainingType<RedGreenRegistry>(); + ObjectFactory.Reset(); + + List<string> colors = new List<string>(); + foreach (IWidget widget in ObjectFactory.GetAllInstances<IWidget>()) + { + if (!(widget is ColorWidget)) + { + continue; + } + + ColorWidget color = (ColorWidget) widget; + colors.Add(color.Color); + } + + Assert.Contains("Red", colors); + Assert.Contains("Green", colors); + Assert.Contains("Yellow", colors); + Assert.Contains("Blue", colors); + Assert.Contains("Brown", colors); + Assert.Contains("Black", colors); + } + } +} Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -1,7 +1,5 @@ using System.Reflection; using NUnit.Framework; -using Rhino.Mocks; -using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.Widget3; @@ -13,19 +11,22 @@ [SetUp] public void SetUp() { + ObjectFactory.Reset(); } + [TearDown] + public void TearDown() + { + StructureMapConfiguration.ResetAll(); + ObjectFactory.Reset(); + } + [Test] public void ScanCallingAssembly() { - PluginGraph graph = new PluginGraph(); + StructureMapConfiguration.ScanAssemblies().IncludeTheCallingAssembly(); + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - using (Registry registry = new Registry(graph)) - { - registry.ScanAssemblies().IncludeTheCallingAssembly(); - } - AssemblyGraph assembly = new AssemblyGraph(Assembly.GetExecutingAssembly()); Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); } @@ -33,15 +34,9 @@ [Test] public void ScanAssemblyContainingType() { - PluginGraph graph = new PluginGraph(); + StructureMapConfiguration.ScanAssemblies().IncludeAssemblyContainingType<IGateway>(); + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - using (Registry registry = new Registry(graph)) - { - registry.ScanAssemblies() - .IncludeAssemblyContainingType<IGateway>(); - } - AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>(); Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); } @@ -49,16 +44,11 @@ [Test] public void Combination1() { - PluginGraph graph = new PluginGraph(); + StructureMapConfiguration.ScanAssemblies() + .IncludeAssemblyContainingType<IGateway>() + .IncludeTheCallingAssembly(); + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - using (Registry registry = new Registry(graph)) - { - registry.ScanAssemblies() - .IncludeAssemblyContainingType<IGateway>() - .IncludeTheCallingAssembly(); - } - AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>(); Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); @@ -70,23 +60,16 @@ [Test] public void Combination2() { - PluginGraph graph = new PluginGraph(); + StructureMapConfiguration.ScanAssemblies() + .IncludeTheCallingAssembly() + .IncludeAssemblyContainingType<IGateway>(); + PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - using (Registry registry = new Registry(graph)) - { - registry.ScanAssemblies() - .IncludeTheCallingAssembly() - .IncludeAssemblyContainingType<IGateway>(); - - } - AssemblyGraph assembly = AssemblyGraph.ContainingType<IGateway>(); Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); assembly = new AssemblyGraph(Assembly.GetExecutingAssembly()); Assert.IsTrue(graph.Assemblies.Contains(assembly.AssemblyName)); } - } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -3,6 +3,7 @@ using NUnit.Framework; using StructureMap.Attributes; using StructureMap.Configuration; +using StructureMap.Configuration.DSL; using StructureMap.Configuration.Tokens; using StructureMap.Graph; using StructureMap.Testing.Configuration.Tokens; @@ -22,7 +23,7 @@ XmlDocument document = new XmlDocument(); document.LoadXml("<StructureMap/>"); - _builder = new DiagnosticGraphBuilder(); + _builder = new DiagnosticGraphBuilder(new Registry[0]); _report = _builder.Report; } Modified: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -2,6 +2,7 @@ using NUnit.Framework; using StructureMap.Attributes; using StructureMap.Configuration; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Interceptors; @@ -19,7 +20,7 @@ builderMock.ExpectAndReturn("Build", chain, theScope); NormalGraphBuilder graphBuilder = - new NormalGraphBuilder((IInterceptorChainBuilder) builderMock.MockInstance); + new NormalGraphBuilder((IInterceptorChainBuilder) builderMock.MockInstance, new Registry[0]); TypePath typePath = new TypePath(GetType()); @@ -36,7 +37,7 @@ [Test] public void AddProfile() { - NormalGraphBuilder graphBuilder = new NormalGraphBuilder(); + NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]); string profileName = "blue"; graphBuilder.AddProfile(profileName); @@ -49,7 +50,7 @@ [Test] public void AddDefaultForAProfile() { - NormalGraphBuilder graphBuilder = new NormalGraphBuilder(); + NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]); string profileName = "blue"; string theTypeName = "the name of the type"; string theKey = "Key1"; @@ -67,7 +68,7 @@ [Test] public void AddMachineWithExistingProfile() { - NormalGraphBuilder graphBuilder = new NormalGraphBuilder(); + NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]); string theMachineName = "some machine"; string theProfileName = "some profile"; graphBuilder.AddProfile(theProfileName); @@ -85,7 +86,7 @@ )] public void AddMachineWithProfileThatDoesNotExist() { - NormalGraphBuilder graphBuilder = new NormalGraphBuilder(); + NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]); string theMachineName = "some machine"; string theProfileName = "some profile"; @@ -95,7 +96,7 @@ [Test] public void AddMachineWithoutProfile() { - NormalGraphBuilder graphBuilder = new NormalGraphBuilder(); + NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]); string theMachineName = "some machine"; graphBuilder.AddMachine(theMachineName, string.Empty); @@ -109,7 +110,7 @@ [Test] public void AddAnOverrideToMachine() { - NormalGraphBuilder graphBuilder = new NormalGraphBuilder(); + NormalGraphBuilder graphBuilder = new NormalGraphBuilder(new Registry[0]); string theMachineName = "some machine"; graphBuilder.AddMachine(theMachineName, string.Empty); Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2007-03-26 14:31:28 UTC (rev 30) +++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -5,6 +5,7 @@ using Rhino.Mocks; using StructureMap.Attributes; using StructureMap.Configuration; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; @@ -42,7 +43,7 @@ [Test] public void NormalGraphBuilderHandlesTheInferredPlugin() { - NormalGraphBuilder builder = new NormalGraphBuilder(); + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); TypePath pluginTypePath = new TypePath(typeof(IGateway)); builder.AddPluginFamily(pluginTypePath, "", new string[0], InstanceScope.PerRequest); @@ -61,7 +62,7 @@ [Test] public void CanBuildTheInstance() { - NormalGraphBuilder builder = new NormalGraphBuilder(); + NormalGraphBuilder builder = new NormalGraphBuilder(new Registry[0]); TypePath pluginTypePath = new TypePath(typeof(IGateway)); builder.AddPluginFamily(pluginTypePath, _memento.InstanceKey, new string[0], InstanceScope.PerRequest); Added: trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs (rev 0) +++ trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs 2007-03-27 11:18:48 UTC (rev 31) @@ -0,0 +1,78 @@ +using StructureMap.Configuration.DSL; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Widget5 +{ + public class RedGreenRegistry : Registry + { + protected override void configure() + { + AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Red").WithName("Red"); + AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Green").WithName("Green"); + } + + + public override bool Equals(object obj) + { + if (this == obj) return true; + RedGreenRegistry redGreenRegistry = obj as RedGreenRegistry; + if (redGreenRegistry == null) return false; + return true; + } + + public override int GetHashCode() + { + return 0; + } + } + + public class YellowBlueRegistry : Registry + { + protected override void configure() + { + AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Yellow").WithName("Yellow"); + AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Blue").WithName("Blue"); + } + + + public override bool Equals(object obj) + { + if (this == obj) return true; + YellowBlueRegistry yellowBlueRegistry = obj as YellowBlueRegistry; + if (yellowBlueRegistry == null) return false; + return true; + } + + public override int GetHashCode() + { + return 0; + } + } + + public class BrownBlackRegistry : Registry + { + protected override void configure() + { + AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Brown").WithName("Brown"); + AddInstanceOf<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Black").WithName("Black"); + } + + + public override bool Equals(object obj) + { + if (this == obj) return true; + BrownBlackRegistry brownBlackRegistry = obj as BrownBlackRegistry; + if (brownBlackRegistry == null) return false; + return true; + } + + public override int GetHashCode() + { + return 0; + } + } + + public abstract class PurpleRegistry : Registry + { + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2007-03-29 18:31:03
|
Revision: 33 http://structuremap.svn.sourceforge.net/structuremap/?rev=33&view=rev Author: jeremydmiller Date: 2007-03-29 11:31:00 -0700 (Thu, 29 Mar 2007) Log Message: ----------- adding diagnostics to StructureMapConfiguration Modified Paths: -------------- trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs Added Paths: ----------- trunk/Source/StructureMap/Verification/IStartUp.cs trunk/Source/StructureMap/Verification/StartUp.cs Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2007-03-29 15:58:10 UTC (rev 32) +++ trunk/Source/StructureMap/StructureMap.csproj 2007-03-29 18:31:00 UTC (rev 33) @@ -556,9 +556,11 @@ <Compile Include="StubbedInstanceFactory.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Verification\IStartUp.cs" /> <Compile Include="Verification\PluginGraphConsoleWriter.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Verification\StartUp.cs" /> <Compile Include="XmlMapping\ConfigEditor.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-29 15:58:10 UTC (rev 32) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-29 18:31:00 UTC (rev 33) @@ -5,6 +5,7 @@ using StructureMap.Configuration; using StructureMap.Configuration.DSL; using StructureMap.Graph; +using StructureMap.Verification; namespace StructureMap { @@ -14,6 +15,7 @@ private static ConfigurationParserCollection _collection = new ConfigurationParserCollection(); private static Registry _registry = new Registry(); private static List<Registry> _registries = new List<Registry>(); + private static StartUp _startUp; static StructureMapConfiguration() { @@ -51,10 +53,16 @@ _registry = new Registry(); _registries = new List<Registry>(); _registries.Add(_registry); + _startUp = null; } public static PluginGraph GetPluginGraph() { + if (_startUp != null) + { + _startUp.RunDiagnostics(); + } + PluginGraphBuilder builder = createBuilder(); return builder.Build(); } @@ -65,10 +73,10 @@ return new PluginGraphBuilder(parsers, _registries.ToArray()); } - public static PluginGraph GetDiagnosticPluginGraph() + public static PluginGraphReport GetDiagnosticReport() { PluginGraphBuilder builder = createBuilder(); - return builder.BuildDiagnosticPluginGraph(); + return builder.Report; } public static void IncludeConfigurationFromFile(string filename) @@ -146,5 +154,15 @@ { _registries.Add(registry); } + + public static IStartUp OnStartUp() + { + if (_startUp == null) + { + _startUp = new StartUp(); + } + + return _startUp; + } } } \ No newline at end of file Added: trunk/Source/StructureMap/Verification/IStartUp.cs =================================================================== --- trunk/Source/StructureMap/Verification/IStartUp.cs (rev 0) +++ trunk/Source/StructureMap/Verification/IStartUp.cs 2007-03-29 18:31:00 UTC (rev 33) @@ -0,0 +1,9 @@ +namespace StructureMap.Verification +{ + public interface IStartUp + { + IStartUp WriteProblemsTo(string fileName); + IStartUp FailOnException(); + IStartUp WriteAllTo(string fileName); + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Verification/StartUp.cs =================================================================== --- trunk/Source/StructureMap/Verification/StartUp.cs (rev 0) +++ trunk/Source/StructureMap/Verification/StartUp.cs 2007-03-29 18:31:00 UTC (rev 33) @@ -0,0 +1,85 @@ +using System; +using System.IO; +using StructureMap.Configuration; + +namespace StructureMap.Verification +{ + public class StartUp : IStartUp + { + private string _problemFile = "StructureMap.error"; + private bool _fail = false; + private string _allFile; + + public IStartUp WriteProblemsTo(string fileName) + { + _problemFile = fileName; + return this; + } + + public IStartUp FailOnException() + { + _fail = true; + return this; + } + + public IStartUp WriteAllTo(string fileName) + { + _allFile = fileName; + return this; + } + + public void RunDiagnostics() + { + PluginGraphReport report = StructureMapConfiguration.GetDiagnosticReport(); + + writeProblems(report); + + writeAll(report); + + fail(report); + } + + private void fail(PluginGraphReport report) + { + if (_fail) + { + ProblemFinder finder = new ProblemFinder(report); + Problem[] problems = finder.GetProblems(); + + if (problems.Length > 0) + { + throw new ApplicationException( + "StructureMap detected configuration or environmental problems. Check the StructureMap error file"); + } + } + } + + private void writeAll(PluginGraphReport report) + { + if (!string.IsNullOrEmpty(_allFile)) + { + PluginGraphConsoleWriter consoleWriter = new PluginGraphConsoleWriter(report); + consoleWriter.WriteAll = true; + consoleWriter.WriteProblems = true; + + using (TextWriter writer = new StreamWriter(_allFile)) + { + consoleWriter.Write(writer); + } + } + } + + private void writeProblems(PluginGraphReport report) + { + using (TextWriter writer = new StreamWriter(_problemFile)) + { + PluginGraphConsoleWriter consoleWriter = new PluginGraphConsoleWriter(report); + consoleWriter.IncludeAllInstances = false; + consoleWriter.IncludePlugins = false; + consoleWriter.IncludeSource = false; + consoleWriter.WriteProblems = true; + consoleWriter.Write(writer); + } + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2007-03-29 15:58:10 UTC (rev 32) +++ trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2007-03-29 18:31:00 UTC (rev 33) @@ -1,4 +1,7 @@ +using System; +using System.IO; using NUnit.Framework; +using StructureMap.Configuration; using StructureMap.Graph; namespace StructureMap.Testing @@ -20,10 +23,67 @@ } [Test] - public void BuildDiagnosticPluginGraph() + public void BuildReport() { - PluginGraph graph = StructureMapConfiguration.GetDiagnosticPluginGraph(); - Assert.IsNotNull(graph); + PluginGraphReport report = StructureMapConfiguration.GetDiagnosticReport(); + Assert.IsNotNull(report); } + + [Test, ExpectedException(typeof(ApplicationException), "StructureMap detected configuration or environmental problems. Check the StructureMap error file")] + public void OnStartUpFail() + { + StructureMapConfiguration.OnStartUp().FailOnException(); + StructureMapConfiguration.AddInstanceOf<ISomething>().UsingConcreteType<Something>(); + + StructureMapConfiguration.GetPluginGraph(); + } + + [Test] + public void WriteAllFile() + { + string filePath = "all.txt"; + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + StructureMapConfiguration.OnStartUp().WriteAllTo(filePath); + StructureMapConfiguration.AddInstanceOf<ISomething>().UsingConcreteType<Something>(); + + StructureMapConfiguration.GetPluginGraph(); + + Assert.IsTrue(File.Exists(filePath)); + } + + + [Test] + public void WriteProblems() + { + string filePath = "problems.txt"; + if (File.Exists(filePath)) + { + File.Delete(filePath); + } + + StructureMapConfiguration.OnStartUp().WriteProblemsTo(filePath); + StructureMapConfiguration.AddInstanceOf<ISomething>().UsingConcreteType<Something>(); + + StructureMapConfiguration.GetPluginGraph(); + + Assert.IsTrue(File.Exists(filePath)); + } } + + public interface ISomething + { + + } + + public class Something : ISomething + { + public Something() + { + throw new ApplicationException("You can't make me!"); + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2007-03-29 15:58:27
|
Revision: 32 http://structuremap.svn.sourceforge.net/structuremap/?rev=32&view=rev Author: jeremydmiller Date: 2007-03-29 08:58:10 -0700 (Thu, 29 Mar 2007) Log Message: ----------- making diagnostics work with generic types Modified Paths: -------------- trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs trunk/Source/StructureMap/Configuration/GraphObject.cs trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs trunk/Source/StructureMap/Configuration/PluginGraphReport.cs trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs trunk/Source/StructureMap/Configuration/Tokens/InstanceToken.cs trunk/Source/StructureMap/Graph/AssemblyGraph.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/Graph/TypePath.cs trunk/Source/StructureMap/IInstanceCreator.cs trunk/Source/StructureMap/IInstanceManager.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs trunk/Source/StructureMap/MemoryInstanceMemento.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserCollectionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.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/LiteralExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/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/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/StructureMapConfigCreator.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/Source/StructureMap.Testing/TestData/DataMother.cs trunk/Source/StructureMap.Testing/TestData/GenericsTesting.xml trunk/Source/StructureMap.Testing.GenericWidgets/Widgets.cs trunk/Source/StructureMap.Testing.Widget5/StructureMap.Testing.Widget5.csproj trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs Modified: trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -42,5 +42,6 @@ "A fatal error in configuration is preventing StructureMap from functioning correctly"; public const string MISSING_TEMPLATE_VALUE = "A required value for a Templated InstanceMemento is missing"; + public const string UNKNOWN_PLUGIN_PROBLEM = "Exception occured while attaching a Plugin to a PluginFamily"; } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -218,7 +218,5 @@ ProfileAndMachineParser parser = new ProfileAndMachineParser(builder, _structureMapNode, _mementoCreator); parser.Parse(); } - - } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -74,4 +74,4 @@ _fetchers.Add(fetcher); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -21,7 +21,8 @@ _propertyName = propertyName; } - public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName, Type childType) + public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName, + Type childType) : this(instance, memento, propertyName) { _childType = childType; Modified: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -59,7 +59,7 @@ public CreatePluginFamilyExpression TheDefaultIsConcreteType<T>() { - ExpressionValidator.ValidatePluggabilityOf(typeof(T)).IntoPluginType(_pluginType); + ExpressionValidator.ValidatePluggabilityOf(typeof (T)).IntoPluginType(_pluginType); _alterations.Add(delegate(PluginFamily family) { Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -42,8 +42,8 @@ } else { - throw new StructureMapException(304, TypePath.GetAssemblyQualifiedName(_pluginType)); - } + throw new StructureMapException(304, TypePath.GetAssemblyQualifiedName(_pluginType)); + } } public ProfileExpression Use(IMementoBuilder mementoBuilder) @@ -52,7 +52,5 @@ return _parent; } - - } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -53,8 +53,6 @@ } - - public PropertyExpression WithProperty(string propertyName) { return new PropertyExpression(this, _memento, propertyName); @@ -118,7 +116,7 @@ public InstanceExpression UsingConcreteType<T>() { - _parent._pluggedType = typeof(T); + _parent._pluggedType = typeof (T); return _parent; } @@ -127,7 +125,6 @@ _parent._memento.ConcreteKey = concreteKey; return _parent; } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -23,7 +23,7 @@ validate(); PluginFamily family = graph.LocateOrCreateFamilyForType((Type) _pluginType); configureMemento(family); - + if (!string.IsNullOrEmpty(_instanceKey)) { memento.InstanceKey = _instanceKey; Modified: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using StructureMap.Graph; @@ -31,7 +30,7 @@ public InstanceDefaultExpression For<T>() { - InstanceDefaultExpression defaultExpression = new InstanceDefaultExpression(typeof(T), this); + InstanceDefaultExpression defaultExpression = new InstanceDefaultExpression(typeof (T), this); _defaults.Add(defaultExpression); return defaultExpression; Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -113,7 +113,7 @@ public static bool IsPublicRegistry(Type type) { - if (!typeof(Registry).IsAssignableFrom(type)) + if (!typeof (Registry).IsAssignableFrom(type)) { return false; } Modified: trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -19,7 +19,7 @@ { _innerBuilder = new NormalGraphBuilder(registries); _systemReport = new PluginGraphReport(); - _report = _innerBuilder.PluginGraph.Report; + _report = new PluginGraphReport(); } public PluginGraph PluginGraph @@ -168,6 +168,11 @@ pluginToken.LogProblem(problem); } } + catch (Exception ex) + { + Problem problem = new Problem(ConfigurationConstants.UNKNOWN_PLUGIN_PROBLEM, ex); + pluginToken.LogProblem(problem); + } return returnValue; } Modified: trunk/Source/StructureMap/Configuration/GraphObject.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphObject.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/GraphObject.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,12 +1,13 @@ using System; using System.Collections; +using System.Collections.Generic; namespace StructureMap.Configuration { [Serializable] public abstract class GraphObject : IComparable { - private ArrayList _problems = new ArrayList(); + private List<Problem> _problems = new List<Problem>(); private Guid _id = Guid.NewGuid(); public GraphObject() @@ -21,8 +22,8 @@ public Problem[] Problems { - get { return (Problem[]) _problems.ToArray(typeof (Problem)); } - set { _problems = new ArrayList(value); } + get { return _problems.ToArray(); } + set { _problems = new List<Problem>(value); } } public void LogProblem(Problem problem) Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -25,7 +25,7 @@ public NormalGraphBuilder(IInterceptorChainBuilder builder, Registry[] registries) { _builder = builder; - + _pluginGraph = new PluginGraph(); foreach (Registry registry in registries) { @@ -154,6 +154,13 @@ public Plugin AddPlugin(TypePath pluginTypePath, TypePath pluginPath, string concreteKey) { PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath]; + if (family == null) + { + string message = + string.Format("Could not find a PluginFamily for {0}", pluginTypePath.AssemblyQualifiedName); + throw new ApplicationException(message); + } + Plugin plugin = new Plugin(pluginPath, concreteKey); plugin.DefinitionSource = DefinitionSource.Explicit; family.Plugins.Add(plugin); Modified: trunk/Source/StructureMap/Configuration/PluginGraphReport.cs =================================================================== --- trunk/Source/StructureMap/Configuration/PluginGraphReport.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/PluginGraphReport.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -18,6 +18,33 @@ { } + public PluginGraphReport(PluginGraph pluginGraph) + { + ReadFromPluginGraph(pluginGraph); + } + + public void ReadFromPluginGraph(PluginGraph pluginGraph) + { + ImportImplicitChildren(pluginGraph); + AnalyzeInstances(pluginGraph); + + Profile defaultProfile = pluginGraph.DefaultManager.CalculateDefaults(); + + InstanceManager manager = new InstanceManager(); + try + { + manager = new InstanceManager(pluginGraph); + } + catch (Exception ex) + { + Problem problem = new Problem(ConfigurationConstants.FATAL_ERROR, ex); + LogProblem(problem); + } + + IInstanceValidator validator = new InstanceValidator(pluginGraph, defaultProfile, manager); + ValidateInstances(validator); + } + public override GraphObject[] Children { get @@ -62,6 +89,8 @@ FamilyToken[] returnValue = new FamilyToken[_families.Count]; _families.Values.CopyTo(returnValue, 0); + + return returnValue; } } @@ -90,6 +119,11 @@ return null; } + public bool HasFamily(Type pluginType) + { + return _families.ContainsKey(new TypePath(pluginType)); + } + public FamilyToken FindFamily(Type pluginType) { TypePath path = new TypePath(pluginType); Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,4 +1,3 @@ -using System; using System.Xml; using StructureMap.Graph; using StructureMap.Graph.Configuration; @@ -62,12 +61,12 @@ private void processOverrideElement(WriteOverride function, XmlElement overrideElement, string profileName) { string fullName = overrideElement.GetAttribute(XmlConstants.TYPE_ATTRIBUTE); - + XmlElement instanceElement = (XmlElement) overrideElement.SelectSingleNode(XmlConstants.INSTANCE_NODE); if (instanceElement == null) { string defaultKey = overrideElement.GetAttribute(XmlConstants.DEFAULT_KEY_ATTRIBUTE); - function(fullName, defaultKey); + function(fullName, defaultKey); } else { @@ -75,7 +74,8 @@ } } - private void createOverrideInstance(string fullName, XmlElement instanceElement, WriteOverride function, string profileName) + private void createOverrideInstance(string fullName, XmlElement instanceElement, WriteOverride function, + string profileName) { string key = Profile.InstanceKeyForProfile(profileName); InstanceMemento memento = _creator.CreateMemento(instanceElement); @@ -91,6 +91,5 @@ { return _structureMapNode.SelectNodes(nodeName); } - } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using StructureMap.Attributes; using StructureMap.Graph; @@ -31,7 +32,7 @@ private DefinitionSource _definitionSource = DefinitionSource.Explicit; private string _defaultKey; - private Hashtable _plugins = new Hashtable(); + private Dictionary<string, PluginToken> _plugins = new Dictionary<string, PluginToken>(); private InstanceToken _sourceInstance; private ArrayList _interceptors = new ArrayList(); private Hashtable _instances = new Hashtable(); @@ -142,7 +143,12 @@ public PluginToken FindPlugin(string concreteKey) { - return (PluginToken) _plugins[concreteKey]; + if (_plugins.ContainsKey(concreteKey)) + { + return _plugins[concreteKey]; + } + + return null; } public TemplateToken[] Templates @@ -180,6 +186,14 @@ public void AddInstance(InstanceToken instance) { + if (_instances.ContainsKey(instance.InstanceKey)) + { + string message = + string.Format("Duplicate Instance '{0}' of PluginFamily '{1}'", instance.InstanceKey, + _typePath.AssemblyQualifiedName); + throw new ApplicationException(message); + } + _instances.Add(instance.InstanceKey, instance); } Modified: trunk/Source/StructureMap/Configuration/Tokens/InstanceToken.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Tokens/InstanceToken.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Configuration/Tokens/InstanceToken.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -146,6 +146,11 @@ return; } + if (_pluginTypePath.FindType().IsGenericType) + { + return; + } + object target = validator.CreateObject(_pluginTypePath.FindType(), _memento); validateInstance(target); } Modified: trunk/Source/StructureMap/Graph/AssemblyGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -184,10 +184,9 @@ { if (Registry.IsPublicRegistry(type)) { - Registry registry = (Registry)Activator.CreateInstance(type); + Registry registry = (Registry) Activator.CreateInstance(type); returnValue.Add(registry); } - } return returnValue; Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -19,8 +19,8 @@ private bool _sealed = false; private PluginFamilyCollection _pluginFamilies; private InstanceDefaultManager _defaultManager = new InstanceDefaultManager(); - private PluginGraphReport _report = new PluginGraphReport(); + /// <summary> /// Default constructor /// </summary> @@ -28,8 +28,6 @@ { _assemblies = new AssemblyGraphCollection(this); _pluginFamilies = new PluginFamilyCollection(this); - - _report.DefaultManager = _defaultManager; } @@ -152,12 +150,6 @@ return pluginGraph; } - public PluginGraphReport Report - { - get { return _report; } - set { _report = value; } - } - public TypePath LocateOrCreateFamilyForType(string fullName) { Type pluginType = findTypeByFullName(fullName); Modified: trunk/Source/StructureMap/Graph/TypePath.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypePath.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Graph/TypePath.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -13,7 +13,7 @@ { public static string GetTypeIdentifier(Type type) { - return type.AssemblyQualifiedName; + return new TypePath(type).AssemblyQualifiedName; } public static TypePath TypePathForFullName(string fullname) Modified: trunk/Source/StructureMap/IInstanceCreator.cs =================================================================== --- trunk/Source/StructureMap/IInstanceCreator.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/IInstanceCreator.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -4,4 +4,4 @@ { object BuildInstance(InstanceMemento memento); } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/IInstanceManager.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -12,9 +12,6 @@ IList<T> GetAllInstances<T>(); void SetDefaultsToProfile(string profile); - InstanceDefaultManager DefaultManager - { - get; - } + InstanceDefaultManager DefaultManager { get; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/InstanceManager.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -469,7 +469,7 @@ public void Inject<T>(T instance) { - InjectStub(typeof(T), instance); + InjectStub(typeof (T), instance); } #endregion Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/InstanceMemento.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -31,7 +31,7 @@ _concreteKey = innerConcreteKey; if (string.IsNullOrEmpty(_concreteKey)) { - Plugin plugin = this.CreateInferredPlugin(); + Plugin plugin = CreateInferredPlugin(); if (plugin != null) { _concreteKey = plugin.ConcreteKey; @@ -62,10 +62,7 @@ return _instanceKey; } } - set - { - _instanceKey = value; - } + set { _instanceKey = value; } } protected abstract string innerInstanceKey { get; } Modified: trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -12,7 +12,6 @@ public HttpContextItemInterceptor() : base() { - } private string getKey(string instanceKey) Modified: trunk/Source/StructureMap/MemoryInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/MemoryInstanceMemento.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/MemoryInstanceMemento.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,7 +1,5 @@ -using System; using System.Collections; using System.Collections.Specialized; -using StructureMap.Graph; namespace StructureMap { @@ -116,7 +114,7 @@ public void ReferenceChild(string name, string instanceKey) { - InstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey); + InstanceMemento child = CreateReferencedInstanceMemento(instanceKey); AddChild(name, child); } Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/ObjectFactory.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -90,7 +90,6 @@ } - /// <summary> /// Restores all default instance settings according to the StructureMap.config files /// </summary> Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -133,8 +133,6 @@ { parser.ParseProfilesAndMachines(graphBuilder); } - - } private void readFamilies(IGraphBuilder graphBuilder) Modified: trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -12,7 +12,7 @@ [SetUp] public void SetUp() { - StructureMapConfiguration.ResetAll(); + StructureMapConfiguration.ResetAll(); DataMother.WriteDocument("Config1.xml"); DataMother.WriteDocument("Config2.xml"); } @@ -20,11 +20,11 @@ [TearDown] public void TearDown() { - StructureMapConfiguration.ResetAll(); + StructureMapConfiguration.ResetAll(); ObjectFactory.Reset(); } - + public void assertTheDefault(string color) { ColorWidget widget = (ColorWidget) ObjectFactory.GetInstance<IWidget>(); @@ -64,7 +64,7 @@ XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); - + StructureMapConfiguration.UseDefaultStructureMapConfigFile = true; StructureMapConfiguration.IncludeConfigurationFromNode(doc.DocumentElement); ObjectFactory.Reset(); @@ -73,4 +73,4 @@ Assert.IsNotNull(service); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserCollectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserCollectionTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserCollectionTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -22,7 +22,8 @@ { Array.Sort(expected); ConfigurationParser[] parsers = _collection.GetParsers(); - Converter<ConfigurationParser, string> converter = delegate(ConfigurationParser parser) { return parser.Id; }; + Converter<ConfigurationParser, string> converter = + delegate(ConfigurationParser parser) { return parser.Id; }; string[] actuals = Array.ConvertAll<ConfigurationParser, string>(parsers, converter); Array.Sort(actuals); @@ -47,7 +48,10 @@ assertParserIdList("Generics"); } - [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 100\nExpected file \"StructureMap.config\" cannot be opened at DoesNotExist.xml")] + [Test, + ExpectedException(typeof (StructureMapException), + "StructureMap Exception Code: 100\nExpected file \"StructureMap.config\" cannot be opened at DoesNotExist.xml" + )] public void FileDoesNotExist() { _collection.UseDefaultFile = false; @@ -105,4 +109,4 @@ assertParserIdList("Somewhere"); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -4,7 +4,6 @@ using StructureMap.Configuration; using StructureMap.Configuration.DSL; using StructureMap.Graph; -using StructureMap.Source; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; @@ -105,7 +104,7 @@ { string[] names = _defaults.GetMachineNames(); Array.Sort(names); - Assert.AreEqual(new string[] {"GREEN-BOX", "SERVER" }, names); + Assert.AreEqual(new string[] {"GREEN-BOX", "SERVER"}, names); } [Test] Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -38,8 +38,6 @@ .WithProperty("Color").EqualToAppSetting("Color"); - - registry.AddInstanceOf<IWidget>().UsingConcreteType<AWidget>(); manager = registry.BuildInstanceManager(); @@ -47,7 +45,7 @@ [Test] public void UseAPreBuiltObjectForAnInstanceAsAPrototype() - { + { Registry registry = new Registry(); // Build an instance for IWidget, then setup StructureMap to return cloned instances of the // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy" @@ -59,7 +57,7 @@ CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); CloneableWidget widget3 = (CloneableWidget) manager.CreateInstance<IWidget>("Jeremy"); - + Assert.AreEqual("Jeremy", widget1.Name); Assert.AreEqual("Jeremy", widget2.Name); Assert.AreEqual("Jeremy", widget3.Name); @@ -80,9 +78,9 @@ manager = registry.BuildInstanceManager(); - CloneableWidget widget1 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia"); - CloneableWidget widget2 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia"); - CloneableWidget widget3 = (CloneableWidget)manager.CreateInstance<IWidget>("Julia"); + CloneableWidget widget1 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); + CloneableWidget widget2 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); + CloneableWidget widget3 = (CloneableWidget) manager.CreateInstance<IWidget>("Julia"); Assert.AreSame(julia, widget1); Assert.AreSame(julia, widget2); @@ -99,17 +97,17 @@ string instanceKey = "OrangeWidgetRule"; registry.AddInstanceOf<Rule>().UsingConcreteType<WidgetRule>().WithName(instanceKey) .Child<IWidget>().Is( - Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>() - .WithProperty("Color").EqualTo("Orange") - .WithName("Orange") - ); + Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>() + .WithProperty("Color").EqualTo("Orange") + .WithName("Orange") + ); IInstanceManager mgr = registry.BuildInstanceManager(); ColorWidget orange = (ColorWidget) mgr.CreateInstance<IWidget>("Orange"); Assert.IsNotNull(orange); - WidgetRule rule = (WidgetRule)mgr.CreateInstance<Rule>(instanceKey); + WidgetRule rule = (WidgetRule) mgr.CreateInstance<Rule>(instanceKey); ColorWidget widget = (ColorWidget) rule.Widget; Assert.AreEqual("Orange", widget.Color); } @@ -126,8 +124,8 @@ manager = registry.BuildInstanceManager(); - WidgetRule rule = (WidgetRule)manager.CreateInstance<Rule>("AWidgetRule"); - Assert.IsInstanceOfType(typeof(AWidget), rule.Widget); + WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("AWidgetRule"); + Assert.IsInstanceOfType(typeof (AWidget), rule.Widget); } [Test] @@ -181,7 +179,6 @@ //registry.ScanAssemblies().IncludeAssemblyContainingType<IWidget>(); - registry.AddInstanceOf<Rule>().UsingConcreteType<ARule>().WithName("Alias"); // Add an instance by specifying the ConcreteKey @@ -196,7 +193,7 @@ manager = registry.BuildInstanceManager(); - Assert.IsInstanceOfType(typeof(ARule), manager.CreateInstance<Rule>("Alias")); + Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>("Alias")); WidgetRule rule = (WidgetRule) manager.CreateInstance<Rule>("RuleThatUsesMyInstance"); ColorWidget widget = (ColorWidget) rule.Widget; @@ -271,6 +268,5 @@ public class ARule : Rule { - } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -12,36 +12,48 @@ { } - [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 303\nType System.String,mscorlib is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing")] + [Test, + ExpectedException(typeof (StructureMapException), + "StructureMap Exception Code: 303\nType System.String,mscorlib is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing" + )] public void CantCastTheRequestedConcreteType() { - InstanceExpression instance = new InstanceExpression(typeof(IStrategy)); + InstanceExpression instance = new InstanceExpression(typeof (IStrategy)); MemoryInstanceMemento memento = new MemoryInstanceMemento(); - ChildInstanceExpression expression = new ChildInstanceExpression(instance, memento, "a property", typeof(IType)); + ChildInstanceExpression expression = + new ChildInstanceExpression(instance, memento, "a property", typeof (IType)); expression.IsConcreteType<string>(); } - [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 303\nType StructureMap.Testing.Configuration.DSL.AbstractType,StructureMap.Testing is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing")] + [Test, + ExpectedException(typeof (StructureMapException), + "StructureMap Exception Code: 303\nType StructureMap.Testing.Configuration.DSL.AbstractType,StructureMap.Testing is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing" + )] public void CantCastTheRequestedConcreteType2() { - InstanceExpression instance = new InstanceExpression(typeof(IStrategy)); + InstanceExpression instance = new InstanceExpression(typeof (IStrategy)); MemoryInstanceMemento memento = new MemoryInstanceMemento(); - ChildInstanceExpression expression = new ChildInstanceExpression(instance, memento, "a property", typeof(IType)); + ChildInstanceExpression expression = + new ChildInstanceExpression(instance, memento, "a property", typeof (IType)); expression.IsConcreteType<AbstractType>(); } - [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 303\nType StructureMap.Testing.Configuration.DSL.AbstractType,StructureMap.Testing is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing")] + [Test, + ExpectedException(typeof (StructureMapException), + "StructureMap Exception Code: 303\nType StructureMap.Testing.Configuration.DSL.AbstractType,StructureMap.Testing is either abstract or cannot be plugged into Type StructureMap.Testing.Configuration.DSL.IType,StructureMap.Testing" + )] public void CantCastTheRequestedPluggedType3() { - InstanceExpression instance = new InstanceExpression(typeof(IStrategy)); + InstanceExpression instance = new InstanceExpression(typeof (IStrategy)); MemoryInstanceMemento memento = new MemoryInstanceMemento(); - ChildInstanceExpression expression = new ChildInstanceExpression(instance, memento, "a property", typeof(IType)); + ChildInstanceExpression expression = + new ChildInstanceExpression(instance, memento, "a property", typeof (IType)); InstanceExpression child = Registry.Instance<IType>().UsingConcreteType<AbstractType>(); - + expression.Is(child); } } @@ -56,6 +68,5 @@ public class ConcreteType : AbstractType { - } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -14,10 +14,9 @@ [SetUp] public void SetUp() { - } - [Test, ExpectedException(typeof(StructureMapException))] + [Test, ExpectedException(typeof (StructureMapException))] public void TheConceteTypeDoesNotCase() { Registry registry = new Registry(); @@ -34,7 +33,7 @@ IInstanceManager manager = registry.BuildInstanceManager(); - Assert.IsInstanceOfType(typeof(ARule), manager.CreateInstance<Rule>()); + Assert.IsInstanceOfType(typeof (ARule), manager.CreateInstance<Rule>()); } [Test] @@ -61,9 +60,9 @@ Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway)manager.CreateInstance(typeof(IGateway)); + IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); - Assert.IsInstanceOfType(typeof(DefaultGateway), gateway); + Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); } [Test] @@ -79,9 +78,9 @@ Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway)manager.CreateInstance(typeof(IGateway)); + IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); - Assert.IsInstanceOfType(typeof(StubbedGateway), gateway); + Assert.IsInstanceOfType(typeof (StubbedGateway), gateway); } [Test] @@ -110,7 +109,7 @@ Assert.IsNotNull(expression); } - PluginFamily family = pluginGraph.PluginFamilies[typeof(IGateway)]; + PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)]; Assert.AreEqual(0, family.InterceptionChain.Count); } @@ -120,12 +119,13 @@ PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { - CreatePluginFamilyExpression expression = registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal); + CreatePluginFamilyExpression expression = + registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal); Assert.IsNotNull(expression); } - PluginFamily family = pluginGraph.PluginFamilies[typeof(IGateway)]; - Assert.IsTrue(family.InterceptionChain.Contains(typeof(ThreadLocalStorageInterceptor))); + PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)]; + Assert.IsTrue(family.InterceptionChain.Contains(typeof (ThreadLocalStorageInterceptor))); } [Test] @@ -134,13 +134,13 @@ PluginGraph pluginGraph = new PluginGraph(); using (Registry registry = new Registry(pluginGraph)) { - CreatePluginFamilyExpression expression = + CreatePluginFamilyExpression expression = registry.BuildInstancesOf<IGateway>().AsSingletons(); Assert.IsNotNull(expression); } PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)]; - Assert.IsTrue(family.InterceptionChain.Contains(typeof(SingletonInterceptor))); + Assert.IsTrue(family.InterceptionChain.Contains(typeof (SingletonInterceptor))); } [Test] @@ -155,10 +155,9 @@ Assert.IsTrue(pluginGraph.PluginFamilies.Contains<IGateway>()); InstanceManager manager = new InstanceManager(pluginGraph); - IGateway gateway = (IGateway)manager.CreateInstance(typeof(IGateway)); + IGateway gateway = (IGateway) manager.CreateInstance(typeof (IGateway)); - Assert.IsInstanceOfType(typeof(FakeGateway), gateway); + Assert.IsInstanceOfType(typeof (FakeGateway), gateway); } - } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,8 +1,5 @@ using NUnit.Framework; -using StructureMap.Configuration.DSL; using StructureMap.Graph; -using StructureMap.Testing.GenericWidgets; -using StructureMap.Testing.Widget; namespace StructureMap.Testing.Configuration.DSL { @@ -36,7 +33,6 @@ [Test] public void CreateProfile() { - } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,5 +1,4 @@ using NUnit.Framework; -using Rhino.Mocks; using StructureMap.Configuration.DSL; using StructureMap.Testing.Widget; @@ -36,7 +35,7 @@ .WithProperty("count").EqualTo(4) .WithProperty("average").EqualTo(.333) .Child<Rule>().Is( - ruleExpression + ruleExpression ) ); @@ -70,7 +69,7 @@ { Registry registry = new Registry(); registry.BuildInstancesOf<IWidget>().TheDefaultIs( - Registry.Object(new ColorWidget("yellow")) + Registry.Object(new ColorWidget("yellow")) ); registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); @@ -109,7 +108,6 @@ } - [Test] public void DeepInstance5() { @@ -136,7 +134,6 @@ assertThingMatches(registry); } - } public class Thing @@ -177,4 +174,4 @@ return result; } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -13,19 +13,22 @@ { } - [Test, ExpectedException(typeof(StructureMapException), "StructureMap Exception Code: 301\nNo concrete type or concrete key is specified for instance TheInstanceKey for PluginType StructureMap.Testing.Widget.IWidget,StructureMap.Testing.Widget")] + [Test, + ExpectedException(typeof (StructureMapException), + "StructureMap Exception Code: 301\nNo concrete type or concrete key is specified for instance TheInstanceKey for PluginType StructureMap.Testing.Widget.IWidget,StructureMap.Testing.Widget" + )] public void BlowUpIfNoConcreteKeyOrTypeDefinied() { - InstanceExpression expression = new InstanceExpression(typeof(IWidget)); + InstanceExpression expression = new InstanceExpression(typeof (IWidget)); expression.InstanceKey = "TheInstanceKey"; PluginGraph pluginGraph = new PluginGraph(); - ((IExpression)expression).Configure(pluginGraph); + ((IExpression) expression).Configure(pluginGraph); } - [Test, ExpectedException(typeof(StructureMapException))] + [Test, ExpectedException(typeof (StructureMapException))] public void BlowUpIfNoPropertyIsFoundForType() { Registry.Instance<IWidget>().UsingConcreteType<AWidget>().Child<Rule>(); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,5 +1,4 @@ using NUnit.Framework; -using Rhino.Mocks; using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.Widget; @@ -20,14 +19,13 @@ ColorWidget theWidget = new ColorWidget("Red"); LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); PluginGraph graph = new PluginGraph(); - ((IExpression)expression).Configure(graph); + ((IExpression) expression).Configure(graph); PluginFamily family = graph.PluginFamilies[typeof (IWidget)]; Assert.IsNotNull(family); LiteralMemento memento = (LiteralMemento) family.Source.GetMemento(expression.InstanceKey); Assert.AreSame(theWidget, memento.Build(null)); - } [Test] @@ -36,7 +34,7 @@ ColorWidget theWidget = new ColorWidget("Red"); LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); PluginGraph graph = new PluginGraph(); - ((IExpression)expression).Configure(graph); + ((IExpression) expression).Configure(graph); InstanceManager manager = new InstanceManager(graph); @@ -51,13 +49,13 @@ LiteralExpression<IWidget> expression = new LiteralExpression<IWidget>(theWidget); expression.WithName("Blue"); PluginGraph graph = new PluginGraph(); - ((IExpression)expression).Configure(graph); + ((IExpression) expression).Configure(graph); - PluginFamily family = graph.PluginFamilies[typeof(IWidget)]; + PluginFamily family = graph.PluginFamilies[typeof (IWidget)]; Assert.IsNotNull(family); - LiteralMemento memento = (LiteralMemento)family.Source.GetMemento(expression.InstanceKey); + LiteralMemento memento = (LiteralMemento) family.Source.GetMemento(expression.InstanceKey); Assert.AreSame(theWidget, memento.Build(null)); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,5 +1,4 @@ using NUnit.Framework; -using Rhino.Mocks; using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.Widget; @@ -12,7 +11,6 @@ [SetUp] public void SetUp() { - } [Test] @@ -22,16 +20,17 @@ string theDefaultName = "TheDefaultName"; ProfileExpression expression = new ProfileExpression(theProfileName); - + ProfileExpression expression2 = expression.For<IWidget>().UseNamedInstance(theDefaultName); Assert.AreSame(expression, expression2); PluginGraph graph = new PluginGraph(); - ((IExpression)expression).Configure(graph); + ((IExpression) expression).Configure(graph); Profile profile = graph.DefaultManager.GetProfile(theProfileName); Assert.IsNotNull(profile); - Assert.AreEqual(new InstanceDefault[] { new InstanceDefault(typeof(IWidget), theDefaultName) }, profile.Defaults); + Assert.AreEqual(new InstanceDefault[] {new InstanceDefault(typeof (IWidget), theDefaultName)}, + profile.Defaults); } [Test] @@ -43,12 +42,11 @@ Registry registry = new Registry(graph); registry.CreateProfile(theProfileName) .For<IWidget>().Use( - Registry.Instance<IWidget>().UsingConcreteType<AWidget>() + Registry.Instance<IWidget>().UsingConcreteType<AWidget>() ); IInstanceManager manager = registry.BuildInstanceManager(); - Profile profile = manager.DefaultManager.GetProfile(theProfileName); InstanceDefault instanceDefault = profile.Defaults[0]; @@ -59,4 +57,4 @@ Assert.IsNotNull(widget); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -43,7 +43,7 @@ graph.Seal(); List<string> colors = new List<string>(); - foreach (InstanceMemento memento in graph.PluginFamilies[typeof(IWidget)].Source.GetAllMementos() ) + foreach (InstanceMemento memento in graph.PluginFamilies[typeof (IWidget)].Source.GetAllMementos()) { colors.Add(memento.InstanceKey); } @@ -83,4 +83,4 @@ Assert.Contains("Black", colors); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,5 +1,4 @@ using System; -using System.Reflection; using NUnit.Framework; using Rhino.Mocks; using StructureMap.Configuration.DSL; @@ -28,7 +27,7 @@ expression1.Configure(graph); expression2.Configure(graph); expression3.Configure(graph); - + mocks.ReplayAll(); TestRegistry registry = new TestRegistry(graph); @@ -48,7 +47,7 @@ IExpression expression1 = mocks.CreateMock<IExpression>(); IExpression expression2 = mocks.CreateMock<IExpression>(); IExpression expression3 = mocks.CreateMock<IExpression>(); - + PluginGraph graph = new PluginGraph(); expression1.Configure(graph); expression2.Configure(graph); @@ -60,15 +59,11 @@ { registry.AddExpression(expression1); registry.AddExpression(expression2); - registry.AddExpression(expression3); + registry.AddExpression(expression3); } mocks.VerifyAll(); } - - - - } public class TestRegistry : Registry @@ -126,4 +121,4 @@ get { throw new NotImplementedException(); } } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2007-03-27 11:18:48 UTC (rev 31) +++ trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2007-03-29 15:58:10 UTC (rev 32) @@ -1,4 +1,3 @@ -using System; using System.Diagnostics; using NUnit.Framework; using StructureMap.Graph; @@ -33,24 +32,24 @@ [Test] public void CanFindTheTwoPluginFamilies() { - Assert.IsTrue(_graph.PluginFamilies.Contains(typeof(IWidget))); - Assert.IsTrue(_graph.PluginFamilies.Contains(typeof(Rule))); + Assert.IsTrue(_graph.PluginFamilies.Contains(typeof (IWidget))); + Assert.IsTrue(_graph.PluginFamilies.Contains(typeof (Rule))); } [Test] public void HasTheOverrideForProfile() { Profile blueProfile = _graph.DefaultManager.GetProfile("Blue"); - Assert.IsTrue(blueProfile.HasOverride(typeof(Rule).FullName)); - Assert.IsTrue(blueProfile.HasOverride(typeof(IWidget).FullName)); + Assert.IsTrue(blueProfile.HasOverride(typeof (Rule).FullName)); + Assert.IsTrue(blueProfile.HasOverride(typeof (IWidget).FullName)); - Assert.IsNotEmpty(blueProfile[typeof(Rule).FullName]); - Assert.IsNotEmpty(blueProfile[typeof(IWidget).FullName]); + Assert.IsNotEmpty(blueProfile[typeof (Rule).FullName]); + Assert.IsNotEmpty(blueProfile[typeof (IWidget).FullName]); - Debug.WriteLine(blueProfile[typeof(IWidget).FullName]); + Debug.WriteLine(blueProfile[typeof (IWidget).FullName]); Profile defaults = _graph.DefaultManager.CalculateDefaults(InstanceDefaultManager.GetMachineName(), "Blue"); - Assert.IsNotEmpty(defaults[typeof(Rule).FullName]); + Assert.IsNotEmpty(defaults[typeof (Rule).FullName]); } [Test] @@ -59,10 +58,8 @@ InstanceManager manager = new InstanceManager(_graph); manager.SetDefaultsToProfile("Green"); - string defaultKey = manager[typeof(Rule)].DefaultInstanceKey; + string defaultKey = manager[typeof (Rule)].DefaultInstanceKey; Assert.IsNotEmpty(defaultKey); - - } [Test] @@ -76,7 +73,7 @@ manager.SetDefaultsToProfile("Blue"); - ColorRule blueRule = (ColorRule)manager.CreateInstance(typeof(Rule)); + ColorRule blueRule = (ColorRule) manager.CreateInstance(typeof (Rule)); Assert.AreEqual("Blue", blueRule.Color); } @@ -85,14 +82,13 @@ { MachineOverride machine = _graph.DefaultManager.GetMachineOverride("SERVER"); Assert.AreEqual(1, machine.InnerDefaults.Length); - Assert.IsTrue(machine.HasOverride(typeof(IWidget).FullName)); + Assert.IsTrue... [truncated message content] |
From: <jer...@us...> - 2007-04-01 18:18:22
|
Revision: 35 http://structuremap.svn.sourceforge.net/structuremap/?rev=35&view=rev Author: jeremydmiller Date: 2007-04-01 11:18:16 -0700 (Sun, 01 Apr 2007) Log Message: ----------- Adding NDoc style comments to the DSL classes Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs trunk/Source/StructureMap/StructureMapConfiguration.cs Modified: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -4,6 +4,10 @@ namespace StructureMap.Configuration.DSL { + /// <summary> + /// Part of the Fluent Interface, represents a nonprimitive argument to a + /// constructure function + /// </summary> public class ChildInstanceExpression : IExpression { private readonly InstanceExpression _instance; @@ -28,7 +32,11 @@ _childType = childType; } - + /// <summary> + /// Use a previously configured and named instance for the child + /// </summary> + /// <param name="instanceKey"></param> + /// <returns></returns> public InstanceExpression IsNamedInstance(string instanceKey) { MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey); @@ -37,6 +45,11 @@ return _instance; } + /// <summary> + /// Start the definition of a child instance by defining the concrete type + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public InstanceExpression IsConcreteType<T>() { Type pluggedType = typeof (T); @@ -78,6 +91,12 @@ set { _childType = value; } } + /// <summary> + /// Registers a configured instance to use as the argument to the parent's + /// constructor + /// </summary> + /// <param name="child"></param> + /// <returns></returns> public InstanceExpression Is(InstanceExpression child) { if (child.PluggedType != null && _childType != null) Modified: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -8,6 +8,9 @@ { public delegate void AlterPluginFamilyDelegate(PluginFamily family); + /// <summary> + /// Represents the parameters for creating instances of a given Type + /// </summary> public class CreatePluginFamilyExpression : IExpression { private Type _pluginType; @@ -42,6 +45,11 @@ graph.Assemblies.Add(assembly); } + /// <summary> + /// Sets the default instance of a Type to the definition represented by builder + /// </summary> + /// <param name="builder"></param> + /// <returns></returns> public CreatePluginFamilyExpression TheDefaultIs(IMementoBuilder builder) { builder.ValidatePluggability(_pluginType); @@ -57,6 +65,13 @@ return this; } + /// <summary> + /// Convenience method that sets the default concrete type of the PluginType. Type T + /// can only accept types that do not have any primitive constructor arguments. + /// StructureMap has to know how to construct all of the constructor argument types. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public CreatePluginFamilyExpression TheDefaultIsConcreteType<T>() { ExpressionValidator.ValidatePluggabilityOf(typeof (T)).IntoPluginType(_pluginType); @@ -70,6 +85,12 @@ return this; } + /// <summary> + /// Sets the object creation of the instances of the PluginType. For example: PerRequest, + /// Singleton, ThreadLocal, HttpContext, or Hybrid + /// </summary> + /// <param name="scope"></param> + /// <returns></returns> public CreatePluginFamilyExpression CacheBy(InstanceScope scope) { _alterations.Add(delegate(PluginFamily family) @@ -81,6 +102,10 @@ return this; } + /// <summary> + /// Convenience method to mark a PluginFamily as a Singleton + /// </summary> + /// <returns></returns> public CreatePluginFamilyExpression AsSingletons() { _alterations.Add( Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -3,6 +3,9 @@ namespace StructureMap.Configuration.DSL { + /// <summary> + /// Use to express the instance of a PluginType for the containing Profile + /// </summary> public class InstanceDefaultExpression { private readonly Type _pluginType; @@ -16,6 +19,11 @@ _parent = parent; } + /// <summary> + /// Use a named, preconfigured instance as the default instance for this profile + /// </summary> + /// <param name="instanceKey"></param> + /// <returns></returns> public ProfileExpression UseNamedInstance(string instanceKey) { _instanceKey = instanceKey; @@ -46,6 +54,11 @@ } } + /// <summary> + /// Define the default instance of the PluginType for the containing Profile + /// </summary> + /// <param name="mementoBuilder"></param> + /// <returns></returns> public ProfileExpression Use(IMementoBuilder mementoBuilder) { _mementoBuilder = mementoBuilder; Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -3,6 +3,9 @@ namespace StructureMap.Configuration.DSL { + /// <summary> + /// Used to define an Instance in code + /// </summary> public class InstanceExpression : MementoBuilder<InstanceExpression> { private Type _pluggedType; @@ -53,12 +56,24 @@ } + /// <summary> + /// Start the definition of a primitive argument to a constructor argument + /// </summary> + /// <param name="propertyName"></param> + /// <returns></returns> public PropertyExpression WithProperty(string propertyName) { return new PropertyExpression(this, _memento, propertyName); } - + /// <summary> + /// Starts the definition of a child instance specifying the argument name + /// in the case of a constructor function that consumes more than one argument + /// of type T + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="propertyName"></param> + /// <returns></returns> public ChildInstanceExpression Child<T>(string propertyName) { ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName); @@ -68,6 +83,11 @@ return child; } + /// <summary> + /// Start the definition of a child instance for type T + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public ChildInstanceExpression Child<T>() { string propertyName = findPropertyName<T>(); @@ -104,7 +124,9 @@ return new InstanceTypeExpression(this); } - + /// <summary> + /// Helper class to capture the actual concrete type of an Instance + /// </summary> public class InstanceTypeExpression { private readonly InstanceExpression _parent; @@ -114,12 +136,22 @@ _parent = parent; } + /// <summary> + /// Use type T for the concrete type of an instance + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public InstanceExpression UsingConcreteType<T>() { _parent._pluggedType = typeof (T); return _parent; } + /// <summary> + /// Use a named Plugin type denoted by a [Pluggable("Key")] attribute + /// </summary> + /// <param name="concreteKey"></param> + /// <returns></returns> public InstanceExpression UsingConcreteTypeNamed(string concreteKey) { _parent._memento.ConcreteKey = concreteKey; Modified: trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -3,6 +3,10 @@ namespace StructureMap.Configuration.DSL { + /// <summary> + /// Small helper class to represent an object to be plugged into a PluginType as is + /// </summary> + /// <typeparam name="T"></typeparam> public class LiteralExpression<T> : MementoBuilder<LiteralExpression<T>> { private readonly T _target; Modified: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -3,6 +3,9 @@ namespace StructureMap.Configuration.DSL { + /// <summary> + /// Expression class to help define a runtime Profile + /// </summary> public class ProfileExpression : IExpression { private readonly string _profileName; @@ -28,6 +31,11 @@ } } + /// <summary> + /// Starts the definition of the default instance for the containing Profile + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public InstanceDefaultExpression For<T>() { InstanceDefaultExpression defaultExpression = new InstanceDefaultExpression(typeof (T), this); Modified: trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -2,6 +2,9 @@ namespace StructureMap.Configuration.DSL { + /// <summary> + /// Defines the value of a primitive argument to a constructur argument + /// </summary> public class PropertyExpression { private readonly InstanceExpression _instance; @@ -15,12 +18,23 @@ _propertyName = propertyName; } + /// <summary> + /// Sets the value of the constructor argument + /// </summary> + /// <param name="propertyValue"></param> + /// <returns></returns> public InstanceExpression EqualTo(object propertyValue) { _memento.SetProperty(_propertyName, propertyValue.ToString()); return _instance; } + /// <summary> + /// Sets the value of the constructor argument to the key/value in the + /// AppSettings + /// </summary> + /// <param name="appSettingKey"></param> + /// <returns></returns> public InstanceExpression EqualToAppSetting(string appSettingKey) { string propertyValue = ConfigurationManager.AppSettings[appSettingKey]; Modified: trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -3,6 +3,10 @@ namespace StructureMap.Configuration.DSL { + /// <summary> + /// Sets up a Prototype instance of type T + /// </summary> + /// <typeparam name="T"></typeparam> public class PrototypeExpression<T> : MementoBuilder<PrototypeExpression<T>> { private readonly T _prototype; Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -48,7 +48,12 @@ ConfigurePluginGraph(_graph); } - + /// <summary> + /// Direct StructureMap to build instances of type T, and look for concrete classes + /// marked with the [Pluggable] attribute that implement type T + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public CreatePluginFamilyExpression BuildInstancesOf<T>() { CreatePluginFamilyExpression expression = new CreatePluginFamilyExpression(typeof (T)); @@ -64,6 +69,11 @@ return new InstanceManager(_graph); } + /// <summary> + /// Starts an instance definition of type T + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public InstanceExpression.InstanceTypeExpression AddInstanceOf<T>() { InstanceExpression expression = new InstanceExpression(typeof (T)); @@ -71,22 +81,45 @@ return expression.TypeExpression(); } + /// <summary> + /// Convenience method to start the definition of an instance of type T + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public static InstanceExpression.InstanceTypeExpression Instance<T>() { InstanceExpression expression = new InstanceExpression(typeof (T)); return expression.TypeExpression(); } + /// <summary> + /// Convenience method to register a prototype instance + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="prototype"></param> + /// <returns></returns> public static PrototypeExpression<T> Prototype<T>(T prototype) { return new PrototypeExpression<T>(prototype); } + /// <summary> + /// Convenience method to register a preconfigured instance of type T + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="instance"></param> + /// <returns></returns> public static LiteralExpression<T> Object<T>(T instance) { return new LiteralExpression<T>(instance); } + /// <summary> + /// Registers a preconfigured instance + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="target"></param> + /// <returns></returns> public LiteralExpression<T> AddInstanceOf<T>(T target) { LiteralExpression<T> literal = new LiteralExpression<T>(target); @@ -95,6 +128,12 @@ return literal; } + /// <summary> + /// Add a preconfigured instance as a Prototype + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="prototype"></param> + /// <returns></returns> public PrototypeExpression<T> AddPrototypeInstanceOf<T>(T prototype) { PrototypeExpression<T> expression = new PrototypeExpression<T>(prototype); @@ -103,11 +142,22 @@ return expression; } + /// <summary> + /// convenience method for a UserControl + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="url"></param> + /// <returns></returns> public static UserControlExpression LoadUserControlFrom<T>(string url) { - return new UserControlExpression(typeof(T), url); + return new UserControlExpression(typeof (T), url); } + /// <summary> + /// Starts the definition of a new Profile + /// </summary> + /// <param name="profileName"></param> + /// <returns></returns> public ProfileExpression CreateProfile(string profileName) { ProfileExpression expression = new ProfileExpression(profileName); @@ -131,9 +181,15 @@ return (type.GetConstructor(new Type[0]) != null); } + /// <summary> + /// Registers a UserControl as an instance + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="url"></param> + /// <returns></returns> public UserControlExpression LoadControlFromUrl<T>(string url) { - UserControlExpression expression = new UserControlExpression(typeof(T), url); + UserControlExpression expression = new UserControlExpression(typeof (T), url); addExpression(expression); return expression; Modified: trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -6,6 +6,10 @@ namespace StructureMap.Configuration.DSL { + /// <summary> + /// Expression that directs StructureMap to scan the named assemblies + /// for [PluginFamily] and [Plugin] attributes + /// </summary> public class ScanAssembliesExpression : IExpression { private List<AssemblyGraph> _assemblies = new List<AssemblyGraph>(); Modified: trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; using StructureMap.Graph; namespace StructureMap.Configuration.DSL @@ -44,4 +42,4 @@ // no-op } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-30 14:26:24 UTC (rev 34) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-04-01 18:18:16 UTC (rev 35) @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Configuration; using System.IO; using System.Xml; using StructureMap.Configuration; @@ -48,7 +47,10 @@ return configPath; } - + /// <summary> + /// Clears StructureMapConfiguration of all configuration options. Returns StructureMap + /// to only using the default StructureMap.config file for configuration. + /// </summary> public static void ResetAll() { _collection = new ConfigurationParserCollection(); @@ -58,6 +60,10 @@ _startUp = null; } + /// <summary> + /// Builds a PluginGraph object for the current configuration. Used by ObjectFactory. + /// </summary> + /// <returns></returns> public static PluginGraph GetPluginGraph() { if (_startUp != null) @@ -73,33 +79,48 @@ { if (_pullConfigurationFromAppConfig) { - _collection.IncludeNode(delegate() - { - - return StructureMapConfigurationSection.GetStructureMapConfiguration(); - }); + _collection.IncludeNode( + delegate() { return StructureMapConfigurationSection.GetStructureMapConfiguration(); }); } ConfigurationParser[] parsers = _collection.GetParsers(); return new PluginGraphBuilder(parsers, _registries.ToArray()); } + /// <summary> + /// Creates a PluginGraphReport that details the current configuration along with any problems found with the configuration. + /// The PluginGraphReport can be used to troubleshoot problems with the StructureMap configuration. + /// </summary> + /// <returns></returns> public static PluginGraphReport GetDiagnosticReport() { PluginGraphBuilder builder = createBuilder(); return builder.Report; } + /// <summary> + /// Directs StructureMap to include Xml configuration information from a separate file + /// </summary> + /// <param name="filename"></param> public static void IncludeConfigurationFromFile(string filename) { _collection.IncludeFile(filename); } + /// <summary> + /// Register a FetchNodeDelegate delegate to retrieve a <StructureMap> + /// node to include Xml configuration + /// </summary> + /// <param name="fetcher"></param> public static void IncludeConfigurationFrom(FetchNodeDelegate fetcher) { _collection.IncludeNode(fetcher); } + /// <summary> + /// Programmatically adds a <StructureMap> node containing Xml configuration + /// </summary> + /// <param name="node"></param> public static void IncludeConfigurationFromNode(XmlNode node) { _collection.IncludeNode( @@ -107,6 +128,10 @@ ); } + /// <summary> + /// Flag to enable or disable the usage of the default StructureMap.config + /// If set to false, StructureMap will not look for a StructureMap.config file + /// </summary> public static bool UseDefaultStructureMapConfigFile { get { return _collection.UseDefaultFile; } @@ -124,6 +149,10 @@ } } + /// <summary> + /// Programmatically determine Assembly's to be scanned for attribute configuration + /// </summary> + /// <returns></returns> public static ScanAssembliesExpression ScanAssemblies() { ScanAssembliesExpression expression = new ScanAssembliesExpression(); @@ -132,51 +161,77 @@ return expression; } + /// <summary> + /// Direct StructureMap to create instances of Type T + /// </summary> + /// <typeparam name="T">The Type to build</typeparam> + /// <returns></returns> public static CreatePluginFamilyExpression BuildInstancesOf<T>() { return _registry.BuildInstancesOf<T>(); } + /// <summary> + /// Adds a new configured instance of Type T + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> public static InstanceExpression.InstanceTypeExpression AddInstanceOf<T>() { return _registry.AddInstanceOf<T>(); } - public static InstanceExpression.InstanceTypeExpression Instance<T>() - { - return Registry.Instance<T>(); - } - public static PrototypeExpression<T> Prototype<T>(T prototype) - { - return new PrototypeExpression<T>(prototype); - } - - public static LiteralExpression<T> Object<T>(T instance) - { - return new LiteralExpression<T>(instance); - } - + /// <summary> + /// Adds a preconfigured instance of Type T to StructureMap. When this instance is requested, + /// StructureMap will always return the original object. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="target"></param> + /// <returns></returns> public static LiteralExpression<T> AddInstanceOf<T>(T target) { return _registry.AddInstanceOf(target); } + /// <summary> + /// Adds a Prototype (GoF) instance of Type T. The actual prototype object must implement the + /// ICloneable interface. When this instance of T is requested, StructureMap will + /// return a cloned copy of the originally registered prototype object. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="prototype"></param> + /// <returns></returns> public static PrototypeExpression<T> AddPrototypeInstanceOf<T>(T prototype) { return _registry.AddPrototypeInstanceOf(prototype); } + /// <summary> + /// Starts the definition of a configuration Profile. + /// </summary> + /// <param name="profileName"></param> + /// <returns></returns> public static ProfileExpression CreateProfile(string profileName) { return _registry.CreateProfile(profileName); } + /// <summary> + /// Directs StructureMap to use a Registry class to construct the + /// PluginGraph + /// </summary> + /// <param name="registry"></param> public static void AddRegistry(Registry registry) { _registries.Add(registry); } + /// <summary> + /// Controls the reporting and diagnostics of StructureMap on + /// startup + /// </summary> + /// <returns></returns> public static IStartUp OnStartUp() { if (_startUp == null) @@ -186,5 +241,26 @@ return _startUp; } + + public static void TheDefaultProfileIs(string profileName) + { + DefaultProfileExpression expression = new DefaultProfileExpression(profileName); + _registry.addExpression(expression); + } + + internal class DefaultProfileExpression : IExpression + { + private readonly string _profileName; + + public DefaultProfileExpression(string profileName) + { + _profileName = profileName; + } + + public void Configure(PluginGraph graph) + { + graph.DefaultManager.DefaultProfileName = _profileName; + } + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2007-05-02 01:32:02
|
Revision: 47 http://structuremap.svn.sourceforge.net/structuremap/?rev=47&view=rev Author: flimflan Date: 2007-05-01 18:32:00 -0700 (Tue, 01 May 2007) Log Message: ----------- The configuration section handler no longer attempts to merge the configuration hiearchy when loading from app.config. It instead returns the configuration from all levels of the hierarchy, and leaves it up to the configuration parsers to do the merging. The full power of this will be realized when the configuration parsers allow you to override settings for plugins that have already been configured. Modified Paths: -------------- trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs Modified: trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2007-05-01 02:31:55 UTC (rev 46) +++ trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2007-05-02 01:32:00 UTC (rev 47) @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Configuration; using System.Xml; @@ -7,25 +8,23 @@ { public object Create(object parent, object configContext, XmlNode section) { - XmlNode parentNode = parent as XmlNode; - if (parentNode == null) return section; - // Might need to make this more intelligent, to merge nodes that override eachother - foreach (XmlNode childNode in section.ChildNodes) + IList<XmlNode> allNodes = parent as IList<XmlNode>; + if (allNodes == null) { - XmlNode importedNode = parentNode.OwnerDocument.ImportNode(childNode, true); - parentNode.AppendChild(importedNode); + allNodes = new List<XmlNode>(); } - return parentNode; + allNodes.Add(section); + return allNodes; } - public static XmlNode GetStructureMapConfiguration() + public static IList<XmlNode> GetStructureMapConfiguration() { - XmlNode node = ConfigurationSettings.GetConfig(XmlConstants.STRUCTUREMAP) as XmlNode; - if (node == null) + IList<XmlNode> nodes = ConfigurationSettings.GetConfig(XmlConstants.STRUCTUREMAP) as IList<XmlNode>; + if (nodes == null) { throw new StructureMapException(105, XmlConstants.STRUCTUREMAP); } - return node; + return nodes; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-05-01 02:31:55 UTC (rev 46) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-05-02 01:32:00 UTC (rev 47) @@ -80,8 +80,12 @@ { if (_pullConfigurationFromAppConfig) { - _collection.IncludeNode( - delegate() { return StructureMapConfigurationSection.GetStructureMapConfiguration(); }); + IList<XmlNode> appConfigNodes = StructureMapConfigurationSection.GetStructureMapConfiguration(); + foreach(XmlNode appConfigNode in appConfigNodes) + { + _collection.IncludeNode( + delegate() { return appConfigNode; }); + } } ConfigurationParser[] parsers = _collection.GetParsers(); Modified: trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2007-05-01 02:31:55 UTC (rev 46) +++ trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2007-05-02 01:32:00 UTC (rev 47) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Xml; using NUnit.Framework; @@ -90,20 +91,22 @@ } [Test] - public void AppConfigShouldIncludeSettingsFromParentConfig() + public void SettingsFromAllParentConfigFilesShouldBeIncluded() { StructureMapConfigurationSection configurationSection = new StructureMapConfigurationSection(); XmlNode fromMachineConfig = createNodeFromText(@"<StructureMap><Assembly Name=""SomeAssembly""/></StructureMap>"); XmlNode fromWebConfig = createNodeFromText(@"<StructureMap><Assembly Name=""AnotherAssembly""/></StructureMap>"); - XmlNode effectiveConfig = configurationSection.Create(fromMachineConfig, null, fromWebConfig) as XmlNode; + IList<XmlNode> parentNodes = new List<XmlNode>(); + parentNodes.Add(fromMachineConfig); - Assert.IsNotNull(effectiveConfig, "A configuration node should have been returned."); - Assert.AreEqual(2, effectiveConfig.ChildNodes.Count, "Both Assembly entries should have been returned."); - Assert.IsTrue(hasAttributeValue("Name", "SomeAssembly", effectiveConfig.ChildNodes[0]), "The parent Assembly entry should have been returned first."); - Assert.IsTrue(hasAttributeValue("Name", "AnotherAssembly", effectiveConfig.ChildNodes[1]), "The child Assembly entry should have been returned second."); + IList<XmlNode> effectiveConfig = configurationSection.Create(parentNodes, null, fromWebConfig) as IList<XmlNode>; + Assert.IsNotNull(effectiveConfig, "A list of configuration nodes should have been returned."); + Assert.AreEqual(2, effectiveConfig.Count, "Both configurations should have been returned."); + Assert.AreEqual(fromMachineConfig, effectiveConfig[0]); + Assert.AreEqual(fromWebConfig, effectiveConfig[1]); } private static XmlNode createNodeFromText(string outerXml) @@ -112,13 +115,6 @@ document.LoadXml(outerXml); return document.DocumentElement; } - - private static bool hasAttributeValue(string attributeName, string attributeValue, XmlNode node) - { - XmlAttribute namedAttribute = node.Attributes[attributeName]; - if (namedAttribute == null) return false; - return namedAttribute.Value == attributeValue; - } } public interface ISomething This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-01-14 03:57:50
|
Revision: 53 http://structuremap.svn.sourceforge.net/structuremap/?rev=53&view=rev Author: jeremydmiller Date: 2008-01-13 19:57:47 -0800 (Sun, 13 Jan 2008) Log Message: ----------- type interception for some AOP support Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/InstanceMementoTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs trunk/Source/StructureMap/Interceptors/EnrichmentInterceptor.cs trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs trunk/Source/StructureMap/Interceptors/Interceptors.cs trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs trunk/Source/StructureMap/Interceptors/TypeInterceptor.cs trunk/Source/StructureMap.Testing/Container/Interceptors/CompoundInterceptorTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/InterceptorLibraryTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/MockTypeInterceptor.cs trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Delegates.cs Modified: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using StructureMap.Graph; +using StructureMap.Interceptors; namespace StructureMap.Configuration.DSL { Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using StructureMap.Graph; +using StructureMap.Interceptors; namespace StructureMap.Configuration.DSL { @@ -34,6 +35,11 @@ _expressions.Add(expression); } + internal void addExpression(PluginGraphAlteration alteration) + { + _expressions.Add(new BasicExpression(alteration)); + } + internal void ConfigurePluginGraph(PluginGraph graph) { foreach (IExpression expression in _expressions) @@ -222,5 +228,70 @@ { return new ReferenceMementoBuilder(referencedKey); } + + public void RegisterInterceptor(TypeInterceptor interceptor) + { + addExpression(delegate (PluginGraph pluginGraph) + { + pluginGraph.InterceptorLibrary.AddInterceptor(interceptor); + }); + } + + public TypeInterceptorExpression IfTypeMatches(TypeMatchDelegate match) + { + TypeInterceptorExpression expression = new TypeInterceptorExpression(match); + _expressions.Add(expression); + + return expression; + } } + + public delegate object InterceptionDelegate(object instance); + public delegate bool TypeMatchDelegate(Type type); + public class TypeInterceptorExpression : IExpression, TypeInterceptor + { + private readonly TypeMatchDelegate _match; + private InterceptionDelegate _interception; + + internal TypeInterceptorExpression(TypeMatchDelegate match) + { + _match = match; + } + + void IExpression.Configure(PluginGraph graph) + { + graph.InterceptorLibrary.AddInterceptor(this); + } + + public void InterceptWith(InterceptionDelegate interception) + { + _interception = interception; + } + + public bool MatchesType(Type type) + { + return _match(type); + } + + public object Process(object target) + { + return _interception(target); + } + } + + internal delegate void PluginGraphAlteration(PluginGraph pluginGraph); + internal class BasicExpression : IExpression + { + private readonly PluginGraphAlteration _alteration; + + internal BasicExpression(PluginGraphAlteration alteration) + { + _alteration = alteration; + } + + public void Configure(PluginGraph graph) + { + _alteration(graph); + } + } } \ No newline at end of file Deleted: trunk/Source/StructureMap/Delegates.cs =================================================================== --- trunk/Source/StructureMap/Delegates.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/Delegates.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -1,52 +0,0 @@ -namespace StructureMap -{ - public delegate T EnrichmentHandler<T>(T target); - - public delegate void StartupHandler<T>(T target); - - public interface InstanceInterceptor - { - object Process(object target); - } - - public class NulloInterceptor : InstanceInterceptor - { - public object Process(object target) - { - return target; - } - } - - public class StartupInterceptor<T> : InstanceInterceptor - { - private readonly StartupHandler<T> _handler; - - public StartupInterceptor(StartupHandler<T> handler) - { - _handler = handler; - } - - - public object Process(object target) - { - _handler((T) target); - return target; - } - } - - public class EnrichmentInterceptor<T> : InstanceInterceptor - { - private readonly EnrichmentHandler<T> _handler; - - - public EnrichmentInterceptor(EnrichmentHandler<T> handler) - { - _handler = handler; - } - - public object Process(object target) - { - return _handler((T) target); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Reflection; using StructureMap.Configuration.DSL; +using StructureMap.Interceptors; namespace StructureMap.Graph { @@ -14,10 +15,11 @@ [Serializable] public class PluginGraph { - private AssemblyGraphCollection _assemblies; + private readonly AssemblyGraphCollection _assemblies; private bool _sealed = false; - private PluginFamilyCollection _pluginFamilies; - private InstanceDefaultManager _defaultManager = new InstanceDefaultManager(); + private readonly PluginFamilyCollection _pluginFamilies; + private readonly InstanceDefaultManager _defaultManager = new InstanceDefaultManager(); + private readonly InterceptorLibrary _interceptorLibrary = new InterceptorLibrary(); /// <summary> @@ -116,6 +118,11 @@ get { return _defaultManager; } } + public InterceptorLibrary InterceptorLibrary + { + get { return _interceptorLibrary; } + } + /// <summary> /// Un-seals a PluginGraph. Makes the PluginGraph editable /// </summary> Modified: trunk/Source/StructureMap/IInstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/IInstanceFactory.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/IInstanceFactory.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -11,8 +11,8 @@ /// <summary> /// Establishes a reference to the parent InstanceManager /// </summary> - /// <param name="Manager"></param> - void SetInstanceManager(InstanceManager Manager); + /// <param name="instanceManager"></param> + void SetInstanceManager(InstanceManager instanceManager); /// <summary> /// The CLR System.Type that the IInstanceManager builds instances Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -6,6 +6,7 @@ using StructureMap.Configuration.DSL; using StructureMap.Emitting; using StructureMap.Graph; +using StructureMap.Interceptors; using StructureMap.Source; namespace StructureMap @@ -19,6 +20,7 @@ private readonly Dictionary<string, InstanceBuilder> _instanceBuilders; private MementoSource _source; private readonly InstanceInterceptor _interceptor = new NulloInterceptor(); + private InterceptorLibrary _interceptorLibrary = InterceptorLibrary.Empty; #region static constructors @@ -123,18 +125,19 @@ /// <summary> /// Links the child InstanceBuilder members to the parent InstanceManager /// </summary> - /// <param name="Manager"></param> - public void SetInstanceManager(InstanceManager Manager) + /// <param name="instanceManager"></param> + public void SetInstanceManager(InstanceManager instanceManager) { + _interceptorLibrary = instanceManager.InterceptorLibrary; foreach (InstanceBuilder builder in _instanceBuilders.Values) { - builder.SetInstanceManager(Manager); + builder.SetInstanceManager(instanceManager); } } #region create instance builders - private void processPlugins(Plugin[] plugins) + private void processPlugins(IEnumerable<Plugin> plugins) { Assembly assembly = createInstanceBuilderAssembly(plugins); foreach (Plugin plugin in plugins) @@ -143,7 +146,7 @@ } } - private Assembly createInstanceBuilderAssembly(Plugin[] plugins) + private Assembly createInstanceBuilderAssembly(IEnumerable<Plugin> plugins) { string assemblyName = Guid.NewGuid().ToString().Replace(".", "") + "InstanceBuilderAssembly"; InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(assemblyName, PluginType); @@ -218,17 +221,15 @@ object IInstanceCreator.BuildInstance(InstanceMemento memento) { - if (!_instanceBuilders.ContainsKey(memento.ConcreteKey)) - { - throw new StructureMapException( - 201, memento.ConcreteKey, memento.InstanceKey, PluginType.FullName); - } + assertThatTheConcreteKeyExists(memento); - InstanceBuilder builder = _instanceBuilders[memento.ConcreteKey]; try { - return builder.BuildInstance(memento); + InstanceBuilder builder = _instanceBuilders[memento.ConcreteKey]; + object constructedInstance = builder.BuildInstance(memento); + CompoundInterceptor interceptor = _interceptorLibrary.FindInterceptor(constructedInstance.GetType()); + return interceptor.Process(constructedInstance); } catch (StructureMapException) { @@ -244,7 +245,16 @@ } } + private void assertThatTheConcreteKeyExists(InstanceMemento memento) + { + if (!_instanceBuilders.ContainsKey(memento.ConcreteKey)) + { + throw new StructureMapException( + 201, memento.ConcreteKey, memento.InstanceKey, PluginType.FullName); + } + } + /// <summary> /// Builds a new instance of the default instance of the PluginType /// </summary> Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -4,6 +4,7 @@ using StructureMap.Configuration.DSL; using StructureMap.Exceptions; using StructureMap.Graph; +using StructureMap.Interceptors; namespace StructureMap { @@ -12,10 +13,11 @@ /// </summary> public class InstanceManager : IInstanceManager, IEnumerable { - private Dictionary<Type, IInstanceFactory> _factories; - private bool _failOnException = true; - private GenericsPluginGraph _genericsGraph; - private InstanceDefaultManager _defaultManager; + private readonly Dictionary<Type, IInstanceFactory> _factories; + private readonly bool _failOnException = true; + private readonly GenericsPluginGraph _genericsGraph; + private readonly InstanceDefaultManager _defaultManager; + private readonly InterceptorLibrary _interceptorLibrary; /// <summary> /// Default constructor @@ -24,6 +26,7 @@ { _factories = new Dictionary<Type, IInstanceFactory>(); _genericsGraph = new GenericsPluginGraph(); + _interceptorLibrary = new InterceptorLibrary(); } /// <summary> @@ -46,6 +49,7 @@ { _failOnException = failOnException; _defaultManager = pluginGraph.DefaultManager; + _interceptorLibrary = pluginGraph.InterceptorLibrary; if (!pluginGraph.IsSealed) { @@ -70,6 +74,12 @@ get { return _defaultManager; } } + + public InterceptorLibrary InterceptorLibrary + { + get { return _interceptorLibrary; } + } + private IInstanceFactory registerPluginFamily(PluginFamily family) { InstanceFactory factory = new InstanceFactory(family, _failOnException); Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -2,6 +2,7 @@ using StructureMap.Configuration; using StructureMap.Configuration.Tokens; using StructureMap.Graph; +using StructureMap.Interceptors; namespace StructureMap { Added: trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap.Interceptors +{ + public class CompoundInterceptor : InstanceInterceptor + { + private readonly InstanceInterceptor[] _interceptors; + + public CompoundInterceptor(InstanceInterceptor[] interceptors) + { + _interceptors = interceptors; + } + + public object Process(object target) + { + object returnValue = target; + foreach (InstanceInterceptor interceptor in _interceptors) + { + returnValue = interceptor.Process(returnValue); + } + + return returnValue; + } + + + public InstanceInterceptor[] Interceptors + { + get { return _interceptors; } + } + } +} Added: trunk/Source/StructureMap/Interceptors/EnrichmentInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/EnrichmentInterceptor.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/EnrichmentInterceptor.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,18 @@ +namespace StructureMap.Interceptors +{ + public class EnrichmentInterceptor<T> : InstanceInterceptor + { + private readonly EnrichmentHandler<T> _handler; + + + public EnrichmentInterceptor(EnrichmentHandler<T> handler) + { + _handler = handler; + } + + public object Process(object target) + { + return _handler((T)target); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,7 @@ +namespace StructureMap.Interceptors +{ + public interface InstanceInterceptor + { + object Process(object target); + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/InterceptorLibrary.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +namespace StructureMap.Interceptors +{ + public class InterceptorLibrary + { + public static readonly InterceptorLibrary Empty = new InterceptorLibrary(); + + private readonly Dictionary<Type, CompoundInterceptor> _analyzedInterceptors + = new Dictionary<Type, CompoundInterceptor>(); + + private readonly List<TypeInterceptor> _interceptors = new List<TypeInterceptor>(); + private readonly object _locker = new object(); + + public void AddInterceptor(TypeInterceptor interceptor) + { + _interceptors.Add(interceptor); + } + + public CompoundInterceptor FindInterceptor(Type type) + { + if (_analyzedInterceptors.ContainsKey(type)) + { + return _analyzedInterceptors[type]; + } + + lock (_locker) + { + if (!_analyzedInterceptors.ContainsKey(type)) + { + TypeInterceptor[] interceptorArray = + _interceptors.FindAll(delegate(TypeInterceptor i) { return i.MatchesType(type); }).ToArray(); + _analyzedInterceptors.Add(type, new CompoundInterceptor(interceptorArray)); + } + } + + return _analyzedInterceptors[type]; + } + + public InstanceInterceptor[] FindInterceptors(Type type) + { + return FindInterceptor(type).Interceptors; + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Interceptors/Interceptors.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/Interceptors.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/Interceptors.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,6 @@ +namespace StructureMap.Interceptors +{ + public delegate T EnrichmentHandler<T>(T target); + + public delegate void StartupHandler<T>(T target); +} Added: trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,10 @@ +namespace StructureMap.Interceptors +{ + public class NulloInterceptor : InstanceInterceptor + { + public object Process(object target) + { + return target; + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,19 @@ +namespace StructureMap.Interceptors +{ + public class StartupInterceptor<T> : InstanceInterceptor + { + private readonly StartupHandler<T> _handler; + + public StartupInterceptor(StartupHandler<T> handler) + { + _handler = handler; + } + + + public object Process(object target) + { + _handler((T)target); + return target; + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Interceptors/TypeInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/TypeInterceptor.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/TypeInterceptor.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,9 @@ +using System; + +namespace StructureMap.Interceptors +{ + public interface TypeInterceptor : InstanceInterceptor + { + bool MatchesType(Type type); + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-01-14 03:57:47 UTC (rev 53) @@ -335,7 +335,6 @@ <SubType>Code</SubType> </Compile> <Compile Include="ConstructorMemento.cs" /> - <Compile Include="Delegates.cs" /> <Compile Include="DeploymentTasks\DeploymentConfiguration.cs"> <SubType>Code</SubType> </Compile> @@ -471,6 +470,8 @@ <Compile Include="Interceptors\CacheInterceptor.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Interceptors\CompoundInterceptor.cs" /> + <Compile Include="Interceptors\EnrichmentInterceptor.cs" /> <Compile Include="Interceptors\HttpContextItemInterceptor.cs"> <SubType>Code</SubType> </Compile> @@ -483,15 +484,21 @@ <Compile Include="Interceptors\InstanceFactoryInterceptor.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Interceptors\InstanceInterceptor.cs" /> <Compile Include="Interceptors\InterceptorChainBuilder.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Interceptors\InterceptorLibrary.cs" /> + <Compile Include="Interceptors\Interceptors.cs" /> + <Compile Include="Interceptors\NulloInterceptor.cs" /> <Compile Include="Interceptors\SingletonInterceptor.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Interceptors\StartupInterceptor.cs" /> <Compile Include="Interceptors\ThreadLocalStorageInterceptor.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Interceptors\TypeInterceptor.cs" /> <Compile Include="IPluginGraphSource.cs" /> <Compile Include="MementoSource.cs"> <SubType>Code</SubType> Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -1,5 +1,6 @@ using NUnit.Framework; using StructureMap.Graph; +using StructureMap.Interceptors; using StructureMap.Source; using StructureMap.Testing.Widget; using StructureMap.Testing.Widget2; Added: trunk/Source/StructureMap.Testing/Container/Interceptors/CompoundInterceptorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Interceptors/CompoundInterceptorTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Container/Interceptors/CompoundInterceptorTester.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,46 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Container.Interceptors +{ + [TestFixture] + public class CompoundInterceptorTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + } + + #endregion + + [Test] + public void CallAllTheInterceptors() + { + MockRepository mocks = new MockRepository(); + InstanceInterceptor interceptor1 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor2 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor3 = mocks.CreateMock<InstanceInterceptor>(); + InstanceInterceptor interceptor4 = mocks.CreateMock<InstanceInterceptor>(); + + Expect.Call(interceptor1.Process("0")).Return("1"); + Expect.Call(interceptor2.Process("1")).Return("2"); + Expect.Call(interceptor3.Process("2")).Return("3"); + Expect.Call(interceptor4.Process("3")).Return("4"); + + mocks.ReplayAll(); + CompoundInterceptor compoundInterceptor = new CompoundInterceptor(new InstanceInterceptor[] + { + interceptor1, + interceptor2, + interceptor3, + interceptor4 + }); + + Assert.AreEqual("4", compoundInterceptor.Process("0")); + mocks.VerifyAll(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Container/Interceptors/InterceptorLibraryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Interceptors/InterceptorLibraryTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Container/Interceptors/InterceptorLibraryTester.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,122 @@ +using System; +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Container.Interceptors +{ + [TestFixture] + public class InterceptorLibraryTester + { + private MockTypeInterceptor _interceptor1; + private MockTypeInterceptor _interceptor2; + private MockTypeInterceptor _interceptor3; + private MockTypeInterceptor _interceptor4; + private InterceptorLibrary _library; + + [SetUp] + public void SetUp() + { + _interceptor1 = new MockTypeInterceptor(typeof(string)); + _interceptor2 = new MockTypeInterceptor(typeof(int), typeof(double)); + _interceptor3 = new MockTypeInterceptor(typeof(string), typeof(bool)); + _interceptor4 = new MockTypeInterceptor(typeof(string), typeof(double)); + + _library = new InterceptorLibrary(); + _library.AddInterceptor(_interceptor1); + _library.AddInterceptor(_interceptor2); + _library.AddInterceptor(_interceptor3); + _library.AddInterceptor(_interceptor4); + } + + [Test] + public void Find_All_Of_The_Interceptors_For_A_Type_On_The_First_Pass() + { + Assert.AreEqual(new TypeInterceptor[]{_interceptor1, _interceptor3, _interceptor4}, _library.FindInterceptors(typeof(string))); + Assert.AreEqual(new TypeInterceptor[]{_interceptor2, _interceptor4}, _library.FindInterceptors(typeof(double))); + Assert.AreEqual(new TypeInterceptor[]{_interceptor2}, _library.FindInterceptors(typeof(int))); + Assert.AreEqual(new TypeInterceptor[]{_interceptor3}, _library.FindInterceptors(typeof(bool))); + } + + [Test] + public void Find_CompoundInterceptor_For_A_Type_On_The_First_Pass() + { + Assert.AreEqual(new TypeInterceptor[] { _interceptor1, _interceptor3, _interceptor4 }, _library.FindInterceptor(typeof(string)).Interceptors); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2, _interceptor4 }, _library.FindInterceptor(typeof(double)).Interceptors); + } + + [Test] + public void Find_All_Of_The_Interceptors_For_A_Type_On_Multiple_Passes() + { + Assert.AreEqual(new TypeInterceptor[] { _interceptor1, _interceptor3, _interceptor4 }, _library.FindInterceptors(typeof(string))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2, _interceptor4 }, _library.FindInterceptors(typeof(double))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2 }, _library.FindInterceptors(typeof(int))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor3 }, _library.FindInterceptors(typeof(bool))); + + Assert.AreEqual(new TypeInterceptor[] { _interceptor1, _interceptor3, _interceptor4 }, _library.FindInterceptors(typeof(string))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2, _interceptor4 }, _library.FindInterceptors(typeof(double))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2 }, _library.FindInterceptors(typeof(int))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor3 }, _library.FindInterceptors(typeof(bool))); + + Assert.AreEqual(new TypeInterceptor[] { _interceptor1, _interceptor3, _interceptor4 }, _library.FindInterceptors(typeof(string))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2, _interceptor4 }, _library.FindInterceptors(typeof(double))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2 }, _library.FindInterceptors(typeof(int))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor3 }, _library.FindInterceptors(typeof(bool))); + + Assert.AreEqual(new TypeInterceptor[] { _interceptor1, _interceptor3, _interceptor4 }, _library.FindInterceptors(typeof(string))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2, _interceptor4 }, _library.FindInterceptors(typeof(double))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor2 }, _library.FindInterceptors(typeof(int))); + Assert.AreEqual(new TypeInterceptor[] { _interceptor3 }, _library.FindInterceptors(typeof(bool))); + } + + + + [Test] + public void When_Interceptors_Are_Requested_For_A_Type_For_The_First_Time_The_Library_Will_Scan_All_The_TypeInterceptors() + { + MockRepository mocks = new MockRepository(); + TypeInterceptor interceptor1 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor2 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor3 = mocks.CreateMock<TypeInterceptor>(); + + _library.AddInterceptor(interceptor1); + _library.AddInterceptor(interceptor2); + _library.AddInterceptor(interceptor3); + + Type type = typeof (string); + Expect.Call(interceptor1.MatchesType(type)).Return(true); + Expect.Call(interceptor2.MatchesType(type)).Return(true); + Expect.Call(interceptor3.MatchesType(type)).Return(true); + + mocks.ReplayAll(); + _library.FindInterceptors(type); + mocks.VerifyAll(); + } + + [Test] + public void When_Interceptors_Are_Requested_For_The_Second_Time_The_Library_Will_NOT_Scan_The_Interceptors_Again() + { + MockRepository mocks = new MockRepository(); + TypeInterceptor interceptor1 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor2 = mocks.CreateMock<TypeInterceptor>(); + TypeInterceptor interceptor3 = mocks.CreateMock<TypeInterceptor>(); + + _library.AddInterceptor(interceptor1); + _library.AddInterceptor(interceptor2); + _library.AddInterceptor(interceptor3); + + Type type = typeof(string); + Expect.Call(interceptor1.MatchesType(type)).Return(true); + Expect.Call(interceptor2.MatchesType(type)).Return(true); + Expect.Call(interceptor3.MatchesType(type)).Return(true); + + mocks.ReplayAll(); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + _library.FindInterceptors(type); + mocks.VerifyAll(); + } + } +} Added: trunk/Source/StructureMap.Testing/Container/Interceptors/MockTypeInterceptor.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Interceptors/MockTypeInterceptor.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Container/Interceptors/MockTypeInterceptor.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using StructureMap.Interceptors; + +namespace StructureMap.Testing.Container.Interceptors +{ + + + public class MockTypeInterceptor : TypeInterceptor + { + private readonly List<Type> _types = new List<Type>(); + private Dictionary<Type, InstanceInterceptor> _innerInterceptors = new Dictionary<Type, InstanceInterceptor>(); + + public MockTypeInterceptor(params Type[] types) + { + _types.AddRange(types); + } + + public void SetToMatch<T>() + { + _types.Add(typeof(T)); + } + + public bool MatchesType(Type type) + { + return _types.Contains(type); + } + + public object Process(object target) + { + return _innerInterceptors[target.GetType()].Process(target); + } + + public void AddHandler<T>(InterceptionDelegate<T> handler) + { + _types.Add(typeof(T)); + _innerInterceptors.Add(typeof(T), new CommonInterceptor<T>(handler)); + } + + public delegate object InterceptionDelegate<T>(T target); + public class CommonInterceptor<T> : InstanceInterceptor + { + private readonly InterceptionDelegate<T> _handler; + + public CommonInterceptor(InterceptionDelegate<T> handler) + { + _handler = handler; + } + + public object Process(object target) + { + return _handler((T) target); + } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -0,0 +1,108 @@ +using System; +using NUnit.Framework; +using StructureMap.Configuration.DSL; + +namespace StructureMap.Testing.Container.Interceptors +{ + [TestFixture] + public class TypeInterceptionTester : Registry + { + private Registry registry; + private IInstanceManager manager; + + [SetUp] + public void SetUp() + { + manager = null; + + // TODO: Want a shorthand for Type + registry = new Registry(); + registry.ForRequestedType<IAnInterfaceOfSomeSort>() + .AddInstance(Instance<IAnInterfaceOfSomeSort>().UsingConcreteType<RedSomething>().WithName("Red")) + .AddInstance(Instance<IAnInterfaceOfSomeSort>().UsingConcreteType<GreenSomething>().WithName("Green")) + .AddInstance(Instance<IAnInterfaceOfSomeSort>().UsingConcreteType<BlueSomething>().WithName("Blue")); + + } + + [Test] + public void If_An_Interceptor_Is_Registered_At_The_PluginGraph_It_Will_Be_Used_To_Construct_An_Instance() + { + MockTypeInterceptor interceptor = new MockTypeInterceptor(); + interceptor.AddHandler<RedSomething>( + delegate(RedSomething something) { return new WrappedSomething(something); }); + + interceptor.AddHandler<GreenSomething>( + delegate(GreenSomething something) { return new WrappedSomething2(something); }); + + registry.RegisterInterceptor(interceptor); + + assertThisIsType<BlueSomething>("Blue"); + assertThatThisIsWrappedSomething<WrappedSomething, RedSomething>("Red"); + assertThatThisIsWrappedSomething<WrappedSomething2, GreenSomething>("Green"); + } + + [Test] + public void Register_A_Type_Interceptor_By_The_Fluent_Interface() + { + registry.IfTypeMatches(delegate(Type type) { return type.Equals(typeof(BlueSomething)); }) + .InterceptWith(delegate(object rawInstance) + { + return new WrappedSomething((IAnInterfaceOfSomeSort)rawInstance); + }); + + assertThisIsType<RedSomething>("Red"); + assertThisIsType<GreenSomething>("Green"); + assertThatThisIsWrappedSomething<WrappedSomething, BlueSomething>("Blue"); + } + + private void assertThisIsType<T>(string name) + { + if (manager == null) + { + manager = registry.BuildInstanceManager(); + } + + Assert.IsInstanceOfType(typeof(T), manager.CreateInstance<IAnInterfaceOfSomeSort>(name)); + } + + private void assertThatThisIsWrappedSomething<OUTERTYPE, INNERTYPE>(string name) where OUTERTYPE : WrappedSomething + { + if (manager == null) + { + manager = registry.BuildInstanceManager(); + } + + OUTERTYPE something = (OUTERTYPE) manager.CreateInstance<IAnInterfaceOfSomeSort>(name); + Assert.IsInstanceOfType(typeof(INNERTYPE), something.Inner); + } + + public interface IAnInterfaceOfSomeSort{} + + public class RedSomething : IAnInterfaceOfSomeSort {} + public class GreenSomething : IAnInterfaceOfSomeSort {} + public class BlueSomething : IAnInterfaceOfSomeSort {} + + public class WrappedSomething : IAnInterfaceOfSomeSort + { + private readonly IAnInterfaceOfSomeSort _inner; + + public WrappedSomething(IAnInterfaceOfSomeSort inner) + { + _inner = inner; + } + + + public IAnInterfaceOfSomeSort Inner + { + get { return _inner; } + } + } + + public class WrappedSomething2 : WrappedSomething + { + public WrappedSomething2(IAnInterfaceOfSomeSort inner) : base(inner) + { + } + } + } +} Modified: trunk/Source/StructureMap.Testing/InstanceMementoTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/InstanceMementoTester.cs 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap.Testing/InstanceMementoTester.cs 2008-01-14 03:57:47 UTC (rev 53) @@ -1,5 +1,6 @@ using NUnit.Framework; using Rhino.Mocks; +using StructureMap.Interceptors; using StructureMap.Testing.Widget3; namespace StructureMap.Testing Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-01-12 03:21:32 UTC (rev 52) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-01-14 03:57:47 UTC (rev 53) @@ -313,15 +313,19 @@ <Compile Include="Container\IntegratedTester.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Container\Interceptors\CompoundInterceptorTester.cs" /> <Compile Include="Container\Interceptors\InteceptorChainBuilderTester.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Container\Interceptors\InterceptorLibraryTester.cs" /> + <Compile Include="Container\Interceptors\MockTypeInterceptor.cs" /> <Compile Include="Container\Interceptors\SingletonInterceptorTester.cs"> <SubType>Code</SubType> </Compile> <Compile Include="Container\Interceptors\ThreadLocalStorageInterceptorTester.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Container\Interceptors\TypeInterceptionTester.cs" /> <Compile Include="Container\MockingTester.cs"> <SubType>Code</SubType> </Compile> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-01-14 04:18:10
|
Revision: 54 http://structuremap.svn.sourceforge.net/structuremap/?rev=54&view=rev Author: jeremydmiller Date: 2008-01-13 20:18:06 -0800 (Sun, 13 Jan 2008) Log Message: ----------- moving code around Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/Expressions/ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/ChildArrayExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,50 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + public class ChildArrayExpression<PLUGINTYPE> : IExpression + { + private readonly InstanceExpression _parent; + private readonly MemoryInstanceMemento _memento; + private readonly string _propertyName; + private IMementoBuilder[] _builders; + private Type _pluginType = typeof (PLUGINTYPE); + + public ChildArrayExpression(InstanceExpression parent, MemoryInstanceMemento memento, string propertyName) + { + _parent = parent; + _memento = memento; + _propertyName = propertyName; + + _pluginType = typeof (PLUGINTYPE).GetElementType(); + } + + void IExpression.Configure(PluginGraph graph) + { + PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); + InstanceMemento[] childMementos = new InstanceMemento[_builders.Length]; + for (int i = 0; i < _builders.Length; i++) + { + InstanceMemento memento = processMementoBuilder(_builders[i], family, graph); + childMementos[i] = memento; + } + + _memento.AddChildArray(_propertyName, childMementos); + } + + private InstanceMemento processMementoBuilder(IMementoBuilder builder, PluginFamily family, PluginGraph graph) + { + builder.ValidatePluggability(_pluginType); + builder.Configure(graph); + return builder.BuildMemento(family); + } + + public InstanceExpression Contains(params IMementoBuilder[] builders) + { + _builders = builders; + + return _parent; + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + /// <summary> + /// Part of the Fluent Interface, represents a nonprimitive argument to a + /// constructure function + /// </summary> + public class ChildInstanceExpression : IExpression + { + private readonly InstanceExpression _instance; + private readonly MemoryInstanceMemento _memento; + private readonly string _propertyName; + private Type _childType; + private List<IExpression> _children = new List<IExpression>(); + private IMementoBuilder _builder; + + + public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName) + { + _instance = instance; + _memento = memento; + _propertyName = propertyName; + } + + public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName, + Type childType) + : this(instance, memento, propertyName) + { + _childType = childType; + } + + /// <summary> + /// Use a previously configured and named instance for the child + /// </summary> + /// <param name="instanceKey"></param> + /// <returns></returns> + public InstanceExpression IsNamedInstance(string instanceKey) + { + MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey); + _memento.AddChild(_propertyName, child); + + return _instance; + } + + /// <summary> + /// Start the definition of a child instance by defining the concrete type + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public InstanceExpression IsConcreteType<T>() + { + Type pluggedType = typeof (T); + ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType); + + + InstanceExpression child = new InstanceExpression(_childType); + child.TypeExpression().UsingConcreteType<T>(); + _children.Add(child); + + _builder = child; + + return _instance; + } + + + void IExpression.Configure(PluginGraph graph) + { + if (_childType == null) + { + return; + } + + PluginFamily family = graph.LocateOrCreateFamilyForType(_childType); + if (_builder != null) + { + InstanceMemento childMemento = _builder.BuildMemento(family); + _memento.AddChild(_propertyName, childMemento); + } + + foreach (IExpression child in _children) + { + child.Configure(graph); + } + } + + internal Type ChildType + { + set { _childType = value; } + } + + /// <summary> + /// Registers a configured instance to use as the argument to the parent's + /// constructor + /// </summary> + /// <param name="child"></param> + /// <returns></returns> + public InstanceExpression Is(InstanceExpression child) + { + if (child.PluggedType != null && _childType != null) + { + ExpressionValidator.ValidatePluggabilityOf(child.PluggedType).IntoPluginType(_childType); + } + + _children.Add(child); + MemoryInstanceMemento childMemento = + MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey); + _memento.AddChild(_propertyName, childMemento); + + return _instance; + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/ConstructorExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ConstructorExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,49 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + public class ConstructorExpression<PLUGINTYPE> : MementoBuilder<ConstructorExpression<PLUGINTYPE>> + { + private ConstructorMemento<PLUGINTYPE> _memento; + + public ConstructorExpression(BuildObjectDelegate<PLUGINTYPE> builder) + : base(typeof (PLUGINTYPE)) + { + _memento.Builder = builder; + } + + + protected override InstanceMemento memento + { + get { return _memento; } + } + + protected override ConstructorExpression<PLUGINTYPE> thisInstance + { + get { return this; } + } + + protected override void configureMemento(PluginFamily family) + { + } + + protected override void validate() + { + } + + protected override void buildMemento() + { + _memento = new ConstructorMemento<PLUGINTYPE>(); + } + + public override void ValidatePluggability(Type pluginType) + { + if (!pluginType.Equals(typeof (PLUGINTYPE))) + { + throw new StructureMapException(306, + typeof (PLUGINTYPE).FullName, pluginType.FullName); + } + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,148 @@ +using System; +using System.Collections.Generic; +using StructureMap.Attributes; +using StructureMap.Graph; +using StructureMap.Interceptors; + +namespace StructureMap.Configuration.DSL.Expressions +{ + public delegate void AlterPluginFamilyDelegate(PluginFamily family); + + /// <summary> + /// Represents the parameters for creating instances of a given Type + /// </summary> + public class CreatePluginFamilyExpression<PLUGINTYPE> : IExpression + { + private readonly Type _pluginType; + private readonly List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>(); + private readonly InstanceScope _scope = InstanceScope.PerRequest; + private readonly List<IExpression> _children = new List<IExpression>(); + + public CreatePluginFamilyExpression() + { + _pluginType = typeof (PLUGINTYPE); + } + + void IExpression.Configure(PluginGraph graph) + { + PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); + InterceptorChainBuilder builder = new InterceptorChainBuilder(); + family.InterceptionChain = builder.Build(_scope); + + foreach (IExpression child in _children) + { + child.Configure(graph); + } + + foreach (AlterPluginFamilyDelegate alteration in _alterations) + { + alteration(family); + } + + graph.PluginFamilies.Add(family); + + AssemblyGraph assembly = new AssemblyGraph(_pluginType.Assembly); + graph.Assemblies.Add(assembly); + } + + /// <summary> + /// Sets the default instance of a Type to the definition represented by builder + /// </summary> + /// <param name="builder"></param> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(IMementoBuilder builder) + { + builder.ValidatePluggability(_pluginType); + + _children.Add(builder); + _alterations.Add(delegate(PluginFamily family) + { + InstanceMemento memento = builder.BuildMemento(family); + family.Source.AddExternalMemento(memento); + family.DefaultInstanceKey = memento.InstanceKey; + }); + + return this; + } + + public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(IMementoBuilder builder) + { + builder.ValidatePluggability(_pluginType); + + _children.Add(builder); + _alterations.Add(delegate(PluginFamily family) + { + InstanceMemento memento = builder.BuildMemento(family); + family.Source.AddExternalMemento(memento); + }); + + return this; + } + + /// <summary> + /// Convenience method that sets the default concrete type of the PluginType. Type T + /// can only accept types that do not have any primitive constructor arguments. + /// StructureMap has to know how to construct all of the constructor argument types. + /// </summary> + /// <typeparam name="CONCRETETYPE"></typeparam> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIsConcreteType<CONCRETETYPE>() + where CONCRETETYPE : PLUGINTYPE + { + ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(_pluginType); + + _alterations.Add(delegate(PluginFamily family) + { + Plugin plugin = family.Plugins.FindOrCreate(typeof (CONCRETETYPE)); + family.DefaultInstanceKey = plugin.ConcreteKey; + }); + + return this; + } + + /// <summary> + /// Sets the object creation of the instances of the PluginType. For example: PerRequest, + /// Singleton, ThreadLocal, HttpContext, or Hybrid + /// </summary> + /// <param name="scope"></param> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> CacheBy(InstanceScope scope) + { + _alterations.Add(delegate(PluginFamily family) + { + InterceptorChainBuilder builder = new InterceptorChainBuilder(); + family.InterceptionChain = builder.Build(scope); + }); + + return this; + } + + /// <summary> + /// Convenience method to mark a PluginFamily as a Singleton + /// </summary> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> AsSingletons() + { + _alterations.Add( + delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(new SingletonInterceptor()); }); + return this; + } + + + public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(StartupHandler<PLUGINTYPE> handler) + { + _alterations.Add( + delegate(PluginFamily family) { family.InstanceInterceptor = new StartupInterceptor<PLUGINTYPE>(handler); }); + + return this; + } + + public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(EnrichmentHandler<PLUGINTYPE> handler) + { + _alterations.Add( + delegate(PluginFamily family) { family.InstanceInterceptor = new EnrichmentInterceptor<PLUGINTYPE>(handler); }); + + return this; + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/IMementoBuilder.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,14 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + public interface IMementoBuilder : IExpression + { + InstanceMemento BuildMemento(PluginFamily family); + InstanceMemento BuildMemento(PluginGraph graph); + void SetInstanceName(string instanceKey); + + void ValidatePluggability(Type pluginType); + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,70 @@ +using System; +using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + /// <summary> + /// Use to express the instance of a PluginType for the containing Profile + /// </summary> + public class InstanceDefaultExpression + { + private readonly Type _pluginType; + private readonly ProfileExpression _parent; + private string _instanceKey = string.Empty; + private IMementoBuilder _mementoBuilder; + + public InstanceDefaultExpression(Type pluginType, ProfileExpression parent) + { + _pluginType = pluginType; + _parent = parent; + } + + /// <summary> + /// Use a named, preconfigured instance as the default instance for this profile + /// </summary> + /// <param name="instanceKey"></param> + /// <returns></returns> + public ProfileExpression UseNamedInstance(string instanceKey) + { + _instanceKey = instanceKey; + return _parent; + } + + internal void Configure(Profile profile, PluginGraph graph) + { + if (!string.IsNullOrEmpty(_instanceKey)) + { + InstanceDefault instanceDefault = new InstanceDefault(_pluginType, _instanceKey); + profile.AddOverride(instanceDefault); + } + else if (_mementoBuilder != null) + { + string defaultKey = Profile.InstanceKeyForProfile(profile.ProfileName); + InstanceMemento memento = _mementoBuilder.BuildMemento(graph); + memento.InstanceKey = defaultKey; + + graph.PluginFamilies[_pluginType].AddInstance(memento); + + InstanceDefault instanceDefault = new InstanceDefault(_pluginType, defaultKey); + profile.AddOverride(instanceDefault); + } + else + { + throw new StructureMapException(304, TypePath.GetAssemblyQualifiedName(_pluginType)); + } + } + + /// <summary> + /// Define the default instance of the PluginType for the containing Profile + /// </summary> + /// <param name="mementoBuilder"></param> + /// <returns></returns> + public ProfileExpression Use(IMementoBuilder mementoBuilder) + { + _mementoBuilder = mementoBuilder; + + return _parent; + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,50 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + /// <summary> + /// Small helper class to represent an object to be plugged into a PluginType as is + /// </summary> + /// <typeparam name="T"></typeparam> + public class LiteralExpression<T> : MementoBuilder<LiteralExpression<T>> + { + private readonly T _target; + private LiteralMemento _memento; + + public LiteralExpression(T target) : base(typeof (T)) + { + _target = target; + } + + + protected override InstanceMemento memento + { + get { return _memento; } + } + + protected override LiteralExpression<T> thisInstance + { + get { return this; } + } + + protected override void configureMemento(PluginFamily family) + { + _memento.Instance = _target; + } + + protected override void validate() + { + } + + protected override void buildMemento() + { + _memento = new LiteralMemento(null); + } + + public override void ValidatePluggability(Type pluginType) + { + ExpressionValidator.ValidatePluggabilityOf(_target.GetType()).IntoPluginType(pluginType); + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,67 @@ +using System; + +namespace StructureMap.Configuration.DSL.Expressions +{ + public class LiteralMemento : InstanceMemento + { + private object _instance; + + public LiteralMemento(object instance) + { + _instance = instance; + InstanceKey = Guid.NewGuid().ToString(); + } + + public LiteralMemento Named(string name) + { + InstanceKey = name; + return this; + } + + public object Instance + { + get { return _instance; } + set { _instance = value; } + } + + protected override string innerConcreteKey + { + get { throw new NotImplementedException(); } + } + + protected override string innerInstanceKey + { + get { throw new NotImplementedException(); } + } + + protected override string getPropertyValue(string Key) + { + throw new NotImplementedException(); + } + + protected override InstanceMemento getChild(string Key) + { + throw new NotImplementedException(); + } + + public override InstanceMemento[] GetChildrenArray(string Key) + { + throw new NotImplementedException(); + } + + public override bool IsReference + { + get { return false; } + } + + public override string ReferenceKey + { + get { throw new NotImplementedException(); } + } + + protected override object buildInstance(IInstanceCreator creator) + { + return _instance; + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,45 @@ +using System.Configuration; + +namespace StructureMap.Configuration.DSL.Expressions +{ + /// <summary> + /// Defines the value of a primitive argument to a constructur argument + /// </summary> + public class PropertyExpression + { + private readonly InstanceExpression _instance; + private readonly MemoryInstanceMemento _memento; + private readonly string _propertyName; + + public PropertyExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName) + { + _instance = instance; + _memento = memento; + _propertyName = propertyName; + } + + /// <summary> + /// Sets the value of the constructor argument + /// </summary> + /// <param name="propertyValue"></param> + /// <returns></returns> + public InstanceExpression EqualTo(object propertyValue) + { + _memento.SetProperty(_propertyName, propertyValue.ToString()); + return _instance; + } + + /// <summary> + /// Sets the value of the constructor argument to the key/value in the + /// AppSettings + /// </summary> + /// <param name="appSettingKey"></param> + /// <returns></returns> + public InstanceExpression EqualToAppSetting(string appSettingKey) + { + string propertyValue = ConfigurationManager.AppSettings[appSettingKey]; + _memento.SetProperty(_propertyName, propertyValue); + return _instance; + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,50 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + /// <summary> + /// Sets up a Prototype instance of type T + /// </summary> + /// <typeparam name="T"></typeparam> + public class PrototypeExpression<T> : MementoBuilder<PrototypeExpression<T>> + { + private readonly T _prototype; + private PrototypeMemento _memento; + + public PrototypeExpression(T prototype) : base(typeof (T)) + { + _prototype = prototype; + } + + protected override InstanceMemento memento + { + get { return _memento; } + } + + protected override PrototypeExpression<T> thisInstance + { + get { return this; } + } + + protected override void configureMemento(PluginFamily family) + { + _memento.Prototype = (ICloneable) _prototype; + } + + protected override void validate() + { + // TODO + } + + protected override void buildMemento() + { + _memento = new PrototypeMemento(string.Empty, (ICloneable) _prototype); + } + + public override void ValidatePluggability(Type pluginType) + { + ExpressionValidator.ValidatePluggabilityOf(_prototype.GetType()).IntoPluginType(pluginType); + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; +using System.Threading; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + /// <summary> + /// Expression that directs StructureMap to scan the named assemblies + /// for [PluginFamily] and [Plugin] attributes + /// </summary> + public class ScanAssembliesExpression : IExpression + { + private List<AssemblyGraph> _assemblies = new List<AssemblyGraph>(); + + void IExpression.Configure(PluginGraph graph) + { + foreach (AssemblyGraph assembly in _assemblies) + { + graph.Assemblies.Add(assembly); + } + } + + public ScanAssembliesExpression IncludeTheCallingAssembly() + { + Assembly callingAssembly = findTheCallingAssembly(); + + if (callingAssembly != null) + { + _assemblies.Add(new AssemblyGraph(callingAssembly)); + } + + return this; + } + + private static Assembly findTheCallingAssembly() + { + StackTrace trace = new StackTrace(Thread.CurrentThread, false); + + Assembly thisAssembly = Assembly.GetExecutingAssembly(); + Assembly callingAssembly = null; + for (int i = 0; i < trace.FrameCount; i++) + { + StackFrame frame = trace.GetFrame(i); + Assembly assembly = frame.GetMethod().DeclaringType.Assembly; + if (assembly != thisAssembly) + { + callingAssembly = assembly; + break; + } + } + return callingAssembly; + } + + public ScanAssembliesExpression IncludeAssemblyContainingType<T>() + { + _assemblies.Add(AssemblyGraph.ContainingType<T>()); + + return this; + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -0,0 +1,45 @@ +using System; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + public class UserControlExpression : MementoBuilder<UserControlExpression> + { + private UserControlMemento _memento; + + public UserControlExpression(Type pluginType, string url) : base(pluginType) + { + _memento.Url = url; + } + + protected override InstanceMemento memento + { + get { return _memento; } + } + + protected override UserControlExpression thisInstance + { + get { return this; } + } + + protected override void configureMemento(PluginFamily family) + { + // no-op + } + + protected override void validate() + { + // no-op + } + + protected override void buildMemento() + { + _memento = new UserControlMemento(); + } + + public override void ValidatePluggability(Type pluginType) + { + // no-op + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; namespace StructureMap.Configuration.DSL Modified: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Interceptors; Modified: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,4 +1,5 @@ using System.Collections.Generic; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; namespace StructureMap.Configuration.DSL Modified: trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; namespace StructureMap.Configuration.DSL Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Interceptors; Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Reflection; -using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Emitting; using StructureMap.Graph; using StructureMap.Interceptors; Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,7 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; -using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Exceptions; using StructureMap.Graph; using StructureMap.Interceptors; Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Security.Permissions; using System.Text; -using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; namespace StructureMap Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-01-14 04:18:06 UTC (rev 54) @@ -209,26 +209,26 @@ <Compile Include="Configuration\DiagnosticGraphBuilder.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Configuration\DSL\ChildArrayExpression.cs" /> - <Compile Include="Configuration\DSL\ChildInstanceExpression.cs" /> - <Compile Include="Configuration\DSL\ConstructorExpression.cs" /> - <Compile Include="Configuration\DSL\CreatePluginFamilyExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\ChildArrayExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\ChildInstanceExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\ConstructorExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\CreatePluginFamilyExpression.cs" /> <Compile Include="Configuration\DSL\ExpressionValidator.cs" /> <Compile Include="Configuration\DSL\IExpression.cs" /> - <Compile Include="Configuration\DSL\IMementoBuilder.cs" /> - <Compile Include="Configuration\DSL\InstanceDefaultExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\IMementoBuilder.cs" /> + <Compile Include="Configuration\DSL\Expressions\InstanceDefaultExpression.cs" /> <Compile Include="Configuration\DSL\InstanceExpression.cs" /> - <Compile Include="Configuration\DSL\LiteralExpression.cs" /> - <Compile Include="Configuration\DSL\LiteralMemento.cs" /> + <Compile Include="Configuration\DSL\Expressions\LiteralExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\LiteralMemento.cs" /> <Compile Include="Configuration\DSL\MementoBuilder.cs" /> <Compile Include="Configuration\DSL\ProfileExpression.cs" /> - <Compile Include="Configuration\DSL\PropertyExpression.cs" /> - <Compile Include="Configuration\DSL\PrototypeExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\PropertyExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\PrototypeExpression.cs" /> <Compile Include="Configuration\DSL\PrototypeMemento.cs" /> <Compile Include="Configuration\DSL\ReferenceMementoBuilder.cs" /> <Compile Include="Configuration\DSL\Registry.cs" /> - <Compile Include="Configuration\DSL\ScanAssembliesExpression.cs" /> - <Compile Include="Configuration\DSL\UserControlExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\ScanAssembliesExpression.cs" /> + <Compile Include="Configuration\DSL\Expressions\UserControlExpression.cs" /> <Compile Include="Configuration\FamilyParser.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -4,6 +4,7 @@ using System.Xml; using StructureMap.Configuration; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Verification; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,5 +1,6 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Testing.Widget4; namespace StructureMap.Testing.Configuration.DSL Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,6 +1,7 @@ using NUnit.Framework; using StructureMap.Attributes; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,5 +1,6 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,6 +1,7 @@ using NUnit.Framework; using Rhino.Mocks; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Testing.Container; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -1,6 +1,6 @@ using NUnit.Framework; using StructureMap.Configuration; -using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; namespace StructureMap.Testing.Configuration.DSL Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-01-14 03:57:47 UTC (rev 53) +++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-01-14 04:18:06 UTC (rev 54) @@ -3,7 +3,7 @@ using System.Collections.Generic; using NUnit.Framework; using Rhino.Mocks; -using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Testing.Widget3; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-01-14 04:24:38
|
Revision: 55 http://structuremap.svn.sourceforge.net/structuremap/?rev=55&view=rev Author: jeremydmiller Date: 2008-01-13 20:24:37 -0800 (Sun, 13 Jan 2008) Log Message: ----------- consolidating namespaces Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs trunk/Source/StructureMap/ConstructorMemento.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap.Testing/Client/Controllers/TreeBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/FamilyTokenTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/InstanceTokenTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/MockInterceptor.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/MockMementoSource.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildArrayPropertyTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildPropertyTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/EnumerationPropertyTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/PrimitivePropertyTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/PropertyDefinitionTester.cs trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs trunk/Source/StructureMap.Testing.Widget/Rule.cs Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/Mementos/ 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 Removed Paths: ------------- trunk/Source/StructureMap/MemoryInstanceMemento.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap.Configuration.DSL.Expressions Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap.Configuration.DSL.Expressions Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs (from rev 54, trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -0,0 +1,193 @@ +using System; +using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + /// <summary> + /// Used to define an Instance in code + /// </summary> + public class InstanceExpression : MementoBuilder<InstanceExpression> + { + private Type _pluggedType; + private MemoryInstanceMemento _memento; + + public InstanceExpression(Type pluginType) : base(pluginType) + { + } + + + internal Type PluggedType + { + get { return _pluggedType; } + } + + protected override void buildMemento() + { + _memento = new MemoryInstanceMemento(); + } + + + protected override InstanceMemento memento + { + get { return _memento; } + } + + protected override InstanceExpression thisInstance + { + get { return this; } + } + + protected override void configureMemento(PluginFamily family) + { + Plugin plugin = _pluggedType == null + ? family.Plugins[_memento.ConcreteKey] + : family.Plugins.FindOrCreate(_pluggedType); + + _memento.ConcreteKey = plugin.ConcreteKey; + } + + protected override void validate() + { + if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey)) + { + throw new StructureMapException(301, _memento.InstanceKey, + TypePath.GetAssemblyQualifiedName(_pluginType)); + } + } + + + /// <summary> + /// Start the definition of a primitive argument to a constructor argument + /// </summary> + /// <param name="propertyName"></param> + /// <returns></returns> + public PropertyExpression WithProperty(string propertyName) + { + return new PropertyExpression(this, _memento, propertyName); + } + + /// <summary> + /// Starts the definition of a child instance specifying the argument name + /// in the case of a constructor function that consumes more than one argument + /// of type T + /// </summary> + /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam> + /// <param name="propertyName"></param> + /// <returns></returns> + public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>(string propertyName) + { + ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName); + addChildExpression(child); + child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); + + return child; + } + + /// <summary> + /// Start the definition of a child instance for type CONSTRUCTORARGUMENTTYPE + /// </summary> + /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam> + /// <returns></returns> + public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>() + { + string propertyName = findPropertyName<CONSTRUCTORARGUMENTTYPE>(); + + ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName); + addChildExpression(child); + child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); + return child; + } + + private string findPropertyName<T>() + { + Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType); + string propertyName = plugin.FindFirstConstructorArgumentOfType<T>(); + + if (string.IsNullOrEmpty(propertyName)) + { + throw new StructureMapException(305, TypePath.GetAssemblyQualifiedName(typeof (T))); + } + + return propertyName; + } + + public override void ValidatePluggability(Type pluginType) + { + if (_pluggedType == null) + { + return; + } + + ExpressionValidator.ValidatePluggabilityOf(_pluggedType).IntoPluginType(pluginType); + } + + internal InstanceTypeExpression TypeExpression() + { + return new InstanceTypeExpression(this); + } + + /// <summary> + /// Helper class to capture the actual concrete type of an Instance + /// </summary> + public class InstanceTypeExpression + { + private readonly InstanceExpression _parent; + + internal InstanceTypeExpression(InstanceExpression parent) + { + _parent = parent; + } + + /// <summary> + /// Use type T for the concrete type of an instance + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public InstanceExpression UsingConcreteType<T>() + { + _parent._pluggedType = typeof (T); + return _parent; + } + + /// <summary> + /// Use a named Plugin type denoted by a [Pluggable("Key")] attribute + /// </summary> + /// <param name="concreteKey"></param> + /// <returns></returns> + public InstanceExpression UsingConcreteTypeNamed(string concreteKey) + { + _parent._memento.ConcreteKey = concreteKey; + return _parent; + } + } + + public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>() + { + validateTypeIsArray<PLUGINTYPE>(); + + string propertyName = findPropertyName<PLUGINTYPE>(); + return ChildArray<PLUGINTYPE>(propertyName); + } + + public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>(string propertyName) + { + validateTypeIsArray<PLUGINTYPE>(); + + ChildArrayExpression<PLUGINTYPE> expression = + new ChildArrayExpression<PLUGINTYPE>(this, _memento, propertyName); + addChildExpression(expression); + + return expression; + } + + private static void validateTypeIsArray<PLUGINTYPE>() + { + if (!typeof (PLUGINTYPE).IsArray) + { + throw new StructureMapException(307); + } + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralExpression.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap.Configuration.DSL.Expressions Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs (from rev 54, trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Graph; +using StructureMap.Interceptors; + +namespace StructureMap.Configuration.DSL.Expressions +{ + public abstract class MementoBuilder<T> : IExpression, IMementoBuilder + { + protected readonly Type _pluginType; + protected List<IExpression> _children = new List<IExpression>(); + private string _instanceKey = null; + + public MementoBuilder(Type pluginType) + { + _pluginType = pluginType; + buildMemento(); + memento.InstanceKey = Guid.NewGuid().ToString(); + } + + void IExpression.Configure(PluginGraph graph) + { + validate(); + PluginFamily family = graph.LocateOrCreateFamilyForType((Type) _pluginType); + configureMemento(family); + + if (!string.IsNullOrEmpty(_instanceKey)) + { + memento.InstanceKey = _instanceKey; + } + + family.Source.AddExternalMemento(memento); + + foreach (IExpression child in _children) + { + child.Configure(graph); + } + } + + protected abstract InstanceMemento memento { get; } + + protected abstract T thisInstance { get; } + + protected abstract void configureMemento(PluginFamily family); + + protected abstract void validate(); + + public T WithName(string instanceKey) + { + memento.InstanceKey = instanceKey; + return thisInstance; + } + + public T OnCreation<TYPE>(StartupHandler<TYPE> handler) + { + StartupInterceptor<TYPE> interceptor = new StartupInterceptor<TYPE>(handler); + memento.Interceptor = interceptor; + + return thisInstance; + } + + public T EnrichWith<TYPE>(EnrichmentHandler<TYPE> handler) + { + EnrichmentInterceptor<TYPE> interceptor = new EnrichmentInterceptor<TYPE>(handler); + memento.Interceptor = interceptor; + + return thisInstance; + } + + public string InstanceKey + { + get { return memento.InstanceKey; } + set { memento.InstanceKey = value; } + } + + internal Type PluginType + { + get { return _pluginType; } + } + + protected abstract void buildMemento(); + + InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family) + { + return buildMementoFromFamily(family); + } + + private InstanceMemento buildMementoFromFamily(PluginFamily family) + { + validate(); + configureMemento(family); + return memento; + } + + + InstanceMemento IMementoBuilder.BuildMemento(PluginGraph graph) + { + PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); + return buildMementoFromFamily(family); + } + + public void SetInstanceName(string instanceKey) + { + _instanceKey = instanceKey; + } + + public abstract void ValidatePluggability(Type pluginType); + + protected void addChildExpression(IExpression expression) + { + _children.Add(expression); + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs (from rev 54, trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Graph; + +namespace StructureMap.Configuration.DSL.Expressions +{ + /// <summary> + /// Expression class to help define a runtime Profile + /// </summary> + public class ProfileExpression : IExpression + { + private readonly string _profileName; + private List<InstanceDefaultExpression> _defaults = new List<InstanceDefaultExpression>(); + + public ProfileExpression(string profileName) + { + _profileName = profileName; + } + + void IExpression.Configure(PluginGraph graph) + { + Profile profile = graph.DefaultManager.GetProfile(_profileName); + if (profile == null) + { + profile = new Profile(_profileName); + graph.DefaultManager.AddProfile(profile); + } + + foreach (InstanceDefaultExpression expression in _defaults) + { + expression.Configure(profile, graph); + } + } + + /// <summary> + /// Starts the definition of the default instance for the containing Profile + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + public InstanceDefaultExpression For<T>() + { + InstanceDefaultExpression defaultExpression = new InstanceDefaultExpression(typeof (T), this); + _defaults.Add(defaultExpression); + + return defaultExpression; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/PropertyExpression.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System.Configuration; +using StructureMap.Configuration.Mementos; namespace StructureMap.Configuration.DSL.Expressions { Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/PrototypeExpression.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap.Configuration.DSL.Expressions Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/UserControlExpression.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap.Configuration.DSL.Expressions Modified: trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,5 +1,6 @@ using System; using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap.Configuration.DSL Copied: trunk/Source/StructureMap/Configuration/Mementos/LiteralMemento.cs (from rev 54, trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/LiteralMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/Mementos/LiteralMemento.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -0,0 +1,67 @@ +using System; + +namespace StructureMap.Configuration.Mementos +{ + public class LiteralMemento : InstanceMemento + { + private object _instance; + + public LiteralMemento(object instance) + { + _instance = instance; + InstanceKey = Guid.NewGuid().ToString(); + } + + public LiteralMemento Named(string name) + { + InstanceKey = name; + return this; + } + + public object Instance + { + get { return _instance; } + set { _instance = value; } + } + + protected override string innerConcreteKey + { + get { throw new NotImplementedException(); } + } + + protected override string innerInstanceKey + { + get { throw new NotImplementedException(); } + } + + protected override string getPropertyValue(string Key) + { + throw new NotImplementedException(); + } + + protected override InstanceMemento getChild(string Key) + { + throw new NotImplementedException(); + } + + public override InstanceMemento[] GetChildrenArray(string Key) + { + throw new NotImplementedException(); + } + + public override bool IsReference + { + get { return false; } + } + + public override string ReferenceKey + { + get { throw new NotImplementedException(); } + } + + protected override object buildInstance(IInstanceCreator creator) + { + return _instance; + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs (from rev 53, trunk/Source/StructureMap/MemoryInstanceMemento.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -0,0 +1,209 @@ +using System.Collections; +using System.Collections.Specialized; +using StructureMap.Graph; + +namespace StructureMap.Configuration.Mementos +{ + public class GenericMemento<T> : MemoryInstanceMemento + { + public GenericMemento(string instanceKey) + : base(Plugin.CreateImplicitPlugin(typeof (T)).ConcreteKey, instanceKey) + { + } + } + + /// <summary> + /// An in-memory implementation of InstanceMemento. + /// </summary> + public class MemoryInstanceMemento : InstanceMemento + { + #region statics + + /// <summary> + /// Creates an instance of MemoryInstanceMemento that represents a reference to another + /// instance. + /// </summary> + /// <param name="referenceKey">The referenced instance key to another instance</param> + /// <returns></returns> + public static MemoryInstanceMemento CreateReferencedInstanceMemento(string referenceKey) + { + MemoryInstanceMemento memento = new MemoryInstanceMemento(); + memento._referenceKey = referenceKey; + memento._isReference = true; + + return memento; + } + + /// <summary> + /// Creates a MemoryInstanceMemento that represents a reference to the default instance + /// of a plugin type. + /// </summary> + /// <returns></returns> + public static MemoryInstanceMemento CreateDefaultInstanceMemento() + { + MemoryInstanceMemento memento = new MemoryInstanceMemento(); + memento._referenceKey = string.Empty; + memento._isReference = true; + + return memento; + } + + #endregion + + private NameValueCollection _properties = new NameValueCollection(); + private Hashtable _children = new Hashtable(); + private string _concreteKey; + private string _instanceKey; + private bool _isReference; + private string _referenceKey; + + + /// <summary> + /// Constructs a MemoryInstanceMemento without properties + /// </summary> + /// <param name="concreteKey">The concrete key of the plugin type</param> + /// <param name="instanceKey">The identifying instance key</param> + public MemoryInstanceMemento(string concreteKey, string instanceKey) + : this(concreteKey, instanceKey, new NameValueCollection()) + { + } + + + /// <summary> + /// Constructs a MemoryInstanceMemento with properties + /// </summary> + /// <param name="concreteKey">The concrete key of the plugin type</param> + /// <param name="instanceKey">The identifying instance key</param> + /// <param name="properties">NameValueCollection of instance properties</param> + public MemoryInstanceMemento(string concreteKey, string instanceKey, NameValueCollection properties) + { + _properties = properties; + _concreteKey = concreteKey; + _instanceKey = instanceKey; + } + + + public MemoryInstanceMemento() + { + } + + /// <summary> + /// Sets the value of the named property + /// </summary> + /// <param name="name"></param> + /// <param name="value"></param> + public void SetProperty(string name, string value) + { + string stringValue = value == string.Empty ? EMPTY_STRING : value; + _properties[name] = stringValue; + } + + public void SetTemplateKey(string templateName) + { + SetProperty(TEMPLATE_ATTRIBUTE, templateName); + } + + /// <summary> + /// Deletes a named property from the DefaultInstanceMemento + /// </summary> + /// <param name="Name"></param> + public void RemoveProperty(string Name) + { + _properties.Remove(Name); + } + + /// <summary> + /// Links a child InstanceMemento as a named property + /// </summary> + /// <param name="name"></param> + /// <param name="Memento"></param> + public void AddChild(string name, InstanceMemento Memento) + { + _children.Add(name, Memento); + } + + public void ReferenceChild(string name, string instanceKey) + { + InstanceMemento child = CreateReferencedInstanceMemento(instanceKey); + AddChild(name, child); + } + + + /// <summary> + /// Links an array of InstanceMemento's to a named array property + /// </summary> + /// <param name="name"></param> + /// <param name="childMementos"></param> + public void AddChildArray(string name, InstanceMemento[] childMementos) + { + _children.Add(name, childMementos); + } + + #region InstanceMemento Members + + /// <summary> + /// See <cref>InstanceMemento</cref> + /// </summary> + protected override string innerConcreteKey + { + get { return _concreteKey; } + } + + /// <summary> + /// See <cref>InstanceMemento</cref> + /// </summary> + protected override string innerInstanceKey + { + get { return _instanceKey; } + } + + + public void SetInstanceKey(string instanceKey) + { + _instanceKey = instanceKey; + } + + protected override string getPropertyValue(string Key) + { + return _properties[Key]; + } + + protected override InstanceMemento getChild(string Key) + { + return (InstanceMemento) _children[Key]; + } + + /// <summary> + /// See <cref>InstanceMemento</cref> + /// </summary> + public override bool IsReference + { + get { return _isReference; } + } + + /// <summary> + /// See <cref>InstanceMemento</cref> + /// </summary> + public override string ReferenceKey + { + get { return _referenceKey; } + } + + + protected bool hasProperty(string propertyName) + { + return _properties[propertyName] != null; + } + + + /// <summary> + /// See <cref>InstanceMemento</cref> + /// </summary> + public override InstanceMemento[] GetChildrenArray(string key) + { + return (InstanceMemento[]) _children[key]; + } + + #endregion + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/Mementos/PrototypeMemento.cs (from rev 53, trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/PrototypeMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/Mementos/PrototypeMemento.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -0,0 +1,63 @@ +using System; + +namespace StructureMap.Configuration.Mementos +{ + public class PrototypeMemento : InstanceMemento + { + private readonly string _instanceKey; + private ICloneable _prototype; + + public PrototypeMemento(string instanceKey, ICloneable prototype) + { + _instanceKey = instanceKey; + _prototype = prototype; + } + + + public ICloneable Prototype + { + get { return _prototype; } + set { _prototype = value; } + } + + protected override object buildInstance(IInstanceCreator creator) + { + return _prototype.Clone(); + } + + protected override string innerConcreteKey + { + get { return string.Empty; } + } + + protected override string innerInstanceKey + { + get { return _instanceKey; } + } + + protected override string getPropertyValue(string Key) + { + throw new NotImplementedException(); + } + + protected override InstanceMemento getChild(string Key) + { + throw new NotImplementedException(); + } + + public override InstanceMemento[] GetChildrenArray(string Key) + { + throw new NotImplementedException(); + } + + public override bool IsReference + { + get { return false; } + } + + public override string ReferenceKey + { + get { throw new NotImplementedException(); } + } + } +} \ No newline at end of file Copied: trunk/Source/StructureMap/Configuration/Mementos/UserControlMemento.cs (from rev 53, trunk/Source/StructureMap/Configuration/UserControlMemento.cs) =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/UserControlMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/Mementos/UserControlMemento.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -0,0 +1,68 @@ +using System; +using System.Web.UI; + +namespace StructureMap.Configuration.Mementos +{ + public class UserControlMemento : InstanceMemento + { + private readonly string _instanceKey; + private string _url; + + public UserControlMemento(string instanceKey, string url) + { + _instanceKey = instanceKey; + _url = url; + } + + + public UserControlMemento() + { + } + + public string Url + { + get { return _url; } + set { _url = value; } + } + + protected override object buildInstance(IInstanceCreator creator) + { + return new Page().LoadControl(_url); + } + + protected override string innerConcreteKey + { + get { return string.Empty; } + } + + protected override string innerInstanceKey + { + get { return _instanceKey; } + } + + protected override string getPropertyValue(string Key) + { + throw new NotImplementedException(); + } + + protected override InstanceMemento getChild(string Key) + { + throw new NotImplementedException(); + } + + public override InstanceMemento[] GetChildrenArray(string Key) + { + throw new NotImplementedException(); + } + + public override bool IsReference + { + get { return false; } + } + + public override string ReferenceKey + { + get { throw new NotImplementedException(); } + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/ConstructorMemento.cs =================================================================== --- trunk/Source/StructureMap/ConstructorMemento.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/ConstructorMemento.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.Mementos; namespace StructureMap { Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Reflection; +using StructureMap.Configuration.Mementos; namespace StructureMap.Graph { Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Reflection; -using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; using StructureMap.Emitting; using StructureMap.Graph; using StructureMap.Interceptors; Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,7 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; -using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; using StructureMap.Exceptions; using StructureMap.Graph; using StructureMap.Interceptors; Deleted: trunk/Source/StructureMap/MemoryInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/MemoryInstanceMemento.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/MemoryInstanceMemento.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,209 +0,0 @@ -using System.Collections; -using System.Collections.Specialized; -using StructureMap.Graph; - -namespace StructureMap -{ - public class GenericMemento<T> : MemoryInstanceMemento - { - public GenericMemento(string instanceKey) - : base(Plugin.CreateImplicitPlugin(typeof (T)).ConcreteKey, instanceKey) - { - } - } - - /// <summary> - /// An in-memory implementation of InstanceMemento. - /// </summary> - public class MemoryInstanceMemento : InstanceMemento - { - #region statics - - /// <summary> - /// Creates an instance of MemoryInstanceMemento that represents a reference to another - /// instance. - /// </summary> - /// <param name="referenceKey">The referenced instance key to another instance</param> - /// <returns></returns> - public static MemoryInstanceMemento CreateReferencedInstanceMemento(string referenceKey) - { - MemoryInstanceMemento memento = new MemoryInstanceMemento(); - memento._referenceKey = referenceKey; - memento._isReference = true; - - return memento; - } - - /// <summary> - /// Creates a MemoryInstanceMemento that represents a reference to the default instance - /// of a plugin type. - /// </summary> - /// <returns></returns> - public static MemoryInstanceMemento CreateDefaultInstanceMemento() - { - MemoryInstanceMemento memento = new MemoryInstanceMemento(); - memento._referenceKey = string.Empty; - memento._isReference = true; - - return memento; - } - - #endregion - - private NameValueCollection _properties = new NameValueCollection(); - private Hashtable _children = new Hashtable(); - private string _concreteKey; - private string _instanceKey; - private bool _isReference; - private string _referenceKey; - - - /// <summary> - /// Constructs a MemoryInstanceMemento without properties - /// </summary> - /// <param name="concreteKey">The concrete key of the plugin type</param> - /// <param name="instanceKey">The identifying instance key</param> - public MemoryInstanceMemento(string concreteKey, string instanceKey) - : this(concreteKey, instanceKey, new NameValueCollection()) - { - } - - - /// <summary> - /// Constructs a MemoryInstanceMemento with properties - /// </summary> - /// <param name="concreteKey">The concrete key of the plugin type</param> - /// <param name="instanceKey">The identifying instance key</param> - /// <param name="properties">NameValueCollection of instance properties</param> - public MemoryInstanceMemento(string concreteKey, string instanceKey, NameValueCollection properties) - { - _properties = properties; - _concreteKey = concreteKey; - _instanceKey = instanceKey; - } - - - public MemoryInstanceMemento() - { - } - - /// <summary> - /// Sets the value of the named property - /// </summary> - /// <param name="name"></param> - /// <param name="value"></param> - public void SetProperty(string name, string value) - { - string stringValue = value == string.Empty ? EMPTY_STRING : value; - _properties[name] = stringValue; - } - - public void SetTemplateKey(string templateName) - { - SetProperty(TEMPLATE_ATTRIBUTE, templateName); - } - - /// <summary> - /// Deletes a named property from the DefaultInstanceMemento - /// </summary> - /// <param name="Name"></param> - public void RemoveProperty(string Name) - { - _properties.Remove(Name); - } - - /// <summary> - /// Links a child InstanceMemento as a named property - /// </summary> - /// <param name="name"></param> - /// <param name="Memento"></param> - public void AddChild(string name, InstanceMemento Memento) - { - _children.Add(name, Memento); - } - - public void ReferenceChild(string name, string instanceKey) - { - InstanceMemento child = CreateReferencedInstanceMemento(instanceKey); - AddChild(name, child); - } - - - /// <summary> - /// Links an array of InstanceMemento's to a named array property - /// </summary> - /// <param name="name"></param> - /// <param name="childMementos"></param> - public void AddChildArray(string name, InstanceMemento[] childMementos) - { - _children.Add(name, childMementos); - } - - #region InstanceMemento Members - - /// <summary> - /// See <cref>InstanceMemento</cref> - /// </summary> - protected override string innerConcreteKey - { - get { return _concreteKey; } - } - - /// <summary> - /// See <cref>InstanceMemento</cref> - /// </summary> - protected override string innerInstanceKey - { - get { return _instanceKey; } - } - - - public void SetInstanceKey(string instanceKey) - { - _instanceKey = instanceKey; - } - - protected override string getPropertyValue(string Key) - { - return _properties[Key]; - } - - protected override InstanceMemento getChild(string Key) - { - return (InstanceMemento) _children[Key]; - } - - /// <summary> - /// See <cref>InstanceMemento</cref> - /// </summary> - public override bool IsReference - { - get { return _isReference; } - } - - /// <summary> - /// See <cref>InstanceMemento</cref> - /// </summary> - public override string ReferenceKey - { - get { return _referenceKey; } - } - - - protected bool hasProperty(string propertyName) - { - return _properties[propertyName] != null; - } - - - /// <summary> - /// See <cref>InstanceMemento</cref> - /// </summary> - public override InstanceMemento[] GetChildrenArray(string key) - { - return (InstanceMemento[]) _children[key]; - } - - #endregion - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Security.Permissions; using System.Text; -using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap Modified: trunk/Source/StructureMap.Testing/Client/Controllers/TreeBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Client/Controllers/TreeBuilderTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Client/Controllers/TreeBuilderTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -4,6 +4,7 @@ using StructureMap.Client.TreeNodes; using StructureMap.Client.Views; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Configuration.Tokens.Properties; using StructureMap.Graph; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,6 +1,7 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; using StructureMap.Testing.Widget4; namespace StructureMap.Testing.Configuration.DSL Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,5 +1,6 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Testing.Widget; namespace StructureMap.Testing.Configuration.DSL Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,5 +1,6 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/LiteralExpressionTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,6 +1,7 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,5 +1,6 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,8 +1,8 @@ using System; using NUnit.Framework; using Rhino.Mocks; -using StructureMap.Configuration; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Testing.Widget3; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,6 +1,6 @@ using NUnit.Framework; -using StructureMap.Configuration; using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap.Testing.Configuration.DSL Modified: trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -4,6 +4,7 @@ using StructureMap.Attributes; using StructureMap.Configuration; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Graph; using StructureMap.Testing.Configuration.Tokens; Modified: trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,5 +1,6 @@ using System.Diagnostics; using NUnit.Framework; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/FamilyTokenTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/FamilyTokenTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/FamilyTokenTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -2,6 +2,7 @@ using NUnit.Framework; using StructureMap.Attributes; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Graph; using StructureMap.Source; Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/InstanceTokenTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/InstanceTokenTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/InstanceTokenTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -2,6 +2,7 @@ using NMock; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Configuration.Tokens.Properties; using StructureMap.Graph; Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/MockInterceptor.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/MockInterceptor.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/MockInterceptor.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.Mementos; using StructureMap.Interceptors; namespace StructureMap.Testing.Configuration.Tokens Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/MockMementoSource.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/MockMementoSource.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/MockMementoSource.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.Mementos; namespace StructureMap.Testing.Configuration.Tokens { Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildArrayPropertyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildArrayPropertyTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildArrayPropertyTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -2,6 +2,7 @@ using NMock; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Configuration.Tokens.Properties; using StructureMap.Testing.Widget3; Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildPropertyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildPropertyTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildPropertyTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,6 +1,7 @@ using NMock; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Configuration.Tokens.Properties; using StructureMap.Testing.Widget3; Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/EnumerationPropertyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/EnumerationPropertyTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/EnumerationPropertyTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -2,6 +2,7 @@ using NUnit.Framework; using StructureMap.Attributes; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Configuration.Tokens.Properties; Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/PrimitivePropertyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/PrimitivePropertyTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/PrimitivePropertyTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,6 +1,7 @@ using NMock; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Configuration.Tokens.Properties; Modified: trunk/Source/StructureMap.Testing/Configuration/Tokens/PropertyDefinitionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/Tokens/PropertyDefinitionTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Configuration/Tokens/PropertyDefinitionTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -4,6 +4,7 @@ using System.Xml; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Configuration.Tokens.Properties; Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -3,7 +3,7 @@ using System.Collections.Generic; using NUnit.Framework; using Rhino.Mocks; -using StructureMap.Configuration.DSL.Expressions; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Testing.Widget3; Modified: trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Container/EnumerationTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using NUnit.Framework; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Source; using StructureMap.Testing.Widget2; Modified: trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using NUnit.Framework; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Source; Modified: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,5 +1,6 @@ using System; using NUnit.Framework; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Source; Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,6 +1,7 @@ using System.Xml; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Source; Modified: trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,6 +1,7 @@ using System.Collections; using System.Xml; using NUnit.Framework; +using StructureMap.Configuration.Mementos; using StructureMap.Source; using StructureMap.Testing.TestData; using StructureMap.Testing.XmlWriting; Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -3,6 +3,7 @@ using System.Reflection; using NUnit.Framework; using StructureMap.Configuration; +using StructureMap.Configuration.Mementos; using StructureMap.Configuration.Tokens; using StructureMap.Graph; using StructureMap.Testing.GenericWidgets; Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -4,6 +4,7 @@ using StructureMap.Attributes; using StructureMap.Configuration; using StructureMap.Configuration.DSL; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; Modified: trunk/Source/StructureMap.Testing.Widget/Rule.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Rule.cs 2008-01-14 04:18:06 UTC (rev 54) +++ trunk/Source/StructureMap.Testing.Widget/Rule.cs 2008-01-14 04:24:37 UTC (rev 55) @@ -1,4 +1,5 @@ using System; +using StructureMap.Configuration.Mementos; namespace ... [truncated message content] |
From: <jer...@us...> - 2008-01-15 15:15:52
|
Revision: 56 http://structuremap.svn.sourceforge.net/structuremap/?rev=56&view=rev Author: jeremydmiller Date: 2008-01-15 07:15:50 -0800 (Tue, 15 Jan 2008) Log Message: ----------- added quite a bit of stuff to the fluent interface for interception, scanning assemblies, a shortcut to add a type as something other than the default, add an assembly by name Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Graph/AssemblyGraph.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs trunk/Source/StructureMap.Testing/Graph/AssemblyGraphTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Delegates.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Configuration/DSL/ChildArrayExpression.cs trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/ConstructorExpression.cs trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs trunk/Source/StructureMap/Configuration/UserControlMemento.cs Deleted: trunk/Source/StructureMap/Configuration/DSL/ChildArrayExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ChildArrayExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/ChildArrayExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,50 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - public class ChildArrayExpression<PLUGINTYPE> : IExpression - { - private readonly InstanceExpression _parent; - private readonly MemoryInstanceMemento _memento; - private readonly string _propertyName; - private IMementoBuilder[] _builders; - private Type _pluginType = typeof (PLUGINTYPE); - - public ChildArrayExpression(InstanceExpression parent, MemoryInstanceMemento memento, string propertyName) - { - _parent = parent; - _memento = memento; - _propertyName = propertyName; - - _pluginType = typeof (PLUGINTYPE).GetElementType(); - } - - void IExpression.Configure(PluginGraph graph) - { - PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); - InstanceMemento[] childMementos = new InstanceMemento[_builders.Length]; - for (int i = 0; i < _builders.Length; i++) - { - InstanceMemento memento = processMementoBuilder(_builders[i], family, graph); - childMementos[i] = memento; - } - - _memento.AddChildArray(_propertyName, childMementos); - } - - private InstanceMemento processMementoBuilder(IMementoBuilder builder, PluginFamily family, PluginGraph graph) - { - builder.ValidatePluggability(_pluginType); - builder.Configure(graph); - return builder.BuildMemento(family); - } - - public InstanceExpression Contains(params IMementoBuilder[] builders) - { - _builders = builders; - - return _parent; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/ChildInstanceExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,115 +0,0 @@ -using System; -using System.Collections.Generic; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - /// <summary> - /// Part of the Fluent Interface, represents a nonprimitive argument to a - /// constructure function - /// </summary> - public class ChildInstanceExpression : IExpression - { - private readonly InstanceExpression _instance; - private readonly MemoryInstanceMemento _memento; - private readonly string _propertyName; - private Type _childType; - private List<IExpression> _children = new List<IExpression>(); - private IMementoBuilder _builder; - - - public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName) - { - _instance = instance; - _memento = memento; - _propertyName = propertyName; - } - - public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName, - Type childType) - : this(instance, memento, propertyName) - { - _childType = childType; - } - - /// <summary> - /// Use a previously configured and named instance for the child - /// </summary> - /// <param name="instanceKey"></param> - /// <returns></returns> - public InstanceExpression IsNamedInstance(string instanceKey) - { - MemoryInstanceMemento child = MemoryInstanceMemento.CreateReferencedInstanceMemento(instanceKey); - _memento.AddChild(_propertyName, child); - - return _instance; - } - - /// <summary> - /// Start the definition of a child instance by defining the concrete type - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - public InstanceExpression IsConcreteType<T>() - { - Type pluggedType = typeof (T); - ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType); - - - InstanceExpression child = new InstanceExpression(_childType); - child.TypeExpression().UsingConcreteType<T>(); - _children.Add(child); - - _builder = child; - - return _instance; - } - - - void IExpression.Configure(PluginGraph graph) - { - if (_childType == null) - { - return; - } - - PluginFamily family = graph.LocateOrCreateFamilyForType(_childType); - if (_builder != null) - { - InstanceMemento childMemento = _builder.BuildMemento(family); - _memento.AddChild(_propertyName, childMemento); - } - - foreach (IExpression child in _children) - { - child.Configure(graph); - } - } - - internal Type ChildType - { - set { _childType = value; } - } - - /// <summary> - /// Registers a configured instance to use as the argument to the parent's - /// constructor - /// </summary> - /// <param name="child"></param> - /// <returns></returns> - public InstanceExpression Is(InstanceExpression child) - { - if (child.PluggedType != null && _childType != null) - { - ExpressionValidator.ValidatePluggabilityOf(child.PluggedType).IntoPluginType(_childType); - } - - _children.Add(child); - MemoryInstanceMemento childMemento = - MemoryInstanceMemento.CreateReferencedInstanceMemento(child.InstanceKey); - _memento.AddChild(_propertyName, childMemento); - - return _instance; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/ConstructorExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ConstructorExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/ConstructorExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,49 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - public class ConstructorExpression<PLUGINTYPE> : MementoBuilder<ConstructorExpression<PLUGINTYPE>> - { - private ConstructorMemento<PLUGINTYPE> _memento; - - public ConstructorExpression(BuildObjectDelegate<PLUGINTYPE> builder) - : base(typeof (PLUGINTYPE)) - { - _memento.Builder = builder; - } - - - protected override InstanceMemento memento - { - get { return _memento; } - } - - protected override ConstructorExpression<PLUGINTYPE> thisInstance - { - get { return this; } - } - - protected override void configureMemento(PluginFamily family) - { - } - - protected override void validate() - { - } - - protected override void buildMemento() - { - _memento = new ConstructorMemento<PLUGINTYPE>(); - } - - public override void ValidatePluggability(Type pluginType) - { - if (!pluginType.Equals(typeof (PLUGINTYPE))) - { - throw new StructureMapException(306, - typeof (PLUGINTYPE).FullName, pluginType.FullName); - } - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/CreatePluginFamilyExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,148 +0,0 @@ -using System; -using System.Collections.Generic; -using StructureMap.Attributes; -using StructureMap.Graph; -using StructureMap.Interceptors; - -namespace StructureMap.Configuration.DSL -{ - public delegate void AlterPluginFamilyDelegate(PluginFamily family); - - /// <summary> - /// Represents the parameters for creating instances of a given Type - /// </summary> - public class CreatePluginFamilyExpression<PLUGINTYPE> : IExpression - { - private Type _pluginType; - private List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>(); - private InstanceScope _scope = InstanceScope.PerRequest; - private List<IExpression> _children = new List<IExpression>(); - - public CreatePluginFamilyExpression() - { - _pluginType = typeof (PLUGINTYPE); - } - - void IExpression.Configure(PluginGraph graph) - { - PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); - InterceptorChainBuilder builder = new InterceptorChainBuilder(); - family.InterceptionChain = builder.Build(_scope); - - foreach (IExpression child in _children) - { - child.Configure(graph); - } - - foreach (AlterPluginFamilyDelegate alteration in _alterations) - { - alteration(family); - } - - graph.PluginFamilies.Add(family); - - AssemblyGraph assembly = new AssemblyGraph(_pluginType.Assembly); - graph.Assemblies.Add(assembly); - } - - /// <summary> - /// Sets the default instance of a Type to the definition represented by builder - /// </summary> - /// <param name="builder"></param> - /// <returns></returns> - public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIs(IMementoBuilder builder) - { - builder.ValidatePluggability(_pluginType); - - _children.Add(builder); - _alterations.Add(delegate(PluginFamily family) - { - InstanceMemento memento = builder.BuildMemento(family); - family.Source.AddExternalMemento(memento); - family.DefaultInstanceKey = memento.InstanceKey; - }); - - return this; - } - - public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(IMementoBuilder builder) - { - builder.ValidatePluggability(_pluginType); - - _children.Add(builder); - _alterations.Add(delegate(PluginFamily family) - { - InstanceMemento memento = builder.BuildMemento(family); - family.Source.AddExternalMemento(memento); - }); - - return this; - } - - /// <summary> - /// Convenience method that sets the default concrete type of the PluginType. Type T - /// can only accept types that do not have any primitive constructor arguments. - /// StructureMap has to know how to construct all of the constructor argument types. - /// </summary> - /// <typeparam name="CONCRETETYPE"></typeparam> - /// <returns></returns> - public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIsConcreteType<CONCRETETYPE>() - where CONCRETETYPE : PLUGINTYPE - { - ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(_pluginType); - - _alterations.Add(delegate(PluginFamily family) - { - Plugin plugin = family.Plugins.FindOrCreate(typeof (CONCRETETYPE)); - family.DefaultInstanceKey = plugin.ConcreteKey; - }); - - return this; - } - - /// <summary> - /// Sets the object creation of the instances of the PluginType. For example: PerRequest, - /// Singleton, ThreadLocal, HttpContext, or Hybrid - /// </summary> - /// <param name="scope"></param> - /// <returns></returns> - public CreatePluginFamilyExpression<PLUGINTYPE> CacheBy(InstanceScope scope) - { - _alterations.Add(delegate(PluginFamily family) - { - InterceptorChainBuilder builder = new InterceptorChainBuilder(); - family.InterceptionChain = builder.Build(scope); - }); - - return this; - } - - /// <summary> - /// Convenience method to mark a PluginFamily as a Singleton - /// </summary> - /// <returns></returns> - public CreatePluginFamilyExpression<PLUGINTYPE> AsSingletons() - { - _alterations.Add( - delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(new SingletonInterceptor()); }); - return this; - } - - - public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(StartupHandler<PLUGINTYPE> handler) - { - _alterations.Add( - delegate(PluginFamily family) { family.InstanceInterceptor = new StartupInterceptor<PLUGINTYPE>(handler); }); - - return this; - } - - public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(EnrichmentHandler<PLUGINTYPE> handler) - { - _alterations.Add( - delegate(PluginFamily family) { family.InstanceInterceptor = new EnrichmentInterceptor<PLUGINTYPE>(handler); }); - - return this; - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using StructureMap.Attributes; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Interceptors; @@ -13,16 +14,18 @@ /// </summary> public class CreatePluginFamilyExpression<PLUGINTYPE> : IExpression { + private readonly List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>(); + private readonly List<IExpression> _children = new List<IExpression>(); private readonly Type _pluginType; - private readonly List<AlterPluginFamilyDelegate> _alterations = new List<AlterPluginFamilyDelegate>(); private readonly InstanceScope _scope = InstanceScope.PerRequest; - private readonly List<IExpression> _children = new List<IExpression>(); public CreatePluginFamilyExpression() { _pluginType = typeof (PLUGINTYPE); } + #region IExpression Members + void IExpression.Configure(PluginGraph graph) { PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); @@ -45,6 +48,8 @@ graph.Assemblies.Add(assembly); } + #endregion + /// <summary> /// Sets the default instance of a Type to the definition represented by builder /// </summary> @@ -144,5 +149,30 @@ return this; } + + public CreatePluginFamilyExpression<PLUGINTYPE> AddConcreteType<CONCRETETYPE>() + { + return AddConcreteType<CONCRETETYPE>(Guid.NewGuid().ToString()); + } + + public CreatePluginFamilyExpression<PLUGINTYPE> AddConcreteType<CONCRETETYPE>(string instanceName) + { + _alterations.Add( + delegate(PluginFamily family) + { + Plugin plugin = Plugin.CreateImplicitPlugin(typeof (CONCRETETYPE)); + plugin.ConcreteKey = instanceName; + family.Plugins.Add(plugin); + } + ); + + return this; + } + + public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(InstanceFactoryInterceptor interceptor) + { + _alterations.Add(delegate(PluginFamily family){family.InterceptionChain.AddInterceptor(interceptor);}); + return this; + } } } \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/LiteralMemento.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,67 +0,0 @@ -using System; - -namespace StructureMap.Configuration.DSL.Expressions -{ - public class LiteralMemento : InstanceMemento - { - private object _instance; - - public LiteralMemento(object instance) - { - _instance = instance; - InstanceKey = Guid.NewGuid().ToString(); - } - - public LiteralMemento Named(string name) - { - InstanceKey = name; - return this; - } - - public object Instance - { - get { return _instance; } - set { _instance = value; } - } - - protected override string innerConcreteKey - { - get { throw new NotImplementedException(); } - } - - protected override string innerInstanceKey - { - get { throw new NotImplementedException(); } - } - - protected override string getPropertyValue(string Key) - { - throw new NotImplementedException(); - } - - protected override InstanceMemento getChild(string Key) - { - throw new NotImplementedException(); - } - - public override InstanceMemento[] GetChildrenArray(string Key) - { - throw new NotImplementedException(); - } - - public override bool IsReference - { - get { return false; } - } - - public override string ReferenceKey - { - get { throw new NotImplementedException(); } - } - - protected override object buildInstance(IInstanceCreator creator) - { - return _instance; - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -10,7 +10,7 @@ public class ProfileExpression : IExpression { private readonly string _profileName; - private List<InstanceDefaultExpression> _defaults = new List<InstanceDefaultExpression>(); + private readonly List<InstanceDefaultExpression> _defaults = new List<InstanceDefaultExpression>(); public ProfileExpression(string profileName) { Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -12,8 +12,14 @@ /// </summary> public class ScanAssembliesExpression : IExpression { - private List<AssemblyGraph> _assemblies = new List<AssemblyGraph>(); + private readonly Registry _registry; + private readonly List<AssemblyGraph> _assemblies = new List<AssemblyGraph>(); + public ScanAssembliesExpression(Registry registry) + { + _registry = registry; + } + void IExpression.Configure(PluginGraph graph) { foreach (AssemblyGraph assembly in _assemblies) @@ -59,5 +65,23 @@ return this; } + + public ScanAssembliesExpression AddAllTypesOf<PLUGINTYPE>() + { + _registry.addExpression(delegate (PluginGraph pluginGraph) + { + PluginFamily family = + pluginGraph.LocateOrCreateFamilyForType(typeof (PLUGINTYPE)); + family.CanUseUnMarkedPlugins = true; + }); + + return this; + } + + public ScanAssembliesExpression IncludeAssembly(string assemblyName) + { + _assemblies.Add(new AssemblyGraph(assemblyName)); + return this; + } } } \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/IMementoBuilder.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,14 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - public interface IMementoBuilder : IExpression - { - InstanceMemento BuildMemento(PluginFamily family); - InstanceMemento BuildMemento(PluginGraph graph); - void SetInstanceName(string instanceKey); - - void ValidatePluggability(Type pluginType); - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceDefaultExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,69 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - /// <summary> - /// Use to express the instance of a PluginType for the containing Profile - /// </summary> - public class InstanceDefaultExpression - { - private readonly Type _pluginType; - private readonly ProfileExpression _parent; - private string _instanceKey = string.Empty; - private IMementoBuilder _mementoBuilder; - - public InstanceDefaultExpression(Type pluginType, ProfileExpression parent) - { - _pluginType = pluginType; - _parent = parent; - } - - /// <summary> - /// Use a named, preconfigured instance as the default instance for this profile - /// </summary> - /// <param name="instanceKey"></param> - /// <returns></returns> - public ProfileExpression UseNamedInstance(string instanceKey) - { - _instanceKey = instanceKey; - return _parent; - } - - internal void Configure(Profile profile, PluginGraph graph) - { - if (!string.IsNullOrEmpty(_instanceKey)) - { - InstanceDefault instanceDefault = new InstanceDefault(_pluginType, _instanceKey); - profile.AddOverride(instanceDefault); - } - else if (_mementoBuilder != null) - { - string defaultKey = Profile.InstanceKeyForProfile(profile.ProfileName); - InstanceMemento memento = _mementoBuilder.BuildMemento(graph); - memento.InstanceKey = defaultKey; - - graph.PluginFamilies[_pluginType].AddInstance(memento); - - InstanceDefault instanceDefault = new InstanceDefault(_pluginType, defaultKey); - profile.AddOverride(instanceDefault); - } - else - { - throw new StructureMapException(304, TypePath.GetAssemblyQualifiedName(_pluginType)); - } - } - - /// <summary> - /// Define the default instance of the PluginType for the containing Profile - /// </summary> - /// <param name="mementoBuilder"></param> - /// <returns></returns> - public ProfileExpression Use(IMementoBuilder mementoBuilder) - { - _mementoBuilder = mementoBuilder; - - return _parent; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/InstanceExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,192 +0,0 @@ -using System; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - /// <summary> - /// Used to define an Instance in code - /// </summary> - public class InstanceExpression : MementoBuilder<InstanceExpression> - { - private Type _pluggedType; - private MemoryInstanceMemento _memento; - - public InstanceExpression(Type pluginType) : base(pluginType) - { - } - - - internal Type PluggedType - { - get { return _pluggedType; } - } - - protected override void buildMemento() - { - _memento = new MemoryInstanceMemento(); - } - - - protected override InstanceMemento memento - { - get { return _memento; } - } - - protected override InstanceExpression thisInstance - { - get { return this; } - } - - protected override void configureMemento(PluginFamily family) - { - Plugin plugin = _pluggedType == null - ? family.Plugins[_memento.ConcreteKey] - : family.Plugins.FindOrCreate(_pluggedType); - - _memento.ConcreteKey = plugin.ConcreteKey; - } - - protected override void validate() - { - if (_pluggedType == null && string.IsNullOrEmpty(_memento.ConcreteKey)) - { - throw new StructureMapException(301, _memento.InstanceKey, - TypePath.GetAssemblyQualifiedName(_pluginType)); - } - } - - - /// <summary> - /// Start the definition of a primitive argument to a constructor argument - /// </summary> - /// <param name="propertyName"></param> - /// <returns></returns> - public PropertyExpression WithProperty(string propertyName) - { - return new PropertyExpression(this, _memento, propertyName); - } - - /// <summary> - /// Starts the definition of a child instance specifying the argument name - /// in the case of a constructor function that consumes more than one argument - /// of type T - /// </summary> - /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam> - /// <param name="propertyName"></param> - /// <returns></returns> - public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>(string propertyName) - { - ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName); - addChildExpression(child); - child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); - - return child; - } - - /// <summary> - /// Start the definition of a child instance for type CONSTRUCTORARGUMENTTYPE - /// </summary> - /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam> - /// <returns></returns> - public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>() - { - string propertyName = findPropertyName<CONSTRUCTORARGUMENTTYPE>(); - - ChildInstanceExpression child = new ChildInstanceExpression(this, _memento, propertyName); - addChildExpression(child); - child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); - return child; - } - - private string findPropertyName<T>() - { - Plugin plugin = Plugin.CreateImplicitPlugin(_pluggedType); - string propertyName = plugin.FindFirstConstructorArgumentOfType<T>(); - - if (string.IsNullOrEmpty(propertyName)) - { - throw new StructureMapException(305, TypePath.GetAssemblyQualifiedName(typeof (T))); - } - - return propertyName; - } - - public override void ValidatePluggability(Type pluginType) - { - if (_pluggedType == null) - { - return; - } - - ExpressionValidator.ValidatePluggabilityOf(_pluggedType).IntoPluginType(pluginType); - } - - internal InstanceTypeExpression TypeExpression() - { - return new InstanceTypeExpression(this); - } - - /// <summary> - /// Helper class to capture the actual concrete type of an Instance - /// </summary> - public class InstanceTypeExpression - { - private readonly InstanceExpression _parent; - - internal InstanceTypeExpression(InstanceExpression parent) - { - _parent = parent; - } - - /// <summary> - /// Use type T for the concrete type of an instance - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - public InstanceExpression UsingConcreteType<T>() - { - _parent._pluggedType = typeof (T); - return _parent; - } - - /// <summary> - /// Use a named Plugin type denoted by a [Pluggable("Key")] attribute - /// </summary> - /// <param name="concreteKey"></param> - /// <returns></returns> - public InstanceExpression UsingConcreteTypeNamed(string concreteKey) - { - _parent._memento.ConcreteKey = concreteKey; - return _parent; - } - } - - public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>() - { - validateTypeIsArray<PLUGINTYPE>(); - - string propertyName = findPropertyName<PLUGINTYPE>(); - return ChildArray<PLUGINTYPE>(propertyName); - } - - public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>(string propertyName) - { - validateTypeIsArray<PLUGINTYPE>(); - - ChildArrayExpression<PLUGINTYPE> expression = - new ChildArrayExpression<PLUGINTYPE>(this, _memento, propertyName); - addChildExpression(expression); - - return expression; - } - - private static void validateTypeIsArray<PLUGINTYPE>() - { - if (!typeof (PLUGINTYPE).IsArray) - { - throw new StructureMapException(307); - } - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/LiteralExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,50 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - /// <summary> - /// Small helper class to represent an object to be plugged into a PluginType as is - /// </summary> - /// <typeparam name="T"></typeparam> - public class LiteralExpression<T> : MementoBuilder<LiteralExpression<T>> - { - private readonly T _target; - private LiteralMemento _memento; - - public LiteralExpression(T target) : base(typeof (T)) - { - _target = target; - } - - - protected override InstanceMemento memento - { - get { return _memento; } - } - - protected override LiteralExpression<T> thisInstance - { - get { return this; } - } - - protected override void configureMemento(PluginFamily family) - { - _memento.Instance = _target; - } - - protected override void validate() - { - } - - protected override void buildMemento() - { - _memento = new LiteralMemento(null); - } - - public override void ValidatePluggability(Type pluginType) - { - ExpressionValidator.ValidatePluggabilityOf(_target.GetType()).IntoPluginType(pluginType); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/LiteralMemento.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,67 +0,0 @@ -using System; - -namespace StructureMap.Configuration.DSL -{ - public class LiteralMemento : InstanceMemento - { - private object _instance; - - public LiteralMemento(object instance) - { - _instance = instance; - InstanceKey = Guid.NewGuid().ToString(); - } - - public LiteralMemento Named(string name) - { - InstanceKey = name; - return this; - } - - public object Instance - { - get { return _instance; } - set { _instance = value; } - } - - protected override string innerConcreteKey - { - get { throw new NotImplementedException(); } - } - - protected override string innerInstanceKey - { - get { throw new NotImplementedException(); } - } - - protected override string getPropertyValue(string Key) - { - throw new NotImplementedException(); - } - - protected override InstanceMemento getChild(string Key) - { - throw new NotImplementedException(); - } - - public override InstanceMemento[] GetChildrenArray(string Key) - { - throw new NotImplementedException(); - } - - public override bool IsReference - { - get { return false; } - } - - public override string ReferenceKey - { - get { throw new NotImplementedException(); } - } - - protected override object buildInstance(IInstanceCreator creator) - { - return _instance; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/MementoBuilder.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,116 +0,0 @@ -using System; -using System.Collections.Generic; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Graph; -using StructureMap.Interceptors; - -namespace StructureMap.Configuration.DSL -{ - // TODO -- T must be constrained to be MementoBuilder - public abstract class MementoBuilder<T> : IExpression, IMementoBuilder - { - protected readonly Type _pluginType; - protected List<IExpression> _children = new List<IExpression>(); - private string _instanceKey = null; - - public MementoBuilder(Type pluginType) - { - _pluginType = pluginType; - buildMemento(); - memento.InstanceKey = Guid.NewGuid().ToString(); - } - - void IExpression.Configure(PluginGraph graph) - { - validate(); - PluginFamily family = graph.LocateOrCreateFamilyForType((Type) _pluginType); - configureMemento(family); - - if (!string.IsNullOrEmpty(_instanceKey)) - { - memento.InstanceKey = _instanceKey; - } - - family.Source.AddExternalMemento(memento); - - foreach (IExpression child in _children) - { - child.Configure(graph); - } - } - - protected abstract InstanceMemento memento { get; } - - protected abstract T thisInstance { get; } - - protected abstract void configureMemento(PluginFamily family); - - protected abstract void validate(); - - public T WithName(string instanceKey) - { - memento.InstanceKey = instanceKey; - return thisInstance; - } - - public T OnCreation<TYPE>(StartupHandler<TYPE> handler) - { - StartupInterceptor<TYPE> interceptor = new StartupInterceptor<TYPE>(handler); - memento.Interceptor = interceptor; - - return thisInstance; - } - - public T EnrichWith<TYPE>(EnrichmentHandler<TYPE> handler) - { - EnrichmentInterceptor<TYPE> interceptor = new EnrichmentInterceptor<TYPE>(handler); - memento.Interceptor = interceptor; - - return thisInstance; - } - - public string InstanceKey - { - get { return memento.InstanceKey; } - set { memento.InstanceKey = value; } - } - - internal Type PluginType - { - get { return _pluginType; } - } - - protected abstract void buildMemento(); - - InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family) - { - return buildMementoFromFamily(family); - } - - private InstanceMemento buildMementoFromFamily(PluginFamily family) - { - validate(); - configureMemento(family); - return memento; - } - - - InstanceMemento IMementoBuilder.BuildMemento(PluginGraph graph) - { - PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); - return buildMementoFromFamily(family); - } - - public void SetInstanceName(string instanceKey) - { - _instanceKey = instanceKey; - } - - public abstract void ValidatePluggability(Type pluginType); - - protected void addChildExpression(IExpression expression) - { - _children.Add(expression); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/ProfileExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,48 +0,0 @@ -using System.Collections.Generic; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - /// <summary> - /// Expression class to help define a runtime Profile - /// </summary> - public class ProfileExpression : IExpression - { - private readonly string _profileName; - private List<InstanceDefaultExpression> _defaults = new List<InstanceDefaultExpression>(); - - public ProfileExpression(string profileName) - { - _profileName = profileName; - } - - void IExpression.Configure(PluginGraph graph) - { - Profile profile = graph.DefaultManager.GetProfile(_profileName); - if (profile == null) - { - profile = new Profile(_profileName); - graph.DefaultManager.AddProfile(profile); - } - - foreach (InstanceDefaultExpression expression in _defaults) - { - expression.Configure(profile, graph); - } - } - - /// <summary> - /// Starts the definition of the default instance for the containing Profile - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - public InstanceDefaultExpression For<T>() - { - InstanceDefaultExpression defaultExpression = new InstanceDefaultExpression(typeof (T), this); - _defaults.Add(defaultExpression); - - return defaultExpression; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/PropertyExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,45 +0,0 @@ -using System.Configuration; - -namespace StructureMap.Configuration.DSL -{ - /// <summary> - /// Defines the value of a primitive argument to a constructur argument - /// </summary> - public class PropertyExpression - { - private readonly InstanceExpression _instance; - private readonly MemoryInstanceMemento _memento; - private readonly string _propertyName; - - public PropertyExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName) - { - _instance = instance; - _memento = memento; - _propertyName = propertyName; - } - - /// <summary> - /// Sets the value of the constructor argument - /// </summary> - /// <param name="propertyValue"></param> - /// <returns></returns> - public InstanceExpression EqualTo(object propertyValue) - { - _memento.SetProperty(_propertyName, propertyValue.ToString()); - return _instance; - } - - /// <summary> - /// Sets the value of the constructor argument to the key/value in the - /// AppSettings - /// </summary> - /// <param name="appSettingKey"></param> - /// <returns></returns> - public InstanceExpression EqualToAppSetting(string appSettingKey) - { - string propertyValue = ConfigurationManager.AppSettings[appSettingKey]; - _memento.SetProperty(_propertyName, propertyValue); - return _instance; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/PrototypeExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,50 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - /// <summary> - /// Sets up a Prototype instance of type T - /// </summary> - /// <typeparam name="T"></typeparam> - public class PrototypeExpression<T> : MementoBuilder<PrototypeExpression<T>> - { - private readonly T _prototype; - private PrototypeMemento _memento; - - public PrototypeExpression(T prototype) : base(typeof (T)) - { - _prototype = prototype; - } - - protected override InstanceMemento memento - { - get { return _memento; } - } - - protected override PrototypeExpression<T> thisInstance - { - get { return this; } - } - - protected override void configureMemento(PluginFamily family) - { - _memento.Prototype = (ICloneable) _prototype; - } - - protected override void validate() - { - // TODO - } - - protected override void buildMemento() - { - _memento = new PrototypeMemento(string.Empty, (ICloneable) _prototype); - } - - public override void ValidatePluggability(Type pluginType) - { - ExpressionValidator.ValidatePluggabilityOf(_prototype.GetType()).IntoPluginType(pluginType); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/PrototypeMemento.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,63 +0,0 @@ -using System; - -namespace StructureMap.Configuration.DSL -{ - public class PrototypeMemento : InstanceMemento - { - private readonly string _instanceKey; - private ICloneable _prototype; - - public PrototypeMemento(string instanceKey, ICloneable prototype) - { - _instanceKey = instanceKey; - _prototype = prototype; - } - - - public ICloneable Prototype - { - get { return _prototype; } - set { _prototype = value; } - } - - protected override object buildInstance(IInstanceCreator creator) - { - return _prototype.Clone(); - } - - protected override string innerConcreteKey - { - get { return string.Empty; } - } - - protected override string innerInstanceKey - { - get { return _instanceKey; } - } - - protected override string getPropertyValue(string Key) - { - throw new NotImplementedException(); - } - - protected override InstanceMemento getChild(string Key) - { - throw new NotImplementedException(); - } - - public override InstanceMemento[] GetChildrenArray(string Key) - { - throw new NotImplementedException(); - } - - public override bool IsReference - { - get { return false; } - } - - public override string ReferenceKey - { - get { throw new NotImplementedException(); } - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -8,8 +8,8 @@ { public class Registry : IDisposable { - private List<IExpression> _expressions = new List<IExpression>(); - private PluginGraph _graph; + private readonly List<IExpression> _expressions = new List<IExpression>(); + private readonly PluginGraph _graph; public Registry(PluginGraph graph) : this() { @@ -22,7 +22,15 @@ configure(); } + #region IDisposable Members + public void Dispose() + { + ConfigurePluginGraph(_graph); + } + + #endregion + /// <summary> /// Implement this method to /// </summary> @@ -50,11 +58,6 @@ } - public void Dispose() - { - ConfigurePluginGraph(_graph); - } - /// <summary> /// Direct StructureMap to build instances of type T, and look for concrete classes /// marked with the [Pluggable] attribute that implement type T @@ -232,43 +235,54 @@ public void RegisterInterceptor(TypeInterceptor interceptor) { - addExpression(delegate (PluginGraph pluginGraph) - { - pluginGraph.InterceptorLibrary.AddInterceptor(interceptor); - }); + addExpression( + delegate(PluginGraph pluginGraph) { pluginGraph.InterceptorLibrary.AddInterceptor(interceptor); }); } - public TypeInterceptorExpression IfTypeMatches(TypeMatchDelegate match) + public TypeInterceptorExpression IfTypeMatches(Predicate<Type> match) { TypeInterceptorExpression expression = new TypeInterceptorExpression(match); _expressions.Add(expression); return expression; } + + + /// <summary> + /// Programmatically determine Assembly's to be scanned for attribute configuration + /// </summary> + /// <returns></returns> + public ScanAssembliesExpression ScanAssemblies() + { + ScanAssembliesExpression expression = new ScanAssembliesExpression(this); + addExpression(expression); + + return expression; + } } - public delegate object InterceptionDelegate(object instance); - public delegate bool TypeMatchDelegate(Type type); + public class TypeInterceptorExpression : IExpression, TypeInterceptor { - private readonly TypeMatchDelegate _match; + private readonly Predicate<Type> _match; private InterceptionDelegate _interception; - internal TypeInterceptorExpression(TypeMatchDelegate match) + internal TypeInterceptorExpression(Predicate<Type> match) { _match = match; } + #region IExpression Members + void IExpression.Configure(PluginGraph graph) { graph.InterceptorLibrary.AddInterceptor(this); } - public void InterceptWith(InterceptionDelegate interception) - { - _interception = interception; - } + #endregion + #region TypeInterceptor Members + public bool MatchesType(Type type) { return _match(type); @@ -278,9 +292,17 @@ { return _interception(target); } + + #endregion + + public void InterceptWith(InterceptionDelegate interception) + { + _interception = interception; + } } internal delegate void PluginGraphAlteration(PluginGraph pluginGraph); + internal class BasicExpression : IExpression { private readonly PluginGraphAlteration _alteration; @@ -290,9 +312,13 @@ _alteration = alteration; } + #region IExpression Members + public void Configure(PluginGraph graph) { _alteration(graph); } + + #endregion } } \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/ScanAssembliesExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,63 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics; -using System.Reflection; -using System.Threading; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - /// <summary> - /// Expression that directs StructureMap to scan the named assemblies - /// for [PluginFamily] and [Plugin] attributes - /// </summary> - public class ScanAssembliesExpression : IExpression - { - private List<AssemblyGraph> _assemblies = new List<AssemblyGraph>(); - - void IExpression.Configure(PluginGraph graph) - { - foreach (AssemblyGraph assembly in _assemblies) - { - graph.Assemblies.Add(assembly); - } - } - - public ScanAssembliesExpression IncludeTheCallingAssembly() - { - Assembly callingAssembly = findTheCallingAssembly(); - - if (callingAssembly != null) - { - _assemblies.Add(new AssemblyGraph(callingAssembly)); - } - - return this; - } - - private static Assembly findTheCallingAssembly() - { - StackTrace trace = new StackTrace(Thread.CurrentThread, false); - - Assembly thisAssembly = Assembly.GetExecutingAssembly(); - Assembly callingAssembly = null; - for (int i = 0; i < trace.FrameCount; i++) - { - StackFrame frame = trace.GetFrame(i); - Assembly assembly = frame.GetMethod().DeclaringType.Assembly; - if (assembly != thisAssembly) - { - callingAssembly = assembly; - break; - } - } - return callingAssembly; - } - - public ScanAssembliesExpression IncludeAssemblyContainingType<T>() - { - _assemblies.Add(AssemblyGraph.ContainingType<T>()); - - return this; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,45 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL -{ - public class UserControlExpression : MementoBuilder<UserControlExpression> - { - private UserControlMemento _memento; - - public UserControlExpression(Type pluginType, string url) : base(pluginType) - { - _memento.Url = url; - } - - protected override InstanceMemento memento - { - get { return _memento; } - } - - protected override UserControlExpression thisInstance - { - get { return this; } - } - - protected override void configureMemento(PluginFamily family) - { - // no-op - } - - protected override void validate() - { - // no-op - } - - protected override void buildMemento() - { - _memento = new UserControlMemento(); - } - - public override void ValidatePluggability(Type pluginType) - { - // no-op - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/UserControlMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/UserControlMemento.cs 2008-01-14 04:24:37 UTC (rev 55) +++ trunk/Source/StructureMap/Configuration/UserControlMemento.cs 2008-01-15 15:15:50 UTC (rev 56) @@ -1,68 +0,0 @@ -using System; -using System.Web.UI; - -namespace StructureMap.Configuration -{ - public class UserControlMemento : InstanceMemento - { - private string _instanceKey; - private string _url; - - public UserControlMemento(string instanceKey, string url) - { - _instanceKey = instanceKey; - _url = url; - } - - - public UserControlMemento() - { - } - - public string Url - { - get { return _url; } - set { _url = value; } - } - - protected override object buildInstance(IInstanceCreator creator) - { - return new Page().LoadControl(_url); - } - - protected override string innerConcreteKey - { - get { return string.Empty; } - } - - protected override string innerInstanceKey - { - get { return _instanceKey; } - } - - protected override string getPropertyValue(string Key) - { - throw new NotImplementedException(); - } - - protected override InstanceMemento getChild(string Key) - { - throw new NotImplementedException(); - } - - public override InstanceMemento[] GetChildrenArray(string Key) - { - throw new NotImplementedException(); - } - - public override bool IsReference - { - get { return false; } - } - - public override string ReferenceKey - { - get { throw new NotImplementedException(); } - } - } -} \ No newline at end of file Added: trunk/Source/StructureMap/Delegates.c... [truncated message content] |
From: <jer...@us...> - 2008-01-15 15:56:18
|
Revision: 57 http://structuremap.svn.sourceforge.net/structuremap/?rev=57&view=rev Author: jeremydmiller Date: 2008-01-15 07:56:14 -0800 (Tue, 15 Jan 2008) Log Message: ----------- reformatting the code Modified Paths: -------------- trunk/Source/StructureMap/AssemblyInfo.cs trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs trunk/Source/StructureMap/Caching/CacheItem.cs trunk/Source/StructureMap/Caching/CacheManager.cs trunk/Source/StructureMap/Caching/CloneStorageStrategy.cs trunk/Source/StructureMap/Caching/Expirations/AbsoluteTimeExpirationPolicy.cs trunk/Source/StructureMap/Caching/Expirations/SlidingTimeExpirationPolicy.cs trunk/Source/StructureMap/Caching/FileModificationWatcher.cs trunk/Source/StructureMap/Caching/LazyCache.cs trunk/Source/StructureMap/Caching/SerializationStorageStrategy.cs trunk/Source/StructureMap/Caching/SharedStorageStrategy.cs trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap/Configuration/DSL/ReferenceMementoBuilder.cs trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs trunk/Source/StructureMap/Configuration/GraphObject.cs trunk/Source/StructureMap/Configuration/IGraphBuilder.cs trunk/Source/StructureMap/Configuration/InstanceValidator.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/PluginGraphReport.cs trunk/Source/StructureMap/Configuration/Problem.cs trunk/Source/StructureMap/Configuration/ProblemFinder.cs trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs trunk/Source/StructureMap/Configuration/Tokens/AssemblyToken.cs trunk/Source/StructureMap/Configuration/Tokens/Deployable.cs trunk/Source/StructureMap/Configuration/Tokens/FamilyToken.cs trunk/Source/StructureMap/Configuration/Tokens/InstanceToken.cs trunk/Source/StructureMap/Configuration/Tokens/InterceptorInstanceToken.cs trunk/Source/StructureMap/Configuration/Tokens/MementoSourceInstanceToken.cs trunk/Source/StructureMap/Configuration/Tokens/PluginToken.cs trunk/Source/StructureMap/Configuration/Tokens/Properties/ChildArrayProperty.cs trunk/Source/StructureMap/Configuration/Tokens/Properties/ChildProperty.cs trunk/Source/StructureMap/Configuration/Tokens/Properties/DefaultChildPropertyMode.cs trunk/Source/StructureMap/Configuration/Tokens/Properties/InlineInstanceChildPropertyMode.cs trunk/Source/StructureMap/Configuration/Tokens/Properties/NulloChildPropertyMode.cs trunk/Source/StructureMap/Configuration/Tokens/Properties/Property.cs trunk/Source/StructureMap/Configuration/Tokens/Properties/ReferencedChildPropertyMode.cs trunk/Source/StructureMap/Configuration/Tokens/Properties/TemplateProperty.cs trunk/Source/StructureMap/Configuration/Tokens/PropertyDefinition.cs trunk/Source/StructureMap/Configuration/Tokens/TemplateToken.cs trunk/Source/StructureMap/Configuration/XmlConstants.cs trunk/Source/StructureMap/ConstructorMemento.cs trunk/Source/StructureMap/Delegates.cs trunk/Source/StructureMap/DeploymentTasks/DeploymentConfiguration.cs trunk/Source/StructureMap/DeploymentTasks/DeploymentExecutor.cs trunk/Source/StructureMap/DeploymentTasks/PluginGraphFilter.cs trunk/Source/StructureMap/Emitting/ClassBuilder.cs trunk/Source/StructureMap/Emitting/DynamicAssembly.cs trunk/Source/StructureMap/Emitting/Method.cs trunk/Source/StructureMap/Exceptions/StructureMapException.cs trunk/Source/StructureMap/Graph/AssemblyGraph.cs trunk/Source/StructureMap/Graph/AssemblyGraphCollection.cs trunk/Source/StructureMap/Graph/Deployable.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/Graph/InstanceDefault.cs trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs trunk/Source/StructureMap/Graph/InterceptionChain.cs trunk/Source/StructureMap/Graph/MachineOverride.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/PluginGraphObjectCollection.cs trunk/Source/StructureMap/Graph/Profile.cs trunk/Source/StructureMap/Graph/RemoteGraph.cs trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs trunk/Source/StructureMap/Graph/TypePath.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/IInstanceManager.cs trunk/Source/StructureMap/IPluginGraphSource.cs trunk/Source/StructureMap/InstanceBuilder.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/EnrichmentInterceptor.cs trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs trunk/Source/StructureMap/Interceptors/Interceptors.cs trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs trunk/Source/StructureMap/MementoSource.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/ObjectFactoryCacheCallback.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/Source/BasicXmlMementoSource.cs trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs trunk/Source/StructureMap/Source/EmbeddedFolderXmlMementoSource.cs trunk/Source/StructureMap/Source/MemoryMementoSource.cs trunk/Source/StructureMap/Source/SingleEmbeddedXmlMementoSource.cs trunk/Source/StructureMap/Source/TemplatedMementoSource.cs trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlFileMementoSource.cs trunk/Source/StructureMap/Source/XmlMementoCreator.cs trunk/Source/StructureMap/Source/XmlMementoSource.cs trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlTemplater.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/Verification/PluginGraphConsoleWriter.cs trunk/Source/StructureMap/Verification/StartUp.cs trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs trunk/Source/StructureMap.AutoMocking/IntegrationSpecification.cs trunk/Source/StructureMap.AutoMocking/Properties/AssemblyInfo.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs trunk/Source/StructureMap.Client/AssemblyInfo.cs trunk/Source/StructureMap.Client/Controllers/HTMLSourceFactory.cs trunk/Source/StructureMap.Client/Controllers/ReportSource.cs trunk/Source/StructureMap.Client/Controllers/TreeBuilder.cs trunk/Source/StructureMap.Client/Shell/ApplicationShell.cs trunk/Source/StructureMap.Client/Shell/SearchPart.cs trunk/Source/StructureMap.Client/TreeNodes/GraphObjectNode.cs trunk/Source/StructureMap.Client/Views/BasicView.cs trunk/Source/StructureMap.Client/Views/CellMaker.cs trunk/Source/StructureMap.Client/Views/ChildHeader.cs trunk/Source/StructureMap.Client/Views/Column.cs trunk/Source/StructureMap.Client/Views/GridView.cs trunk/Source/StructureMap.Client/Views/HTMLBuilder.cs trunk/Source/StructureMap.Client/Views/IColumn.cs trunk/Source/StructureMap.Client/Views/IndexColumn.cs trunk/Source/StructureMap.Client/Views/InstanceHierarchyView.cs trunk/Source/StructureMap.Client/Views/ProblemColumn.cs trunk/Source/StructureMap.Client/Views/ProblemView.cs trunk/Source/StructureMap.Client/Views/RecordView.cs trunk/Source/StructureMap.Client/Views/SummaryView.cs trunk/Source/StructureMap.Client/Views/TableMaker.cs trunk/Source/StructureMap.Client/Views/ViewConstants.cs trunk/Source/StructureMap.DataAccess/AssemblyInfo.cs trunk/Source/StructureMap.DataAccess/CommandCollection.cs trunk/Source/StructureMap.DataAccess/CommandFactory.cs trunk/Source/StructureMap.DataAccess/CommandFailureException.cs trunk/Source/StructureMap.DataAccess/Commands/CommandBase.cs trunk/Source/StructureMap.DataAccess/Commands/QueryFilter.cs trunk/Source/StructureMap.DataAccess/Commands/StoredProcedureCommand.cs trunk/Source/StructureMap.DataAccess/Commands/TemplatedCommand.cs trunk/Source/StructureMap.DataAccess/Commands/TemplatedQuery.cs trunk/Source/StructureMap.DataAccess/DataSession.cs trunk/Source/StructureMap.DataAccess/DataSetMapping/ReaderToColumnMap.cs trunk/Source/StructureMap.DataAccess/DataSetMapping/YesNoReaderToColumnMap.cs trunk/Source/StructureMap.DataAccess/DefaultConnectionStringProvider.cs trunk/Source/StructureMap.DataAccess/ExecutionStates/AutoCommitExecutionState.cs trunk/Source/StructureMap.DataAccess/ExecutionStates/TransactionalExecutionState.cs trunk/Source/StructureMap.DataAccess/ICommand.cs trunk/Source/StructureMap.DataAccess/IDataSession.cs trunk/Source/StructureMap.DataAccess/IParameter.cs trunk/Source/StructureMap.DataAccess/IReaderSource.cs trunk/Source/StructureMap.DataAccess/JSON/Field.cs trunk/Source/StructureMap.DataAccess/JSON/JSONProperty.cs trunk/Source/StructureMap.DataAccess/MSSQL/MSSQLDatabaseEngine.cs trunk/Source/StructureMap.DataAccess/ParameterCollection.cs trunk/Source/StructureMap.DataAccess/Parameterization/BasicParameterTemplate.cs trunk/Source/StructureMap.DataAccess/Parameterization/IParameterTemplate.cs trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommandBuilder.cs trunk/Source/StructureMap.DataAccess/Parameterization/StringParameterTemplate.cs trunk/Source/StructureMap.DataAccess/Parameters/Parameter.cs trunk/Source/StructureMap.DataAccess/Parameters/TemplateParameter.cs trunk/Source/StructureMap.DataAccess/ReaderSourceCollection.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/CommandExpectation.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockCommand.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockDataSession.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockReaderSource.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterList.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterValidationFailureException.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/ReaderExpectation.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedCommandCollection.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSourceCollection.cs trunk/Source/StructureMap.DataAccess/Tools/TableDataReader.cs trunk/Source/StructureMap.DeploymentTasks/AddAssembly.cs trunk/Source/StructureMap.DeploymentTasks/AssemblyInfo.cs trunk/Source/StructureMap.DeploymentTasks/Deployment.cs trunk/Source/StructureMap.DeploymentTasks/DumbConfigMergeTask.cs trunk/Source/StructureMap.DeploymentTasks/ImportFamilyTask.cs trunk/Source/StructureMap.DeploymentTasks/RemoveAssemblyTask.cs trunk/Source/StructureMap.DeploymentTasks/SetOverrideTask.cs trunk/Source/StructureMap.DeploymentTasks/SubstitutionTask.cs trunk/Source/StructureMap.DeploymentTasks/Verification.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/CheckVersionTask.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedDirectory.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedFile.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DotNetAssembly.cs trunk/Source/StructureMap.Diagnostics/AssemblyInfo.cs trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/AssemblyInfo.cs trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/Caching/ExpirationTester.cs trunk/Source/StructureMap.Testing/Caching/FileModificationWatcherTester.cs trunk/Source/StructureMap.Testing/Caching/MockManagedCache.cs trunk/Source/StructureMap.Testing/Caching/StorageAndCacheItemTester.cs trunk/Source/StructureMap.Testing/Client/Controllers/ApplicationControllerTester.cs trunk/Source/StructureMap.Testing/Client/Controllers/TreeBuilderTester.cs trunk/Source/StructureMap.Testing/Client/Controllers/TreeNodeExpectation.cs trunk/Source/StructureMap.Testing/Client/GraphObjectNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserCollectionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddTypesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ChildInstanceExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreateProfileTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.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/LiteralExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ReferenceMementoBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/InstanceValidatorTester.cs trunk/Source/StructureMap.Testing/Configuration/MockGraphObject.cs trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/PluginGraphReportTester.cs trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/FamilyTokenTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/GraphObjectTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/InstanceTokenTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/MockInterceptor.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/MockMementoSource.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/PluginTokenTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildArrayPropertyTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/ChildPropertyTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/EnumerationPropertyTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/Properties/PrimitivePropertyTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/PropertyDefinitionTester.cs trunk/Source/StructureMap.Testing/ConstructorMementoTester.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/ExceptionHandling/ExceptionTestRunner.cs trunk/Source/StructureMap.Testing/Container/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Container/FillDependenciesTester.cs trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/InterceptorLibraryTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/MockTypeInterceptor.cs trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/TypeInterceptionTester.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/Container/Source/DirectoryXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Container/Source/EmbeddedFolderXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Container/Source/SingleEmbeddedXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Container/Source/TemplatingTester.cs trunk/Source/StructureMap.Testing/Container/Source/XmlAttributeInstanceMementoTester.cs trunk/Source/StructureMap.Testing/Container/Source/XmlInstanceMementoTester.cs trunk/Source/StructureMap.Testing/Container/Source/XmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Container/Source/XmlTemplaterTester.cs trunk/Source/StructureMap.Testing/Container/TypeFindingTester.cs trunk/Source/StructureMap.Testing/DataAccess/CommandFactoryTester.cs trunk/Source/StructureMap.Testing/DataAccess/Commands/ParameterizedQueryFilterTester.cs trunk/Source/StructureMap.Testing/DataAccess/Commands/StoredProcedureCommandTester.cs trunk/Source/StructureMap.Testing/DataAccess/Commands/TemplatedQueryFilterTester.cs trunk/Source/StructureMap.Testing/DataAccess/Commands/TemplatedQueryTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSessionTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSetMapping/ReaderToColumnMapTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSetMapping/ReaderToTableMapperTester.cs trunk/Source/StructureMap.Testing/DataAccess/DataSetMapping/YesNoReaderToColumnMapTester.cs trunk/Source/StructureMap.Testing/DataAccess/ExecutionStates/AutoCommitExecutionStateTester.cs trunk/Source/StructureMap.Testing/DataAccess/ExecutionStates/TransactionalExecutionStateTester.cs trunk/Source/StructureMap.Testing/DataAccess/JSON/FieldTester.cs trunk/Source/StructureMap.Testing/DataAccess/JSON/PropertyTester.cs trunk/Source/StructureMap.Testing/DataAccess/MSSQL/MSSQLDatabaseEngineTester.cs trunk/Source/StructureMap.Testing/DataAccess/Parameterization/ParameterTemplateTester.cs trunk/Source/StructureMap.Testing/DataAccess/StubbedCommand.cs trunk/Source/StructureMap.Testing/DataAccess/StubbedReaderSource.cs trunk/Source/StructureMap.Testing/DataAccess/TemplatedCommandTester.cs trunk/Source/StructureMap.Testing/DataAccess/Tools/Mocks/CommandExpectationTester.cs trunk/Source/StructureMap.Testing/DataAccess/Tools/Mocks/MockCommandTester.cs trunk/Source/StructureMap.Testing/DataAccess/Tools/Mocks/MockReaderSourceTester.cs trunk/Source/StructureMap.Testing/DataAccess/Tools/Mocks/ParameterListTester.cs trunk/Source/StructureMap.Testing/DataAccess/Tools/TableDataReaderTester.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/InstanceTarget.cs trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs trunk/Source/StructureMap.Testing/Graph/OverrideGraphTester.cs trunk/Source/StructureMap.Testing/Graph/OverrideTester.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/Graph/SetterInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs trunk/Source/StructureMap.Testing/InstanceMementoTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs trunk/Source/StructureMap.Testing/ObjectMother.cs trunk/Source/StructureMap.Testing/StructureMapConfigCreator.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/Source/StructureMap.Testing.DeploymentTasks/DeploymentExecutorTester.cs trunk/Source/StructureMap.Testing.DeploymentTasks/DeploymentTaskAcceptanceTests.cs trunk/Source/StructureMap.Testing.DeploymentTasks/DeploymentTester.cs trunk/Source/StructureMap.Testing.DeploymentTasks/SetOverrideTaskTester.cs trunk/Source/StructureMap.Testing.DeploymentTasks/SubstitutionTaskTester.cs trunk/Source/StructureMap.Testing.DeploymentTasks/Versioning/DeployedFileTester.cs trunk/Source/StructureMap.Testing.DeploymentTasks/Versioning/DotNetAssemblyTester.cs trunk/Source/StructureMap.Testing.GenericWidgets/Properties/AssemblyInfo.cs trunk/Source/StructureMap.Testing.GenericWidgets/Widgets.cs trunk/Source/StructureMap.Testing.Widget/AssemblyInfo.cs trunk/Source/StructureMap.Testing.Widget/Columns.cs trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs trunk/Source/StructureMap.Testing.Widget/IWidget.cs trunk/Source/StructureMap.Testing.Widget/Rule.cs trunk/Source/StructureMap.Testing.Widget2/AssemblyInfo.cs trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs trunk/Source/StructureMap.Testing.Widget3/AssemblyInfo.cs trunk/Source/StructureMap.Testing.Widget3/Gateways.cs trunk/Source/StructureMap.Testing.Widget4/AssemblyInfo.cs trunk/Source/StructureMap.Testing.Widget4/Strategy.cs trunk/Source/StructureMap.Testing.Widget5/AssemblyInfo.cs trunk/Source/StructureMap.Testing.Widget5/BasicGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/CannotBeAutoFilledGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/LinkGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/OtherGridColumn.cs trunk/Source/StructureMapExplorer/AssemblyInfo.cs Modified: trunk/Source/StructureMap/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap/AssemblyInfo.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/AssemblyInfo.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -1,8 +1,10 @@ using System.Reflection; + // // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. // + [assembly : AssemblyTitle("StructureMap")] [assembly : AssemblyDescription("Main Library")] \ No newline at end of file Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -12,8 +12,8 @@ public class PluginFamilyAttribute : Attribute { private string _default = string.Empty; + private InstanceScope _scope = InstanceScope.PerRequest; private Type _source = null; - private InstanceScope _scope = InstanceScope.PerRequest; public PluginFamilyAttribute() { Modified: trunk/Source/StructureMap/Caching/CacheItem.cs =================================================================== --- trunk/Source/StructureMap/Caching/CacheItem.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/CacheItem.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -5,12 +5,12 @@ { public abstract class CacheItem : ICacheItem { + private int _accesses; + private DateTime _created; + private bool _isEmpty = false; private object _key; private DateTime _lastAccessed; - private DateTime _created; - private int _accesses; private ReaderWriterLock rwl; - private bool _isEmpty = false; public CacheItem(object Key) { @@ -20,6 +20,13 @@ reset(); } + public bool IsEmpty + { + get { return _isEmpty; } + } + + #region ICacheItem Members + public object Key { get { return _key; } @@ -40,23 +47,6 @@ get { return _accesses; } } - - private void reset() - { - _accesses = 0; - _lastAccessed = _created = DateTime.Now; - } - - private void markAccess() - { - lock (this) - { - _accesses++; - _lastAccessed = DateTime.Now; - } - } - - public object Value { get @@ -77,12 +67,24 @@ } } - public bool IsEmpty + #endregion + + private void reset() { - get { return _isEmpty; } + _accesses = 0; + _lastAccessed = _created = DateTime.Now; } + private void markAccess() + { + lock (this) + { + _accesses++; + _lastAccessed = DateTime.Now; + } + } + protected abstract object getValue(); protected abstract void setValue(object Value); } Modified: trunk/Source/StructureMap/Caching/CacheManager.cs =================================================================== --- trunk/Source/StructureMap/Caching/CacheManager.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/CacheManager.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -17,11 +17,11 @@ #endregion + private EventDispatcher _clearAllDispatcher; + private bool _continuePolling = true; private HybridDictionary _dispatchers; - private bool _continuePolling = true; private bool _isPolling = false; private int _PollingTimeInMinutes; - private EventDispatcher _clearAllDispatcher; private EventDispatcher _pruneAllDispatcher; @@ -91,8 +91,27 @@ _clearAllDispatcher.Dispatch(); } + public void DispatchEvent(string EventName) + { + if (_dispatchers.Contains(EventName)) + { + EventDispatcher _dispatcher = (EventDispatcher) _dispatchers[EventName]; + _dispatcher.Dispatch(); + } + } + #region polling + public bool IsPolling + { + get { return _isPolling; } + } + + public int PollingTimeInMinutes + { + get { return _PollingTimeInMinutes; } + } + public void StartPolling() { if (!IsPolling) @@ -108,17 +127,7 @@ _continuePolling = false; } - public bool IsPolling - { - get { return _isPolling; } - } - public int PollingTimeInMinutes - { - get { return _PollingTimeInMinutes; } - } - - private void poll() { while (_continuePolling) @@ -135,14 +144,5 @@ } #endregion - - public void DispatchEvent(string EventName) - { - if (_dispatchers.Contains(EventName)) - { - EventDispatcher _dispatcher = (EventDispatcher) _dispatchers[EventName]; - _dispatcher.Dispatch(); - } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Caching/CloneStorageStrategy.cs =================================================================== --- trunk/Source/StructureMap/Caching/CloneStorageStrategy.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/CloneStorageStrategy.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -2,9 +2,13 @@ { public class CloneStorageStrategy : IStorageStrategy { + #region IStorageStrategy Members + public ICacheItem BuildCacheItem(object Key) { return new CloneCacheItem(Key); } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Caching/Expirations/AbsoluteTimeExpirationPolicy.cs =================================================================== --- trunk/Source/StructureMap/Caching/Expirations/AbsoluteTimeExpirationPolicy.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/Expirations/AbsoluteTimeExpirationPolicy.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -5,8 +5,8 @@ [Pluggable("AbsoluteTime")] public class AbsoluteTimeExpirationPolicy : IExpirationPolicy { + private DateTime _currentTime; private long _ticks; - private DateTime _currentTime; public AbsoluteTimeExpirationPolicy(int minutes) { Modified: trunk/Source/StructureMap/Caching/Expirations/SlidingTimeExpirationPolicy.cs =================================================================== --- trunk/Source/StructureMap/Caching/Expirations/SlidingTimeExpirationPolicy.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/Expirations/SlidingTimeExpirationPolicy.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -5,8 +5,8 @@ [Pluggable("SlidingTime")] public class SlidingTimeExpirationPolicy : IExpirationPolicy { + private DateTime _currentTime; private long _ticks; - private DateTime _currentTime; public SlidingTimeExpirationPolicy(int minutes) { Modified: trunk/Source/StructureMap/Caching/FileModificationWatcher.cs =================================================================== --- trunk/Source/StructureMap/Caching/FileModificationWatcher.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/FileModificationWatcher.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -4,9 +4,9 @@ { public class FileModificationWatcher : ClearEventDispatcher { + private string _fullPath; private string _key; private FileSystemWatcher _watcher; - private string _fullPath; public FileModificationWatcher(string FilePath) : base(SubjectNameFromFilePath(FilePath)) Modified: trunk/Source/StructureMap/Caching/LazyCache.cs =================================================================== --- trunk/Source/StructureMap/Caching/LazyCache.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/LazyCache.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -6,12 +6,12 @@ { public class LazyCache : IManagedCache { + private IExpirationPolicy[] _expirations; + private HybridDictionary _items; private string _name; - private IExpirationPolicy[] _expirations; + private bool _refillOnExpiration; private IValueSource _source; private IStorageStrategy _storage; - private HybridDictionary _items; - private bool _refillOnExpiration; public LazyCache(string CacheName, IExpirationPolicy[] Expirations, IValueSource Source, @@ -27,6 +27,52 @@ CacheManager.CurrentManager.ManageCache(this); } + [IndexerName("Value")] + public object this[object key] + { + get + { + if (!_items.Contains(key)) + { + lock (_items.SyncRoot) + { + if (!_items.Contains(key)) + { + ICacheItem newItem = _storage.BuildCacheItem(key); + newItem.Value = _source.GetValue(key); + _items.Add(key, newItem); + } + } + } + + ICacheItem item = (ICacheItem) _items[key]; + return item.Value; + } + set + { + ICacheItem item = null; + + if (!_items.Contains(key)) + { + lock (_items.SyncRoot) + { + if (!_items.Contains(key)) + { + item = _storage.BuildCacheItem(key); + _items.Add(key, item); + } + } + } + + if (item == null) + { + item = (ICacheItem) _items[key]; + } + + item.Value = value; + } + } + #region IManagedCache Members public string CacheName @@ -61,6 +107,13 @@ } } + public void AddWatches(CacheManager Manager) + { + // TODO: Add LazyCache.AddWatches implementation + } + + #endregion + private void expire(ICacheItem item) { if (_refillOnExpiration) @@ -73,59 +126,6 @@ } } - public void AddWatches(CacheManager Manager) - { - // TODO: Add LazyCache.AddWatches implementation - } - - #endregion - // TODO -- optimize this. Go to record level locking - - [IndexerName("Value")] - public object this[object key] - { - get - { - if (!_items.Contains(key)) - { - lock (_items.SyncRoot) - { - if (!_items.Contains(key)) - { - ICacheItem newItem = _storage.BuildCacheItem(key); - newItem.Value = _source.GetValue(key); - _items.Add(key, newItem); - } - } - } - - ICacheItem item = (ICacheItem) _items[key]; - return item.Value; - } - set - { - ICacheItem item = null; - - if (!_items.Contains(key)) - { - lock (_items.SyncRoot) - { - if (!_items.Contains(key)) - { - item = _storage.BuildCacheItem(key); - _items.Add(key, item); - } - } - } - - if (item == null) - { - item = (ICacheItem) _items[key]; - } - - item.Value = value; - } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Caching/SerializationStorageStrategy.cs =================================================================== --- trunk/Source/StructureMap/Caching/SerializationStorageStrategy.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/SerializationStorageStrategy.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -2,9 +2,13 @@ { public class SerializationStorageStrategy : IStorageStrategy { + #region IStorageStrategy Members + public ICacheItem BuildCacheItem(object Key) { return new SerializationCacheItem(Key); } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Caching/SharedStorageStrategy.cs =================================================================== --- trunk/Source/StructureMap/Caching/SharedStorageStrategy.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Caching/SharedStorageStrategy.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -2,9 +2,13 @@ { public class SharedStorageStrategy : IStorageStrategy { + #region IStorageStrategy Members + public ICacheItem BuildCacheItem(object Key) { return new SharedCacheItem(Key); } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/ConfigurationConstants.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -2,46 +2,52 @@ { public class ConfigurationConstants { - private ConfigurationConstants() - { - } + public const string CONFIGURED_DEFAULT_KEY_CANNOT_BE_FOUND = + "The default instance key configured for this PluginFamily cannot be found"; + public const string COULD_NOT_CREATE_INSTANCE = "Cannot create the configured InstanceMemento"; + public const string COULD_NOT_CREATE_MEMENTO_SOURCE = "Could not create the externally configured MementoSource"; + public const string COULD_NOT_LOAD_ASSEMBLY = "Could not load Assembly into target AppDomain"; public const string COULD_NOT_LOAD_TYPE = "Could not load Type into target AppDomain"; - public const string PLUGIN_IS_MISSING_CONCRETE_KEY = "Plugin definition is missing a value for ConcreteKey"; - public const string INVALID_SETTER = "Requested Setter property does not exist"; - public const string MEMENTO_PROPERTY_IS_MISSING = "Property is missing from the InstanceMemento configuration"; + + public const string FATAL_ERROR = + "A fatal error in configuration is preventing StructureMap from functioning correctly"; + public const string INVALID_ENUMERATION_VALUE = "Property value is not a valid name for this Enumeration type"; + public const string INVALID_PLUGIN = "Requested ConcreteKey for this PluginType cannot be found"; + public const string INVALID_PLUGIN_FAMILY = "The PluginFamily is not configured in StructureMap"; + public const string INVALID_PROPERTY_CAST = "Property value in the configured InstanceMemento could not be casted to the target type"; - public const string INVALID_PLUGIN = "Requested ConcreteKey for this PluginType cannot be found"; - public const string MISSING_INSTANCE_KEY = "InstanceKey is required"; - public const string MISSING_CHILD = "Child memento is not defined"; - public const string INVALID_PLUGIN_FAMILY = "The PluginFamily is not configured in StructureMap"; - public const string VALIDATION_METHOD_FAILURE = "A Validation Method Failed"; - public const string COULD_NOT_CREATE_INSTANCE = "Cannot create the configured InstanceMemento"; - public const string NO_DEFAULT_INSTANCE_CONFIGURED = "No default instance is configured for this PluginFamily"; - public const string NO_MATCHING_INSTANCE_CONFIGURED = "No matching instance is configured for this PluginFamily"; - public const string COULD_NOT_CREATE_MEMENTO_SOURCE = "Could not create the externally configured MementoSource"; + public const string INVALID_SETTER = "Requested Setter property does not exist"; + public const string MEMENTO_PROPERTY_IS_MISSING = "Property is missing from the InstanceMemento configuration"; public const string MEMENTO_SOURCE_CANNOT_RETRIEVE = "The configured MementoSource cannot retrieve InstanceMemento objects"; - public const string CONFIGURED_DEFAULT_KEY_CANNOT_BE_FOUND = - "The default instance key configured for this PluginFamily cannot be found"; + public const string MISSING_CHILD = "Child memento is not defined"; + public const string MISSING_INSTANCE_KEY = "InstanceKey is required"; + public const string MISSING_TEMPLATE_VALUE = "A required value for a Templated InstanceMemento is missing"; - public const string PLUGIN_FAMILY_CANNOT_BE_FOUND_FOR_INSTANCE = - "No matching PluginFamily for the embedded memento in the <Instances> node"; + public const string NO_DEFAULT_INSTANCE_CONFIGURED = "No default instance is configured for this PluginFamily"; + public const string NO_MATCHING_INSTANCE_CONFIGURED = "No matching instance is configured for this PluginFamily"; public const string PLUGIN_CANNOT_READ_CONSTRUCTOR_PROPERTIES = "There was an error trying to determine the constructor arguments for a Plugin. Check for missing dependencies of the concrete type."; - public const string FATAL_ERROR = - "A fatal error in configuration is preventing StructureMap from functioning correctly"; + public const string PLUGIN_FAMILY_CANNOT_BE_FOUND_FOR_INSTANCE = + "No matching PluginFamily for the embedded memento in the <Instances> node"; - public const string MISSING_TEMPLATE_VALUE = "A required value for a Templated InstanceMemento is missing"; + public const string PLUGIN_IS_MISSING_CONCRETE_KEY = "Plugin definition is missing a value for ConcreteKey"; + public const string UNKNOWN_PLUGIN_PROBLEM = "Exception occured while attaching a Plugin to a PluginFamily"; + public const string VALIDATION_METHOD_FAILURE = "A Validation Method Failed"; + + private ConfigurationConstants() + { + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -94,8 +94,8 @@ #endregion + private readonly XmlMementoCreator _mementoCreator; private readonly XmlNode _structureMapNode; - private readonly XmlMementoCreator _mementoCreator; public ConfigurationParser(XmlNode structureMapNode) { Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -9,10 +9,16 @@ public class ConfigurationParserCollection { + private List<FetchNodeDelegate> _fetchers = new List<FetchNodeDelegate>(); + private List<string> _otherFiles = new List<string>(); private bool _useDefaultFile = true; - private List<string> _otherFiles = new List<string>(); - private List<FetchNodeDelegate> _fetchers = new List<FetchNodeDelegate>(); + public bool UseDefaultFile + { + get { return _useDefaultFile; } + set { _useDefaultFile = value; } + } + public ConfigurationParser[] GetParsers() { List<ConfigurationParser> list = new List<ConfigurationParser>(); @@ -58,12 +64,6 @@ list.AddRange(parsers); } - public bool UseDefaultFile - { - get { return _useDefaultFile; } - set { _useDefaultFile = value; } - } - public void IncludeFile(string filename) { _otherFiles.Add(filename); Modified: trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -10,6 +10,7 @@ return new ValidateExpression(pluggedType); } + #region Nested type: ValidateExpression public class ValidateExpression { @@ -31,5 +32,7 @@ } } } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildArrayExpression.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -6,8 +6,8 @@ { public class ChildArrayExpression<PLUGINTYPE> : IExpression { + private readonly MemoryInstanceMemento _memento; private readonly InstanceExpression _parent; - private readonly MemoryInstanceMemento _memento; private readonly string _propertyName; private IMementoBuilder[] _builders; private Type _pluginType = typeof (PLUGINTYPE); @@ -21,6 +21,8 @@ _pluginType = typeof (PLUGINTYPE).GetElementType(); } + #region IExpression Members + void IExpression.Configure(PluginGraph graph) { PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); @@ -34,6 +36,8 @@ _memento.AddChildArray(_propertyName, childMementos); } + #endregion + private InstanceMemento processMementoBuilder(IMementoBuilder builder, PluginFamily family, PluginGraph graph) { builder.ValidatePluggability(_pluginType); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ChildInstanceExpression.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -14,9 +14,9 @@ private readonly InstanceExpression _instance; private readonly MemoryInstanceMemento _memento; private readonly string _propertyName; + private IMementoBuilder _builder; + private List<IExpression> _children = new List<IExpression>(); private Type _childType; - private List<IExpression> _children = new List<IExpression>(); - private IMementoBuilder _builder; public ChildInstanceExpression(InstanceExpression instance, MemoryInstanceMemento memento, string propertyName) @@ -33,6 +33,35 @@ _childType = childType; } + internal Type ChildType + { + set { _childType = value; } + } + + #region IExpression Members + + void IExpression.Configure(PluginGraph graph) + { + if (_childType == null) + { + return; + } + + PluginFamily family = graph.LocateOrCreateFamilyForType(_childType); + if (_builder != null) + { + InstanceMemento childMemento = _builder.BuildMemento(family); + _memento.AddChild(_propertyName, childMemento); + } + + foreach (IExpression child in _children) + { + child.Configure(graph); + } + } + + #endregion + /// <summary> /// Use a previously configured and named instance for the child /// </summary> @@ -67,31 +96,6 @@ } - void IExpression.Configure(PluginGraph graph) - { - if (_childType == null) - { - return; - } - - PluginFamily family = graph.LocateOrCreateFamilyForType(_childType); - if (_builder != null) - { - InstanceMemento childMemento = _builder.BuildMemento(family); - _memento.AddChild(_propertyName, childMemento); - } - - foreach (IExpression child in _children) - { - child.Configure(graph); - } - } - - internal Type ChildType - { - set { _childType = value; } - } - /// <summary> /// Registers a configured instance to use as the argument to the parent's /// constructor Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using StructureMap.Attributes; -using StructureMap.Configuration.Mementos; using StructureMap.Graph; using StructureMap.Interceptors; @@ -171,7 +170,7 @@ public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(InstanceFactoryInterceptor interceptor) { - _alterations.Add(delegate(PluginFamily family){family.InterceptionChain.AddInterceptor(interceptor);}); + _alterations.Add(delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(interceptor); }); return this; } } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -1,5 +1,4 @@ using System; -using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; namespace StructureMap.Configuration.DSL.Expressions @@ -9,8 +8,8 @@ /// </summary> public class InstanceDefaultExpression { - private readonly Type _pluginType; private readonly ProfileExpression _parent; + private readonly Type _pluginType; private string _instanceKey = string.Empty; private IMementoBuilder _mementoBuilder; Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -1,5 +1,4 @@ using System; -using StructureMap.Configuration.DSL.Expressions; using StructureMap.Configuration.Mementos; using StructureMap.Graph; @@ -10,8 +9,8 @@ /// </summary> public class InstanceExpression : MementoBuilder<InstanceExpression> { + private MemoryInstanceMemento _memento; private Type _pluggedType; - private MemoryInstanceMemento _memento; public InstanceExpression(Type pluginType) : base(pluginType) { @@ -23,12 +22,7 @@ get { return _pluggedType; } } - protected override void buildMemento() - { - _memento = new MemoryInstanceMemento(); - } - protected override InstanceMemento memento { get { return _memento; } @@ -39,6 +33,11 @@ get { return this; } } + protected override void buildMemento() + { + _memento = new MemoryInstanceMemento(); + } + protected override void configureMemento(PluginFamily family) { Plugin plugin = _pluggedType == null @@ -128,6 +127,35 @@ return new InstanceTypeExpression(this); } + public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>() + { + validateTypeIsArray<PLUGINTYPE>(); + + string propertyName = findPropertyName<PLUGINTYPE>(); + return ChildArray<PLUGINTYPE>(propertyName); + } + + public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>(string propertyName) + { + validateTypeIsArray<PLUGINTYPE>(); + + ChildArrayExpression<PLUGINTYPE> expression = + new ChildArrayExpression<PLUGINTYPE>(this, _memento, propertyName); + addChildExpression(expression); + + return expression; + } + + private static void validateTypeIsArray<PLUGINTYPE>() + { + if (!typeof (PLUGINTYPE).IsArray) + { + throw new StructureMapException(307); + } + } + + #region Nested type: InstanceTypeExpression + /// <summary> /// Helper class to capture the actual concrete type of an Instance /// </summary> @@ -163,31 +191,6 @@ } } - public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>() - { - validateTypeIsArray<PLUGINTYPE>(); - - string propertyName = findPropertyName<PLUGINTYPE>(); - return ChildArray<PLUGINTYPE>(propertyName); - } - - public ChildArrayExpression<PLUGINTYPE> ChildArray<PLUGINTYPE>(string propertyName) - { - validateTypeIsArray<PLUGINTYPE>(); - - ChildArrayExpression<PLUGINTYPE> expression = - new ChildArrayExpression<PLUGINTYPE>(this, _memento, propertyName); - addChildExpression(expression); - - return expression; - } - - private static void validateTypeIsArray<PLUGINTYPE>() - { - if (!typeof (PLUGINTYPE).IsArray) - { - throw new StructureMapException(307); - } - } + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/MementoBuilder.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Interceptors; @@ -19,6 +18,23 @@ memento.InstanceKey = Guid.NewGuid().ToString(); } + protected abstract InstanceMemento memento { get; } + + protected abstract T thisInstance { get; } + + public string InstanceKey + { + get { return memento.InstanceKey; } + set { memento.InstanceKey = value; } + } + + internal Type PluginType + { + get { return _pluginType; } + } + + #region IExpression Members + void IExpression.Configure(PluginGraph graph) { validate(); @@ -38,10 +54,30 @@ } } - protected abstract InstanceMemento memento { get; } + #endregion - protected abstract T thisInstance { get; } + #region IMementoBuilder Members + InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family) + { + return buildMementoFromFamily(family); + } + + InstanceMemento IMementoBuilder.BuildMemento(PluginGraph graph) + { + PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); + return buildMementoFromFamily(family); + } + + public void SetInstanceName(string instanceKey) + { + _instanceKey = instanceKey; + } + + public abstract void ValidatePluggability(Type pluginType); + + #endregion + protected abstract void configureMemento(PluginFamily family); protected abstract void validate(); @@ -68,24 +104,8 @@ return thisInstance; } - public string InstanceKey - { - get { return memento.InstanceKey; } - set { memento.InstanceKey = value; } - } - - internal Type PluginType - { - get { return _pluginType; } - } - protected abstract void buildMemento(); - InstanceMemento IMementoBuilder.BuildMemento(PluginFamily family) - { - return buildMementoFromFamily(family); - } - private InstanceMemento buildMementoFromFamily(PluginFamily family) { validate(); @@ -94,19 +114,6 @@ } - InstanceMemento IMementoBuilder.BuildMemento(PluginGraph graph) - { - PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType); - return buildMementoFromFamily(family); - } - - public void SetInstanceName(string instanceKey) - { - _instanceKey = instanceKey; - } - - public abstract void ValidatePluggability(Type pluginType); - protected void addChildExpression(IExpression expression) { _children.Add(expression); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-01-15 15:15:50 UTC (rev 56) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-01-15 15:56:14 UTC (rev 57) @@ -1,5 +1,4 @@ using System.Collections.Generic; -using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; namespace StructureMap.Configuration.DSL.Expressions @@ -9,14 +8,16 @@ /// </summary> public class ProfileExpression : IExpression { + private readonly List<InstanceDefaultExpression> _defaults = new List<Instanc... [truncated message content] |
From: <jer...@us...> - 2008-01-16 14:23:28
|
Revision: 58 http://structuremap.svn.sourceforge.net/structuremap/?rev=58&view=rev Author: jeremydmiller Date: 2008-01-16 06:23:24 -0800 (Wed, 16 Jan 2008) Log Message: ----------- adding work to interception cleanup Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs trunk/Source/StructureMap/StructureMap.csproj Added Paths: ----------- trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs Removed Paths: ------------- trunk/Source/StructureMap/Delegates.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-15 15:56:14 UTC (rev 57) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-01-16 14:23:24 UTC (rev 58) @@ -6,6 +6,8 @@ namespace StructureMap.Configuration.DSL { + public delegate object InterceptionDelegate(object target); + public class Registry : IDisposable { private readonly List<IExpression> _expressions = new List<IExpression>(); Modified: trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-01-15 15:56:14 UTC (rev 57) +++ trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-01-16 14:23:24 UTC (rev 58) @@ -50,11 +50,11 @@ #endregion - private Hashtable _children = new Hashtable(); - private string _concreteKey; + private readonly Hashtable _children = new Hashtable(); + private readonly string _concreteKey; private string _instanceKey; private bool _isReference; - private NameValueCollection _properties = new NameValueCollection(); + private readonly NameValueCollection _properties = new NameValueCollection(); private string _referenceKey; @@ -66,6 +66,7 @@ public MemoryInstanceMemento(string concreteKey, string instanceKey) : this(concreteKey, instanceKey, new NameValueCollection()) { + } Deleted: trunk/Source/StructureMap/Delegates.cs =================================================================== --- trunk/Source/StructureMap/Delegates.cs 2008-01-15 15:56:14 UTC (rev 57) +++ trunk/Source/StructureMap/Delegates.cs 2008-01-16 14:23:24 UTC (rev 58) @@ -1,4 +0,0 @@ -namespace StructureMap -{ - public delegate object InterceptionDelegate(object instance); -} \ No newline at end of file Added: trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs (rev 0) +++ trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2008-01-16 14:23:24 UTC (rev 58) @@ -0,0 +1,9 @@ +using System; + +namespace StructureMap.Interceptors +{ + public interface TypeInterceptor : InstanceInterceptor + { + bool MatchesType(Type type); + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-01-15 15:56:14 UTC (rev 57) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-01-16 14:23:24 UTC (rev 58) @@ -335,7 +335,6 @@ <SubType>Code</SubType> </Compile> <Compile Include="ConstructorMemento.cs" /> - <Compile Include="Delegates.cs" /> <Compile Include="DeploymentTasks\DeploymentConfiguration.cs"> <SubType>Code</SubType> </Compile> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-01-17 17:46:09
|
Revision: 59 http://structuremap.svn.sourceforge.net/structuremap/?rev=59&view=rev Author: jeremydmiller Date: 2008-01-17 09:46:06 -0800 (Thu, 17 Jan 2008) Log Message: ----------- the explicit argument functionality Modified Paths: -------------- trunk/Source/StructureMap/AssemblyInfo.cs trunk/Source/StructureMap/IInstanceCreator.cs trunk/Source/StructureMap/IInstanceManager.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs Modified: trunk/Source/StructureMap/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap/AssemblyInfo.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/AssemblyInfo.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; // // General Information about an assembly is controlled through the following @@ -7,4 +8,5 @@ // [assembly : AssemblyTitle("StructureMap")] -[assembly : AssemblyDescription("Main Library")] \ No newline at end of file +[assembly : AssemblyDescription("Main Library")] +[assembly : InternalsVisibleTo("StructureMap.AutoMocking")] \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Text; +using StructureMap.Graph; + +namespace StructureMap.Configuration.Mementos +{ + public class ExplicitArgumentMemento : InstanceMemento + { + private readonly ExplicitArguments _args; + private InstanceMemento _inner; + + public ExplicitArgumentMemento(ExplicitArguments args, InstanceMemento inner) + { + _args = args; + _inner = inner; + } + + + protected override object buildInstance(IInstanceCreator creator) + { + if (_inner == null) + { + _inner = creator.DefaultMemento; + } + + return base.buildInstance(creator); + } + + protected override string innerConcreteKey + { + get { return _inner.ConcreteKey; } + } + + protected override string innerInstanceKey + { + get { return _inner.InstanceKey; } + } + + public override bool IsReference + { + get { return false; } + } + + public override string ReferenceKey + { + get { return _inner.ReferenceKey; } + } + + protected override string getPropertyValue(string Key) + { + return _args.GetArg(Key) ?? _inner.GetProperty(Key); + } + + protected override InstanceMemento getChild(string Key) + { + return _inner.GetChildMemento(Key); + } + + public override object GetChild(string key, string typeName, InstanceManager manager) + { + Type type = Type.GetType(typeName, true); + return _args.Get(type) ?? base.GetChild(key, typeName, manager); + } + + public override InstanceMemento[] GetChildrenArray(string Key) + { + return _inner.GetChildrenArray(Key); + } + } +} Added: trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace StructureMap.Configuration.Mementos +{ + public class ExplicitArguments + { + private readonly Dictionary<Type, object> _children = new Dictionary<Type, object>(); + private readonly Dictionary<string, string> _args = new Dictionary<string, string>(); + + public T Get<T>() where T : class + { + return (T) Get(typeof(T)); + } + + public object Get(Type type) + { + return _children.ContainsKey(type) ? _children[type] : null; + } + + public void Set<T>(T arg) + { + _children.Add(typeof(T), arg); + } + + public void SetArg(string key, object argValue) + { + _args.Add(key, argValue.ToString()); + } + + public string GetArg(string key) + { + return _args.ContainsKey(key) ? _args[key] : null; + } + } +} Modified: trunk/Source/StructureMap/IInstanceCreator.cs =================================================================== --- trunk/Source/StructureMap/IInstanceCreator.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/IInstanceCreator.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -3,5 +3,6 @@ public interface IInstanceCreator { object BuildInstance(InstanceMemento memento); + InstanceMemento DefaultMemento{ get;} } } \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/IInstanceManager.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -1,4 +1,7 @@ +using System; +using System.Collections; using System.Collections.Generic; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap @@ -9,10 +12,73 @@ T CreateInstance<T>(string instanceKey); T CreateInstance<T>(); T FillDependencies<T>(); + object FillDependencies(Type type); void InjectStub<T>(T instance); IList<T> GetAllInstances<T>(); void SetDefaultsToProfile(string profile); T CreateInstance<T>(InstanceMemento memento); + + /// <summary> + /// Sets up the InstanceManager to return the object in the "stub" argument anytime + /// any instance of the PluginType is requested + /// </summary> + /// <param name="pluginType"></param> + /// <param name="stub"></param> + void InjectStub(Type pluginType, object stub); + + IList GetAllInstances(Type type); + void AddInstance<T>(InstanceMemento memento); + void AddInstance<PLUGINTYPE, CONCRETETYPE>(); + void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>(); + string WhatDoIHave(); + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceMemento"></param> + void SetDefault(Type pluginType, InstanceMemento instanceMemento); + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + void SetDefault(Type pluginType, string instanceKey); + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginTypeName"></param> + /// <param name="instanceKey"></param> + void SetDefault(string pluginTypeName, string instanceKey); + + /// <summary> + /// Creates a new object instance of the requested type + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + object CreateInstance(Type pluginType); + + + /// <summary> + /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other + /// classes to link children members + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceMemento"></param> + /// <returns></returns> + object CreateInstance(Type pluginType, InstanceMemento instanceMemento); + + /// <summary> + /// Creates the named instance of the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + /// <returns></returns> + object CreateInstance(Type pluginType, string instanceKey); + + PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args); } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -385,5 +385,11 @@ 201, memento.ConcreteKey, memento.InstanceKey, PluginType.FullName); } } + + + InstanceMemento IInstanceCreator.DefaultMemento + { + get { return _source.DefaultMemento; } + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Text; using StructureMap.Configuration.Mementos; using StructureMap.Exceptions; using StructureMap.Graph; @@ -147,6 +148,13 @@ return (T) CreateInstance(typeof (T), memento); } + public PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args) + { + ExplicitArgumentMemento memento = new ExplicitArgumentMemento(args, null); + return CreateInstance<PLUGINTYPE>(memento); + + } + public T CreateInstance<T>() { return (T) CreateInstance(typeof (T)); @@ -266,6 +274,8 @@ return instanceFactory.GetInstance(instanceKey); } + + /// <summary> /// Creates a new object instance of the requested type /// </summary> @@ -461,5 +471,18 @@ protected delegate InstanceFactory CreateFactoryDelegate(Type type); #endregion + + public string WhatDoIHave() + { + StringBuilder sb = new StringBuilder(); + + foreach (IInstanceFactory factory in this) + { + sb.AppendFormat("PluginType {0}, Default: {1}\r\n", factory.PluginType.AssemblyQualifiedName, + factory.DefaultInstanceKey); + } + + return sb.ToString(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -180,6 +180,7 @@ /// <returns></returns> protected abstract InstanceMemento getChild(string Key); + /// <summary> /// Using InstanceManager and the TypeName, creates an object instance using the /// child InstanceMemento specified by Key @@ -188,7 +189,7 @@ /// <param name="typeName"></param> /// <param name="manager"></param> /// <returns></returns> - public object GetChild(string key, string typeName, InstanceManager manager) + public virtual object GetChild(string key, string typeName, InstanceManager manager) { InstanceMemento memento = GetChildMemento(key); object returnValue = null; Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -16,8 +16,8 @@ [EnvironmentPermission(SecurityAction.Assert, Read="COMPUTERNAME")] public class ObjectFactory { - private static object _lockObject = new object(); - private static InstanceManager _manager; + private static readonly object _lockObject = new object(); + private static IInstanceManager _manager; private static string _profile = string.Empty; @@ -79,15 +79,7 @@ public static string WhatDoIHave() { - StringBuilder sb = new StringBuilder(); - - foreach (IInstanceFactory factory in manager) - { - sb.AppendFormat("PluginType {0}, Default: {1}\r\n", factory.PluginType.AssemblyQualifiedName, - factory.DefaultInstanceKey); - } - - return sb.ToString(); + return _manager.WhatDoIHave(); } /// <summary> @@ -151,7 +143,7 @@ #region InstanceManager and setting defaults - private static InstanceManager manager + private static IInstanceManager manager { get { @@ -200,7 +192,16 @@ } } + /// <summary> + /// Strictly used for testing scenarios + /// </summary> + /// <param name="manager"></param> + internal static void ReplaceManager(IInstanceManager manager) + { + _manager = manager; + } + /// <summary> /// Fires when the ObjectFactory is refreshed /// </summary> @@ -374,6 +375,57 @@ return specificInstances; } + public static ExplicitArgsExpression With<T>(T arg) + { + return new ExplicitArgsExpression(manager).With<T>(arg); + } + + public static IExplicitProperty With(string argName) + { + return new ExplicitArgsExpression(manager).With(argName); + } + + public interface IExplicitProperty + { + ExplicitArgsExpression EqualTo(object value); + } + + public class ExplicitArgsExpression : IExplicitProperty + { + private readonly IInstanceManager _manager; + private readonly ExplicitArguments _args = new ExplicitArguments(); + private string _lastArgName; + + internal ExplicitArgsExpression(IInstanceManager manager) + { + _manager = manager; + } + + public ExplicitArgsExpression With<T>(T arg) + { + _args.Set<T>(arg); + return this; + } + + public IExplicitProperty With(string argName) + { + _lastArgName = argName; + return this; + } + + + public T GetInstance<T>() + { + return _manager.CreateInstance<T>(_args); + } + + ExplicitArgsExpression IExplicitProperty.EqualTo(object value) + { + _args.SetArg(_lastArgName, value); + return this; + } + } + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-01-17 17:46:06 UTC (rev 59) @@ -219,6 +219,8 @@ <Compile Include="Configuration\DSL\Expressions\InstanceDefaultExpression.cs" /> <Compile Include="Configuration\DSL\Expressions\InstanceExpression.cs" /> <Compile Include="Configuration\DSL\Expressions\LiteralExpression.cs" /> + <Compile Include="Configuration\Mementos\ExplicitArgumentMemento.cs" /> + <Compile Include="Configuration\Mementos\ExplicitArguments.cs" /> <Compile Include="Configuration\Mementos\LiteralMemento.cs" /> <Compile Include="Configuration\DSL\Expressions\MementoBuilder.cs" /> <Compile Include="Configuration\DSL\Expressions\ProfileExpression.cs" /> Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -173,6 +173,16 @@ } /// <summary> + /// Direct StructureMap to create instances of Type T + /// </summary> + /// <typeparam name="PLUGINTYPE">The Type to build</typeparam> + /// <returns></returns> + public static CreatePluginFamilyExpression<PLUGINTYPE> ForRequestedType<PLUGINTYPE>() + { + return _registry.BuildInstancesOf<PLUGINTYPE>(); + } + + /// <summary> /// Adds a new configured instance of Type T /// </summary> /// <typeparam name="T"></typeparam> Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -13,7 +13,7 @@ public class RhinoAutoMocker<TARGETCLASS> : MockRepository where TARGETCLASS : class { - private AutoMockedInstanceManager _manager; + private readonly AutoMockedInstanceManager _manager; public RhinoAutoMocker() { @@ -21,6 +21,11 @@ _manager = new AutoMockedInstanceManager(locator); } + public void MockObjectFactory() + { + ObjectFactory.ReplaceManager(_manager); + } + public TARGETCLASS Create() { return _manager.FillDependencies<TARGETCLASS>(); Added: trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -0,0 +1,232 @@ +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Configuration.Mementos; +using StructureMap.Graph; + +namespace StructureMap.Testing.Container +{ + [TestFixture] + public class ExplicitArgumentTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + StructureMapConfiguration.ResetAll(); + StructureMapConfiguration.UseDefaultStructureMapConfigFile = false; + } + + [TearDown] + public void TearDown() + { + StructureMapConfiguration.ResetAll(); + ObjectFactory.Reset(); + + } + + #endregion + + public void GetTypedArgumentsFromAnExplicitArgumentsMementoIfThereIsAnExplicitArgument() + { + PluginGraph pluginGraph = new PluginGraph(); + using (Registry registry = new Registry(pluginGraph)) + { + registry.ForRequestedType<ExplicitTarget>().TheDefaultIs( + Registry.Instance<ExplicitTarget>() + .UsingConcreteType<ExplicitTarget>() + .Child<IProvider>().IsConcreteType<RedProvider>() + .WithProperty("name").EqualTo("Jeremy") + ); + } + + InstanceMemento inner = pluginGraph.PluginFamilies[typeof (ExplicitTarget)].Source.GetAllMementos()[0]; + ExplicitArguments args = new ExplicitArguments(); + ExplicitArgumentMemento memento = new ExplicitArgumentMemento(args, inner); + + InstanceManager manager = new InstanceManager(pluginGraph); + + // Get the ExplicitTarget without setting an explicit arg for IProvider + ExplicitTarget firstTarget = manager.CreateInstance<ExplicitTarget>(memento); + Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); + + // Now, set the explicit arg for IProvider + args.Set<IProvider>(new BlueProvider()); + ExplicitTarget secondTarget = manager.CreateInstance<ExplicitTarget>(memento); + Assert.IsInstanceOfType(typeof (BlueProvider), secondTarget.Provider); + } + + + public interface IExplicitTarget + { + } + + public class RedTarget : IExplicitTarget + { + } + + public class GreenTarget : IExplicitTarget + { + } + + public class ExplicitTarget : IExplicitTarget + { + private readonly string _name; + private readonly IProvider _provider; + + public ExplicitTarget(string name, IProvider provider) + { + _name = name; + _provider = provider; + } + + + public string Name + { + get { return _name; } + } + + public IProvider Provider + { + get { return _provider; } + } + } + + public interface IProvider + { + } + + public class RedProvider : IProvider + { + } + + public class BlueProvider : IProvider + { + } + + [Test] + public void NowDoItWithObjectFactoryItself() + { + StructureMapConfiguration.ForRequestedType<ExplicitTarget>().TheDefaultIs( + Registry.Instance<ExplicitTarget>() + .UsingConcreteType<ExplicitTarget>() + .Child<IProvider>().IsConcreteType<RedProvider>() + .WithProperty("name").EqualTo("Jeremy") + ); + + ObjectFactory.Reset(); + + // Get the ExplicitTarget without setting an explicit arg for IProvider + ExplicitTarget firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); + Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); + + // Now, set the explicit arg for IProvider + BlueProvider theBlueProvider = new BlueProvider(); + ExplicitTarget secondTarget = ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>(); + Assert.AreSame(theBlueProvider, secondTarget.Provider); + } + + [Test] + public void OverrideAPrimitiveWithObjectFactory() + { + StructureMapConfiguration.ForRequestedType<ExplicitTarget>().TheDefaultIs( + Registry.Instance<ExplicitTarget>() + .UsingConcreteType<ExplicitTarget>() + .Child<IProvider>().IsConcreteType<RedProvider>() + .WithProperty("name").EqualTo("Jeremy") + ); + + ObjectFactory.Reset(); + + // Get the ExplicitTarget without setting an explicit arg for IProvider + ExplicitTarget firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); + Assert.AreEqual("Jeremy", firstTarget.Name); + + // Now, set the explicit arg for IProvider + ExplicitTarget secondTarget = ObjectFactory.With("name").EqualTo("Julia").GetInstance<ExplicitTarget>(); + Assert.AreEqual("Julia", secondTarget.Name); + } + + [Test] + public void OverridePrimitiveArgs() + { + PluginGraph pluginGraph = new PluginGraph(); + using (Registry registry = new Registry(pluginGraph)) + { + registry.ForRequestedType<ExplicitTarget>().TheDefaultIs( + Registry.Instance<ExplicitTarget>() + .UsingConcreteType<ExplicitTarget>() + .Child<IProvider>().IsConcreteType<RedProvider>() + .WithProperty("name").EqualTo("Jeremy") + ); + } + + InstanceMemento inner = pluginGraph.PluginFamilies[typeof (ExplicitTarget)].Source.GetAllMementos()[0]; + ExplicitArguments args = new ExplicitArguments(); + ExplicitArgumentMemento memento = new ExplicitArgumentMemento(args, inner); + + InstanceManager manager = new InstanceManager(pluginGraph); + + // Once without an explicit arg set + Assert.AreEqual("Jeremy", manager.CreateInstance<ExplicitTarget>(memento).Name); + + // Now, set the explicit arg + args.SetArg("name", "Max"); + Assert.AreEqual("Max", manager.CreateInstance<ExplicitTarget>(memento).Name); + } + + [Test] + public void PassExplicitArgsIntoInstanceManager() + { + Registry registry = new Registry(); + + registry.ForRequestedType<ExplicitTarget>().TheDefaultIs( + Registry.Instance<ExplicitTarget>() + .UsingConcreteType<ExplicitTarget>() + .Child<IProvider>().IsConcreteType<RedProvider>() + .WithProperty("name").EqualTo("Jeremy") + ); + + IInstanceManager manager = registry.BuildInstanceManager(); + + ExplicitArguments args = new ExplicitArguments(); + + // Get the ExplicitTarget without setting an explicit arg for IProvider + ExplicitTarget firstTarget = manager.CreateInstance<ExplicitTarget>(args); + Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); + + // Now, set the explicit arg for IProvider + args.Set<IProvider>(new BlueProvider()); + ExplicitTarget secondTarget = manager.CreateInstance<ExplicitTarget>(args); + Assert.IsInstanceOfType(typeof (BlueProvider), secondTarget.Provider); + } + + [Test] + public void RegisterAndFindServicesOnTheExplicitArgument() + { + ExplicitArguments args = new ExplicitArguments(); + Assert.IsNull(args.Get<IProvider>()); + + RedProvider red = new RedProvider(); + args.Set<IProvider>(red); + + Assert.AreSame(red, args.Get<IProvider>()); + + args.Set<IExplicitTarget>(new RedTarget()); + Assert.IsInstanceOfType(typeof (RedTarget), args.Get<IExplicitTarget>()); + } + + [Test] + public void RegisterAndRetrieveArgs() + { + ExplicitArguments args = new ExplicitArguments(); + Assert.IsNull(args.GetArg("name")); + + args.SetArg("name", "Jeremy"); + Assert.AreEqual("Jeremy", args.GetArg("name")); + + args.SetArg("age", 34); + Assert.AreEqual("34", args.GetArg("age")); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs 2008-01-17 17:46:06 UTC (rev 59) @@ -67,6 +67,13 @@ Assert.IsNotNull(target.Rule); } + [Test] + public void FillDependenc1ies2() + { + FilledTarget target = ObjectFactory.FillDependencies<FilledTarget>(); + Assert.IsNotNull(target.Gateway); + Assert.IsNotNull(target.Rule); + } [Test] public void GetChildWithDefinedGrandChild() Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-01-16 14:23:24 UTC (rev 58) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-01-17 17:46:06 UTC (rev 59) @@ -296,6 +296,7 @@ <Compile Include="Container\ExceptionHandling\StructureMapExceptionTester.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Container\ExplicitArgumentTester.cs" /> <Compile Include="Container\FillDependenciesTester.cs"> <SubType>Code</SubType> </Compile> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-02-09 16:11:00
|
Revision: 63 http://structuremap.svn.sourceforge.net/structuremap/?rev=63&view=rev Author: jeremydmiller Date: 2008-02-09 08:10:55 -0800 (Sat, 09 Feb 2008) Log Message: ----------- spiffing up the automocking container stuff Modified Paths: -------------- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-01-29 02:02:34 UTC (rev 62) +++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-02-09 16:10:55 UTC (rev 63) @@ -32,7 +32,7 @@ registry.ConfigurePluginGraph(_pluginGraph); } - _systemGraph = new PluginGraph(); + _systemGraph = new PluginGraph(false); _systemGraph.Assemblies.Add(Assembly.GetExecutingAssembly()); } Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-01-29 02:02:34 UTC (rev 62) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-02-09 16:10:55 UTC (rev 63) @@ -20,8 +20,8 @@ private readonly InterceptorLibrary _interceptorLibrary = new InterceptorLibrary(); private readonly PluginFamilyCollection _pluginFamilies; private bool _sealed = false; + private bool _useExternalRegistries = true; - /// <summary> /// Default constructor /// </summary> @@ -32,6 +32,11 @@ } + public PluginGraph(bool useExternalRegistries) : this() + { + _useExternalRegistries = useExternalRegistries; + } + public AssemblyGraphCollection Assemblies { get { return _assemblies; } @@ -70,7 +75,10 @@ return; } - searchAssembliesForRegistries(); + if (_useExternalRegistries) + { + searchAssembliesForRegistries(); + } foreach (AssemblyGraph assembly in _assemblies) { Modified: trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-01-29 02:02:34 UTC (rev 62) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs 2008-02-09 16:10:55 UTC (rev 63) @@ -1,4 +1,5 @@ using System; +using StructureMap.Graph; namespace StructureMap.AutoMocking { Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-01-29 02:02:34 UTC (rev 62) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-02-09 16:10:55 UTC (rev 63) @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Reflection; using Rhino.Mocks; +using StructureMap.Configuration.Mementos; using StructureMap.Graph; namespace StructureMap.AutoMocking @@ -10,10 +11,11 @@ public delegate void VoidMethod(); - + // Note that it subclasses the RhinoMocks.MockRepository class public class RhinoAutoMocker<TARGETCLASS> : MockRepository where TARGETCLASS : class { private readonly AutoMockedInstanceManager _manager; + private TARGETCLASS _classUnderTest; public RhinoAutoMocker() { @@ -21,19 +23,34 @@ _manager = new AutoMockedInstanceManager(locator); } + // Replaces the inner InstanceManager in ObjectFactory with the mocked + // InstanceManager from the auto mocking container. This will make ObjectFactory + // return mocks for everything. Use cautiously!!!!!!!!!!!!!!! public void MockObjectFactory() { ObjectFactory.ReplaceManager(_manager); } - public TARGETCLASS Create() + // Gets the ClassUnderTest with mock objects (or stubs) pushed in + // for all of its dependencies + public TARGETCLASS ClassUnderTest { - return _manager.FillDependencies<TARGETCLASS>(); + get + { + if (_classUnderTest == null) + { + _classUnderTest = _manager.FillDependencies<TARGETCLASS>(); + } + + return _classUnderTest; + } } - public TARGETCLASS CreatePartialMocked() + // I find it useful from time to time to use partial mocks for the ClassUnderTest + // Especially in Presenter testing + public void PartialMockTheClassUnderTest() { - return PartialMock<TARGETCLASS>(getConstructorArgs()); + _classUnderTest = PartialMock<TARGETCLASS>(getConstructorArgs()); } private object[] getConstructorArgs() @@ -50,14 +67,20 @@ return list.ToArray(); } - public T Service<T>() + // Get one of the mock objects that are injected into the constructor function + // of the ClassUnderTest + public T Get<T>() { return _manager.CreateInstance<T>(); } + // Set the auto mocking container to use a Stub for Type T public void InjectStub<T>(T stub) { _manager.InjectStub<T>(stub); } } + + + } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-01-29 02:02:34 UTC (rev 62) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-02-09 16:10:55 UTC (rev 63) @@ -157,10 +157,10 @@ StubService stub = new StubService(); autoMocker.InjectStub<IMockedService>(stub); - IMockedService2 service2 = autoMocker.Service<IMockedService2>(); - IMockedService3 service3 = autoMocker.Service<IMockedService3>(); + IMockedService2 service2 = autoMocker.Get<IMockedService2>(); + IMockedService3 service3 = autoMocker.Get<IMockedService3>(); - ConcreteClass concreteClass = autoMocker.Create(); + ConcreteClass concreteClass = autoMocker.ClassUnderTest; Assert.AreSame(stub, concreteClass.Service); Assert.AreSame(service2, concreteClass.Service2); @@ -172,11 +172,12 @@ { RhinoAutoMocker<ConcreteClass> autoMocker = new RhinoAutoMocker<ConcreteClass>(); - IMockedService service = autoMocker.Service<IMockedService>(); - IMockedService2 service2 = autoMocker.Service<IMockedService2>(); - IMockedService3 service3 = autoMocker.Service<IMockedService3>(); + IMockedService service = autoMocker.Get<IMockedService>(); + IMockedService2 service2 = autoMocker.Get<IMockedService2>(); + IMockedService3 service3 = autoMocker.Get<IMockedService3>(); - ConcreteClass concreteClass = autoMocker.CreatePartialMocked(); + autoMocker.PartialMockTheClassUnderTest(); + ConcreteClass concreteClass = autoMocker.ClassUnderTest; Assert.AreSame(service, concreteClass.Service); Assert.AreSame(service2, concreteClass.Service2); @@ -190,18 +191,30 @@ using (autoMocker.Record()) { - Expect.Call(autoMocker.Service<IMockedService>().Name).Return("Jeremy"); + Expect.Call(autoMocker.Get<IMockedService>().Name).Return("Jeremy"); } - Assert.AreEqual("Jeremy", autoMocker.Create().Name); + Assert.AreEqual("Jeremy", autoMocker.ClassUnderTest.Name); } [Test] + public void GetTheSameConcreteClassTwiceFromCreate() + { + RhinoAutoMocker<ConcreteClass> autoMocker = new RhinoAutoMocker<ConcreteClass>(); + ConcreteClass concreteClass = autoMocker.ClassUnderTest; + + Assert.AreSame(concreteClass, autoMocker.ClassUnderTest); + Assert.AreSame(concreteClass, autoMocker.ClassUnderTest); + Assert.AreSame(concreteClass, autoMocker.ClassUnderTest); + } + + [Test] public void UseTheAutoMockerToStartUpTheConcreteClassAsAPartialMockAndSetTheNameMethodUp() { RhinoAutoMocker<ConcreteClass> autoMocker = new RhinoAutoMocker<ConcreteClass>(); - ConcreteClass concreteClass = autoMocker.CreatePartialMocked(); + autoMocker.PartialMockTheClassUnderTest(); + ConcreteClass concreteClass = autoMocker.ClassUnderTest; using (autoMocker.Record()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-02-28 15:00:21
|
Revision: 68 http://structuremap.svn.sourceforge.net/structuremap/?rev=68&view=rev Author: jeremydmiller Date: 2008-02-28 07:00:17 -0800 (Thu, 28 Feb 2008) Log Message: ----------- Fixing the bug with AddInstanceOf<Blah>() creating two instances in the call to GetAllInstances() Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs trunk/Source/StructureMap/Graph/PluginCollection.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/IInstanceManager.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -97,7 +97,7 @@ _alterations.Add(delegate(PluginFamily family) { - Plugin plugin = family.Plugins.FindOrCreate(typeof (CONCRETETYPE)); + Plugin plugin = family.Plugins.FindOrCreate(typeof (CONCRETETYPE), true); family.DefaultInstanceKey = plugin.ConcreteKey; }); @@ -161,7 +161,7 @@ { Plugin plugin = Plugin.CreateImplicitPlugin(typeof (CONCRETETYPE)); plugin.ConcreteKey = instanceName; - family.Plugins.Add(plugin); + family.Plugins.Add(plugin, true); } ); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -25,7 +25,10 @@ protected override InstanceMemento memento { - get { return _memento; } + get + { + return _memento; + } } protected override InstanceExpression thisInstance @@ -42,7 +45,7 @@ { Plugin plugin = _pluggedType == null ? family.Plugins[_memento.ConcreteKey] - : family.Plugins.FindOrCreate(_pluggedType); + : family.Plugins.FindOrCreate(_pluggedType, false); _memento.ConcreteKey = plugin.ConcreteKey; } @@ -176,6 +179,7 @@ public InstanceExpression UsingConcreteType<T>() { _parent._pluggedType = typeof (T); + _parent._memento.InstanceKey = typeof (T).Name; return _parent; } Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -159,7 +159,7 @@ Plugin plugin = new Plugin(pluginPath, concreteKey); plugin.DefinitionSource = DefinitionSource.Explicit; - family.Plugins.Add(plugin); + family.Plugins.Add(plugin, true); return plugin; } @@ -200,7 +200,7 @@ Plugin inferredPlugin = memento.CreateInferredPlugin(); if (inferredPlugin != null) { - family.Plugins.Add(inferredPlugin); + family.Plugins.Add(inferredPlugin, true); } family.Source.AddExternalMemento(memento); Modified: trunk/Source/StructureMap/Graph/PluginCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -93,7 +93,7 @@ public void Add(TypePath path, string concreteKey) { Plugin plugin = new Plugin(path, concreteKey); - Add(plugin); + Add(plugin, true); } /// <summary> @@ -105,10 +105,10 @@ public void Add(Type pluggedType, string concreteKey) { Plugin plugin = Plugin.CreateExplicitPlugin(pluggedType, concreteKey, string.Empty); - Add(plugin); + Add(plugin, true); } - public void Add(Plugin plugin) + public void Add(Plugin plugin, bool addInstanceOfTypeIfPossible) { // Reject if a duplicate ConcreteKey if (_plugins.ContainsKey(plugin.ConcreteKey)) @@ -129,10 +129,12 @@ throw new StructureMapException(114, plugin.PluggedType.FullName, _family.PluginTypeName); } - plugin.AddToSource(_family.Source); + _plugins.Add(plugin.ConcreteKey, plugin); - - _plugins.Add(plugin.ConcreteKey, plugin); + if (addInstanceOfTypeIfPossible) + { + plugin.AddToSource(_family.Source); + } } /// <summary> @@ -162,10 +164,10 @@ } } - public Plugin FindOrCreate(Type pluggedType) + public Plugin FindOrCreate(Type pluggedType, bool createDefaultInstanceOfType) { Plugin plugin = Plugin.CreateImplicitPlugin(pluggedType); - Add(plugin); + Add(plugin, createDefaultInstanceOfType); return plugin; } Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -20,7 +20,7 @@ PluginFamily family = new PluginFamily(pluginType); family.DefinitionSource = DefinitionSource.Implicit; - family.Plugins.Add(plugin); + family.Plugins.Add(plugin, true); family.DefaultInstanceKey = plugin.ConcreteKey; return family; @@ -135,7 +135,7 @@ if (isOfCorrectGenericType(plugin, templateTypes)) { Plugin templatedPlugin = plugin.CreateTemplatedClone(templateTypes); - templatedFamily.Plugins.Add(templatedPlugin); + templatedFamily.Plugins.Add(templatedPlugin, true); foreach (InstanceMemento memento in _source.GetAllMementos()) { if (memento.ConcreteKey == plugin.ConcreteKey) @@ -196,7 +196,7 @@ foreach (Plugin plugin in plugins) { - _plugins.Add(plugin); + _plugins.Add(plugin, true); } return plugins; Modified: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap/IInstanceManager.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -80,5 +80,6 @@ object CreateInstance(Type pluginType, string instanceKey); PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args); + void Inject<PLUGINTYPE>(PLUGINTYPE instance); } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -163,6 +163,13 @@ } + public void Inject<PLUGINTYPE>(PLUGINTYPE instance) + { + LiteralMemento memento = new LiteralMemento(instance); + AddInstance<PLUGINTYPE>(memento); + SetDefault(typeof(PLUGINTYPE), memento); + } + public T CreateInstance<T>() { return (T) CreateInstance(typeof (T)); Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -88,9 +88,7 @@ /// <param name="instance"></param> public static void Inject<PLUGINTYPE>(PLUGINTYPE instance) { - LiteralMemento memento = new LiteralMemento(instance); - manager.AddInstance<PLUGINTYPE>(memento); - manager.SetDefault(typeof (PLUGINTYPE), memento); + manager.Inject<PLUGINTYPE>(instance); } /// <summary> Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -77,7 +77,7 @@ // Set the auto mocking container to use a Stub for Type T public void InjectStub<T>(T stub) { - _manager.InjectStub<T>(stub); + _manager.Inject<T>(stub); } // So that Aaron Jensen can use his concrete HubService object Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using NUnit.Framework; using StructureMap.Attributes; using StructureMap.Configuration.DSL; @@ -174,6 +175,39 @@ Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); } + + [Test] + public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() + { + Registry registry = new Registry(); + registry.ForRequestedType<Something>().AddInstance( + Registry.Instance<Something>().UsingConcreteType<RedSomething>().WithName("Red") + ); + + IInstanceManager manager = registry.BuildInstanceManager(); + IList<Something> instances = manager.GetAllInstances<Something>(); + Assert.AreEqual(1, instances.Count); + } + + [Test] + public void AddInstanceWithNameOnlyAddsOneInstanceToStructureMap() + { + PluginGraph graph = new PluginGraph(); + Registry registry = new Registry(graph); + registry.AddInstanceOf<Something>().UsingConcreteType<RedSomething>().WithName("Red"); + + + + IInstanceManager manager = registry.BuildInstanceManager(); + IList<Something> instances = manager.GetAllInstances<Something>(); + Assert.AreEqual(1, instances.Count); + } + + public class Something{} + + public class RedSomething : Something{} + public class GreenSomething : Something{} + } public class StubbedInstanceFactoryInterceptor : InstanceFactoryInterceptor Modified: trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs 2008-02-14 15:31:38 UTC (rev 67) +++ trunk/Source/StructureMap.Testing/Container/SetterInjectionEmittingTester.cs 2008-02-28 15:00:17 UTC (rev 68) @@ -54,7 +54,7 @@ { PluginFamily family = new PluginFamily(typeof (IGridColumn)); Plugin plugin = Plugin.CreateImplicitPlugin(typeof (EnumGridColumn)); - family.Plugins.Add(plugin); + family.Plugins.Add(plugin, true); InstanceFactory factory = new InstanceFactory(family, true); InstanceMemento memento = _source.GetMemento("Enum"); @@ -69,7 +69,7 @@ { PluginFamily family = new PluginFamily(typeof (IGridColumn)); Plugin plugin = Plugin.CreateImplicitPlugin(typeof (LongGridColumn)); - family.Plugins.Add(plugin); + family.Plugins.Add(plugin, true); InstanceFactory factory = new InstanceFactory(family, true); InstanceMemento memento = _source.GetMemento("Long"); @@ -86,7 +86,7 @@ { PluginFamily family = new PluginFamily(typeof (IGridColumn)); Plugin plugin = Plugin.CreateImplicitPlugin(typeof (StringGridColumn)); - family.Plugins.Add(plugin); + family.Plugins.Add(plugin, true); InstanceFactory factory = new InstanceFactory(family, true); InstanceMemento memento = _source.GetMemento("String"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-04-06 16:26:11
|
Revision: 70 http://structuremap.svn.sourceforge.net/structuremap/?rev=70&view=rev Author: jeremydmiller Date: 2008-04-06 09:26:03 -0700 (Sun, 06 Apr 2008) Log Message: ----------- cleaning out trash code and reformatting code Modified Paths: -------------- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/Configuration/IGraphBuilder.cs trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs trunk/Source/StructureMap/Graph/MachineOverride.cs trunk/Source/StructureMap/Graph/Profile.cs trunk/Source/StructureMap/IInstanceCreator.cs trunk/Source/StructureMap/IPluginGraphSource.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/MementoSource.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/Properties/AssemblyInfo.cs trunk/Source/StructureMap/Source/TemplatedMementoSource.cs trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlTemplater.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs trunk/Source/StructureMap.Testing/Container/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs trunk/Source/StructureMap.Testing/Container/Interceptors/MockTypeInterceptor.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/Source/StructureMap.Testing/TestData/DataMother.cs Removed Paths: ------------- trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs trunk/Source/StructureMap/Configuration/GraphObject.cs trunk/Source/StructureMap/Configuration/GraphObjectIterator.cs trunk/Source/StructureMap/Configuration/IConfigurationVisitor.cs trunk/Source/StructureMap/Configuration/IInstanceValidator.cs trunk/Source/StructureMap/Configuration/InstanceValidator.cs trunk/Source/StructureMap/Configuration/PluginGraphReport.cs trunk/Source/StructureMap/Configuration/ProblemFinder.cs trunk/Source/StructureMap/Configuration/Tokens/ trunk/Source/StructureMap/DeploymentTasks/ trunk/Source/StructureMap/Graph/RemoteGraph.cs trunk/Source/StructureMap/Graph/RemoteGraphContainer.cs trunk/Source/StructureMap/Verification/ trunk/Source/StructureMap.DeploymentTasks/Deployment.cs trunk/Source/StructureMap.DeploymentTasks/DumbConfigMergeTask.cs trunk/Source/StructureMap.DeploymentTasks/ImportFamilyTask.cs trunk/Source/StructureMap.DeploymentTasks/RemoveAssemblyTask.cs trunk/Source/StructureMap.DeploymentTasks/Verification.cs trunk/Source/StructureMap.Testing/Client/ trunk/Source/StructureMap.Testing/Configuration/DiagnosticGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/GraphObjectIteratorTester.cs trunk/Source/StructureMap.Testing/Configuration/InstanceValidatorTester.cs trunk/Source/StructureMap.Testing/Configuration/MockGraphObject.cs trunk/Source/StructureMap.Testing/Configuration/PluginGraphReportTester.cs trunk/Source/StructureMap.Testing/Configuration/Tokens/ Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -3,7 +3,6 @@ using System.IO; using System.Xml; using StructureMap.Graph; -using StructureMap.Graph.Configuration; using StructureMap.Source; namespace StructureMap.Configuration Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserCollection.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -10,9 +10,9 @@ public class ConfigurationParserCollection { private List<FetchNodeDelegate> _fetchers = new List<FetchNodeDelegate>(); + private bool _ignoreDefaultFile = false; private List<string> _otherFiles = new List<string>(); private bool _UseAndEnforceExistenceOfDefaultFile = false; - private bool _ignoreDefaultFile = false; public bool UseAndEnforceExistenceOfDefaultFile { @@ -33,7 +33,7 @@ // Pick up the configuration in the default StructureMap.config string pathToStructureMapConfig = StructureMapConfiguration.GetStructureMapConfigurationPath(); - if ( (_UseAndEnforceExistenceOfDefaultFile || File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile) + if ((_UseAndEnforceExistenceOfDefaultFile || File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile) { addParsersFromFile(pathToStructureMapConfig, list); } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -25,10 +25,7 @@ protected override InstanceMemento memento { - get - { - return _memento; - } + get { return _memento; } } protected override InstanceExpression thisInstance Deleted: trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/DiagnosticGraphBuilder.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,287 +0,0 @@ -using System; -using StructureMap.Attributes; -using StructureMap.Configuration.DSL; -using StructureMap.Configuration.Tokens; -using StructureMap.Graph; -using StructureMap.Graph.Configuration; -using StructureMap.Interceptors; - -namespace StructureMap.Configuration -{ - public class DiagnosticGraphBuilder : IGraphBuilder - { - private NormalGraphBuilder _innerBuilder; - private PluginGraphReport _report; - private PluginGraphReport _systemReport; - private InstanceValidator _systemValidator; - - public DiagnosticGraphBuilder(Registry[] registries) - { - _innerBuilder = new NormalGraphBuilder(registries); - _systemReport = new PluginGraphReport(); - _report = new PluginGraphReport(); - } - - public PluginGraphReport Report - { - get { return _report; } - } - - #region IGraphBuilder Members - - public PluginGraph PluginGraph - { - get { return _innerBuilder.PluginGraph; } - } - - public void AddProfile(string profileName) - { - _innerBuilder.AddProfile(profileName); - } - - public void OverrideProfile(string fullTypeName, string instanceKey) - { - _innerBuilder.OverrideProfile(fullTypeName, instanceKey); - } - - public void AddMachine(string machineName, string profileName) - { - try - { - _innerBuilder.AddMachine(machineName, profileName); - } - catch (Exception e) - { - _report.LogProblem(new Problem("Could not add Machine", e)); - } - } - - public void OverrideMachine(string fullTypeName, string instanceKey) - { - _innerBuilder.OverrideMachine(fullTypeName, instanceKey); - } - - public TypePath LocateOrCreateFamilyForType(string fullName) - { - try - { - return _innerBuilder.LocateOrCreateFamilyForType(fullName); - } - catch (Exception e) - { - string message = - string.Format("Could not find the implied type '{0}' in any of the designated Assemblies", fullName); - _report.LogProblem(new Problem(message, e)); - - return null; - } - } - - public void AddAssembly(string assemblyName, string[] deployableTargets) - { - AssemblyToken assemblyToken = new AssemblyToken(assemblyName, deployableTargets); - _report.AddAssembly(assemblyToken); - _systemReport.AddAssembly(assemblyToken); - - try - { - _innerBuilder.AddAssembly(assemblyName, deployableTargets); - } - catch (Exception ex) - { - assemblyToken.MarkLoadFailure(ex); - } - } - - - public void StartFamilies() - { - _innerBuilder.StartFamilies(); - InstanceManager systemInstanceManager = new InstanceManager(_innerBuilder.SystemGraph); - _systemValidator = - new InstanceValidator(_innerBuilder.SystemGraph, new Profile("defaults"), systemInstanceManager); - _systemReport.ImportImplicitChildren(SystemGraph); - } - - public void AddPluginFamily(TypePath typePath, string defaultKey, string[] deploymentTargets, - InstanceScope scope) - { - FamilyToken family = new FamilyToken(typePath, defaultKey, deploymentTargets); - family.DefinitionSource = DefinitionSource.Explicit; - family.Scope = scope; - _report.AddFamily(family); - - try - { - Type type = typePath.FindType(); - _innerBuilder.AddPluginFamily(typePath, defaultKey, deploymentTargets, scope); - } - catch (Exception ex) - { - family.MarkAsInvalidType(ex); - } - } - - - public void AttachSource(TypePath pluginTypePath, InstanceMemento sourceMemento) - { - FamilyToken family = _report.FindFamily(pluginTypePath); - - MementoSourceInstanceToken sourceInstance = - new MementoSourceInstanceToken(typeof (MementoSource), _systemReport, sourceMemento); - family.SourceInstance = sourceInstance; - sourceInstance.Validate(_systemValidator); - - try - { - _innerBuilder.AttachSource(pluginTypePath, sourceMemento); - } - catch (Exception ex) - { - Problem problem = new Problem(ConfigurationConstants.COULD_NOT_CREATE_MEMENTO_SOURCE, ex); - family.LogProblem(problem); - } - } - - public void AttachSource(TypePath pluginTypePath, MementoSource source) - { - _innerBuilder.AttachSource(pluginTypePath, source); - } - - public Plugin AddPlugin(TypePath pluginTypePath, TypePath pluginPath, string concreteKey) - { - PluginToken pluginToken = new PluginToken(pluginPath, concreteKey, DefinitionSource.Explicit); - FamilyToken familyToken = _report.FindFamily(pluginTypePath); - familyToken.AddPlugin(pluginToken); - - Plugin returnValue = null; - - try - { - Plugin plugin = _innerBuilder.AddPlugin(pluginTypePath, pluginPath, concreteKey); - pluginToken.ReadProperties(plugin); - returnValue = plugin; - } - catch (StructureMapException ex) - { - if (ex.ErrorCode == 112) - { - Problem problem = new Problem(ConfigurationConstants.PLUGIN_IS_MISSING_CONCRETE_KEY, ex); - pluginToken.LogProblem(problem); - } - else - { - Problem problem = new Problem(ConfigurationConstants.COULD_NOT_LOAD_TYPE, ex); - pluginToken.LogProblem(problem); - } - } - catch (Exception ex) - { - Problem problem = new Problem(ConfigurationConstants.UNKNOWN_PLUGIN_PROBLEM, ex); - pluginToken.LogProblem(problem); - } - - return returnValue; - } - - public SetterProperty AddSetter(TypePath pluginTypePath, string concreteKey, string setterName) - { - FamilyToken familyToken = _report.FindFamily(pluginTypePath); - PluginToken pluginToken = familyToken.FindPlugin(concreteKey); - - SetterProperty setter = null; - - try - { - setter = _innerBuilder.AddSetter(pluginTypePath, concreteKey, setterName); - PropertyDefinition property = PropertyDefinitionBuilder.CreatePropertyDefinition(setter.Property); - pluginToken.AddPropertyDefinition(property); - } - catch (Exception ex) - { - PropertyDefinition property = - new PropertyDefinition(setterName, PropertyDefinitionType.Setter, ArgumentType.Primitive); - pluginToken.AddPropertyDefinition(property); - Problem problem = new Problem(ConfigurationConstants.INVALID_SETTER, ex); - - property.LogProblem(problem); - } - - return setter; - } - - public void AddInterceptor(TypePath pluginTypePath, InstanceMemento interceptorMemento) - { - InstanceToken instance = - new InterceptorInstanceToken(typeof (InstanceFactoryInterceptor), _systemReport, interceptorMemento); - instance.Validate(_systemValidator); - FamilyToken family = _report.FindFamily(pluginTypePath); - family.AddInterceptor(instance); - - try - { - _innerBuilder.AddInterceptor(pluginTypePath, interceptorMemento); - } - catch (Exception) - { - // no-op; The call above to instance.Validate(_systemValidator) will find the Problem - } - } - - - public void FinishFamilies() - { - _innerBuilder.FinishFamilies(); - } - - public PluginGraph CreatePluginGraph() - { - PluginGraph pluginGraph = _innerBuilder.CreatePluginGraph(); - _report.ImportImplicitChildren(pluginGraph); - _report.AnalyzeInstances(pluginGraph); - - Profile defaultProfile = _innerBuilder.DefaultManager.CalculateDefaults(); - - InstanceManager manager = new InstanceManager(); - try - { - manager = new InstanceManager(pluginGraph); - } - catch (Exception ex) - { - Problem problem = new Problem(ConfigurationConstants.FATAL_ERROR, ex); - _report.LogProblem(problem); - } - - IInstanceValidator validator = new InstanceValidator(pluginGraph, defaultProfile, manager); - _report.ValidateInstances(validator); - - return pluginGraph; - } - - public PluginGraph SystemGraph - { - get { return _innerBuilder.SystemGraph; } - } - - public InstanceDefaultManager DefaultManager - { - get { return _innerBuilder.DefaultManager; } - } - - public void RegisterMemento(TypePath pluginTypePath, InstanceMemento memento) - { - try - { - _innerBuilder.RegisterMemento(pluginTypePath, memento); - } - catch (Exception ex) - { - Problem problem = new Problem(ConfigurationConstants.PLUGIN_FAMILY_CANNOT_BE_FOUND_FOR_INSTANCE, ex); - _report.LogProblem(problem); - } - } - - #endregion - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -2,7 +2,6 @@ using System.Xml; using StructureMap.Attributes; using StructureMap.Graph; -using StructureMap.Graph.Configuration; using StructureMap.Source; namespace StructureMap.Configuration Deleted: trunk/Source/StructureMap/Configuration/GraphObject.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphObject.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/GraphObject.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace StructureMap.Configuration -{ - [Serializable] - public abstract class GraphObject : IComparable - { - private Guid _id = Guid.NewGuid(); - private List<Problem> _problems = new List<Problem>(); - - public GraphObject() - { - } - - public Guid Id - { - get { return _id; } - set { _id = value; } - } - - public Problem[] Problems - { - get { return _problems.ToArray(); } - set { _problems = new List<Problem>(value); } - } - - public virtual GraphObject[] Children - { - get { return new GraphObject[0]; } - } - - protected abstract string key { get; } - - #region IComparable Members - - public int CompareTo(object obj) - { - GraphObject peer = (GraphObject) obj; - return key.CompareTo(peer.key); - } - - #endregion - - public void LogProblem(Problem problem) - { - _problems.Add(problem); - } - - public virtual void AcceptVisitor(IConfigurationVisitor visitor) - { - // no-op - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/GraphObjectIterator.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphObjectIterator.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/GraphObjectIterator.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,25 +0,0 @@ -namespace StructureMap.Configuration -{ - public class GraphObjectIterator - { - private readonly IConfigurationVisitor _visitor; - - public GraphObjectIterator(IConfigurationVisitor visitor) - { - _visitor = visitor; - } - - public void Visit(GraphObject startNode) - { - _visitor.StartObject(startNode); - startNode.AcceptVisitor(_visitor); - - foreach (GraphObject child in startNode.Children) - { - Visit(child); - } - - _visitor.EndObject(startNode); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/IConfigurationVisitor.cs =================================================================== --- trunk/Source/StructureMap/Configuration/IConfigurationVisitor.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/IConfigurationVisitor.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,28 +0,0 @@ -using StructureMap.Configuration.Tokens; -using StructureMap.Configuration.Tokens.Properties; - -namespace StructureMap.Configuration -{ - public interface IConfigurationVisitor - { - void StartObject(GraphObject node); - void EndObject(GraphObject node); - - void HandleAssembly(AssemblyToken assembly); - void HandleFamily(FamilyToken family); - void HandleMementoSource(MementoSourceInstanceToken source); - void HandlePlugin(PluginToken plugin); - void HandleInterceptor(InterceptorInstanceToken interceptor); - void HandleInstance(InstanceToken instance); - void HandlePrimitiveProperty(PrimitiveProperty property); - void HandleEnumerationProperty(EnumerationProperty property); - void HandleInlineChildProperty(ChildProperty property); - void HandleDefaultChildProperty(ChildProperty property); - void HandleReferenceChildProperty(ChildProperty property); - void HandlePropertyDefinition(PropertyDefinition propertyDefinition); - void HandleChildArrayProperty(ChildArrayProperty property); - void HandleNotDefinedChildProperty(ChildProperty property); - void HandleTemplate(TemplateToken template); - void HandleTemplateProperty(TemplateProperty property); - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,6 +1,7 @@ using StructureMap.Attributes; +using StructureMap.Graph; -namespace StructureMap.Graph.Configuration +namespace StructureMap.Configuration { public interface IGraphBuilder { @@ -28,6 +29,7 @@ void OverrideProfile(string fullTypeName, string instanceKey); void AddMachine(string machineName, string profileName); void OverrideMachine(string fullTypeName, string instanceKey); + TypePath LocateOrCreateFamilyForType(string fullName); } } \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/IInstanceValidator.cs =================================================================== --- trunk/Source/StructureMap/Configuration/IInstanceValidator.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/IInstanceValidator.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,11 +0,0 @@ -using System; - -namespace StructureMap.Configuration -{ - public interface IInstanceValidator - { - object CreateObject(Type pluginType, InstanceMemento memento); - bool HasDefaultInstance(Type pluginType); - bool InstanceExists(Type pluginType, string instanceKey); - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/InstanceValidator.cs =================================================================== --- trunk/Source/StructureMap/Configuration/InstanceValidator.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/InstanceValidator.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,59 +0,0 @@ -using System; -using StructureMap.Graph; - -namespace StructureMap.Configuration -{ - public class InstanceValidator : IInstanceValidator - { - private readonly Profile _defaultProfile; - private readonly PluginGraph _pluginGraph; - private InstanceManager _instanceManager; - - public InstanceValidator(PluginGraph pluginGraph, Profile defaultProfile, InstanceManager instanceManager) - { - if (defaultProfile == null) - { - throw new ArgumentNullException("defaultProfile", "Cannot be null"); - } - - _pluginGraph = pluginGraph; - _defaultProfile = defaultProfile; - _instanceManager = instanceManager; - } - - #region IInstanceValidator Members - - public object CreateObject(Type pluginType, InstanceMemento memento) - { - return _instanceManager.CreateInstance(pluginType, memento); - } - - public bool HasDefaultInstance(Type pluginType) - { - return _defaultProfile.HasOverride(TypePath.GetAssemblyQualifiedName(pluginType)); - } - - public bool InstanceExists(Type pluginType, string instanceKey) - { - bool returnValue = false; - - try - { - PluginFamily family = _pluginGraph.PluginFamilies[pluginType]; - InstanceMemento memento = family.Source.GetMemento(instanceKey); - if (memento != null) - { - returnValue = true; - } - } - catch (Exception) - { - returnValue = false; - } - - return returnValue; - } - - #endregion - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -14,16 +14,6 @@ } - protected override object buildInstance(IInstanceCreator creator) - { - if (_inner == null) - { - _inner = creator.DefaultMemento; - } - - return base.buildInstance(creator); - } - protected override string innerConcreteKey { get { return _inner.ConcreteKey; } @@ -44,6 +34,16 @@ get { return _inner.ReferenceKey; } } + protected override object buildInstance(IInstanceCreator creator) + { + if (_inner == null) + { + _inner = creator.DefaultMemento; + } + + return base.buildInstance(creator); + } + protected override string getPropertyValue(string Key) { return _args.GetArg(Key) ?? _inner.GetProperty(Key); @@ -65,4 +65,4 @@ return _inner.GetChildrenArray(Key); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/Mementos/ExplicitArguments.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -5,12 +5,12 @@ { public class ExplicitArguments { + private readonly Dictionary<string, string> _args = new Dictionary<string, string>(); private readonly Dictionary<Type, object> _children = new Dictionary<Type, object>(); - private readonly Dictionary<string, string> _args = new Dictionary<string, string>(); public T Get<T>() where T : class { - return (T) Get(typeof(T)); + return (T) Get(typeof (T)); } public object Get(Type type) @@ -20,7 +20,7 @@ public void Set<T>(T arg) { - _children.Add(typeof(T), arg); + _children.Add(typeof (T), arg); } public void SetArg(string key, object argValue) @@ -33,4 +33,4 @@ return _args.ContainsKey(key) ? _args[key] : null; } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/Mementos/MemoryInstanceMemento.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -52,9 +52,9 @@ private readonly Hashtable _children = new Hashtable(); private readonly string _concreteKey; + private readonly NameValueCollection _properties = new NameValueCollection(); private string _instanceKey; private bool _isReference; - private readonly NameValueCollection _properties = new NameValueCollection(); private string _referenceKey; @@ -66,7 +66,6 @@ public MemoryInstanceMemento(string concreteKey, string instanceKey) : this(concreteKey, instanceKey, new NameValueCollection()) { - } Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -3,7 +3,6 @@ using StructureMap.Attributes; using StructureMap.Configuration.DSL; using StructureMap.Graph; -using StructureMap.Graph.Configuration; using StructureMap.Interceptors; namespace StructureMap.Configuration Deleted: trunk/Source/StructureMap/Configuration/PluginGraphReport.cs =================================================================== --- trunk/Source/StructureMap/Configuration/PluginGraphReport.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/PluginGraphReport.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,215 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using StructureMap.Configuration.Tokens; -using StructureMap.Exceptions; -using StructureMap.Graph; - -namespace StructureMap.Configuration -{ - [Serializable] - public class PluginGraphReport : GraphObject - { - private Hashtable _assemblies = new Hashtable(); - private InstanceDefaultManager _defaultManager; - private Dictionary<TypePath, FamilyToken> _families = new Dictionary<TypePath, FamilyToken>(); - - public PluginGraphReport() - { - } - - public PluginGraphReport(PluginGraph pluginGraph) - { - ReadFromPluginGraph(pluginGraph); - } - - public override GraphObject[] Children - { - get - { - ArrayList list = new ArrayList(); - - list.AddRange(_assemblies.Values); - list.AddRange(_families.Values); - - list.Sort(); - - return (GraphObject[]) list.ToArray(typeof (GraphObject)); - } - } - - public InstanceDefaultManager DefaultManager - { - get { return _defaultManager; } - set { _defaultManager = value; } - } - - public AssemblyToken[] Assemblies - { - get - { - AssemblyToken[] returnValue = new AssemblyToken[_assemblies.Count]; - _assemblies.Values.CopyTo(returnValue, 0); - - return returnValue; - } - } - - public FamilyToken[] Families - { - get - { - FamilyToken[] returnValue = new FamilyToken[_families.Count]; - _families.Values.CopyTo(returnValue, 0); - - - return returnValue; - } - } - - protected override string key - { - get { return string.Empty; } - } - - public void ReadFromPluginGraph(PluginGraph pluginGraph) - { - ImportImplicitChildren(pluginGraph); - AnalyzeInstances(pluginGraph); - - Profile defaultProfile = pluginGraph.DefaultManager.CalculateDefaults(); - - InstanceManager manager = new InstanceManager(); - try - { - manager = new InstanceManager(pluginGraph); - } - catch (Exception ex) - { - Problem problem = new Problem(ConfigurationConstants.FATAL_ERROR, ex); - LogProblem(problem); - } - - IInstanceValidator validator = new InstanceValidator(pluginGraph, defaultProfile, manager); - ValidateInstances(validator); - } - - public void AddAssembly(AssemblyToken assemblyToken) - { - _assemblies.Add(assemblyToken.AssemblyName, assemblyToken); - } - - public void AddFamily(FamilyToken family) - { - _families.Add(family.TypePath, family); - } - - public FamilyToken FindFamily(string pluginTypeClassName) - { - TypePath path = TypePath.GetTypePath(pluginTypeClassName); - if (path != null) - { - return FindFamily(path); - } - - foreach (KeyValuePair<TypePath, FamilyToken> pair in _families) - { - if (pair.Key.Matches(pluginTypeClassName)) - { - return pair.Value; - } - } - - return null; - } - - public bool HasFamily(Type pluginType) - { - return _families.ContainsKey(new TypePath(pluginType)); - } - - public FamilyToken FindFamily(Type pluginType) - { - TypePath path = new TypePath(pluginType); - - if (!_families.ContainsKey(path)) - { - throw new MissingPluginFamilyException(path.AssemblyQualifiedName); - } - - return _families[path]; - } - - - public PluginToken FindPlugin(TypePath pluginTypePath, string concreteKey) - { - return FindFamily(pluginTypePath).FindPlugin(concreteKey); - } - - public PluginToken FindPlugin(Type pluginType, string concreteKey) - { - return FindPlugin(new TypePath(pluginType), concreteKey); - } - - public void ImportImplicitChildren(PluginGraph pluginGraph) - { - foreach (PluginFamily family in pluginGraph.PluginFamilies) - { - if (family.DefinitionSource == DefinitionSource.Implicit) - { - FamilyToken token = FamilyToken.CreateImplicitFamily(family); - AddFamily(token); - } - - addImplicitPlugins(family); - } - } - - private void addImplicitPlugins(PluginFamily family) - { - FamilyToken familyToken = FindFamily(family.PluginType); - - foreach (Plugin plugin in family.Plugins) - { - if (plugin.DefinitionSource == DefinitionSource.Implicit) - { - PluginToken pluginToken = PluginToken.CreateImplicitToken(plugin); - familyToken.AddPlugin(pluginToken); - } - } - } - - public void AnalyzeInstances(PluginGraph pluginGraph) - { - foreach (PluginFamily family in pluginGraph.PluginFamilies) - { - FamilyToken token = FindFamily(family.PluginType); - token.ReadInstances(family, this); - } - } - - public void ValidateInstances(IInstanceValidator validator) - { - foreach (FamilyToken family in _families.Values) - { - family.Validate(validator); - } - } - - public bool HasAssembly(string assemblyName) - { - return _assemblies.ContainsKey(assemblyName); - } - - public TemplateToken FindTemplate(TypePath pluginTypePath, string templateName) - { - FamilyToken family = FindFamily(pluginTypePath); - return family.FindTemplate(templateName); - } - - public FamilyToken FindFamily(TypePath path) - { - return _families[path]; - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Configuration/ProblemFinder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProblemFinder.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/ProblemFinder.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,178 +0,0 @@ -using System.Collections; -using StructureMap.Configuration.Tokens; -using StructureMap.Configuration.Tokens.Properties; -using StructureMap.Graph; - -namespace StructureMap.Configuration -{ - public class ProblemFinder : IConfigurationVisitor - { - private readonly PluginGraphReport _report; - private Stack _graphPath = new Stack(); - private ArrayList _problems = new ArrayList(); - - public ProblemFinder(PluginGraphReport report) - { - _report = report; - } - - #region IConfigurationVisitor Members - - public void StartObject(GraphObject node) - { - _graphPath.Push(node.ToString()); - - Problem[] problems = node.Problems; - if (problems.Length > 0) - { - string path = buildPathString(); - foreach (Problem problem in problems) - { - problem.Path = path; - problem.ObjectId = node.Id; - } - - _problems.AddRange(problems); - } - } - - public void EndObject(GraphObject node) - { - _graphPath.Pop(); - } - - public void HandleAssembly(AssemblyToken assembly) - { - // no-op - } - - public void HandleFamily(FamilyToken family) - { - // no-op - } - - public void HandleMementoSource(MementoSourceInstanceToken source) - { - // no-op - } - - public void HandlePlugin(PluginToken plugin) - { - // no-op - } - - public void HandleInterceptor(InterceptorInstanceToken interceptor) - { - // no-op - } - - public void HandleInstance(InstanceToken instance) - { - // no-op - } - - public void HandlePrimitiveProperty(PrimitiveProperty property) - { - // no-op - } - - public void HandleEnumerationProperty(EnumerationProperty property) - { - // no-op - } - - public void HandleInlineChildProperty(ChildProperty property) - { - // no-op - } - - public void HandleDefaultChildProperty(ChildProperty property) - { - // no-op - } - - public void HandleReferenceChildProperty(ChildProperty property) - { - // no-op - } - - public void HandlePropertyDefinition(PropertyDefinition propertyDefinition) - { - // no-op - } - - public void HandleChildArrayProperty(ChildArrayProperty property) - { - // no-op - } - - public void HandleNotDefinedChildProperty(ChildProperty property) - { - // no-op - } - - public void HandleTemplate(TemplateToken template) - { - // no-op - } - - public void HandleTemplateProperty(TemplateProperty property) - { - // no-op - } - - #endregion - - public static Problem[] FindProblems(string configPath) - { - RemoteGraphContainer container = new RemoteGraphContainer(configPath); - RemoteGraph remoteGraph = container.GetRemoteGraph(); - PluginGraphReport report = remoteGraph.GetReport(); - ProblemFinder finder = new ProblemFinder(report); - - return finder.GetProblems(); - } - - public static Problem[] FindProblems(string configPath, string binPath) - { - if (binPath == string.Empty || binPath == null) - { - return FindProblems(configPath); - } - - RemoteGraphContainer container = new RemoteGraphContainer(configPath, binPath); - RemoteGraph remoteGraph = container.GetRemoteGraph(); - PluginGraphReport report = remoteGraph.GetReport(); - ProblemFinder finder = new ProblemFinder(report); - - return finder.GetProblems(); - } - - public static Problem[] FindProblems(PluginGraphReport report) - { - ProblemFinder finder = new ProblemFinder(report); - return finder.GetProblems(); - } - - public Problem[] GetProblems() - { - GraphObjectIterator iterator = new GraphObjectIterator(this); - iterator.Visit(_report); - return (Problem[]) _problems.ToArray(typeof (Problem)); - } - - private string buildPathString() - { - string pad = ""; - string path = ""; - - foreach (object node in _graphPath) - { - path += pad + node + "\n"; - pad += " "; - } - - return path; - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,6 +1,5 @@ using System.Xml; using StructureMap.Graph; -using StructureMap.Graph.Configuration; using StructureMap.Source; namespace StructureMap.Configuration Modified: trunk/Source/StructureMap/Graph/MachineOverride.cs =================================================================== --- trunk/Source/StructureMap/Graph/MachineOverride.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Graph/MachineOverride.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; -using StructureMap.Configuration; namespace StructureMap.Graph { @@ -122,6 +121,5 @@ { return (_defaults.ContainsKey(pluginTypeName) || _profile.HasOverride(pluginTypeName)); } - } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/Profile.cs =================================================================== --- trunk/Source/StructureMap/Graph/Profile.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Graph/Profile.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; -using StructureMap.Configuration; namespace StructureMap.Graph { Deleted: trunk/Source/StructureMap/Graph/RemoteGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/RemoteGraph.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Graph/RemoteGraph.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,72 +0,0 @@ -using System; -using System.Reflection; -using StructureMap.Configuration; -using StructureMap.DeploymentTasks; - -namespace StructureMap.Graph -{ - /// <summary> - /// Manages the setup and teardown of a new AppDomain to test a StructureMap configuration. - /// </summary> - public class RemoteGraph : MarshalByRefObject - { - private string _binPath; - private string _configPath; - private PluginGraph _pluginGraph; - private PluginGraphReport _report; - - public RemoteGraph() : base() - { - } - - public string ConfigPath - { - get { return _configPath; } - } - - - public void Load(string configPath, string binPath) - { - _configPath = configPath; - _binPath = binPath; - AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); - } - - private void initializeChildren() - { - if (_pluginGraph != null) - { - return; - } - - PluginGraphBuilder builder = new PluginGraphBuilder(_configPath); - _pluginGraph = builder.BuildDiagnosticPluginGraph(); - _report = builder.Report; - } - - - public DeploymentExecutor CreateDeploymentExecutor() - { - return new DeploymentExecutor(); - } - - public PluginGraphReport GetReport() - { - initializeChildren(); - return _report; - } - - public PluginGraph GetPluginGraph() - { - PluginGraphBuilder builder = new PluginGraphBuilder(_configPath); - return builder.Build(); - } - - - private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) - { - string fileName = string.Format("{0}\\{1}.Dll", _binPath, args.Name); - return Assembly.LoadFile(fileName); - } - } -} \ No newline at end of file Deleted: trunk/Source/StructureMap/Graph/RemoteGraphContainer.cs =================================================================== --- trunk/Source/StructureMap/Graph/RemoteGraphContainer.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/Graph/RemoteGraphContainer.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,70 +0,0 @@ -using System; -using System.IO; -using System.Reflection; -using System.Security.Policy; - -namespace StructureMap.Graph -{ - /// <summary> - /// Manages the setup and teardown of a new AppDomain to test a StructureMap configuration. - /// </summary> - [Serializable] - public class RemoteGraphContainer : MarshalByRefObject - { - private readonly string _assembliesPath; - private readonly string _configPath; - private AppDomain _domain; - - public RemoteGraphContainer(string configPath, string binPath) - { - _configPath = Path.GetFullPath(configPath); - _assembliesPath = Path.GetFullPath(binPath); - } - - public RemoteGraphContainer(string configPath) - { - _configPath = Path.GetFullPath(configPath); - _assembliesPath = Path.GetDirectoryName(_configPath); - } - - - public string BinPath - { - get { return _assembliesPath; } - } - - public string ConfigPath - { - get { return _configPath; } - } - - - public RemoteGraph GetRemoteGraph() - { - AppDomainSetup setup = new AppDomainSetup(); - setup = new AppDomainSetup(); - setup.ApplicationBase = _assembliesPath; - - string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; - string binPath = Path.Combine(baseDirectory, "bin"); - setup.PrivateBinPath = _assembliesPath + ";" + baseDirectory + ";" + binPath; - - - Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence); - string domainName = "StructureMap-" + Guid.NewGuid().ToString(); - _domain = AppDomain.CreateDomain(domainName, evidence, setup); - - - // Got to inject this copy of StructureMap.dll into new domain - string assemblyName = Assembly.GetExecutingAssembly().GetName().Name; - Assembly assem = _domain.Load(assemblyName); - object obj = _domain.CreateInstanceAndUnwrap(assemblyName, typeof (RemoteGraph).FullName); - - RemoteGraph graph = (RemoteGraph) obj; - - graph.Load(_configPath, _assembliesPath); - - return graph; - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceCreator.cs =================================================================== --- trunk/Source/StructureMap/IInstanceCreator.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/IInstanceCreator.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -2,7 +2,7 @@ { public interface IInstanceCreator { + InstanceMemento DefaultMemento { get; } object BuildInstance(InstanceMemento memento); - InstanceMemento DefaultMemento{ get;} } } \ No newline at end of file Modified: trunk/Source/StructureMap/IPluginGraphSource.cs =================================================================== --- trunk/Source/StructureMap/IPluginGraphSource.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/IPluginGraphSource.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -1,4 +1,3 @@ -using StructureMap.Configuration; using StructureMap.Graph; namespace StructureMap Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -163,6 +163,11 @@ } } + InstanceMemento IInstanceCreator.DefaultMemento + { + get { return _source.DefaultMemento; } + } + #endregion #region IInstanceFactory Members @@ -384,11 +389,5 @@ return memento; } - - - InstanceMemento IInstanceCreator.DefaultMemento - { - get { return _source.DefaultMemento; } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-04-06 16:08:28 UTC (rev 69) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-04-06 16:26:03 UTC (rev 70) @@ -160,14 +160,13 @@ { ExplicitArgumentMemento memento = new ExplicitArgumentMemento(args, null); return CreateInstance<PLUGINTYPE>(memento); - } public void Inject<PLUGINTYPE>(PLUGINTYPE instance) { LiteralMemento memento = new LiteralMemento(instance); AddInstance<PLUGINTYPE>(memento); - SetDefault(typeof(PLUGINTYPE), memento); + SetDefault(typeof (PLUGINTYPE), memento); } public T CreateInstance<T>() @@ -205,6 +204,152 @@ SetDefaults(defaultProfile); } + /// <summary> + /// Creates the named instance of the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + /// <returns></returns> + public object CreateInstance(Type pluginType, string instanceKey) + { + IInstanceFactory instanceFactory = this[pluginType]; + return instanceFactory.GetInstance(instanceKey); + } + + + /// <summary> + /// Creates a new object instance of the requested type + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + public object CreateInstance(Type pluginType) + { + IInstanceFactory instanceFactory = this[pluginType]; + return instanceFactory.GetInstance(); + } + + + /// <summary> + /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other + /// classes to link children members + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceMemento"></param> + /// <returns></returns> + public object CreateInstance(Type pluginType, InstanceMemento instanceMemento) + { + IInstanceFactory instanceFactory = this[pluginType]; + return instanceFactory.GetInstance(instanceMemento); + } + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceMemento"></param> + public void SetDefault(Type pluginType, InstanceMemento instanceMemento) + { + IInstanceFactory instanceFactory = this[pluginType]; + instanceFactory.SetDefault(instanceMemento); + } + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + public void SetDefault(Type pluginType, string instanceKey) + { + IInstanceFactory instanceFactory = this[pluginType]; + instanceFactory.SetDefault(instanceKey); + } + + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginTypeName"></param> + /// <param name="instanceKey"></param> + public void SetDefault(string pluginTypeName, string instanceKey) + { + IInstanceFactory instanceFactory = this[pluginTypeName]; + instanceFactory.SetDefault(instanceKey); + } + + + /// <summary> + /// Attempts to create a new instance of the requested type. Automatically inserts the default + /// configured instance for each dependency in the StructureMap constructor function. + /// </summary> + /// <param name="type"></param> + /// <returns></returns> + public object FillDependencies(Type type) + { + if (type.IsInterface || type.IsAbstract) + { + throw new StructureMapException(230); + } + + IInstanceFactory factory = getOrCreateFactory(type); + return factory.GetInstance(); + } + + /// <summary> + /// Sets up the InstanceManager to return the object in the "stub" argument anytime + /// any instance of the PluginType is requested + /// </summary> + /// <param name="pluginType"></param> + /// <param name="stub"></param> + public void InjectStub(Type pluginType, object stub) + { + if (!Plugin.CanBeCast(pluginType, stub.GetType())) + { + throw new StructureMapException(220, pluginType.FullName, + stub.GetType().FullName); + } + + LiteralMemento memento = new LiteralMemento(stub); + this[pluginType].SetDefault(memento); + } + + public IList GetAllInstances(Type type) + { + return this[type].GetAllInstances(); + } + + public void AddInstance<T>(InstanceMemento memento) + { + IInstanceFactory factory = getOrCreateFactory(typeof (T), createFactory); + factory.AddInstance(memento); + } + + public void AddInstance<PLUGINTYPE, CONCRETETYPE>() + { + IInstanceFactory factory = getOrCreateFactory(typeof (PLUGINTYPE), createFactory); + InstanceMemento memento = factory.AddType<CONCRETETYPE>(); + factory.AddInstance(memento); + } + + public void AddDefaultInstance<PLUGINTYPE, CONCRETETYPE>() + { + IInstanceFactory factory = getOrCreateFactory(typeof (PLUGINTYPE), createFactory); + InstanceMemento memento = factory.AddType<CONCRETETYPE>(); + factory.SetDefault(memento); + } + + public string WhatDoIHave() + { + StringBuilder sb = new StringBuilder(); + + foreach (IInstanceFactory factory in this) + { + sb.AppendFormat("PluginType {0}, Default: {1}\r\n", factory.PluginType.AssemblyQualifiedName, + factory.DefaultInstanceKey); + } + + return sb.ToString(); + } + #endregion private IInstanceFactory registerPluginFamily(PluginFamily family) @@ -278,33 +423,8 @@ } /// <summary> - /// Creates the named instance of the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - /// <returns></returns> - public object CreateInstance(Type pluginType, string instanceKey) - { - IInstanceFactory instanceFactory = this[pluginType]; - return instanceFactory.GetInstance(instanceKey); - } - - - - /// <summary> /// Creates a new object instance of the requested type /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - public object CreateInstance(Type pluginType) - { - IInstanceFactory instanceFactory = this[pluginType]; - return instanceFactory.GetInstance(); - } - - /// <summary> - /// Creates a new object instance of the requested type - /// </summary> /// <param name="pluginTypeName">Fully qualified name of the CLR Type to create</param> /// <returns></returns> public object CreateInstance(string pluginTypeName) @@ -326,21 +446,7 @@ return instanceFactory.GetInstance(instanceMemento); } - /// <summary> - /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other - /// classes to link children members - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceMemento"></param> - /// <returns></returns> - public object CreateInstance(Type pluginType, InstanceMemento instanceMemento) - { - IInstanceFactory instanceFactory = this[pluginType]; - return instanceFactory.GetInstance(instanceMemento); - } - - /// <summary> /// Creates an array of object instances of the requested type /// </summary> /// <param name="pluginType"></param> @@ -357,58 +463,6 @@ return instanceFactory.GetArray(instanceMementoes); } - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceMemento"></param> - public void SetDefault(Type pluginType, InstanceMemento instanceMemento) - { - IInstanceFactory instanceFactory = this[pluginType]; - instanceFactory.SetDefault(instanceMemento); - } - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instanceKey"></param> - public void SetDefault(Type pluginType, string instanceKey) - { - IInstanceFactory instanceFactory = this[pluginType]; - instanceFactory.SetDefault(instanceKey); - } - - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginTypeName"></param> - /// <param name="instanceKey"></param> - public void SetDefault(string pluginTypeName, string instanceKey) - { - IInstanceFactory instanceFactory = this[pluginTypeName]; - instanceFactory.SetDefault(instanceKey); - } - - - /// <summary> - /// Attempts to create a new instance of the requested type. Automatically inserts the default - /// configured instance for each dependency in the StructureMap constructor function. - /// </summary> - /// <param name="type"></param> - /// <returns></returns> - public object FillDependencies(Type type) - { - if (type.IsInterface || type.IsAbstract) - { - t... [truncated message content] |
From: <jer...@us...> - 2008-04-06 19:02:31
|
Revision: 72 http://structuremap.svn.sourceforge.net/structuremap/?rev=72&view=rev Author: jeremydmiller Date: 2008-04-06 12:02:29 -0700 (Sun, 06 Apr 2008) Log Message: ----------- Substituted in the IConfiguredInstance into the construction pipeline instead of InstanceMemento Modified Paths: -------------- trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs trunk/Source/StructureMap/Emitting/ClassBuilder.cs trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs trunk/Source/StructureMap/InstanceBuilder.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs trunk/Source/StructureMap.Testing.Widget/Decision.cs trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs Modified: trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs =================================================================== --- trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -3,6 +3,7 @@ using System.Reflection.Emit; using StructureMap.Emitting.Parameters; using StructureMap.Graph; +using StructureMap.Pipeline; namespace StructureMap.Emitting { @@ -13,8 +14,8 @@ public class BuildInstanceMethod : Method { private readonly Plugin _plugin; - private ConstructorInfo _constructor; - private ParameterEmitter _parameterEmitter; + private readonly ConstructorInfo _constructor; + private readonly ParameterEmitter _parameterEmitter; public BuildInstanceMethod(Plugin plugin) : base() { @@ -32,7 +33,7 @@ public override Type[] ArgumentList { - get { return new Type[] {typeof (InstanceMemento)}; } + get { return new Type[] {typeof (IConfiguredInstance)}; } } public override string MethodName Modified: trunk/Source/StructureMap/Emitting/ClassBuilder.cs =================================================================== --- trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap/Emitting/ClassBuilder.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -13,13 +13,13 @@ private const TypeAttributes PUBLIC_ATTS = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.BeforeFieldInit; - private string _ClassName; + private readonly string _className; - private ArrayList _Methods; - private TypeBuilder newTypeBuilder; - private Type superType; + private readonly ArrayList _methods; + private readonly TypeBuilder _newTypeBuilder; + private readonly Type _superType; - public ClassBuilder(ModuleBuilder module, string ClassName) : this(module, ClassName, typeof (Object)) + public ClassBuilder(ModuleBuilder module, string className) : this(module, className, typeof (Object)) { } @@ -27,11 +27,11 @@ { try { - _Methods = new ArrayList(); + _methods = new ArrayList(); - newTypeBuilder = module.DefineType(ClassName, PUBLIC_ATTS, superType); - this.superType = superType; - _ClassName = ClassName; + _newTypeBuilder = module.DefineType(ClassName, PUBLIC_ATTS, superType); + _superType = superType; + _className = ClassName; addDefaultConstructor(); } @@ -44,25 +44,25 @@ public string ClassName { - get { return _ClassName; } + get { return _className; } } public void AddMethod(Method method) { - _Methods.Add(method); - method.Attach(newTypeBuilder); + _methods.Add(method); + method.Attach(_newTypeBuilder); } internal void Bake() { - foreach (Method method in _Methods) + foreach (Method method in _methods) { method.Build(); } - newTypeBuilder.CreateType(); + _newTypeBuilder.CreateType(); } @@ -71,14 +71,14 @@ MethodAttributes atts = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.RTSpecialName; - ConstructorBuilder construct = newTypeBuilder.DefineConstructor(atts, CallingConventions.Standard, null); + ConstructorBuilder construct = _newTypeBuilder.DefineConstructor(atts, CallingConventions.Standard, null); ILGenerator ilgen = construct.GetILGenerator(); ilgen.Emit(OpCodes.Ldarg_0); - ConstructorInfo constructor = superType.GetConstructor(new Type[0]); + ConstructorInfo constructor = _superType.GetConstructor(new Type[0]); ilgen.Emit(OpCodes.Call, constructor); ilgen.Emit(OpCodes.Ret); } @@ -87,7 +87,7 @@ public void AddReadonlyStringProperty(string PropertyName, string Value, bool Override) { PropertyBuilder prop = - newTypeBuilder.DefineProperty(PropertyName, PropertyAttributes.HasDefault, typeof (string), null); + _newTypeBuilder.DefineProperty(PropertyName, PropertyAttributes.HasDefault, typeof (string), null); MethodAttributes atts = MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.Final | MethodAttributes.SpecialName; @@ -95,7 +95,7 @@ string _GetMethodName = "get_" + PropertyName; MethodBuilder methodGet = - newTypeBuilder.DefineMethod(_GetMethodName, atts, CallingConventions.Standard, typeof (string), null); + _newTypeBuilder.DefineMethod(_GetMethodName, atts, CallingConventions.Standard, typeof (string), null); ILGenerator gen = methodGet.GetILGenerator(); LocalBuilder ilReturn = gen.DeclareLocal(typeof (string)); Modified: trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -1,6 +1,7 @@ using System; using System.Reflection; using System.Reflection.Emit; +using StructureMap.Pipeline; namespace StructureMap.Emitting.Parameters { @@ -11,12 +12,12 @@ /// </summary> public abstract class ParameterEmitter { - private ParameterEmitter _NextSibling; + private ParameterEmitter _nextSibling; protected ParameterEmitter NextSibling { - set { _NextSibling = value; } - get { return _NextSibling; } + set { _nextSibling = value; } + get { return _nextSibling; } } public void Generate(ILGenerator ilgen, ParameterInfo parameter) @@ -25,9 +26,9 @@ { generate(ilgen, parameter); } - else if (_NextSibling != null) + else if (_nextSibling != null) { - _NextSibling.Generate(ilgen, parameter); + _nextSibling.Generate(ilgen, parameter); } else { @@ -44,9 +45,9 @@ { generateSetter(ilgen, property); } - else if (_NextSibling != null) + else if (_nextSibling != null) { - _NextSibling.GenerateSetter(ilgen, property); + _nextSibling.GenerateSetter(ilgen, property); } else { @@ -72,9 +73,9 @@ protected abstract bool canProcess(Type parameterType); protected abstract void generate(ILGenerator ilgen, ParameterInfo parameter); - protected void callInstanceMemento(ILGenerator ilgen, string MethodName) + protected void callInstanceMemento(ILGenerator ilgen, string methodName) { - MethodInfo _method = typeof (InstanceMemento).GetMethod(MethodName); + MethodInfo _method = typeof (IConfiguredInstance).GetMethod(methodName); ilgen.Emit(OpCodes.Callvirt, _method); } Modified: trunk/Source/StructureMap/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilder.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -1,4 +1,5 @@ using System; +using StructureMap.Pipeline; namespace StructureMap { @@ -23,7 +24,7 @@ get { return _manager; } } - public abstract object BuildInstance(InstanceMemento memento); + public abstract object BuildInstance(IConfiguredInstance instance); public void SetInstanceManager(InstanceManager manager) { @@ -35,10 +36,5 @@ Type plugged = Type.GetType(PluggedType); return plugged.Equals(type); } - - //public Type GetPluggedType() - //{ - // return Type.GetType(PluggedType); - //} } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -2,13 +2,14 @@ using StructureMap.Configuration; using StructureMap.Graph; using StructureMap.Interceptors; +using StructureMap.Pipeline; namespace StructureMap { /// <summary> /// GoF Memento representing an Object Instance /// </summary> - public abstract class InstanceMemento + public abstract class InstanceMemento : IConfiguredInstance { public const string EMPTY_STRING = "STRING.EMPTY"; public const string SUBSTITUTIONS_ATTRIBUTE = "Substitutions"; Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -1,18 +1,16 @@ using System; -using System.Collections.Generic; -using System.Text; namespace StructureMap.Pipeline { public interface IConfiguredInstance { - + InstanceMemento[] GetChildrenArray(string propertyName); + string GetProperty(string propertyName); + object GetChild(string propertyName, string typeName, InstanceManager manager); } public class ConfiguredInstance : Instance { - - protected override T build<T>(IInstanceCreator creator) { throw new NotImplementedException(); @@ -28,4 +26,4 @@ throw new NotImplementedException(); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -68,7 +68,7 @@ } - public override object BuildInstance(InstanceMemento memento) + public override object BuildInstance(IConfiguredInstance instance) { return null; } Modified: trunk/Source/StructureMap.Testing.Widget/Decision.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -31,10 +31,10 @@ get { return null; } } - public override object BuildInstance(InstanceMemento memento) + public override object BuildInstance(IConfiguredInstance instance) { return new Decision( - (Rule[]) Manager.CreateInstanceArray("StructureMap.Testing.Widget", memento.GetChildrenArray("Rules"))); + (Rule[]) Manager.CreateInstanceArray("StructureMap.Testing.Widget", instance.GetChildrenArray("Rules"))); } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -108,7 +108,7 @@ } - public override object BuildInstance(InstanceMemento instance) + public override object BuildInstance(IConfiguredInstance instance) { return new Child( instance.GetProperty("Name"), Modified: trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -45,7 +45,7 @@ } - public override object BuildInstance(InstanceMemento instance) + public override object BuildInstance(IConfiguredInstance instance) { return new Cow( long.Parse(instance.GetProperty("Weight")), Modified: trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-04-06 18:45:47 UTC (rev 71) +++ trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-04-06 19:02:29 UTC (rev 72) @@ -29,7 +29,7 @@ get { throw new NotImplementedException(); } } - public override object BuildInstance(InstanceMemento instance) + public override object BuildInstance(IConfiguredInstance instance) { BasicGridColumn column = new BasicGridColumn(instance.GetProperty("headerText")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-04-06 19:13:16
|
Revision: 73 http://structuremap.svn.sourceforge.net/structuremap/?rev=73&view=rev Author: jeremydmiller Date: 2008-04-06 12:13:08 -0700 (Sun, 06 Apr 2008) Log Message: ----------- refactoring the emitting code Modified Paths: -------------- trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs trunk/Source/StructureMap/InstanceBuilder.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap.Testing/Container/EmittingTester.cs trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs trunk/Source/StructureMap.Testing.Widget/Decision.cs trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs Modified: trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs =================================================================== --- trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -33,7 +33,7 @@ public override Type[] ArgumentList { - get { return new Type[] {typeof (IConfiguredInstance)}; } + get { return new Type[] { typeof(IConfiguredInstance), typeof(StructureMap.Pipeline.IInstanceCreator) }; } } public override string MethodName Modified: trunk/Source/StructureMap/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilder.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -24,7 +24,7 @@ get { return _manager; } } - public abstract object BuildInstance(IConfiguredInstance instance); + public abstract object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator); public void SetInstanceManager(InstanceManager manager) { Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -145,7 +145,7 @@ try { InstanceBuilder builder = _instanceBuilders[memento.ConcreteKey]; - object constructedInstance = builder.BuildInstance(memento); + object constructedInstance = builder.BuildInstance(memento, null); CompoundInterceptor interceptor = _interceptorLibrary.FindInterceptor(constructedInstance.GetType()); return interceptor.Process(constructedInstance); } Modified: trunk/Source/StructureMap.Testing/Container/EmittingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap.Testing/Container/EmittingTester.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Reflection; using NUnit.Framework; using StructureMap.Emitting; @@ -36,12 +37,13 @@ if (builder != null) { - rule = (ComplexRule) builder.BuildInstance(memento); + rule = (ComplexRule) builder.BuildInstance(memento, null); } } catch (Exception e) { ex = e; + Debug.WriteLine(e.ToString()); } } Modified: trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -68,7 +68,7 @@ } - public override object BuildInstance(IConfiguredInstance instance) + public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator) { return null; } Modified: trunk/Source/StructureMap.Testing.Widget/Decision.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -31,7 +31,7 @@ get { return null; } } - public override object BuildInstance(IConfiguredInstance instance) + public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator) { return new Decision( (Rule[]) Manager.CreateInstanceArray("StructureMap.Testing.Widget", instance.GetChildrenArray("Rules"))); Modified: trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -108,7 +108,7 @@ } - public override object BuildInstance(IConfiguredInstance instance) + public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator) { return new Child( instance.GetProperty("Name"), Modified: trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap.Testing.Widget2/EnumerationCheck.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -45,7 +45,7 @@ } - public override object BuildInstance(IConfiguredInstance instance) + public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator) { return new Cow( long.Parse(instance.GetProperty("Weight")), Modified: trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-04-06 19:02:29 UTC (rev 72) +++ trunk/Source/StructureMap.Testing.Widget5/BasicGridColumnInstanceBuilder.cs 2008-04-06 19:13:08 UTC (rev 73) @@ -29,7 +29,7 @@ get { throw new NotImplementedException(); } } - public override object BuildInstance(IConfiguredInstance instance) + public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator) { BasicGridColumn column = new BasicGridColumn(instance.GetProperty("headerText")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-04-06 19:52:40
|
Revision: 74 http://structuremap.svn.sourceforge.net/structuremap/?rev=74&view=rev Author: jeremydmiller Date: 2008-04-06 12:52:39 -0700 (Sun, 06 Apr 2008) Log Message: ----------- changing out the construction pipeline Modified Paths: -------------- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap.Testing.Widget/Decision.cs trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs Modified: trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/Configuration/Mementos/ExplicitArgumentMemento.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -54,10 +54,10 @@ return _inner.GetChildMemento(Key); } - public override object GetChild(string key, string typeName, InstanceManager manager) + public override object GetChild(string key, string typeName, Pipeline.IInstanceCreator instanceCreator) { Type type = Type.GetType(typeName, true); - return _args.Get(type) ?? base.GetChild(key, typeName, manager); + return _args.Get(type) ?? base.GetChild(key, typeName, instanceCreator); } public override InstanceMemento[] GetChildrenArray(string Key) Modified: trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -33,15 +33,14 @@ private void putChildArrayFromInstanceMementoOntoStack(ILGenerator ilgen, Type argumentType, string argumentName) { - ilgen.Emit(OpCodes.Ldarg_0); - callGetInstanceManager(ilgen); + ilgen.Emit(OpCodes.Ldarg_2); ilgen.Emit(OpCodes.Ldstr, argumentType.GetElementType().AssemblyQualifiedName); ilgen.Emit(OpCodes.Ldarg_1); ilgen.Emit(OpCodes.Ldstr, argumentName); callInstanceMemento(ilgen, "GetChildrenArray"); - MethodInfo methodCreateInstanceArray = (typeof (InstanceManager).GetMethod("CreateInstanceArray")); + MethodInfo methodCreateInstanceArray = (typeof (StructureMap.Pipeline.IInstanceCreator).GetMethod("CreateInstanceArray")); ilgen.Emit(OpCodes.Callvirt, methodCreateInstanceArray); cast(ilgen, argumentType); } Modified: trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/Emitting/Parameters/ChildParameterEmitter.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -30,9 +30,8 @@ ilgen.Emit(OpCodes.Ldarg_1); ilgen.Emit(OpCodes.Ldstr, parameterName); ilgen.Emit(OpCodes.Ldstr, fullName); - ilgen.Emit(OpCodes.Ldarg_0); + ilgen.Emit(OpCodes.Ldarg_2); - callGetInstanceManager(ilgen); callInstanceMemento(ilgen, "GetChild"); cast(ilgen, parameterType); } Modified: trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -79,13 +79,6 @@ ilgen.Emit(OpCodes.Callvirt, _method); } - protected void callGetInstanceManager(ILGenerator ilgen) - { - PropertyInfo property = (typeof (InstanceBuilder)).GetProperty("Manager"); - MethodInfo methodGetInstanceManager = property.GetGetMethod(); - ilgen.Emit(OpCodes.Call, methodGetInstanceManager); - } - protected void cast(ILGenerator ilgen, Type parameterType) { ilgen.Emit(OpCodes.Castclass, parameterType); Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -145,7 +145,7 @@ try { InstanceBuilder builder = _instanceBuilders[memento.ConcreteKey]; - object constructedInstance = builder.BuildInstance(memento, null); + object constructedInstance = builder.BuildInstance(memento, builder.Manager); CompoundInterceptor interceptor = _interceptorLibrary.FindInterceptor(constructedInstance.GetType()); return interceptor.Process(constructedInstance); } Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/InstanceManager.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -12,7 +12,7 @@ /// <summary> /// A collection of IInstanceFactory's. /// </summary> - public class InstanceManager : IInstanceManager, IEnumerable + public class InstanceManager : IInstanceManager, IEnumerable, StructureMap.Pipeline.IInstanceCreator { private readonly InstanceDefaultManager _defaultManager; private readonly Dictionary<Type, IInstanceFactory> _factories; Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -187,27 +187,27 @@ /// </summary> /// <param name="key"></param> /// <param name="typeName"></param> - /// <param name="manager"></param> + /// <param name="instanceCreator"></param> /// <returns></returns> - public virtual object GetChild(string key, string typeName, InstanceManager manager) + public virtual object GetChild(string key, string typeName, Pipeline.IInstanceCreator instanceCreator) { InstanceMemento memento = GetChildMemento(key); object returnValue = null; if (memento == null) { - returnValue = buildDefaultChild(key, manager, typeName); + returnValue = buildDefaultChild(key, instanceCreator, typeName); } else { - returnValue = manager.CreateInstance(typeName, memento); + returnValue = instanceCreator.CreateInstance(typeName, memento); } return returnValue; } - private static object buildDefaultChild(string key, InstanceManager manager, string typeName) + private static object buildDefaultChild(string key, StructureMap.Pipeline.IInstanceCreator manager, string typeName) { object returnValue; try Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -6,7 +6,7 @@ { InstanceMemento[] GetChildrenArray(string propertyName); string GetProperty(string propertyName); - object GetChild(string propertyName, string typeName, InstanceManager manager); + object GetChild(string propertyName, string typeName, IInstanceCreator instanceCreator); } public class ConfiguredInstance : Instance Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -1,4 +1,5 @@ using System; +using System.Data; using System.Web.UI; using StructureMap.Interceptors; @@ -8,6 +9,9 @@ { T CreateInstance<T>(string referenceKey); T CreateInstance<T>(); + Array CreateInstanceArray(string pluginType, InstanceMemento[] instanceMementoes); + object CreateInstance(string typeName, InstanceMemento memento); + object CreateInstance(string typeName); } public interface IInstanceDiagnostics Modified: trunk/Source/StructureMap.Testing.Widget/Decision.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap.Testing.Widget/Decision.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -34,7 +34,7 @@ public override object BuildInstance(IConfiguredInstance instance, StructureMap.Pipeline.IInstanceCreator creator) { return new Decision( - (Rule[]) Manager.CreateInstanceArray("StructureMap.Testing.Widget", instance.GetChildrenArray("Rules"))); + (Rule[]) creator.CreateInstanceArray("StructureMap.Testing.Widget", instance.GetChildrenArray("Rules"))); } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs =================================================================== --- trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-04-06 19:13:08 UTC (rev 73) +++ trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs 2008-04-06 19:52:39 UTC (rev 74) @@ -112,7 +112,7 @@ { return new Child( instance.GetProperty("Name"), - (GrandChild) instance.GetChild("MyGrandChild", "StructureMap.Testing.Widget.GrandChild", Manager)); + (GrandChild) instance.GetChild("MyGrandChild", "StructureMap.Testing.Widget.GrandChild", creator)); } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-04-06 23:53:50
|
Revision: 75 http://structuremap.svn.sourceforge.net/structuremap/?rev=75&view=rev Author: jeremydmiller Date: 2008-04-06 16:53:49 -0700 (Sun, 06 Apr 2008) Log Message: ----------- refactoring the new Instance's to use a Type instead of a generic. Alas, it is not a perfect world Modified Paths: -------------- 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.Testing/Pipeline/DefaultInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -11,19 +11,9 @@ public class ConfiguredInstance : Instance { - protected override T build<T>(IInstanceCreator creator) + protected override object build(Type type, IInstanceCreator creator) { throw new NotImplementedException(); } - - public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/DefaultInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/DefaultInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/DefaultInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -6,19 +6,9 @@ { public class DefaultInstance : Instance { - protected override T build<T>(IInstanceCreator creator) + protected override object build(Type type, IInstanceCreator creator) { - return creator.CreateInstance<T>(); + return creator.CreateInstance(type); } - - public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -7,11 +7,11 @@ { public interface IInstanceCreator { - T CreateInstance<T>(string referenceKey); - T CreateInstance<T>(); + object CreateInstance(Type type, string referenceKey); Array CreateInstanceArray(string pluginType, InstanceMemento[] instanceMementoes); object CreateInstance(string typeName, InstanceMemento memento); object CreateInstance(string typeName); + object CreateInstance(Type type); } public interface IInstanceDiagnostics @@ -35,15 +35,15 @@ set { _interceptor = value; } } - public T Build<T>(IInstanceCreator creator) where T : class + public object Build(Type type, IInstanceCreator creator) { - T rawValue = build<T>(creator); - return (T) _interceptor.Process(rawValue); + object rawValue = build(type, creator); + return _interceptor.Process(rawValue); } - protected abstract T build<T>(IInstanceCreator creator) where T : class; + protected abstract object build(Type type, IInstanceCreator creator); - public abstract void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) where T : class; - public abstract void Describe<T>(IInstanceDiagnostics diagnostics) where T : class; + //public abstract void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) where T : class; + //public abstract void Describe<T>(IInstanceDiagnostics diagnostics) where T : class; } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -4,7 +4,7 @@ { public class LiteralInstance<PLUGINTYPE> : Instance { - private PLUGINTYPE _object; + private readonly PLUGINTYPE _object; public LiteralInstance(PLUGINTYPE anObject) { @@ -13,22 +13,12 @@ // TODO: VALIDATE NOT NULL } - protected override T build<T>(IInstanceCreator creator) + + protected override object build(Type type, IInstanceCreator creator) { - T returnValue = _object as T; // TODO: VALIDATE THE CAST AND NULL - return returnValue; + return _object; } - - public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -13,20 +13,10 @@ } - protected override T build<T>(IInstanceCreator creator) + protected override object build(Type type, IInstanceCreator creator) { // TODO: VALIDATION IF IT CAN'T BE CAST - return (T) _prototype.Clone(); + return _prototype.Clone(); } - - public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -13,19 +13,10 @@ _referenceKey = referenceKey; } - protected override T build<T>(IInstanceCreator creator) - { - return creator.CreateInstance<T>(_referenceKey); - } - public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + protected override object build(Type type, IInstanceCreator creator) { - throw new NotImplementedException(); + return creator.CreateInstance(type, _referenceKey); } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/UserControlInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -12,20 +12,11 @@ _url = url; } - protected override T build<T>(IInstanceCreator creator) - { - // TODO: VALIDATION if it doesn't cast or can't be built - return new Page().LoadControl(_url) as T; - } - public override void Diagnose<T>(IInstanceCreator creator, IInstanceDiagnostics diagnostics) + protected override object build(Type type, IInstanceCreator creator) { - throw new NotImplementedException(); + // TODO: VALIDATE that the type works + return new Page().LoadControl(_url); } - - public override void Describe<T>(IInstanceDiagnostics diagnostics) - { - throw new NotImplementedException(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -28,13 +28,13 @@ using (mocks.Record()) { - Expect.Call(instanceCreator.CreateInstance<IDefault>()).Return(theDefault); + Expect.Call(instanceCreator.CreateInstance(typeof(IDefault))).Return(theDefault); } using (mocks.Playback()) { DefaultInstance instance = new DefaultInstance(); - Assert.AreSame(theDefault, instance.Build<IDefault>(instanceCreator)); + Assert.AreSame(theDefault, instance.Build(typeof(IDefault), instanceCreator)); } } Modified: trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -1,3 +1,4 @@ +using System; using NUnit.Framework; using Rhino.Mocks; using StructureMap.Interceptors; @@ -33,7 +34,7 @@ using (mocks.Playback()) { - Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build<object>(null)); + Assert.AreEqual(objectReturnedByInterceptor, instanceUnderTest.Build(typeof(object), null)); } } @@ -44,19 +45,10 @@ { public object TheInstanceThatWasBuilt = new object(); - public override void Diagnose<T>(StructureMap.Pipeline.IInstanceCreator creator, IInstanceDiagnostics diagnostics) - { - throw new System.NotImplementedException(); - } - public override void Describe<T>(IInstanceDiagnostics diagnostics) + protected override object build(Type type, StructureMap.Pipeline.IInstanceCreator creator) { - throw new System.NotImplementedException(); + return TheInstanceThatWasBuilt; } - - protected override T build<T>(StructureMap.Pipeline.IInstanceCreator creator) - { - return (T) TheInstanceThatWasBuilt; - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -17,7 +17,7 @@ { ATarget target = new ATarget(); LiteralInstance<ITarget> instance = new LiteralInstance<ITarget>(target); - Assert.AreSame(target, instance.Build<ITarget>(null)); + Assert.AreSame(target, instance.Build(typeof(ITarget), null)); } public interface ITarget Modified: trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -19,7 +19,7 @@ PrototypeTarget target = new PrototypeTarget("Jeremy"); PrototypeInstance instance = new PrototypeInstance(target); - object returnedValue = instance.Build<PrototypeTarget>(null); + object returnedValue = instance.Build(typeof(PrototypeTarget), null); Assert.AreEqual(target, returnedValue); Assert.AreNotSame(target, returnedValue); Modified: trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs 2008-04-06 19:52:39 UTC (rev 74) +++ trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs 2008-04-06 23:53:49 UTC (rev 75) @@ -24,12 +24,12 @@ using (mocks.Record()) { - Expect.Call(instanceCreator.CreateInstance<IReferenced>(theReferenceKey)).Return(returnedValue); + Expect.Call(instanceCreator.CreateInstance(typeof(IReferenced), theReferenceKey)).Return(returnedValue); } using (mocks.Playback()) { - Assert.AreSame(returnedValue, instance.Build<IReferenced>(instanceCreator)); + Assert.AreSame(returnedValue, instance.Build(typeof(IReferenced), instanceCreator)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |