From: <jer...@us...> - 2007-03-30 14:26:25
|
Revision: 34 http://structuremap.svn.sourceforge.net/structuremap/?rev=34&view=rev Author: jeremydmiller Date: 2007-03-30 07:26:24 -0700 (Fri, 30 Mar 2007) Log Message: ----------- last set of changes for the configuration, UserControl support Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/Verification/PluginGraphConsoleWriter.cs trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/cruise.build Added Paths: ----------- trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs trunk/Source/StructureMap/Configuration/UserControlMemento.cs trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/CommonAssemblyInfo.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -14,7 +14,7 @@ [assembly: ComVisibleAttribute(false)] [assembly: AssemblyVersionAttribute("1.0.0.0000")] -[assembly: AssemblyCopyrightAttribute("Copyright (c) 2005, Jeremy D. Miller, Jeffrey Palermo")] +[assembly: AssemblyCopyrightAttribute("Copyright (c) 2007, Jeremy D. Miller")] [assembly: AssemblyProductAttribute("StructureMap")] [assembly: AssemblyCompanyAttribute("")] [assembly: AssemblyConfigurationAttribute("release")] Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -103,6 +103,11 @@ return expression; } + public static UserControlExpression LoadUserControlFrom<T>(string url) + { + return new UserControlExpression(typeof(T), url); + } + public ProfileExpression CreateProfile(string profileName) { ProfileExpression expression = new ProfileExpression(profileName); @@ -125,5 +130,13 @@ return (type.GetConstructor(new Type[0]) != null); } + + public UserControlExpression LoadControlFromUrl<T>(string url) + { + UserControlExpression expression = new UserControlExpression(typeof(T), url); + addExpression(expression); + + return expression; + } } } \ No newline at end of file Added: trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/DSL/UserControlExpression.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text; +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 + } + } +} Added: trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -0,0 +1,35 @@ + + +using System.Configuration; +using System.Diagnostics; +using System.Xml; + +namespace StructureMap.Configuration +{ + public class StructureMapConfigurationSection : IConfigurationSectionHandler + { + private XmlNode _node; + + public object Create(object parent, object configContext, XmlNode section) + { + return _node; + } + + public static XmlNode GetStructureMapConfiguration() + { + object config = ConfigurationManager.GetSection(XmlConstants.STRUCTUREMAP); + + + return null; + /* + object o = ConfigurationSettings.GetConfig(XmlConstants.STRUCTUREMAP); + XmlNode node = o as XmlNode; + if (node == null) + { + throw new ApplicationException("No <StructureMap> section was found in the application config file"); + } + return node; + */ + } + } +} Added: trunk/Source/StructureMap/Configuration/UserControlMemento.cs =================================================================== --- trunk/Source/StructureMap/Configuration/UserControlMemento.cs (rev 0) +++ trunk/Source/StructureMap/Configuration/UserControlMemento.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -0,0 +1,68 @@ +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; } + } + + public override object Build(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(); } + } + } +} Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap/StructureMap.csproj 2007-03-30 14:26:24 UTC (rev 34) @@ -229,6 +229,7 @@ <Compile Include="Configuration\DSL\PrototypeMemento.cs" /> <Compile Include="Configuration\DSL\Registry.cs" /> <Compile Include="Configuration\DSL\ScanAssembliesExpression.cs" /> + <Compile Include="Configuration\DSL\UserControlExpression.cs" /> <Compile Include="Configuration\FamilyParser.cs"> <SubType>Code</SubType> </Compile> @@ -263,6 +264,7 @@ <SubType>Code</SubType> </Compile> <Compile Include="Configuration\ProfileAndMachineParser.cs" /> + <Compile Include="Configuration\StructureMapConfigurationSection.cs" /> <Compile Include="Configuration\Tokens\AssemblyToken.cs"> <SubType>Code</SubType> </Compile> @@ -329,6 +331,7 @@ <Compile Include="Configuration\Tokens\TemplateToken.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="Configuration\UserControlMemento.cs" /> <Compile Include="Configuration\XmlConstants.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Configuration; using System.IO; using System.Xml; using StructureMap.Configuration; @@ -16,6 +17,7 @@ private static Registry _registry = new Registry(); private static List<Registry> _registries = new List<Registry>(); private static StartUp _startUp; + private static bool _pullConfigurationFromAppConfig; static StructureMapConfiguration() { @@ -69,6 +71,15 @@ private static PluginGraphBuilder createBuilder() { + if (_pullConfigurationFromAppConfig) + { + _collection.IncludeNode(delegate() + { + + return StructureMapConfigurationSection.GetStructureMapConfiguration(); + }); + } + ConfigurationParser[] parsers = _collection.GetParsers(); return new PluginGraphBuilder(parsers, _registries.ToArray()); } @@ -102,6 +113,17 @@ set { _collection.UseDefaultFile = value; } } + [Obsolete("Not ready yet")] + public static bool PullConfigurationFromAppConfig + { + get { return _pullConfigurationFromAppConfig; } + set + { + throw new NotImplementedException("This feature has not been completed"); + _pullConfigurationFromAppConfig = value; + } + } + public static ScanAssembliesExpression ScanAssemblies() { ScanAssembliesExpression expression = new ScanAssembliesExpression(); Modified: trunk/Source/StructureMap/Verification/PluginGraphConsoleWriter.cs =================================================================== --- trunk/Source/StructureMap/Verification/PluginGraphConsoleWriter.cs 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap/Verification/PluginGraphConsoleWriter.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -140,6 +140,7 @@ { _writer.WriteLine(problem.Path); _writer.WriteLine(problem.ToString()); + writeSeparator(); } } Modified: trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -15,6 +15,7 @@ StructureMapConfiguration.ResetAll(); DataMother.WriteDocument("Config1.xml"); DataMother.WriteDocument("Config2.xml"); + DataMother.WriteDocument("FullTesting.XML"); } [TearDown] Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -142,7 +142,7 @@ Assert.AreEqual("Purple", widget.Color); } - [Test] + [Test, Explicit] public void CreateAnInstancePullAPropertyFromTheApplicationConfig() { Assert.AreEqual("Blue", ConfigurationManager.AppSettings["Color"]); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -1,6 +1,7 @@ using System; using NUnit.Framework; using Rhino.Mocks; +using StructureMap.Configuration; using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.Widget3; @@ -64,6 +65,26 @@ mocks.VerifyAll(); } + + [Test] + public void LoadControl() + { + PluginGraph graph = new PluginGraph(); + Registry registry = new Registry(graph); + + string theUrl = "some url"; + string theKey = "the memento"; + registry.LoadControlFromUrl<IGateway>(theUrl).WithName(theKey); + + registry.Dispose(); + + PluginFamily family = graph.PluginFamilies[typeof (IGateway)]; + UserControlMemento memento = (UserControlMemento) family.Source.GetMemento(theKey); + Assert.IsNotNull(memento); + + Assert.AreEqual(theUrl, memento.Url); + Assert.AreEqual(theKey, memento.InstanceKey); + } } public class TestRegistry : Registry Added: trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/UserControlExpressionTester.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -0,0 +1,53 @@ +using NUnit.Framework; +using Rhino.Mocks; +using StructureMap.Configuration; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; + +namespace StructureMap.Testing.Configuration.DSL +{ + [TestFixture] + public class UserControlExpressionTester + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void CreateMementoHappyPath() + { + string theUrl = "alskdjf"; + + UserControlExpression expression = new UserControlExpression(typeof(IControl), theUrl); + + UserControlMemento memento = (UserControlMemento) ((IMementoBuilder) expression).BuildMemento(new PluginGraph()); + Assert.IsNotNull(memento); + + Assert.AreEqual(theUrl, memento.Url); + Assert.IsNotEmpty(memento.InstanceKey); + Assert.IsNotNull(memento.InstanceKey); + } + + [Test] + public void CreateMementoHappyPathWithName() + { + string theUrl = "alskdjf"; + string theName = "the name"; + + UserControlExpression expression = new UserControlExpression(typeof(IControl), theUrl); + expression.WithName(theName); + + UserControlMemento memento = (UserControlMemento)((IMementoBuilder)expression).BuildMemento(new PluginGraph()); + Assert.IsNotNull(memento); + + Assert.AreEqual(theUrl, memento.Url); + Assert.AreEqual(theName, memento.InstanceKey); + } + } + + public interface IControl + { + + } +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2007-03-30 14:26:24 UTC (rev 34) @@ -195,6 +195,7 @@ <Compile Include="Configuration\DSL\RegistryIntegratedTester.cs" /> <Compile Include="Configuration\DSL\RegistryTester.cs" /> <Compile Include="Configuration\DSL\ScanAssembliesTester.cs" /> + <Compile Include="Configuration\DSL\UserControlExpressionTester.cs" /> <Compile Include="Configuration\FamilyParserTester.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config 2007-03-30 14:26:24 UTC (rev 34) @@ -1,7 +1,37 @@ <?xml version="1.0" encoding="utf-8" ?> <configuration> + <configSections> + <section name="StructureMap" type="StructureMap.Configuration.StructureMapConfigurationSection,StructureMap"/> + </configSections> + + <StructureMap> + <Assembly Name="StructureMap.Testing.GenericWidgets"/> + + <PluginFamily Assembly="StructureMap.Testing.GenericWidgets" Type="StructureMap.Testing.GenericWidgets.IThing`2" DefaultKey="Cornflower"> + <Plugin Assembly="StructureMap.Testing.GenericWidgets" Type="StructureMap.Testing.GenericWidgets.ColorThing`2" ConcreteKey="Color" /> + <Plugin Assembly="StructureMap.Testing.GenericWidgets" Type="StructureMap.Testing.GenericWidgets.ComplexThing`2" ConcreteKey="Complex" /> + + <Instance Key="Cornflower" Type="Color"> + <Property Name="color" Value="Cornflower"/> + </Instance> + + <Instance Key="Complicated" Type="Complex"> + <Property Name="name" Value="Jeremy" /> + <Property Name="age" Value="32" /> + <Property Name="ready" Value="true" /> + </Instance> + </PluginFamily> + + <PluginFamily Assembly="StructureMap.Testing.GenericWidgets" Type="StructureMap.Testing.GenericWidgets.ISimpleThing`1" DefaultKey="Simple"> + <Plugin Assembly="StructureMap.Testing.GenericWidgets" Type="StructureMap.Testing.GenericWidgets.SimpleThing`1" ConcreteKey="Simple" /> + </PluginFamily> + </StructureMap> + + <appSettings> <add key="Color" value="Blue"/> <add key="Day" value="Monday"/> </appSettings> + + </configuration> \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs 2007-03-30 14:26:24 UTC (rev 34) @@ -3,6 +3,7 @@ using NUnit.Framework; using StructureMap.Configuration; using StructureMap.Graph; +using StructureMap.Testing.GenericWidgets; namespace StructureMap.Testing { @@ -72,6 +73,19 @@ Assert.IsTrue(File.Exists(filePath)); } + + + [Test, Ignore("Not complete")] + public void PullConfigurationFromTheAppConfig() + { + StructureMapConfiguration.UseDefaultStructureMapConfigFile = false; + StructureMapConfiguration.PullConfigurationFromAppConfig = true; + + ColorThing<string, bool> thing = (ColorThing<string, bool>) ObjectFactory.GetInstance < IThing<string, bool>>(); + Assert.AreEqual("Cornflower", thing.Color, "Cornflower is the color from the App.config file"); + } + + } public interface ISomething Modified: trunk/cruise.build =================================================================== --- trunk/cruise.build 2007-03-29 18:31:00 UTC (rev 33) +++ trunk/cruise.build 2007-03-30 14:26:24 UTC (rev 34) @@ -48,7 +48,7 @@ <attributes> <attribute type="ComVisibleAttribute" value="false" /> <attribute type="AssemblyVersionAttribute" value="${assembly-version}" /> - <attribute type="AssemblyCopyrightAttribute" value="Copyright (c) 2005, Jeremy D. Miller, Jeffrey Palermo" /> + <attribute type="AssemblyCopyrightAttribute" value="Copyright (c) 2007, Jeremy D. Miller" /> <attribute type="AssemblyProductAttribute" value="StructureMap" /> <attribute type="AssemblyCompanyAttribute" value="" /> <attribute type="AssemblyConfigurationAttribute" value="${project.config}" /> @@ -118,14 +118,16 @@ </target> <target name="unit-test"> - <nunit2 failonerror="true"> - <formatter type="Xml" outputdir="${results.dir}" usefile="true" extension=".xml"/> - <formatter type="Plain" /> - - <test assemblyname="${build.dir}\StructureMap.Testing.dll" appconfig="${nant.location}nant.tests.config" /> - <test assemblyname="${build.dir}\StructureMap.Testing.DeploymentTasks.dll" appconfig="${nant.location}nant.tests.config" /> - </nunit2> + <property name="nunit-console.exe" value="bin\NUnit\nunit-console.exe" /> + <exec program="${nunit-console.exe}" workingdir="${build.dir}"> + <arg value="StructureMap.Testing.dll" /> + </exec> +<!-- + <exec program="${nunit-console.exe}" workingdir="${build.dir}"> + <arg value="StructureMap.Testing.DeploymentTasks.dll" /> + </exec> +--> </target> <target name="runDoctor"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |