From: <jer...@us...> - 2008-10-03 15:36:15
|
Revision: 165 http://structuremap.svn.sourceforge.net/structuremap/?rev=165&view=rev Author: jeremydmiller Date: 2008-10-03 15:36:06 +0000 (Fri, 03 Oct 2008) Log Message: ----------- The PluginGraphVisitor is DEAD!!!!!!!!!! Modified Paths: -------------- trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs Modified: trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2008-10-03 15:12:28 UTC (rev 164) +++ trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2008-10-03 15:36:06 UTC (rev 165) @@ -10,13 +10,13 @@ namespace StructureMap.Diagnostics { - public class ValidationBuildSession : BuildSession, IPipelineGraphVisitor + public class ValidationBuildSession : BuildSession { private ErrorCollection _errors; private readonly List<ValidationError> _validationErrors = new List<ValidationError>(); private readonly Stack<BuildDependency> _dependencyStack = new Stack<BuildDependency>(); - private List<Instance> _explicitInstances; + private List<IInstance> _explicitInstances; public ValidationBuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) : base(pipelineGraph, interceptorLibrary) @@ -84,15 +84,8 @@ return _errors.Find(pluginType, name); } - - - void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy) + private void validateInstance(Type pluginType, Instance instance) { - // don't care - } - - void IPipelineGraphVisitor.Instance(Type pluginType, Instance instance) - { try { _dependencyStack.Clear(); @@ -107,11 +100,6 @@ } } - public void Source(string source) - { - throw new NotImplementedException(); - } - private void validate(Type pluginType, Instance instance, object builtObject) { if (builtObject == null) return; @@ -136,7 +124,13 @@ _explicitInstances = pipelineGraph.GetAllInstances(); _errors = new ErrorCollection(); - pipelineGraph.Visit(this); + foreach (var pluginType in pipelineGraph.PluginTypes) + { + foreach (Instance instance in pluginType.Instances) + { + validateInstance(pluginType.PluginType, instance); + } + } } public string BuildErrorMessages() Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-10-03 15:12:28 UTC (rev 164) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-10-03 15:36:06 UTC (rev 165) @@ -7,7 +7,7 @@ namespace StructureMap.Diagnostics { - public class WhatDoIHaveWriter : IPipelineGraphVisitor + public class WhatDoIHaveWriter { private readonly PipelineGraph _graph; private TextReportWriter _writer; @@ -99,22 +99,6 @@ } - void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy) - { - _writer.AddDivider('-'); - string[] contents = new string[]{TypePath.GetAssemblyQualifiedName(pluginType), string.Empty, string.Empty}; - - if (defaultInstance != null) - { - setContents(contents, defaultInstance); - - } - - _writer.AddText(contents); - - _writer.AddContent("Built by: " + policy.ToString()); - } - private void setContents(string[] contents, IInstance instance) { contents[1] = instance.Name; @@ -123,18 +107,6 @@ _instances.Add(instance); } - void IPipelineGraphVisitor.Instance(Type pluginType, Instance instance) - { - if (_instances.Contains(instance)) - { - return; - } - string[] contents = new string[]{string.Empty, string.Empty, string.Empty}; - setContents(contents, instance); - - _writer.AddText(contents); - } - } } Modified: trunk/Source/StructureMap/IInstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/IInstanceFactory.cs 2008-10-03 15:12:28 UTC (rev 164) +++ trunk/Source/StructureMap/IInstanceFactory.cs 2008-10-03 15:36:06 UTC (rev 165) @@ -24,7 +24,6 @@ void ForEachInstance(Action<Instance> action); void ImportFrom(PluginFamily family); - void AcceptVisitor(IPipelineGraphVisitor visitor, Instance defaultInstance); void EjectAllInstances(); } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-10-03 15:12:28 UTC (rev 164) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-10-03 15:36:06 UTC (rev 165) @@ -141,12 +141,6 @@ family.EachInstance(instance => _instances.Fill(instance.Name, instance)); } - public void AcceptVisitor(IPipelineGraphVisitor visitor, Instance defaultInstance) - { - visitor.PluginType(PluginType, defaultInstance, _policy); - ForEachInstance(i => visitor.Instance(PluginType, i)); - } - public void EjectAllInstances() { _instances.Clear(); Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-10-03 15:12:28 UTC (rev 164) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-10-03 15:36:06 UTC (rev 165) @@ -9,12 +9,6 @@ { public delegate InstanceFactory MissingFactoryFunction(Type pluginType, ProfileManager profileManager); - [Obsolete("I think we can eliminate this in favor of IEnumerable")] - public interface IPipelineGraphVisitor - { - void PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy); - void Instance(Type pluginType, Instance instance); - } public class PluginTypeConfiguration { @@ -90,44 +84,6 @@ set { _profileManager.CurrentProfile = value; } } - public void Visit(IPipelineGraphVisitor visitor) - { - var factories = new IInstanceFactory[_factories.Count]; - _factories.Values.CopyTo(factories, 0); - - foreach (IInstanceFactory factory in factories) - { - Type pluginType = factory.PluginType; - Instance defaultInstance = _profileManager.GetDefault(pluginType); - - factory.AcceptVisitor(visitor, defaultInstance); - } - } - - // Useful for the validation logic - public List<Instance> GetAllInstances() - { - PipelineGraphFlattener flattener = new PipelineGraphFlattener(); - Visit(flattener); - - return flattener.Instances; - } - - internal class PipelineGraphFlattener : IPipelineGraphVisitor - { - internal List<Instance> Instances = new List<Instance>(); - - public void PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy) - { - // don't care - } - - public void Instance(Type pluginType, Instance instance) - { - Instances.Add(instance); - } - } - public IInstanceFactory ForType(Type pluginType) { createFactoryIfMissing(pluginType); @@ -245,5 +201,17 @@ } + + public List<IInstance> GetAllInstances() + { + List<IInstance> list = new List<IInstance>(); + + foreach (var pair in _factories) + { + list.AddRange(pair.Value.Instances); + } + + return list; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/PipelineGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/PipelineGraphTester.cs 2008-10-03 15:12:28 UTC (rev 164) +++ trunk/Source/StructureMap.Testing/PipelineGraphTester.cs 2008-10-03 15:36:06 UTC (rev 165) @@ -25,48 +25,10 @@ #endregion - private void expectVisits(Registry registry, Action<IPipelineGraphVisitor> action) - { - MockRepository mocks = new MockRepository(); - IPipelineGraphVisitor visitor = mocks.StrictMock<IPipelineGraphVisitor>(); - using (mocks.Record()) - { - action(visitor); - } - using (mocks.Playback()) - { - PluginGraph graph = registry.Build(); - PipelineGraph pipeline = new PipelineGraph(graph); - pipeline.Visit(visitor); - } - } - - [Test] - public void Visit_a_single_family_with_a_default_and_another_instance() - { - Registry registry = new Registry(); - registry.BuildInstancesOf<ISomething>() - .TheDefaultIsConcreteType<SomethingOne>() - .AddConcreteType<SomethingTwo>(); - - expectVisits(registry, visitor => - { - visitor.PluginType(typeof (ISomething), null, null); - LastCall.Constraints(Is.Equal(typeof (ISomething)), Is.TypeOf(typeof (ConfiguredInstance)), Is.TypeOf<BuildPolicy>()); - - visitor.Instance(typeof(ISomething), null); - LastCall.Constraints(Is.Equal(typeof(ISomething)), Is.TypeOf(typeof(ConfiguredInstance))); - - visitor.Instance(typeof (ISomething), null); - LastCall.Constraints(Is.Equal(typeof(ISomething)), Is.TypeOf(typeof(SmartInstance<SomethingTwo>))); - }); - } - - [Test] public void can_iterate_through_instances_of_pipelineGraph_for_generics_if_not_registered() { PipelineGraph pipeline = new PipelineGraph(new PluginGraph()); @@ -138,58 +100,6 @@ pipeline.InstancesOf(typeof(ISomething)).Count().ShouldEqual(0); } - [Test] - public void Visit_a_single_family_with_no_default() - { - Registry registry = new Registry(); - registry.BuildInstancesOf<ISomething>() - .AddConcreteType<SomethingOne>() - .AddConcreteType<SomethingTwo>(); - expectVisits(registry, visitor => - { - visitor.PluginType(typeof(ISomething), null, new BuildPolicy()); - - visitor.Instance(typeof (ISomething), null); - LastCall.Constraints(Is.Equal(typeof (ISomething)), Is.TypeOf(typeof (SmartInstance<SomethingOne>))); - - visitor.Instance(typeof(ISomething), null); - LastCall.Constraints(Is.Equal(typeof(ISomething)), Is.TypeOf(typeof(SmartInstance<SomethingTwo>))); - }); - } - - [Test] - public void Visit_a_single_family_with_only_a_default() - { - Registry registry = new Registry(); - registry.BuildInstancesOf<ISomething>() - .TheDefaultIsConcreteType<SomethingOne>(); - - expectVisits(registry, visitor => - { - visitor.PluginType(typeof(ISomething), null, null); - LastCall.Constraints(Is.Equal(typeof (ISomething)), Is.TypeOf(typeof (ConfiguredInstance)), Is.TypeOf<BuildPolicy>()); - - visitor.Instance(typeof (ISomething), null); - LastCall.Constraints(Is.Equal(typeof (ISomething)), Is.TypeOf(typeof (ConfiguredInstance))); - }); - } - - - [Test] - public void Visit_three_families() - { - Registry registry = new Registry(); - registry.BuildInstancesOf<ISomething>(); - registry.BuildInstancesOf<IWidget>(); - registry.BuildInstancesOf<Rule>(); - - expectVisits(registry, visitor => - { - visitor.PluginType(typeof(ISomething), null, new BuildPolicy()); - visitor.PluginType(typeof(IWidget), null, new BuildPolicy()); - visitor.PluginType(typeof(Rule), null, new BuildPolicy()); - }); - } } } \ 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-10-03 16:34:42
|
Revision: 167 http://structuremap.svn.sourceforge.net/structuremap/?rev=167&view=rev Author: jeremydmiller Date: 2008-10-03 16:34:30 +0000 (Fri, 03 Oct 2008) Log Message: ----------- more tests Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/Model.cs trunk/Source/StructureMap/ObjectFactory.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-10-03 16:24:32 UTC (rev 166) +++ trunk/Source/StructureMap/Container.cs 2008-10-03 16:34:30 UTC (rev 167) @@ -79,7 +79,7 @@ #region IContainer Members - public Model Model + public IModel Model { get { return _model; } } Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-10-03 16:24:32 UTC (rev 166) +++ trunk/Source/StructureMap/IContainer.cs 2008-10-03 16:34:30 UTC (rev 167) @@ -9,7 +9,7 @@ { public interface IContainer { - Model Model { get; } + IModel Model { get; } T GetInstance<T>(string instanceKey); T GetInstance<T>(); Modified: trunk/Source/StructureMap/Model.cs =================================================================== --- trunk/Source/StructureMap/Model.cs 2008-10-03 16:24:32 UTC (rev 166) +++ trunk/Source/StructureMap/Model.cs 2008-10-03 16:34:30 UTC (rev 167) @@ -6,8 +6,19 @@ namespace StructureMap { - public class Model : TypeRules + public interface IModel { + bool HasDefaultImplementationFor(Type pluginType); + bool HasDefaultImplementationFor<T>(); + IEnumerable<PluginTypeConfiguration> PluginTypes { get; } + IEnumerable<IInstance> InstancesOf(Type pluginType); + IEnumerable<IInstance> InstancesOf<T>(); + bool HasImplementationsFor(Type pluginType); + bool HasImplementationsFor<T>(); + } + + public class Model : TypeRules, IModel + { private readonly PipelineGraph _graph; internal Model(PipelineGraph graph) Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-10-03 16:24:32 UTC (rev 166) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-10-03 16:34:30 UTC (rev 167) @@ -105,7 +105,7 @@ container.Inject(name, instance); } - public static Model Model + public static IModel Model { get { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-04 01:09:03
|
Revision: 168 http://structuremap.svn.sourceforge.net/structuremap/?rev=168&view=rev Author: jeremydmiller Date: 2008-10-04 01:08:55 +0000 (Sat, 04 Oct 2008) Log Message: ----------- Cleaning up some obsolete methods in the DSL and some obsolete code Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Pipeline/SerializedInstance.cs trunk/Source/StructureMap/Pipeline/SmartInstance.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.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/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Pipeline/OptionalSetterInjectionTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -28,27 +28,31 @@ return this; } - public GenericFamilyExpression TheDefaultIsConcreteType(Type concreteType) + public ConfiguredInstance TheDefaultIsConcreteType(Type concreteType) { - ConfiguredInstance instance = new ConfiguredInstance(concreteType); - return TheDefaultIs(instance); + var instance = new ConfiguredInstance(concreteType); + alterAndContinue(family => + { + family.AddInstance(instance); + family.DefaultInstanceKey = instance.Name; + }); + + return instance; } - public GenericFamilyExpression TheDefaultIs(Instance instance) + public ConfiguredInstance AddType(Type concreteType) { - return alterAndContinue(family => + var instance = new ConfiguredInstance(concreteType); + + alterAndContinue(family => { family.AddInstance(instance); - family.DefaultInstanceKey = instance.Name; }); - } - public GenericFamilyExpression TheDefaultIs(Func<object> func) - { - ConstructorInstance<object> instance = new ConstructorInstance<object>(func); - return TheDefaultIs(instance); + return instance; } + public GenericFamilyExpression AddInstance(Instance instance) { return alterAndContinue(family => family.AddInstance(instance)); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -84,5 +84,15 @@ { return returnInstance(new PrototypeInstance((ICloneable) template)); } + + public SerializedInstance SerializedCopyOf(T template) + { + return returnInstance(new SerializedInstance(template)); + } + + public UserControlInstance LoadControlFrom(string url) + { + return returnInstance(new UserControlInstance(url)); + } } } Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -7,7 +7,7 @@ namespace StructureMap.Configuration.DSL { - public class Registry : RegistryExpressions + public class Registry { private readonly List<Action> _basicActions = new List<Action>(); private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>(); @@ -65,6 +65,30 @@ return new GenericFamilyExpression(pluginType, this); } + public class BuildWithExpression<T> + { + private SmartInstance<T> _instance; + + public BuildWithExpression(SmartInstance<T> instance) + { + _instance = instance; + } + + public SmartInstance<T> Configure + { + get + { + return _instance; + } + } + } + + public BuildWithExpression<T> ForConcreteType<T>() + { + var instance = ForRequestedType<T>().TheDefault.Is.OfConcreteType<T>(); + return new BuildWithExpression<T>(instance); + } + /// <summary> /// Direct StructureMap to build instances of type T, and look for concrete classes /// marked with the [Pluggable] attribute that implement type T. Deleted: trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap/Configuration/DSL/RegistryExpressions.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -1,64 +0,0 @@ -using System; -using StructureMap.Pipeline; - -namespace StructureMap.Configuration.DSL -{ - public class RegistryExpressions - { - /// <summary> - /// Convenience method to start the definition of an instance of type T - /// </summary> - /// <typeparam name="PLUGGEDTYPE"></typeparam> - /// <returns></returns> - public static ConfiguredInstance Instance<PLUGGEDTYPE>() - { - ConfiguredInstance instance = new ConfiguredInstance(typeof (PLUGGEDTYPE)); - - return instance; - } - - /// <summary> - /// Convenience method to register a prototype instance - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <param name="prototype"></param> - /// <returns></returns> - public static PrototypeInstance Prototype<PLUGINTYPE>(PLUGINTYPE prototype) - { - return new PrototypeInstance((ICloneable) prototype); - } - - /// <summary> - /// Convenience method to register a preconfigured instance of type T - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <param name="instance"></param> - /// <returns></returns> - public static LiteralInstance Object<PLUGINTYPE>(PLUGINTYPE instance) - { - return new LiteralInstance(instance); - } - - /// <summary> - /// Registers a UserControl as an instance - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <param name="url"></param> - /// <returns></returns> - public UserControlInstance LoadControlFromUrl(string url) - { - return new UserControlInstance(url); - } - - public static ConstructorInstance<T> ConstructedBy<T> - (Func<T> builder) - { - return new ConstructorInstance<T>(() => builder()); - } - - public static ReferencedInstance Instance(string referencedKey) - { - return new ReferencedInstance(referencedKey); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/SerializedInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SerializedInstance.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap/Pipeline/SerializedInstance.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -7,7 +7,7 @@ namespace StructureMap.Pipeline { - public class SerializedInstance : Instance + public class SerializedInstance : ExpressedInstance<SerializedInstance> { private MemoryStream _stream; private object _locker = new object(); @@ -33,5 +33,10 @@ return formatter.Deserialize(_stream); } } + + protected override SerializedInstance thisInstance + { + get { return this; } + } } } Modified: trunk/Source/StructureMap/Pipeline/SmartInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SmartInstance.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap/Pipeline/SmartInstance.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -121,9 +121,14 @@ Plugin plugin = PluginCache.GetPlugin(typeof (T)); string propertyName = plugin.FindArgumentNameForType(typeof (CHILD).MakeArrayType()); - return new ArrayDefinitionExpression<T, CHILD>(this, propertyName); + return TheArrayOf<CHILD>(propertyName); } + public ArrayDefinitionExpression<T, CHILD> TheArrayOf<CHILD>(string ctorOrPropertyName) + { + return new ArrayDefinitionExpression<T, CHILD>(this, ctorOrPropertyName); + } + public class ArrayDefinitionExpression<T, ARRAY> { private SmartInstance<T> _instance; @@ -147,7 +152,7 @@ return _instance; } - public SmartInstance<T> Contains(Instance[] arrayInstances) + public SmartInstance<T> Contains(params Instance[] arrayInstances) { _instance.setChildArray(_propertyName, arrayInstances); @@ -184,7 +189,19 @@ { return Is(new LiteralInstance(value)); } + + public SmartInstance<T> IsTheDefault() + { + return Is(new DefaultInstance()); + } + + public SmartInstance<T> Is<CONCRETETYPE>() where CONCRETETYPE : CHILD + { + return Is(new SmartInstance<CONCRETETYPE>()); + } } + + } Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-10-04 01:08:55 UTC (rev 168) @@ -137,7 +137,6 @@ </Compile> <Compile Include="BuildSession.cs" /> <Compile Include="Configuration\DSL\Expressions\GenericFamilyExpression.cs" /> - <Compile Include="Configuration\DSL\RegistryExpressions.cs" /> <Compile Include="Configuration\ProfileBuilder.cs" /> <Compile Include="Diagnostics\BuildError.cs" /> <Compile Include="Diagnostics\CharacterWidth.cs" /> Modified: trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -1,3 +1,4 @@ +using System; using System.Xml; using NUnit.Framework; using StructureMap.Testing.GenericWidgets; @@ -16,7 +17,6 @@ { DataMother.BackupStructureMapConfig(); - StructureMapConfiguration.ResetAll(); DataMother.WriteDocument("Config1.xml"); DataMother.WriteDocument("Config2.xml"); DataMother.WriteDocument("FullTesting.XML"); @@ -25,16 +25,16 @@ [TearDown] public void TearDown() { - StructureMapConfiguration.ResetAll(); DataMother.RestoreStructureMapConfig(); } #endregion - public void assertTheDefault(string color) + public void assertTheDefault(string color, Action<ConfigurationExpression> action) { - ColorWidget widget = (ColorWidget) ObjectFactory.GetInstance<IWidget>(); - Assert.AreEqual(color, widget.Color); + var container = new Container(action); + + container.GetInstance<IWidget>().ShouldBeOfType<ColorWidget>().Color.ShouldEqual(color); } [Test] @@ -45,27 +45,33 @@ doc.LoadXml(xml); - StructureMapConfiguration.UseDefaultStructureMapConfigFile = true; - StructureMapConfiguration.IncludeConfigurationFromNode(doc.DocumentElement, string.Empty); + var container = new Container(x => + { + x.AddConfigurationFromXmlFile("StructureMap.config"); + x.AddConfigurationFromNode(doc.DocumentElement); + }); - IPlug<string> service = ObjectFactory.GetInstance<IPlug<string>>(); - Assert.IsNotNull(service); + container.GetInstance<IPlug<string>>().ShouldNotBeNull(); } [Test] public void NotTheDefault() { - StructureMapConfiguration.UseDefaultStructureMapConfigFile = false; - StructureMapConfiguration.IgnoreStructureMapConfig = true; - StructureMapConfiguration.IncludeConfigurationFromFile("Config1.xml"); - - assertTheDefault("Orange"); + assertTheDefault("Orange", x => + { + x.AddConfigurationFromXmlFile("Config1.xml"); + }); } [Test] public void WithTheDefault() { - assertTheDefault("Red"); + ObjectFactory.Initialize(x => + { + x.UseDefaultStructureMapConfigFile = true; + }); + + ObjectFactory.GetInstance<IWidget>().ShouldBeOfType<ColorWidget>().Color.ShouldEqual("Red"); } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -7,7 +7,7 @@ namespace StructureMap.Testing.Configuration.DSL { [TestFixture] - public class AddInstanceTester : RegistryExpressions + public class AddInstanceTester { #region Setup/Teardown @@ -161,6 +161,32 @@ [Test] + public void UseAPreBuiltObjectForAnInstanceAsASerializedCopy() + { + // Build an instance for IWidget, then setup StructureMap to return cloned instances of the + // "Prototype" (GoF pattern) whenever someone asks for IWidget named "Jeremy" + var theWidget = new CloneableWidget("Jeremy"); + + + container = + new Container( + registry => registry.InstanceOf<IWidget>().Is.SerializedCopyOf(theWidget).WithName("Jeremy")); + + var widget1 = (CloneableWidget)container.GetInstance<IWidget>("Jeremy"); + var widget2 = (CloneableWidget)container.GetInstance<IWidget>("Jeremy"); + var widget3 = (CloneableWidget)container.GetInstance<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 UseAPreBuiltObjectWithAName() { // Return the specific instance when an IWidget named "Julia" is requested @@ -222,6 +248,7 @@ #endregion } + [Serializable] public class CloneableWidget : IWidget, ICloneable { private readonly string _name; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -6,16 +6,6 @@ [TestFixture] public class ConstructorExpressionTester : Registry { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - StructureMapConfiguration.ResetAll(); - } - - #endregion - public interface Abstraction { } @@ -46,11 +36,8 @@ { Concretion concretion = new Concretion(); - IContainer manager = new Container(registry => registry.ForRequestedType<Abstraction>().TheDefaultIs( - ConstructedBy<Abstraction>(() => concretion) - )); - - Assert.AreSame(concretion, manager.GetInstance<Abstraction>()); + IContainer container = new Container(registry => registry.ForRequestedType<Abstraction>().TheDefault.Is.ConstructedBy(() => concretion)); + container.GetInstance<Abstraction>().ShouldBeTheSameAs(concretion); } [Test] @@ -61,17 +48,16 @@ IContainer manager = new Container(registry => { - registry.ForRequestedType<Abstraction>().AddInstance( - ConstructedBy<Abstraction>(() => concretion1).WithName("One") - ); + registry.ForRequestedType<Abstraction>().AddInstances(x => + { + x.ConstructedBy(() => concretion1).WithName("One"); + x.ConstructedBy(() => concretion2).WithName("Two"); + }); - registry.ForRequestedType<Abstraction>().AddInstance( - ConstructedBy<Abstraction>(() => concretion2).WithName("Two") - ); }); - Assert.AreSame(concretion1, manager.GetInstance<Abstraction>("One")); - Assert.AreSame(concretion2, manager.GetInstance<Abstraction>("Two")); + manager.GetInstance<Abstraction>("One").ShouldBeTheSameAs(concretion1); + manager.GetInstance<Abstraction>("Two").ShouldBeTheSameAs(concretion2); } [Test] @@ -79,11 +65,12 @@ { Concretion concretion = new Concretion(); - IContainer manager = new Container(registry => registry.ForRequestedType<Abstraction>().AddInstance( - ConstructedBy<Abstraction>(() => concretion) - )); + var container = new Container(r => + { + r.InstanceOf<Abstraction>().Is.ConstructedBy(() => concretion); + }); - Abstraction actual = manager.GetAllInstances<Abstraction>()[0]; + Abstraction actual = container.GetAllInstances<Abstraction>()[0]; Assert.AreSame(concretion, actual); } } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -59,11 +59,12 @@ [Test] public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() { - IContainer manager = new Container(registry => registry.ForRequestedType<Something>().AddInstance( - RegistryExpressions.Instance<RedSomething>().WithName( - "Red") - )); - IList<Something> instances = manager.GetAllInstances<Something>(); + var container = new Container(r => + { + r.InstanceOf<Something>().Is.OfConcreteType<RedSomething>().WithName("Red"); + }); + + IList<Something> instances = container.GetAllInstances<Something>(); Assert.AreEqual(1, instances.Count); } @@ -163,15 +164,13 @@ [Test] public void CreatePluginFamilyWithADefault() { - IContainer manager = new Container(registry => registry.BuildInstancesOf<IWidget>().TheDefaultIs( - RegistryExpressions.Instance<ColorWidget>().WithProperty( - "color"). - EqualTo( - "Red") - )); + var container = new Container(r => + { + r.ForRequestedType<IWidget>().TheDefault.Is.OfConcreteType<ColorWidget>() + .WithCtorArg("color").EqualTo("Red"); + }); - var widget = (ColorWidget) manager.GetInstance<IWidget>(); - Assert.AreEqual("Red", widget.Color); + container.GetInstance<IWidget>().ShouldBeOfType<ColorWidget>().Color.ShouldEqual("Red"); } [Test] Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -7,7 +7,7 @@ namespace StructureMap.Testing.Configuration.DSL { [TestFixture] - public class DeepInstanceTester : RegistryExpressions + public class DeepInstanceTester { private readonly Thing _prototype = new Thing(4, "Jeremy", .333, new WidgetRule(new ColorWidget("yellow"))); @@ -21,41 +21,34 @@ [Test] public void DeepInstance2() { - assertThingMatches(registry => + assertThingMatches(r => { - registry.BuildInstancesOf<IWidget>().TheDefaultIs( - Instance<ColorWidget>() - .WithProperty("color").EqualTo("yellow") - ); + r.ForRequestedType<IWidget>().TheDefault.Is.OfConcreteType<ColorWidget>() + .WithProperty("color").EqualTo("yellow"); - registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + r.ForRequestedType<Rule>().TheDefaultIsConcreteType<WidgetRule>(); - registry.BuildInstancesOf<Thing>().TheDefaultIs( - Instance<Thing>() - .WithProperty("average").EqualTo(.333) - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - ); + r.ForRequestedType<Thing>().TheDefault.Is.OfConcreteType<Thing>() + .WithCtorArg("average").EqualTo(.333) + .WithCtorArg("name").EqualTo("Jeremy") + .WithCtorArg("count").EqualTo(4); + }); } [Test] public void DeepInstance3() { - assertThingMatches(registry => + assertThingMatches(r => { - registry.BuildInstancesOf<IWidget>().TheDefaultIs( - Object<IWidget>(new ColorWidget("yellow")) - ); + r.ForRequestedType<IWidget>().TheDefault.IsThis(new ColorWidget("yellow")); - registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + r.ForRequestedType<Rule>().TheDefaultIsConcreteType<WidgetRule>(); - registry.BuildInstancesOf<Thing>().TheDefaultIs( - Instance<Thing>() - .WithProperty("average").EqualTo(.333) - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - ); + r.ForRequestedType<Thing>().TheDefault.Is.OfConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4); }); } @@ -63,20 +56,16 @@ [Test] public void DeepInstance4() { - assertThingMatches(registry => + assertThingMatches(r => { - registry.BuildInstancesOf<IWidget>().TheDefaultIs( - Prototype<IWidget>(new ColorWidget("yellow")) - ); + r.ForRequestedType<IWidget>().TheDefault.Is.PrototypeOf(new ColorWidget("yellow")); - registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); + r.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<WidgetRule>(); - registry.BuildInstancesOf<Thing>().TheDefaultIs( - Instance<Thing>() - .WithProperty("average").EqualTo(.333) - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - ); + r.ForRequestedType<Thing>().TheDefault.Is.OfConcreteType<Thing>() + .WithProperty("average").EqualTo(.333) + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4); }); } @@ -107,22 +96,25 @@ [Test] public void DeepInstanceTest1() { - ConfiguredInstance widgetExpression = Instance<ColorWidget>() - .WithProperty("color").EqualTo("yellow"); + assertThingMatches(r => + { + r.ForRequestedType<Thing>().TheDefault.Is.OfConcreteType<Thing>() + .WithProperty("name").EqualTo("Jeremy") + .WithProperty("count").EqualTo(4) + .WithProperty("average").EqualTo(.333) + .CtorDependency<Rule>().Is(x => + { + x.OfConcreteType<WidgetRule>() + .WithCtorArg("color").EqualTo("yellow") + .CtorDependency<IWidget>().Is( + w => + { + w.OfConcreteType<ColorWidget>().WithProperty("color").EqualTo("yellow"); + }); + }); + + }); - ConfiguredInstance ruleExpression = Instance<WidgetRule>() - .Child<IWidget>().Is(widgetExpression); - - - assertThingMatches(registry => registry.BuildInstancesOf<Thing>().TheDefaultIs( - Instance<Thing>() - .WithProperty("name").EqualTo("Jeremy") - .WithProperty("count").EqualTo(4) - .WithProperty("average").EqualTo(.333) - .Child<Rule>().Is( - ruleExpression - ) - )); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -8,7 +8,7 @@ namespace StructureMap.Testing.Configuration.DSL { [TestFixture] - public class GenericFamilyExpressionTester : RegistryExpressions + public class GenericFamilyExpressionTester { public interface ITarget { @@ -104,11 +104,12 @@ [Test] public void Add_default_instance() { - Container manager = - new Container( - r => r.ForRequestedType(typeof (ITarget)).TheDefaultIs(Instance<Target2>())); + var container = new Container(r => + { + r.ForRequestedType(typeof (ITarget)).TheDefaultIsConcreteType(typeof (Target2)); + }); - Assert.IsInstanceOfType(typeof (Target2), manager.GetInstance<ITarget>()); + container.GetInstance<ITarget>().ShouldBeOfType<Target2>(); } [Test, Explicit] @@ -143,35 +144,29 @@ } public class Invoice{} - [Test] - public void Add_instance_by_lambda() - { - Container manager = - new Container( - r => r.ForRequestedType(typeof (ITarget)).TheDefaultIs(delegate { return new Target1(); })); - Assert.IsInstanceOfType(typeof (Target1), manager.GetInstance<ITarget>()); - } - [Test] public void Add_instance_directly() { - Container manager = - new Container( - r => r.ForRequestedType(typeof (ITarget)).AddInstance(Instance<Target2>())); + var container = new Container(r => + { + r.InstanceOf<ITarget>().Is.OfConcreteType<Target2>(); + }); - - Assert.IsInstanceOfType(typeof (Target2), manager.GetAllInstances<ITarget>()[0]); + Assert.IsInstanceOfType(typeof (Target2), container.GetAllInstances<ITarget>()[0]); } [Test] public void Enrichment() { - Container manager = new Container(r => r.ForRequestedType(typeof (ITarget)) - .TheDefaultIsConcreteType(typeof (Target1)) - .EnrichWith(raw => new WrappedTarget((ITarget) raw))); + var container = new Container(r => + { + r.ForRequestedType(typeof (ITarget)).EnrichWith(raw => new WrappedTarget((ITarget) raw)) + .TheDefaultIsConcreteType(typeof (Target1)); - WrappedTarget target = (WrappedTarget) manager.GetInstance<ITarget>(); + }); + + WrappedTarget target = (WrappedTarget) container.GetInstance<ITarget>(); Assert.IsInstanceOfType(typeof (Target1), target.Inner); } @@ -191,13 +186,13 @@ { ITarget created = null; - Container manager = new Container(r => r.ForRequestedType(typeof (ITarget)) - .TheDefaultIsConcreteType(typeof (Target3)) - .OnCreation(raw => created = (ITarget) raw)); + var container = new Container(r => + { + r.ForRequestedType(typeof (ITarget)).OnCreation(raw => created = (ITarget) raw) + .TheDefaultIsConcreteType(typeof (Target3)); + }); - manager.GetInstance<ITarget>(); - - Assert.IsInstanceOfType(typeof (Target3), created); + container.GetInstance<ITarget>().ShouldBeOfType<Target3>(); } [Test] Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -1,10 +1,11 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; +using StructureMap.Pipeline; namespace StructureMap.Testing.Configuration.DSL { [TestFixture] - public class InjectArrayTester : RegistryExpressions + public class InjectArrayTester { #region Setup/Teardown @@ -82,40 +83,41 @@ [Test] public void CanStillAddOtherPropertiesAfterTheCallToChildArray() { - IContainer manager = new Container( - registry => registry.ForRequestedType<Processor>() - .TheDefaultIs( - Instance<Processor>() - .ChildArray<IHandler[]>().Contains( - Instance<Handler1>(), - Instance<Handler2>(), - Instance<Handler3>() - ) - .WithProperty("name").EqualTo("Jeremy") - )); + var container = new Container(x => + { + x.ForRequestedType<Processor>().TheDefault.Is + .OfConcreteType<Processor>() + .TheArrayOf<IHandler>().Contains( + new SmartInstance<Handler1>(), + new SmartInstance<Handler2>(), + new SmartInstance<Handler3>() + ) + .WithCtorArg("name").EqualTo("Jeremy"); + }); - var processor = manager.GetInstance<Processor>(); - Assert.AreEqual("Jeremy", processor.Name); + container.GetInstance<Processor>().Name.ShouldEqual("Jeremy"); } [Test] public void InjectPropertiesByName() { - IContainer manager = new Container(registry => registry.ForRequestedType<Processor2>() - .TheDefaultIs( - Instance<Processor2>() - .ChildArray<IHandler[]>("first").Contains( - Instance<Handler1>(), - Instance<Handler2>() - ) - .ChildArray<IHandler[]>("second").Contains( - Instance<Handler2>(), - Instance<Handler3>() - ) - )); + var container = new Container(r => + { + r.ForRequestedType<Processor2>().TheDefault.Is.OfConcreteType<Processor2>() + .TheArrayOf<IHandler>("first").Contains(x => + { + x.OfConcreteType<Handler1>(); + x.OfConcreteType<Handler2>(); + }) + .TheArrayOf<IHandler>("second").Contains(x => + { + x.OfConcreteType<Handler2>(); + x.OfConcreteType<Handler3>(); + }); + }); - var processor = manager.GetInstance<Processor2>(); + var processor = container.GetInstance<Processor2>(); Assert.IsInstanceOfType(typeof (Handler1), processor.First[0]); Assert.IsInstanceOfType(typeof (Handler2), processor.First[1]); @@ -123,28 +125,7 @@ Assert.IsInstanceOfType(typeof (Handler3), processor.Second[1]); } - [Test, - ExpectedException(typeof (StructureMapException), - ExpectedMessage = - "StructureMap Exception Code: 307\nIn the call to ChildArray<T>(), the type T must be an array")] - public void InjectPropertiesByNameButUseTheElementType() - { - var registry = new Registry(); - registry.ForRequestedType<Processor2>() - .TheDefaultIs( - Instance<Processor2>() - .ChildArray<IHandler>("first").Contains( - Instance<Handler1>(), - Instance<Handler2>() - ) - .ChildArray<IHandler[]>("second").Contains( - Instance<Handler2>(), - Instance<Handler3>() - ) - ); - } - [Test] public void PlaceMemberInArrayByReference() { @@ -153,15 +134,13 @@ r.InstanceOf<IHandler>().Is.OfConcreteType<Handler1>().WithName("One"); r.InstanceOf<IHandler>().Is.OfConcreteType<Handler2>().WithName("Two"); - r.ForRequestedType<Processor>() - .TheDefaultIs( - Instance<Processor>() - .WithProperty("name").EqualTo("Jeremy") - .ChildArray<IHandler[]>().Contains( - Instance("Two"), - Instance("One") - ) - ); + r.ForRequestedType<Processor>().TheDefault.Is.OfConcreteType<Processor>() + .WithCtorArg("name").EqualTo("Jeremy") + .TheArrayOf<IHandler>().Contains(x => + { + x.References("Two"); + x.References("One"); + }); }); var processor = manager.GetInstance<Processor>(); @@ -198,19 +177,21 @@ [Test] public void ProgrammaticallyInjectArrayAllInline() { - IContainer manager = new Container(registry => registry.ForRequestedType<Processor>() - .TheDefaultIs( - Instance<Processor>() - .ChildArray<IHandler[]>().Contains( - Instance<Handler1>(), - Instance<Handler2>(), - Instance<Handler3>() - ) - .WithProperty("name").EqualTo("Jeremy") - )); + var container = new Container(x => + { + x.ForRequestedType<Processor>().TheDefault.Is.OfConcreteType<Processor>() + .WithCtorArg("name").EqualTo("Jeremy") + .TheArrayOf<IHandler>().Contains(y => + { + y.OfConcreteType<Handler1>(); + y.OfConcreteType<Handler2>(); + y.OfConcreteType<Handler3>(); + }); + }); - var processor = manager.GetInstance<Processor>(); + var processor = container.GetInstance<Processor>(); + Assert.IsInstanceOfType(typeof (Handler1), processor.Handlers[0]); Assert.IsInstanceOfType(typeof (Handler2), processor.Handlers[1]); Assert.IsInstanceOfType(typeof (Handler3), processor.Handlers[2]); @@ -221,7 +202,6 @@ { IContainer container = new Container(r => { -// ReSharper disable ConvertToLambdaExpression r.ForRequestedType<Processor>().TheDefault.Is.OfConcreteType<Processor>() .WithCtorArg("name").EqualTo("Jeremy") .TheArrayOf<IHandler>().Contains(x => @@ -230,7 +210,6 @@ x.OfConcreteType<Handler2>(); x.OfConcreteType<Handler3>(); }); -// ReSharper restore ConvertToLambdaExpression }); @@ -241,21 +220,5 @@ Assert.IsInstanceOfType(typeof(Handler3), processor.Handlers[2]); } - [Test, - ExpectedException(typeof (StructureMapException), - ExpectedMessage = - "StructureMap Exception Code: 307\nIn the call to ChildArray<T>(), the type T must be an array")] - public void TryToInjectByTheElementTypeInsteadOfTheArrayType() - { - var registry = new Registry(); - - registry.ForRequestedType<Processor>() - .TheDefaultIs( - Instance<Processor>() - .WithProperty("name").EqualTo("Jeremy") - .ChildArray<IHandler>().Contains( - Instance<Handler1>()) - ); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InstanceExpressionTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -1,5 +1,6 @@ using NUnit.Framework; using StructureMap.Configuration.DSL; +using StructureMap.Pipeline; using StructureMap.Testing.Widget; namespace StructureMap.Testing.Configuration.DSL @@ -19,7 +20,7 @@ [Test, ExpectedException(typeof (StructureMapException))] public void BlowUpIfNoPropertyIsFoundForType() { - RegistryExpressions.Instance<AWidget>().Child<Rule>(); + new SmartInstance<AWidget>().CtorDependency<Rule>(); } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -52,7 +52,7 @@ private IContainer _manager; private Action<Registry> _defaultRegistry; - private IService getService(Action<Registry> action, string name) + private IService getService(string name, Action<Registry> action) { if (_manager == null) { @@ -69,41 +69,42 @@ [Test] public void EnrichForAll() { - Action<Registry> action = registry => registry.ForRequestedType<IService>() - .EnrichWith(s => new DecoratorService(s)) - .AddInstance( - ConstructedBy<IService>(() => new ColorService("Green")) - .WithName("Green")); + var green = getService("Green", r => + { + r.ForRequestedType<IService>().EnrichWith(s => new DecoratorService(s)) + .AddInstances(x => + { + x.ConstructedBy(() => new ColorService("Green")).WithName("Green"); + }); + }); - - IService green = getService(action, "Green"); - - - var decoratorService = (DecoratorService) green; - var innerService = (ColorService) decoratorService.Inner; - Assert.AreEqual("Green", innerService.Color); + green.ShouldBeOfType<DecoratorService>() + .Inner.ShouldBeOfType<ColorService>().Color.ShouldEqual("Green"); } [Test] public void OnStartupForAll() { - Action<Registry> action = registry => registry.ForRequestedType<IService>() - .OnCreation(s => _lastService = s) - .AddInstance( - ConstructedBy<IService>(() => new ColorService("Green")) - .WithName("Green")); + Action<Registry> action = r => + { + r.ForRequestedType<IService>().OnCreation(s => _lastService = s) + .AddInstances(x => + { + x.ConstructedBy(() => new ColorService("Green")).WithName("Green"); + }); + }; - - IService red = getService(action, "Red"); + + IService red = getService("Red", action); Assert.AreSame(red, _lastService); - IService purple = getService(action, "Purple"); + IService purple = getService("Purple", action); Assert.AreSame(purple, _lastService); - IService green = getService(action, "Green"); + IService green = getService("Green", action); Assert.AreSame(green, _lastService); - IService yellow = getService(action, "Yellow"); + IService yellow = getService("Yellow", action); Assert.AreEqual(yellow, _lastService); } } @@ -157,11 +158,14 @@ [Test] public void EnrichForAll() { - Action<Registry> action = registry => registry.ForRequestedType<IService>() - .EnrichWith(s => new DecoratorService(s)) - .AddInstance( - ConstructedBy<IService>(() => new ColorService("Green")) - .WithName("Green")); + Action<Registry> action = r => + { + r.ForRequestedType<IService>().EnrichWith(s => new DecoratorService(s)) + .AddInstances(x => + { + x.ConstructedBy(() => new ColorService("Green")).WithName("Green"); + }); + }; IService green = getService(action, "Green"); @@ -175,13 +179,15 @@ [Test] public void OnStartupForAll() { - Action<Registry> action = registry => registry.ForRequestedType<IService>() - .OnCreation(s => _lastService = s) - .AddInstance( - ConstructedBy<IService>(() => new ColorService("Green")) - .WithName("Green")); + Action<Registry> action = r => + { + r.ForRequestedType<IService>().OnCreation(s => _lastService = s) + .AddInstances(x => + { + x.ConstructedBy(() => new ColorService("Green")).WithName("Green"); + }); + }; - IService red = getService(action, "Red"); Assert.AreSame(red, _lastService); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -107,9 +107,7 @@ Registry registry = new Registry(); registry.CreateProfile(theProfileName) - .For<IWidget>().Use( - Instance<AWidget>() - ); + .For<IWidget>().UseConcreteType<AWidget>(); PluginGraph graph = registry.Build(); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -9,21 +9,6 @@ [TestFixture] public class RegistryIntegratedTester { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - } - - [TearDown] - public void TearDown() - { - StructureMapConfiguration.ResetAll(); - } - - #endregion - [Test] public void AutomaticallyFindRegistryFromAssembly() { Modified: trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -4,7 +4,6 @@ using System.Reflection; using System.Xml; using NUnit.Framework; -using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Pipeline; @@ -13,7 +12,7 @@ namespace StructureMap.Testing.Diagnostics { [TestFixture] - public class DoctorTester : RegistryExpressions + public class DoctorTester { private DoctorReport fetchReport<T>(string config) where T : IBootstrapper { @@ -167,7 +166,8 @@ public void BootstrapStructureMap() { - StructureMapConfiguration.AddInstanceOf<IWidget>(new ConfiguredInstance(typeof (ColorRule))); + ObjectFactory.Initialize( + x => { x.InstanceOf<IWidget>().IsThis(new ConfiguredInstance(typeof (ColorRule))); }); } #endregion @@ -210,15 +210,8 @@ public void BootstrapStructureMap() { - ObjectFactory.Initialize(x => - { - x.InstanceOf<IWidget>().Is.ConstructedBy(() => - { - throw new NotImplementedException(); - }); - }); - - + ObjectFactory.Initialize( + x => { x.InstanceOf<IWidget>().Is.ConstructedBy(() => { throw new NotImplementedException(); }); }); } #endregion @@ -230,8 +223,11 @@ public void BootstrapStructureMap() { - StructureMapConfiguration.IgnoreStructureMapConfig = true; - StructureMapConfiguration.BuildInstancesOf<IWidget>().TheDefault.Is.Object(new ColorWidget("Red")); + ObjectFactory.Initialize(x => + { + x.IgnoreStructureMapConfig = true; + x.BuildInstancesOf<IWidget>().TheDefault.Is.Object(new ColorWidget("Red")); + }); } #endregion @@ -243,9 +239,13 @@ public void BootstrapStructureMap() { - StructureMapConfiguration.IgnoreStructureMapConfig = true; - StructureMapConfiguration.ForRequestedType<IWidget>().TheDefaultIs( - RegistryExpressions.Instance<DoctorTester.NumberWidget>().WithProperty("age").EqualToAppSetting("age")); + ObjectFactory.Initialize(x => + { + x.IgnoreStructureMapConfig = true; + x.ForRequestedType<IWidget>().TheDefault.Is + .OfConcreteType<DoctorTester.NumberWidget>() + .WithCtorArg("age").EqualToAppSetting("age"); + }); } #endregion Modified: trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -13,11 +13,11 @@ { private ValidationBuildSession validatedSession(Action<Registry> action) { - Registry registry = new Registry(); + var registry = new Registry(); action(registry); PluginGraph graph = registry.Build(); - ValidationBuildSession session = new ValidationBuildSession(graph); + var session = new ValidationBuildSession(graph); session.PerformValidations(); return session; @@ -32,20 +32,20 @@ private ConstructorInstance<IWidget> errorInstance() { - return ConstructedBy<IWidget>(delegate { throw new NotSupportedException("You can't make me!"); }); + return + new ConstructorInstance<IWidget>(delegate() { throw new NotSupportedException("You can't make me!"); }); } [Test] public void Attach_dependency_to_the_build_error_but_do_not_create_new_error_for_dependency() { - ValidationBuildSession session = validatedSession(registry => + ValidationBuildSession session = validatedSession(r => { - registry.AddInstanceOf<IWidget>(errorInstance().WithName("BadInstance")); + r.AddInstanceOf<IWidget>(errorInstance().WithName("BadInstance")); - registry.AddInstanceOf<SomethingThatNeedsAWidget>( - Instance<SomethingThatNeedsAWidget>().WithName("DependentInstance") - .Child<IWidget>().IsNamedInstance("BadInstance") - ); + r.InstanceOf<SomethingThatNeedsAWidget>().Is.OfConcreteType<SomethingThatNeedsAWidget>() + .WithName("DependentInstance") + .CtorDependency<IWidget>().Is(x => x.References("BadInstance")); }); BuildError error = getFirstAndOnlyError(session); @@ -69,14 +69,13 @@ [Test] public void Create_an_instance_that_fails_and_an_instance_that_depends_on_that_exception() { - ValidationBuildSession session = validatedSession(registry => + ValidationBuildSession session = validatedSession(r => { - registry.AddInstanceOf<IWidget>(errorInstance().WithName("BadInstance")); + r.AddInstanceOf<IWidget>(errorInstance().WithName("BadInstance")); - registry.AddInstanceOf<SomethingThatNeedsAWidget>( - Instance<SomethingThatNeedsAWidget>().WithName("DependentInstance") - .Child<IWidget>().IsNamedInstance("BadInstance") - ); + r.InstanceOf<SomethingThatNeedsAWidget>().Is.OfConcreteType<SomethingThatNeedsAWidget>() + .WithName("DependentInstance") + .CtorDependency<IWidget>().Is(x => x.References("BadInstance")); }); Assert.AreEqual(1, session.BuildErrors.Length); @@ -92,10 +91,12 @@ public void Create_an_instance_that_fails_because_of_an_inline_child() { ValidationBuildSession session = validatedSession( - registry => registry.AddInstanceOf<SomethingThatNeedsAWidget>( - Instance<SomethingThatNeedsAWidget>().WithName("BadInstance") - .Child<IWidget>().Is(errorInstance()) - )); + r => + { + r.InstanceOf<SomethingThatNeedsAWidget>().Is.OfConcreteType<SomethingThatNeedsAWidget>() + .WithName("BadInstance") + .CtorDependency<IWidget>().Is(errorInstance()); + }); BuildError error = getFirstAndOnlyError(session); @@ -130,9 +131,9 @@ [Test] public void Request_an_instance_for_the_second_time_successfully_and_get_the_same_object() { - ValidationBuildSession session = new ValidationBuildSession(new PluginGraph()); + var session = new ValidationBuildSession(new PluginGraph()); - LiteralInstance instance = Object(new ColorWidget("Red")); + var instance = new LiteralInstance(new ColorWidget("Red")); object widget1 = session.CreateInstance(typeof (IWidget), instance); object widget2 = session.CreateInstance(typeof (IWidget), instance); @@ -152,7 +153,7 @@ [Test] public void Validate_a_single_object_with_both_a_passing_validation_method_and_a_failing_validation_method() { - LiteralInstance instance = new LiteralInstance(new WidgetWithOneValidationFailure()); + var instance = new LiteralInstance(new WidgetWithOneValidationFailure()); ValidationBuildSession session = validatedSession(registry => registry.AddInstanceOf<IWidget>(instance)); Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-10-03 16:34:30 UTC (rev 167) +++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-10-04 01:08:55 UTC (rev 168) @@ -80,28 +80,32 @@ [Test] public void Can_set_profile_name_and_reset_defaults() { - IContainer manager = new Container(registry => + var container = new Container(r => { - registry.ForRequestedType<IService>() - .TheDefaultIs(Instance<ColorService>().WithName("Orange").WithProperty("color").EqualTo("Orange")) - .AddInstance(Instance<ColorService>().WithName("Red").WithProperty("color").EqualTo("Red")) - .AddInstance(Instance<ColorService>().WithName("Blue").WithProperty("color").EqualTo("Blue")) - .AddInstance(Instance<ColorService>().WithName("Green").WithProperty("color").EqualTo("Green")); + r.ForRequestedType<IService>() + .TheDefault.Is.OfConcreteType<ColorService>().WithName("Orange").WithProperty("color").EqualTo("Orange"); - registry.CreateProfile("Red").For<IService>().UseNamedInstance("Red"); - registry.CreateProfile(... [truncated message content] |
From: <jer...@us...> - 2008-10-03 14:48:09
|
Revision: 163 http://structuremap.svn.sourceforge.net/structuremap/?rev=163&view=rev Author: jeremydmiller Date: 2008-10-03 14:47:59 +0000 (Fri, 03 Oct 2008) Log Message: ----------- doing some work for querying the state of the container Modified Paths: -------------- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/Profile.cs trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using StructureMap.Pipeline; using StructureMap.Util; @@ -19,6 +20,17 @@ get { return _families.Count; } } + public IEnumerable<PluginTypeConfiguration> Families + { + get + { + foreach (var family in _families) + { + yield return family.GetConfiguration(); + } + } + } + public static bool CanBeCast(Type pluginType, Type pluggedType) { try @@ -101,9 +113,6 @@ { PluginFamily templatedFamily = baseFamily.CreateTemplatedClone(templateTypes); - - - return templatedFamily; } @@ -155,5 +164,10 @@ { return _families.Retrieve(pluginType); } + + public bool HasFamily(Type pluginType) + { + return _families.Has(pluginType); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -257,6 +257,11 @@ get { return _instances.Count; } } + public IEnumerable<IInstance> Instances + { + get { return _instances.GetAll(); } + } + #endregion public Plugin FindPlugin(Type pluggedType) @@ -356,5 +361,16 @@ AddPlugin(concreteType, name); } } + + public PluginTypeConfiguration GetConfiguration() + { + return new PluginTypeConfiguration() + { + Instance = GetDefaultInstance(), + PluginType = PluginType, + Policy = _buildPolicy, + Instances = Instances + }; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/IContainer.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -34,9 +34,6 @@ string WhatDoIHave(); - - - /// <summary> /// Creates a new object instance of the requested type /// </summary> @@ -70,5 +67,6 @@ void AssertConfigurationIsValid(); object GetInstance(Type type, ExplicitArguments args); PluginGraph PluginGraph { get; } + void EjectAllInstancesOf<T>(); } } \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/IInstanceFactory.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/IInstanceFactory.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using StructureMap.Graph; using StructureMap.Pipeline; @@ -11,6 +12,8 @@ public interface IInstanceFactory { Type PluginType { get; } + IEnumerable<IInstance> Instances { get; } + IBuildPolicy Policy { get; } void AddInstance(Instance instance); Instance AddType<T>(); Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -79,6 +79,16 @@ get { return _pluginType; } } + public IEnumerable<IInstance> Instances + { + get { return _instances.GetAll(); } + } + + public IBuildPolicy Policy + { + get { return _policy; } + } + public void ForEachInstance(Action<Instance> action) { _instances.Each(action); Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -2,8 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Security.Permissions; -using StructureMap.Configuration.DSL; -using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Pipeline; @@ -14,7 +12,7 @@ /// <summary> /// The main static Facade for the StructureMap container /// </summary> - [EnvironmentPermission(SecurityAction.Assert, Read="COMPUTERNAME")] + [EnvironmentPermission(SecurityAction.Assert, Read = "COMPUTERNAME")] public class ObjectFactory { private static readonly object _lockObject = new object(); @@ -44,17 +42,17 @@ public static void Initialize(Action<InitializationExpression> action) { - lock (typeof(ObjectFactory)) + lock (typeof (ObjectFactory)) { - InitializationExpression expression = new InitializationExpression(); + var expression = new InitializationExpression(); action(expression); - var graph = expression.BuildGraph(); + PluginGraph graph = expression.BuildGraph(); StructureMapConfiguration.Seal(); _container = new Container(graph); Profile = expression.DefaultProfileName; - } + } } @@ -94,30 +92,26 @@ [Obsolete("Please use Inject() instead.")] public static void InjectStub<PLUGINTYPE>(PLUGINTYPE stub) { - Inject<PLUGINTYPE>(stub); + Inject(stub); } public static void Inject<PLUGINTYPE>(PLUGINTYPE instance) { - container.Inject<PLUGINTYPE>(instance); + container.Inject(instance); } public static void Inject<PLUGINTYPE>(string name, PLUGINTYPE instance) { - container.Inject<PLUGINTYPE>(name, instance); + container.Inject(name, instance); } [Obsolete("Please use Inject<PLUGINTYPE>(name) instead.")] public static void InjectStub<PLUGINTYPE>(string name, PLUGINTYPE stub) { - Inject<PLUGINTYPE>(name, stub); + Inject(name, stub); } - - - - public static string WhatDoIHave() { return container.WhatDoIHave(); @@ -128,7 +122,114 @@ container.AssertConfigurationIsValid(); } + /// <summary> + /// Returns and/or constructs the default instance of the requested System.Type + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + public static object GetInstance(Type pluginType) + { + return container.GetInstance(pluginType); + } + /// <summary> + /// Returns and/or constructs the default instance of the requested System.Type + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <returns></returns> + public static PLUGINTYPE GetInstance<PLUGINTYPE>() + { + return (PLUGINTYPE) container.GetInstance(typeof (PLUGINTYPE)); + } + + public static object GetInstance(Type TargetType, Instance instance) + { + return container.GetInstance(TargetType, instance); + } + + public static TargetType GetInstance<TargetType>(Instance instance) + { + return (TargetType) container.GetInstance(typeof (TargetType), instance); + } + + /// <summary> + /// Retrieves an instance of pluginType by name + /// </summary> + /// <param name="pluginType">The PluginType</param> + /// <param name="name">The instance name</param> + /// <returns></returns> + public static object GetNamedInstance(Type pluginType, string name) + { + return container.GetInstance(pluginType, name); + } + + /// <summary> + /// Retrieves an instance of PLUGINTYPE by name + /// </summary> + /// <typeparam name="PLUGINTYPE">The PluginType</typeparam> + /// <param name="name">The instance name</param> + /// <returns></returns> + public static PLUGINTYPE GetNamedInstance<PLUGINTYPE>(string name) + { + return (PLUGINTYPE) container.GetInstance(typeof (PLUGINTYPE), name); + } + + public static void SetDefaultInstanceName(Type TargetType, string InstanceName) + { + container.SetDefault(TargetType, InstanceName); + } + + public static void SetDefaultInstanceName<TargetType>(string InstanceName) + { + container.SetDefault(typeof (TargetType), InstanceName); + } + + /// <summary> + /// Retrieves all instances of the pluginType + /// </summary> + /// <param name="pluginType"></param> + /// <returns></returns> + public static IList GetAllInstances(Type pluginType) + { + return container.GetAllInstances(pluginType); + } + + /// <summary> + /// Retrieves all instances of the PLUGINTYPE + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <returns></returns> + public static IList<PLUGINTYPE> GetAllInstances<PLUGINTYPE>() + { + return container.GetAllInstances<PLUGINTYPE>(); + } + + /// <summary> + /// Pass in an explicit argument of Type T + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="arg"></param> + /// <returns></returns> + public static ExplicitArgsExpression With<T>(T arg) + { + return container.With(arg); + } + + /// <summary> + /// Pass in an explicit argument by name + /// </summary> + /// <param name="argName"></param> + /// <returns></returns> + public static IExplicitProperty With(string argName) + { + return container.With(argName); + } + + public static void EjectAllInstancesOf<T>() + { + container.EjectAllInstancesOf<T>(); + } + #region Container and setting defaults private static IContainer container @@ -149,7 +250,6 @@ return _container; } } - public static string Profile @@ -185,7 +285,7 @@ { container.SetDefault(pluginType, instance); } - + public static void SetDefault<PLUGINTYPE>(Instance instance) { container.SetDefault<PLUGINTYPE>(instance); @@ -232,120 +332,12 @@ PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); StructureMapConfiguration.Seal(); - Container container = new Container(graph); + var container = new Container(graph); container.SetDefaultsToProfile(_profile); return container; } #endregion - - - /// <summary> - /// Returns and/or constructs the default instance of the requested System.Type - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - public static object GetInstance(Type pluginType) - { - return container.GetInstance(pluginType); - } - - /// <summary> - /// Returns and/or constructs the default instance of the requested System.Type - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <returns></returns> - public static PLUGINTYPE GetInstance<PLUGINTYPE>() - { - return (PLUGINTYPE) container.GetInstance(typeof (PLUGINTYPE)); - } - - public static object GetInstance(Type TargetType, Instance instance) - { - return container.GetInstance(TargetType, instance); - } - - public static TargetType GetInstance<TargetType>(Instance instance) - { - return (TargetType) container.GetInstance(typeof (TargetType), instance); - } - - /// <summary> - /// Retrieves an instance of pluginType by name - /// </summary> - /// <param name="pluginType">The PluginType</param> - /// <param name="name">The instance name</param> - /// <returns></returns> - public static object GetNamedInstance(Type pluginType, string name) - { - return container.GetInstance(pluginType, name); - } - - /// <summary> - /// Retrieves an instance of PLUGINTYPE by name - /// </summary> - /// <typeparam name="PLUGINTYPE">The PluginType</typeparam> - /// <param name="name">The instance name</param> - /// <returns></returns> - public static PLUGINTYPE GetNamedInstance<PLUGINTYPE>(string name) - { - return (PLUGINTYPE) container.GetInstance(typeof (PLUGINTYPE), name); - } - - public static void SetDefaultInstanceName(Type TargetType, string InstanceName) - { - container.SetDefault(TargetType, InstanceName); - } - - public static void SetDefaultInstanceName<TargetType>(string InstanceName) - { - container.SetDefault(typeof (TargetType), InstanceName); - } - - /// <summary> - /// Retrieves all instances of the pluginType - /// </summary> - /// <param name="pluginType"></param> - /// <returns></returns> - public static IList GetAllInstances(Type pluginType) - { - return container.GetAllInstances(pluginType); - } - - /// <summary> - /// Retrieves all instances of the PLUGINTYPE - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <returns></returns> - public static IList<PLUGINTYPE> GetAllInstances<PLUGINTYPE>() - { - return container.GetAllInstances<PLUGINTYPE>(); - } - - /// <summary> - /// Pass in an explicit argument of Type T - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="arg"></param> - /// <returns></returns> - public static ExplicitArgsExpression With<T>(T arg) - { - return container.With(arg); - } - - /// <summary> - /// Pass in an explicit argument by name - /// </summary> - /// <param name="argName"></param> - /// <returns></returns> - public static IExplicitProperty With(string argName) - { - return container.With(argName); - } - - } - - } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -46,7 +46,7 @@ protected override string getDescription() { - string typeName = TypePath.GetAssemblyQualifiedName(_pluggedType); + string typeName = _pluggedType.AssemblyQualifiedName; Constructor ctor = new Constructor(_pluggedType); if (ctor.HasArguments()) { Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -16,14 +16,20 @@ } } - public interface IDiagnosticInstance + public interface IInstance { + string Name { get; } + Type ConcreteType { get; } + string Description { get; } + } + + public interface IDiagnosticInstance : IInstance + { bool CanBePartOfPluginFamily(PluginFamily family); Instance FindInstanceForProfile(PluginFamily family, string profileName, GraphLog log); InstanceToken CreateToken(); void Preprocess(PluginFamily family); void AddTemplatedInstanceTo(PluginFamily family, Type[] templateTypes); - Type ConcreteType { get; } } public abstract class Instance : IDiagnosticInstance @@ -126,11 +132,16 @@ addTemplatedInstanceTo(family, templateTypes); } - Type IDiagnosticInstance.ConcreteType + Type IInstance.ConcreteType { get { return getConcreteType(null); } } + string IInstance.Description + { + get { return getDescription(); } + } + protected virtual Type getConcreteType(Type pluginType) { return pluginType; Modified: trunk/Source/StructureMap/Pipeline/Profile.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Profile.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/Pipeline/Profile.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -108,5 +108,9 @@ } + public void Remove<T>() + { + _instances.Remove(typeof (T)); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -231,5 +231,14 @@ CurrentProfile = CurrentProfile; } + + public void EjectAllInstancesOf<T>() + { + _currentProfile.Remove<T>(); + foreach (var pair in _profiles) + { + pair.Value.Remove<T>(); + } + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -3,17 +3,28 @@ using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Pipeline; +using System.Linq; namespace StructureMap { public delegate InstanceFactory MissingFactoryFunction(Type pluginType, ProfileManager profileManager); + [Obsolete("I think we can eliminate this in favor of IEnumerable")] public interface IPipelineGraphVisitor { void PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy); void Instance(Type pluginType, Instance instance); } + public class PluginTypeConfiguration + { + public Type PluginType { get; set; } + public IInstance Instance { get; set; } + public IBuildPolicy Policy { get; set; } + + public IEnumerable<IInstance> Instances { get; set; } + } + public class PipelineGraph { private readonly Dictionary<Type, IInstanceFactory> _factories @@ -166,6 +177,7 @@ public void SetDefault(Type pluginType, Instance instance) { createFactoryIfMissing(pluginType); + ForType(pluginType).AddInstance(instance); _profileManager.SetDefault(pluginType, instance); } @@ -195,6 +207,43 @@ public void EjectAllInstancesOf<T>() { ForType(typeof (T)).EjectAllInstances(); + _profileManager.EjectAllInstancesOf<T>(); } + + public IEnumerable<IInstance> InstancesOf(Type pluginType) + { + if (_genericsGraph.HasFamily(pluginType)) + { + return _genericsGraph.FindFamily(pluginType).Instances; + } + + return ForType(pluginType).Instances; + } + + public IEnumerable<PluginTypeConfiguration> PluginTypes + { + get + { + foreach (PluginTypeConfiguration configuration in _genericsGraph.Families) + { + yield return configuration; + } + + foreach (var pair in _factories) + { + var factory = pair.Value; + + yield return new PluginTypeConfiguration() + { + Instance = _profileManager.GetDefault(factory.PluginType), + PluginType = factory.PluginType, + Policy = factory.Policy, + Instances = factory.Instances + }; + } + } + + + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -27,7 +27,11 @@ [Test] public void AutomaticallyFindRegistryFromAssembly() { - ObjectFactory.Initialize(x => { x.Scan(s => { s.AssemblyContainingType<RedGreenRegistry>(); }); }); + ObjectFactory.Initialize(x => { x.Scan(s => + { + s.AssemblyContainingType<RedGreenRegistry>(); + s.LookForRegistries(); + }); }); var colors = new List<string>(); foreach (IWidget widget in ObjectFactory.GetAllInstances<IWidget>()) @@ -57,6 +61,7 @@ var scanner = new AssemblyScanner(); scanner.AssemblyContainingType(typeof (RedGreenRegistry)); + scanner.LookForRegistries(); scanner.ScanForAll(graph); graph.Seal(); Modified: trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -1,7 +1,10 @@ using System; using NUnit.Framework; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; +using StructureMap.Testing.GenericWidgets; +using System.Linq; namespace StructureMap.Testing.Graph { @@ -27,7 +30,16 @@ Assert.IsFalse(GenericsPluginGraph.CanBeCast(pluginType, pluggedType)); } + [Test] + public void can_iterate_through_families() + { + GenericsPluginGraph graph = new GenericsPluginGraph(); + graph.FindFamily(typeof(IGenericService<>)).AddType(typeof(GenericService<>)); + graph.FindFamily(typeof(IService<>)).AddType(typeof(Service<>)); + graph.Families.Count().ShouldEqual(2); + } + [Test] public void Check_the_generic_plugin_family_expression() { Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Linq; using System.Reflection; using NUnit.Framework; using StructureMap.Attributes; @@ -33,6 +34,29 @@ } [Test] + public void can_get_configuration_object_from_PluginFamily() + { + PluginFamily family = new PluginFamily(typeof(IWidget)); + + var instance1 = new SmartInstance<ColorWidget>().WithCtorArg("color").EqualTo("Red"); + var instance2 = new SmartInstance<ColorWidget>().WithCtorArg("color").EqualTo("Blue"); + + family.AddInstance(instance1); + family.AddInstance(instance2); + + family.DefaultInstanceKey = instance1.Name; + + var configuration = family.GetConfiguration(); + + configuration.Instance.ShouldBeTheSameAs(instance1); + configuration.PluginType.ShouldEqual(typeof (IWidget)); + configuration.Policy.ShouldBeTheSameAs(family.Policy); + + configuration.Instances.Count().ShouldEqual(2); + } + + + [Test] public void add_plugins_at_seal_from_the_list_of_types() { var family = new PluginFamily(typeof (IServiceProvider)); Modified: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -138,7 +138,7 @@ public void Create_description_if_has_plugged_type_and_plugged_type_has_no_arguments() { var instance = new ConfiguredInstance(GetType()); - TestUtility.AssertDescriptionIs(instance, TypePath.GetAssemblyQualifiedName(GetType())); + TestUtility.AssertDescriptionIs(instance, GetType().AssemblyQualifiedName); } [Test] @@ -146,7 +146,7 @@ { var instance = new ConfiguredInstance(typeof (ColorService)); TestUtility.AssertDescriptionIs(instance, - "Configured " + TypePath.GetAssemblyQualifiedName(typeof (ColorService))); + "Configured " + typeof (ColorService).AssemblyQualifiedName); } [Test] Modified: trunk/Source/StructureMap.Testing/PipelineGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/PipelineGraphTester.cs 2008-10-02 18:44:00 UTC (rev 162) +++ trunk/Source/StructureMap.Testing/PipelineGraphTester.cs 2008-10-03 14:47:59 UTC (rev 163) @@ -1,12 +1,15 @@ using System; +using System.Diagnostics; using NUnit.Framework; using Rhino.Mocks; using Rhino.Mocks.Constraints; using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; +using StructureMap.Testing.GenericWidgets; using StructureMap.Testing.Graph; using StructureMap.Testing.Widget; +using System.Linq; namespace StructureMap.Testing { @@ -62,8 +65,80 @@ LastCall.Constraints(Is.Equal(typeof(ISomething)), Is.TypeOf(typeof(SmartInstance<SomethingTwo>))); }); } + + [Test] + public void can_iterate_through_instances_of_pipelineGraph_for_generics_if_not_registered() + { + PipelineGraph pipeline = new PipelineGraph(new PluginGraph()); + pipeline.InstancesOf(typeof(IService<>)).Count().ShouldEqual(0); + } [Test] + public void can_iterate_through_families_including_both_generics_and_normal() + { + Registry registry = new Registry(); + registry.ForRequestedType(typeof(IService<>)) + .AddConcreteType(typeof(Service<>)) + .AddConcreteType(typeof(Service2<>)); + + registry.BuildInstancesOf<ISomething>() + .TheDefaultIsConcreteType<SomethingOne>() + .AddConcreteType<SomethingTwo>(); + + PluginGraph graph = registry.Build(); + PipelineGraph pipeline = new PipelineGraph(graph); + + pipeline.PluginTypes.Count().ShouldEqual(2); + } + + [Test] + public void can_iterate_through_instance_of_pipelineGraph_for_generics() + { + Registry registry = new Registry(); + registry.ForRequestedType(typeof (IService<>)) + .AddConcreteType(typeof (Service<>)) + .AddConcreteType(typeof (Service2<>)); + + var graph = registry.Build(); + var pipeline = new PipelineGraph(graph); + + foreach (var instance in pipeline.InstancesOf(typeof(IService<>))) + { + Debug.WriteLine(instance.Description); + } + + pipeline.InstancesOf(typeof (IService<>)).Count().ShouldEqual(2); + } + + [Test] + public void can_iterate_through_instances_of_pipelineGraph_on_a_type_that_is_registered() + { + Registry registry = new Registry(); + registry.BuildInstancesOf<ISomething>() + .TheDefaultIsConcreteType<SomethingOne>() + .AddConcreteType<SomethingTwo>(); + + PluginGraph graph = registry.Build(); + + PipelineGraph pipeline = new PipelineGraph(graph); + + pipeline.InstancesOf(typeof(ISomething)).Count().ShouldEqual(2); + + pipeline.Inject<ISomething>(new SomethingTwo()); + + pipeline.InstancesOf(typeof(ISomething)).Count().ShouldEqual(3); + } + + [Test] + public void can_iterate_through_empty_array_of_pipelineGraph_for_a_type_that_is_not_registered() + { + PluginGraph graph = new PluginGraph(); + PipelineGraph pipeline = new PipelineGraph(graph); + + pipeline.InstancesOf(typeof(ISomething)).Count().ShouldEqual(0); + } + + [Test] public void Visit_a_single_family_with_no_default() { Registry registry = new Registry(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-03 15:12:58
|
Revision: 164 http://structuremap.svn.sourceforge.net/structuremap/?rev=164&view=rev Author: jeremydmiller Date: 2008-10-03 15:12:28 +0000 (Fri, 03 Oct 2008) Log Message: ----------- Getting ready to eliminate IPluginGraphVisitor and finish out querying the model Modified Paths: -------------- trunk/Source/StructureMap/Diagnostics/TextLine.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs Modified: trunk/Source/StructureMap/Diagnostics/TextLine.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/TextLine.cs 2008-10-03 14:47:59 UTC (rev 163) +++ trunk/Source/StructureMap/Diagnostics/TextLine.cs 2008-10-03 15:12:28 UTC (rev 164) @@ -9,6 +9,11 @@ internal TextLine(string[] contents) { _contents = contents; + for (int i = 0; i < contents.Length; i++) + { + if (contents[i] == null) contents[i] = string.Empty; + + } } public void OverwriteCounts(CharacterWidth[] widths) Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-10-03 14:47:59 UTC (rev 163) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-10-03 15:12:28 UTC (rev 164) @@ -11,7 +11,7 @@ { private readonly PipelineGraph _graph; private TextReportWriter _writer; - private List<Instance> _instances; + private List<IInstance> _instances; public WhatDoIHaveWriter(PipelineGraph graph) { @@ -33,12 +33,15 @@ private void writeContentsOfPluginTypes(StringWriter stringWriter) { _writer = new TextReportWriter(3); - _instances = new List<Instance>(); + _instances = new List<IInstance>(); _writer.AddDivider('='); _writer.AddText("PluginType", "Name", "Description"); - _graph.Visit(this); + foreach (var pluginType in _graph.PluginTypes) + { + writePluginType(pluginType); + } _writer.AddDivider('='); @@ -61,6 +64,41 @@ writer.WriteLine(); } + private void writePluginType(PluginTypeConfiguration pluginType) + { + _writer.AddDivider('-'); + string[] contents = new string[] { pluginType.PluginType.AssemblyQualifiedName ?? pluginType.PluginType.Name, string.Empty, string.Empty }; + + if (pluginType.Default != null) + { + setContents(contents, pluginType.Default); + + } + + _writer.AddText(contents); + + _writer.AddContent("Built by: " + pluginType.Policy.ToString()); + + foreach (var instance in pluginType.Instances) + { + writeInstance(instance); + } + } + + private void writeInstance(IInstance instance) + { + if (_instances.Contains(instance)) + { + return; + } + + string[] contents = new[] { string.Empty, string.Empty, string.Empty }; + setContents(contents, instance); + + _writer.AddText(contents); + } + + void IPipelineGraphVisitor.PluginType(Type pluginType, Instance defaultInstance, IBuildPolicy policy) { _writer.AddDivider('-'); @@ -77,11 +115,10 @@ _writer.AddContent("Built by: " + policy.ToString()); } - private void setContents(string[] contents, Instance instance) + private void setContents(string[] contents, IInstance instance) { - InstanceToken token = ((IDiagnosticInstance)instance).CreateToken(); - contents[1] = token.Name; - contents[2] = token.Description; + contents[1] = instance.Name; + contents[2] = instance.Description; _instances.Add(instance); } Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-10-03 14:47:59 UTC (rev 163) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-10-03 15:12:28 UTC (rev 164) @@ -366,7 +366,7 @@ { return new PluginTypeConfiguration() { - Instance = GetDefaultInstance(), + Default = GetDefaultInstance(), PluginType = PluginType, Policy = _buildPolicy, Instances = Instances Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-10-03 14:47:59 UTC (rev 163) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-10-03 15:12:28 UTC (rev 164) @@ -19,7 +19,7 @@ public class PluginTypeConfiguration { public Type PluginType { get; set; } - public IInstance Instance { get; set; } + public IInstance Default { get; set; } public IBuildPolicy Policy { get; set; } public IEnumerable<IInstance> Instances { get; set; } @@ -235,7 +235,7 @@ yield return new PluginTypeConfiguration() { - Instance = _profileManager.GetDefault(factory.PluginType), + Default = _profileManager.GetDefault(factory.PluginType), PluginType = factory.PluginType, Policy = factory.Policy, Instances = factory.Instances Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-10-03 14:47:59 UTC (rev 163) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-10-03 15:12:28 UTC (rev 164) @@ -48,7 +48,7 @@ var configuration = family.GetConfiguration(); - configuration.Instance.ShouldBeTheSameAs(instance1); + configuration.Default.ShouldBeTheSameAs(instance1); configuration.PluginType.ShouldEqual(typeof (IWidget)); configuration.Policy.ShouldBeTheSameAs(family.Policy); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-03 16:24:42
|
Revision: 166 http://structuremap.svn.sourceforge.net/structuremap/?rev=166&view=rev Author: jeremydmiller Date: 2008-10-03 16:24:32 +0000 (Fri, 03 Oct 2008) Log Message: ----------- the ability to query what StructureMap has Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Graph/Constructor.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Model.cs trunk/Source/StructureMap.Testing/ModelQueryTester.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap/Container.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -20,6 +20,7 @@ private InterceptorLibrary _interceptorLibrary; private PipelineGraph _pipelineGraph; private PluginGraph _pluginGraph; + private Model _model; public Container(Action<ConfigurationExpression> action) { @@ -66,6 +67,7 @@ pluginGraph.Log.AssertFailures(); _pipelineGraph = new PipelineGraph(pluginGraph); + _model = new Model(_pipelineGraph); PluginCache.Compile(); } @@ -77,6 +79,11 @@ #region IContainer Members + public Model Model + { + get { return _model; } + } + public T GetInstance<T>(string instanceKey) { return (T) GetInstance(typeof (T), instanceKey); Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -64,6 +64,8 @@ public bool CanBeAutoFilled() { + if (_ctor == null) return false; + foreach (ParameterInfo parameter in _ctor.GetParameters()) { if (!IsAutoFillable(parameter.ParameterType)) Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap/IContainer.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -9,6 +9,8 @@ { public interface IContainer { + Model Model { get; } + T GetInstance<T>(string instanceKey); T GetInstance<T>(); T FillDependencies<T>(); Added: trunk/Source/StructureMap/Model.cs =================================================================== --- trunk/Source/StructureMap/Model.cs (rev 0) +++ trunk/Source/StructureMap/Model.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap +{ + public class Model : TypeRules + { + private readonly PipelineGraph _graph; + + internal Model(PipelineGraph graph) + { + _graph = graph; + } + + public bool HasDefaultImplementationFor(Type pluginType) + { + var family = PluginTypes.FirstOrDefault(x => x.PluginType == pluginType); + return family == null ? false : family.Default != null; + } + + public bool HasDefaultImplementationFor<T>() + { + return HasDefaultImplementationFor(typeof (T)); + } + + public IEnumerable<PluginTypeConfiguration> PluginTypes + { + get + { + return _graph.PluginTypes; + } + } + + public IEnumerable<IInstance> InstancesOf(Type pluginType) + { + return _graph.InstancesOf(pluginType); + } + + public IEnumerable<IInstance> InstancesOf<T>() + { + return _graph.InstancesOf(typeof(T)); + } + + public bool HasImplementationsFor(Type pluginType) + { + return _graph.InstancesOf(pluginType).Count() > 0; + } + + public bool HasImplementationsFor<T>() + { + return HasImplementationsFor(typeof(T)); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -105,6 +105,14 @@ container.Inject(name, instance); } + public static Model Model + { + get + { + return container.Model; + } + } + [Obsolete("Please use Inject<PLUGINTYPE>(name) instead.")] public static void InjectStub<PLUGINTYPE>(string name, PLUGINTYPE stub) { Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -173,7 +173,12 @@ return _genericsGraph.FindFamily(pluginType).Instances; } - return ForType(pluginType).Instances; + if (_factories.ContainsKey(pluginType)) + { + return _factories[pluginType].Instances; + } + + return new IInstance[0]; } public IEnumerable<PluginTypeConfiguration> PluginTypes Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-10-03 16:24:32 UTC (rev 166) @@ -410,6 +410,7 @@ <Compile Include="Graph\PluginCache.cs" /> <Compile Include="IBootstrapper.cs" /> <Compile Include="InitializationExpression.cs" /> + <Compile Include="Model.cs" /> <Compile Include="Pipeline\BuildFrame.cs" /> <Compile Include="Pipeline\BuildStack.cs" /> <Compile Include="Pipeline\ConfiguredInstanceBase.cs" /> Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -112,7 +112,19 @@ container.GetInstance<IEngine>(instance).ShouldBeOfType(typeof (DOHCEngine)); } + public class ClassWithNoConstructor + { + private ClassWithNoConstructor(){} + } + [Test] + public void cannot_be_auto_filled_with_no_contructors() + { + var plugin = new Plugin(typeof (ClassWithNoConstructor)); + plugin.CanBeAutoFilled.ShouldBeFalse(); + } + + [Test] public void CanBeAutoFilled_with_child_array_in_ctor() { var ctor = new Constructor(typeof (CanBeAutoFilledWithArray)); Added: trunk/Source/StructureMap.Testing/ModelQueryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ModelQueryTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/ModelQueryTester.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Testing.GenericWidgets; +using StructureMap.Testing.Graph; + +namespace StructureMap.Testing +{ + [TestFixture] + public class ModelQueryTester + { + private Model _model; + private Container _container; + + [SetUp] + public void SetUp() + { + Registry registry = new Registry(); + registry.ForRequestedType(typeof(IService<>)) + .AddConcreteType(typeof(Service<>)) + .AddConcreteType(typeof(Service2<>)); + + registry.BuildInstancesOf<ISomething>() + .TheDefaultIsConcreteType<SomethingOne>() + .AddConcreteType<SomethingTwo>(); + + registry.BuildInstancesOf<IServiceProvider>().AddConcreteType<DataSet>().AddConcreteType<DataView>(); + + PluginGraph graph = registry.Build(); + PipelineGraph pipeline = new PipelineGraph(graph); + + _model = new Model(pipeline); + + _container = new Container(graph); + + } + + + [Test] + public void HasImplementationFor() + { + _model.HasDefaultImplementationFor(typeof(ISomething)).ShouldBeTrue(); + _model.HasDefaultImplementationFor(GetType()).ShouldBeFalse(); + _model.HasDefaultImplementationFor(typeof(IServiceProvider)).ShouldBeFalse(); + } + + [Test] + public void HasImplementationsFor() + { + _model.HasImplementationsFor(typeof(ISomething)).ShouldBeTrue(); + _model.HasImplementationsFor(GetType()).ShouldBeFalse(); + _model.HasImplementationsFor(typeof(IServiceProvider)).ShouldBeTrue(); + } + + [Test] + public void Iterate_over_pluginTypes() + { + _model.PluginTypes.Count().ShouldEqual(3); + } + + [Test] + public void iterate_over_instances_of_a_type() + { + _model.InstancesOf(typeof (IServiceProvider)).Count().ShouldEqual(2); + _model.InstancesOf(typeof (IService<>)).Count().ShouldEqual(2); + _model.InstancesOf<IServiceProvider>().Count().ShouldEqual(2); + } + + [Test] + public void HasImplementationFor_w_container() + { + _container.Model.HasDefaultImplementationFor(typeof(ISomething)).ShouldBeTrue(); + _container.Model.HasDefaultImplementationFor(GetType()).ShouldBeFalse(); + _container.Model.HasDefaultImplementationFor(typeof(IServiceProvider)).ShouldBeFalse(); + } + + [Test] + public void HasImplementationsFor_w_container() + { + _container.Model.HasImplementationsFor(typeof(ISomething)).ShouldBeTrue(); + _container.Model.HasImplementationsFor(GetType()).ShouldBeFalse(); + _container.Model.HasImplementationsFor(typeof(IServiceProvider)).ShouldBeTrue(); + } + + [Test] + public void Iterate_over_pluginTypes_w_container() + { + _container.Model.PluginTypes.Count().ShouldEqual(3); + } + + [Test] + public void iterate_over_instances_of_a_type_w_container() + { + _container.Model.InstancesOf(typeof (IServiceProvider)).Count().ShouldEqual(2); + _container.Model.InstancesOf(typeof (IService<>)).Count().ShouldEqual(2); + _container.Model.InstancesOf<IServiceProvider>().Count().ShouldEqual(2); + } + } +} Modified: trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Diagnostics; +using System.Linq; using System.Threading; using System.Xml; using NUnit.Framework; @@ -31,6 +32,12 @@ } [Test] + public void SmokeTestModelAccess() + { + ObjectFactory.Model.PluginTypes.Count().ShouldBeGreaterThan(0); + } + + [Test] public void SmokeTestGetAllInstancesGeneric() { IList<GrandChild> list = ObjectFactory.GetAllInstances<GrandChild>(); Modified: trunk/Source/StructureMap.Testing/PipelineGraphTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/PipelineGraphTester.cs 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap.Testing/PipelineGraphTester.cs 2008-10-03 16:24:32 UTC (rev 166) @@ -25,9 +25,6 @@ #endregion - - - [Test] public void can_iterate_through_instances_of_pipelineGraph_for_generics_if_not_registered() { @@ -53,6 +50,7 @@ pipeline.PluginTypes.Count().ShouldEqual(2); } + [Test] public void can_iterate_through_instance_of_pipelineGraph_for_generics() { Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-03 15:36:06 UTC (rev 165) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-03 16:24:32 UTC (rev 166) @@ -349,6 +349,7 @@ <Compile Include="InstanceMementoInstanceCreationTester.cs" /> <Compile Include="MementoTester.cs" /> <Compile Include="MergingTester.cs" /> + <Compile Include="ModelQueryTester.cs" /> <Compile Include="ObjectFactoryInitializeTester.cs" /> <Compile Include="ObjectFactoryTester.cs"> <SubType>Code</SubType> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-05 02:32:37
|
Revision: 169 http://structuremap.svn.sourceforge.net/structuremap/?rev=169&view=rev Author: jeremydmiller Date: 2008-10-05 02:29:44 +0000 (Sun, 05 Oct 2008) Log Message: ----------- eliminating some obsolete methods from the DSL, adding ability to configure generics instances from DSL Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -15,7 +15,6 @@ private readonly List<Action<PluginFamily>> _alterations = new List<Action<PluginFamily>>(); private readonly List<Action<PluginGraph>> _children = new List<Action<PluginGraph>>(); private readonly Type _pluginType; - private readonly InstanceScope _scope = InstanceScope.PerRequest; public CreatePluginFamilyExpression(Registry registry) { @@ -24,18 +23,22 @@ registry.addExpression(graph => { PluginFamily family = graph.FindFamily(_pluginType); - family.SetScopeTo(_scope); _children.ForEach(action => action(graph)); _alterations.ForEach(action => action(family)); }); } + public IsExpression<PLUGINTYPE> TheDefault + { + get { return new InstanceExpression<PLUGINTYPE>(i => registerDefault(i)); } + } + public CreatePluginFamilyExpression<PLUGINTYPE> AddInstances(Action<InstanceExpression<PLUGINTYPE>> action) { - List<Instance> list = new List<Instance>(); + var list = new List<Instance>(); - InstanceExpression<PLUGINTYPE> child = new InstanceExpression<PLUGINTYPE>(i => list.Add(i)); + var child = new InstanceExpression<PLUGINTYPE>(i => list.Add(i)); action(child); return alterAndContinue(family => @@ -55,25 +58,6 @@ } /// <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(Instance instance) - { - return alterAndContinue(family => - { - family.AddInstance(instance); - family.DefaultInstanceKey = instance.Name; - }); - } - - public CreatePluginFamilyExpression<PLUGINTYPE> AddInstance(Instance instance) - { - return alterAndContinue(family => family.AddInstance(instance)); - } - - /// <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. @@ -83,13 +67,14 @@ public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIsConcreteType<CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE { - var concreteType = typeof(CONCRETETYPE); + Type concreteType = typeof (CONCRETETYPE); ExpressionValidator.ValidatePluggabilityOf(concreteType).IntoPluginType(_pluginType); return alterAndContinue(family => { - ConfiguredInstance instance = new ConfiguredInstance(concreteType).WithName(concreteType.AssemblyQualifiedName); + ConfiguredInstance instance = + new ConfiguredInstance(concreteType).WithName(concreteType.AssemblyQualifiedName); family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; }); @@ -130,7 +115,7 @@ return target; }; - PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); + var interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); graph.InterceptorLibrary.AddInterceptor(interceptor); }); @@ -144,7 +129,7 @@ { Func<object, object> function = target => handler((PLUGINTYPE) target); - PluginTypeInterceptor interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); + var interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); graph.InterceptorLibrary.AddInterceptor(interceptor); }); @@ -157,7 +142,7 @@ _alterations.Add(family => { string name = PluginCache.GetPlugin(typeof (PLUGGEDTYPE)).ConcreteKey; - var instance = new SmartInstance<PLUGGEDTYPE>().WithName(name); + SmartInstance<PLUGGEDTYPE> instance = new SmartInstance<PLUGGEDTYPE>().WithName(name); family.AddInstance(instance); }); @@ -177,12 +162,13 @@ return this; } - public IsExpression<PLUGINTYPE> TheDefault + private void registerDefault(Instance instance) { - get + _alterations.Add(family => { - return new InstanceExpression<PLUGINTYPE>(i => TheDefaultIs(i)); - } + family.AddInstance(instance); + family.DefaultInstanceKey = instance.Name; + }); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -53,7 +53,7 @@ } - public GenericFamilyExpression AddInstance(Instance instance) + private GenericFamilyExpression add(Instance instance) { return alterAndContinue(family => family.AddInstance(instance)); } @@ -92,12 +92,12 @@ public GenericFamilyExpression AddConcreteType(Type concreteType) { - return AddInstance(new ConfiguredInstance(concreteType)); + return add(new ConfiguredInstance(concreteType)); } public GenericFamilyExpression AddConcreteType(Type concreteType, string instanceName) { - return AddInstance(new ConfiguredInstance(concreteType).WithName(instanceName)); + return add(new ConfiguredInstance(concreteType).WithName(instanceName)); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -10,6 +10,25 @@ LiteralInstance IsThis(T obj); } + public class GenericIsExpression + { + private readonly Action<Instance> _action; + + public GenericIsExpression(Action<Instance> action) + { + _action = action; + } + + + public ConfiguredInstance Is(Type concreteType) + { + var instance = new ConfiguredInstance(concreteType); + _action(instance); + + return instance; + } + } + public class InstanceExpression<T> : IsExpression<T> { private readonly Action<Instance> _action; Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -120,6 +120,17 @@ }); } + public GenericIsExpression InstanceOf(Type pluginType) + { + return new GenericIsExpression(instance => + { + _actions.Add(graph => + { + graph.FindFamily(pluginType).AddInstance(instance); + }); + }); + } + /// <summary> /// Starts the definition of a new Profile /// </summary> @@ -173,18 +184,6 @@ _actions.Add(graph => graph.AddScanner(scanner)); } - [Obsolete("Like to get rid of this")] - public void AddInstanceOf(Type pluginType, Instance instance) - { - _actions.Add(graph => graph.FindFamily(pluginType).AddInstance(instance)); - } - - [Obsolete("Like to get rid of this")] - public void AddInstanceOf<PLUGINTYPE>(Instance instance) - { - _actions.Add(graph => graph.FindFamily(typeof (PLUGINTYPE)).AddInstance(instance)); - } - public bool Equals(Registry obj) { if (ReferenceEquals(null, obj)) return false; Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -197,17 +197,7 @@ return registry.ForRequestedType(pluginType); } - public static void AddInstanceOf<T>(Func<T> func) - { - registry.AddInstanceOf<T>(new ConstructorInstance<T>(func)); - } - public static void AddInstanceOf<T>(Instance instance) - { - registry.ForRequestedType<T>().AddInstance(instance); - } - - /// <summary> /// Starts the definition of a configuration Profile. /// </summary> Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -126,7 +126,7 @@ return new ColorRule("Red"); }); Registry registry = new Registry(); - registry.ForRequestedType<ColorRule>().TheDefaultIs(instance); + registry.ForRequestedType<ColorRule>().TheDefault.IsThis(instance); PluginGraph graph = registry.Build(); BuildSession session = new BuildSession(graph); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -45,8 +45,8 @@ manager.SetDefaultsToProfile(theProfileName); - IWidget widget1 = manager.GetInstance<IWidget>(); - IWidget widget2 = manager.GetInstance<IWidget>(); + var widget1 = manager.GetInstance<IWidget>(); + var widget2 = manager.GetInstance<IWidget>(); Assert.IsNotNull(widget1); Assert.IsNotNull(widget2); @@ -70,15 +70,15 @@ [Test] public void Add_default_instance_with_literal() { - Registry registry = new Registry(); - AWidget theWidget = new AWidget(); + var registry = new Registry(); + var theWidget = new AWidget(); string theProfileName = "something"; registry.CreateProfile(theProfileName) .For<IWidget>().Use(theWidget); PluginGraph graph = registry.Build(); - LiteralInstance instance = (LiteralInstance) graph.ProfileManager.GetDefault(typeof (IWidget), "something"); + var instance = (LiteralInstance) graph.ProfileManager.GetDefault(typeof (IWidget), "something"); Assert.AreSame(theWidget, instance.Object); } @@ -89,12 +89,13 @@ string theProfileName = "TheProfile"; string theDefaultName = "TheDefaultName"; - Registry registry = new Registry(); + var registry = new Registry(); registry.CreateProfile(theProfileName) .For<IWidget>().UseNamedInstance(theDefaultName) .For<Rule>().UseNamedInstance("DefaultRule"); - var masterInstance = registry.InstanceOf<IWidget>().Is.Object(new AWidget()).WithName(theDefaultName); + LiteralInstance masterInstance = + registry.InstanceOf<IWidget>().Is.Object(new AWidget()).WithName(theDefaultName); ProfileManager manager = registry.Build().ProfileManager; Assert.AreSame(masterInstance, manager.GetDefault(typeof (IWidget), theProfileName)); @@ -105,7 +106,7 @@ { string theProfileName = "TheProfile"; - Registry registry = new Registry(); + var registry = new Registry(); registry.CreateProfile(theProfileName) .For<IWidget>().UseConcreteType<AWidget>(); @@ -116,9 +117,9 @@ Assert.AreEqual(Profile.InstanceKeyForProfile(theProfileName), defaultInstance.Name); - Container manager = new Container(graph); + var manager = new Container(graph); manager.SetDefaultsToProfile(theProfileName); - AWidget widget = (AWidget) manager.GetInstance<IWidget>(); + var widget = (AWidget) manager.GetInstance<IWidget>(); Assert.IsNotNull(widget); } } Modified: trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -41,7 +41,7 @@ { ValidationBuildSession session = validatedSession(r => { - r.AddInstanceOf<IWidget>(errorInstance().WithName("BadInstance")); + r.InstanceOf<IWidget>().IsThis(errorInstance().WithName("BadInstance")); r.InstanceOf<SomethingThatNeedsAWidget>().Is.OfConcreteType<SomethingThatNeedsAWidget>() .WithName("DependentInstance") @@ -71,8 +71,9 @@ { ValidationBuildSession session = validatedSession(r => { - r.AddInstanceOf<IWidget>(errorInstance().WithName("BadInstance")); + r.InstanceOf<IWidget>().IsThis(errorInstance().WithName("BadInstance")); + r.InstanceOf<SomethingThatNeedsAWidget>().Is.OfConcreteType<SomethingThatNeedsAWidget>() .WithName("DependentInstance") .CtorDependency<IWidget>().Is(x => x.References("BadInstance")); @@ -109,7 +110,7 @@ { Instance instance = errorInstance().WithName("Bad"); ValidationBuildSession session = - validatedSession(registry => registry.AddInstanceOf<IWidget>(instance)); + validatedSession(registry => registry.InstanceOf<IWidget>().IsThis(instance)); BuildError error = getFirstAndOnlyError(session); @@ -155,7 +156,7 @@ { var instance = new LiteralInstance(new WidgetWithOneValidationFailure()); ValidationBuildSession session = - validatedSession(registry => registry.AddInstanceOf<IWidget>(instance)); + validatedSession(registry => registry.InstanceOf<IWidget>().IsThis(instance)); Assert.AreEqual(1, session.ValidationErrors.Length); Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -160,14 +160,13 @@ [Test] public void Define_profile_with_generics_with_named_instance() { - IContainer manager = new Container(registry => + IContainer manager = new Container(r => { - registry.AddInstanceOf(typeof (IService<>), - new ConfiguredInstance(typeof (Service<>)).WithName("Service1")); - registry.AddInstanceOf(typeof (IService<>), - new ConfiguredInstance(typeof (Service2<>)).WithName("Service2")); - registry.CreateProfile("1").For(typeof (IService<>)).UseNamedInstance("Service1"); - registry.CreateProfile("2").For(typeof (IService<>)).UseNamedInstance("Service2"); + r.InstanceOf(typeof (IService<>)).Is(typeof (Service<>)).WithName("Service1"); + r.InstanceOf(typeof (IService<>)).Is(typeof (Service2<>)).WithName("Service2"); + + r.CreateProfile("1").For(typeof (IService<>)).UseNamedInstance("Service1"); + r.CreateProfile("2").For(typeof (IService<>)).UseNamedInstance("Service2"); }); manager.SetDefaultsToProfile("1"); Modified: trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2008-10-04 01:08:55 UTC (rev 168) +++ trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2008-10-05 02:29:44 UTC (rev 169) @@ -25,7 +25,7 @@ SmartInstance<T> instance = instanceOf<T>(); action(instance); - var container = new Container(r => r.ForRequestedType<T>().TheDefaultIs(instance)); + var container = new Container(r => r.ForRequestedType<T>().TheDefault.IsThis(instance)); return container.GetInstance<T>(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-05 02:38:28
|
Revision: 170 http://structuremap.svn.sourceforge.net/structuremap/?rev=170&view=rev Author: jeremydmiller Date: 2008-10-05 02:35:54 +0000 (Sun, 05 Oct 2008) Log Message: ----------- Removed all warnings except for the obsolete warnings on StructureMapConfiguration. Gonna leave that alone for awhile Modified Paths: -------------- trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Removed Paths: ------------- trunk/Source/StructureMap.Testing/Examples/ Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-10-05 02:29:44 UTC (rev 169) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-10-05 02:35:54 UTC (rev 170) @@ -24,7 +24,7 @@ /// <summary> /// Restarts ObjectFactory and blows away all Singleton's and cached instances. Use with caution. /// </summary> - public static void Reset() + internal static void Reset() { lock (_lockObject) { Modified: trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs 2008-10-05 02:29:44 UTC (rev 169) +++ trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs 2008-10-05 02:35:54 UTC (rev 170) @@ -13,16 +13,12 @@ [SetUp] public void SetUp() { - StructureMapConfiguration.ResetAll(); - StructureMapConfiguration.UseDefaultStructureMapConfigFile = false; + ObjectFactory.Initialize(x => + { + x.UseDefaultStructureMapConfigFile = false; + }); } - [TearDown] - public void TearDown() - { - StructureMapConfiguration.ResetAll(); - } - #endregion public interface IExplicitTarget Modified: trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs 2008-10-05 02:29:44 UTC (rev 169) +++ trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs 2008-10-05 02:35:54 UTC (rev 170) @@ -1,5 +1,4 @@ using NUnit.Framework; -using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; @@ -16,17 +15,29 @@ [SetUp] public void SetUp() { - StructureMapConfiguration.ResetAll(); - - DataMother.WriteDocument("SampleConfig.xml"); DataMother.WriteDocument("FullTesting.XML"); - ObjectFactory.Reset(); + ObjectFactory.Initialize(x => {}); } #endregion + public class AClass + { + private readonly string _name; + + public AClass(string name) + { + _name = name; + } + + public string Name + { + get { return _name; } + } + } + [Test] public void BuildAllInstances() { @@ -34,7 +45,7 @@ PluginGraph pluginGraph = DataMother.GetDiagnosticPluginGraph("SampleConfig.xml"); - Container manager = new Container(pluginGraph); + var manager = new Container(pluginGraph); IList list = manager.GetAllInstances(typeof (IWidget)); @@ -50,7 +61,7 @@ public void ChangeDefault() { ObjectFactory.SetDefaultInstanceName(typeof (IWidget), "Green"); - ColorWidget green = (ColorWidget) ObjectFactory.GetInstance(typeof (IWidget)); + var green = (ColorWidget) ObjectFactory.GetInstance(typeof (IWidget)); Assert.IsNotNull(green); Assert.AreEqual("Green", green.Color); } @@ -59,7 +70,7 @@ public void ChangeDefaultWithGenericMethod() { ObjectFactory.SetDefaultInstanceName<IWidget>("Green"); - ColorWidget green = (ColorWidget) ObjectFactory.GetInstance<IWidget>(); + var green = (ColorWidget) ObjectFactory.GetInstance<IWidget>(); Assert.IsNotNull(green); Assert.AreEqual("Green", green.Color); } @@ -67,7 +78,7 @@ [Test] public void FillDependenc1ies2() { - FilledTarget target = ObjectFactory.FillDependencies<FilledTarget>(); + var target = ObjectFactory.FillDependencies<FilledTarget>(); Assert.IsNotNull(target.Gateway); Assert.IsNotNull(target.Rule); } @@ -75,7 +86,7 @@ [Test] public void FillDependencies() { - FilledTarget target = (FilledTarget) ObjectFactory.FillDependencies(typeof (FilledTarget)); + var target = (FilledTarget) ObjectFactory.FillDependencies(typeof (FilledTarget)); Assert.IsNotNull(target.Gateway); Assert.IsNotNull(target.Rule); } @@ -83,7 +94,7 @@ [Test] public void GetChildWithDefinedGrandChild() { - Child child = ObjectFactory.GetNamedInstance(typeof (Child), "Tom") as Child; + var child = ObjectFactory.GetNamedInstance(typeof (Child), "Tom") as Child; Assert.IsNotNull(child); Assert.AreEqual("Tom", child.Name); @@ -97,13 +108,13 @@ [Test, ExpectedException(typeof (StructureMapException))] public void GetChildWithInvalidGrandChild() { - Child child = ObjectFactory.GetNamedInstance(typeof (Child), "Monte") as Child; + var child = ObjectFactory.GetNamedInstance(typeof (Child), "Monte") as Child; } [Test] public void GetChildWithReferencedGrandChild() { - Child child = ObjectFactory.GetNamedInstance(typeof (Child), "Marsha") as Child; + var child = ObjectFactory.GetNamedInstance(typeof (Child), "Marsha") as Child; Assert.IsNotNull(child); Assert.AreEqual("Marsha", child.Name); @@ -117,7 +128,7 @@ public void GetDefaultWidget() { // "Red" is marked as the default in the configuration - ColorWidget red = (ColorWidget) ObjectFactory.GetInstance(typeof (IWidget)); + var red = (ColorWidget) ObjectFactory.GetInstance(typeof (IWidget)); Assert.IsNotNull(red); Assert.AreEqual("Red", red.Color); } @@ -125,10 +136,10 @@ [Test] public void GetNamedWidgets() { - IWidget widget = (IWidget) ObjectFactory.GetNamedInstance(typeof (IWidget), "NotPluggableInstance"); + var widget = (IWidget) ObjectFactory.GetNamedInstance(typeof (IWidget), "NotPluggableInstance"); Assert.IsNotNull(widget); - ConfigurationWidget confWidget = + var confWidget = (ConfigurationWidget) ObjectFactory.GetNamedInstance(typeof (IWidget), "BigOne"); Assert.IsNotNull(confWidget); } @@ -137,7 +148,7 @@ [Test] public void GetParentWithDefinedChild() { - Parent parent = ObjectFactory.GetNamedInstance(typeof (Parent), "Jackie") as Parent; + var parent = ObjectFactory.GetNamedInstance(typeof (Parent), "Jackie") as Parent; Assert.IsNotNull(parent); Assert.AreEqual(70, parent.Age, "Age = 70"); Assert.AreEqual("Green", parent.EyeColor); @@ -155,7 +166,7 @@ [Test] public void GetParentWithReferencedChild() { - Parent parent = ObjectFactory.GetNamedInstance(typeof (Parent), "Jerry") as Parent; + var parent = ObjectFactory.GetNamedInstance(typeof (Parent), "Jerry") as Parent; Assert.IsNotNull(parent); Assert.AreEqual(72, parent.Age, "Age = 72"); Assert.AreEqual("Blue", parent.EyeColor); @@ -175,7 +186,7 @@ { ObjectFactory.SetDefaultInstanceName(typeof (GrandChild), "Trevor"); - Child child = ObjectFactory.GetNamedInstance(typeof (Child), "Jessica") as Child; + var child = ObjectFactory.GetNamedInstance(typeof (Child), "Jessica") as Child; Assert.IsNotNull(child); @@ -191,54 +202,38 @@ [Test] public void GetRules() { - ColorRule red = (ColorRule) ObjectFactory.GetNamedInstance(typeof (Rule), "Red"); + var red = (ColorRule) ObjectFactory.GetNamedInstance(typeof (Rule), "Red"); Assert.IsNotNull(red); Assert.AreEqual("Red", red.Color); - ColorRule blue = (ColorRule) ObjectFactory.GetNamedInstance(typeof (Rule), "Blue"); + var blue = (ColorRule) ObjectFactory.GetNamedInstance(typeof (Rule), "Blue"); Assert.IsNotNull(blue); Assert.AreEqual("Blue", blue.Color); - GreaterThanRule bigger = (GreaterThanRule) ObjectFactory.GetNamedInstance(typeof (Rule), "Bigger"); + var bigger = (GreaterThanRule) ObjectFactory.GetNamedInstance(typeof (Rule), "Bigger"); Assert.IsNotNull(bigger); } [Test] - public void SingletonInterceptorAlwaysReturnsSameInstance() - { - Rule rule1 = (Rule) ObjectFactory.GetNamedInstance(typeof (Rule), "Red"); - Rule rule2 = (Rule) ObjectFactory.GetNamedInstance(typeof (Rule), "Red"); - Rule rule3 = (Rule) ObjectFactory.GetNamedInstance(typeof (Rule), "Red"); - - Assert.AreSame(rule1, rule2); - Assert.AreSame(rule1, rule3); - } - - [Test] public void If_there_is_only_one_instance_of_a_type_use_that_as_default() { - AClass target = new AClass("Me"); + var target = new AClass("Me"); - Container container = new Container(registry => registry.InstanceOf<AClass>().Is.Object(target)); + var container = new Container(registry => registry.InstanceOf<AClass>().Is.Object(target)); Assert.AreSame(target, container.GetInstance<AClass>()); } - public class AClass + [Test] + public void SingletonInterceptorAlwaysReturnsSameInstance() { - private readonly string _name; + var rule1 = (Rule) ObjectFactory.GetNamedInstance(typeof (Rule), "Red"); + var rule2 = (Rule) ObjectFactory.GetNamedInstance(typeof (Rule), "Red"); + var rule3 = (Rule) ObjectFactory.GetNamedInstance(typeof (Rule), "Red"); - public AClass(string name) - { - _name = name; - } - - public string Name - { - get { return _name; } - } + Assert.AreSame(rule1, rule2); + Assert.AreSame(rule1, rule3); } - } Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-05 02:29:44 UTC (rev 169) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-05 02:35:54 UTC (rev 170) @@ -209,9 +209,6 @@ <Compile Include="Examples.cs"> <SubType>Form</SubType> </Compile> - <Compile Include="Examples\QuickStart.cs"> - <SubType>Component</SubType> - </Compile> <Compile Include="Graph\ArrayConstructorTester.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-10-05 02:43:43
|
Revision: 171 http://structuremap.svn.sourceforge.net/structuremap/?rev=171&view=rev Author: jeremydmiller Date: 2008-10-05 02:43:34 +0000 (Sun, 05 Oct 2008) Log Message: ----------- doing some ReSharper clean ups Modified Paths: -------------- trunk/Source/StructureMap/Attributes/DefaultConstructorAttribute.cs trunk/Source/StructureMap/Attributes/PluggableAttribute.cs trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs trunk/Source/StructureMap/Attributes/SetterPropertyAttribute.cs trunk/Source/StructureMap/Attributes/ValidationMethodAttribute.cs trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DictionaryReader.cs trunk/Source/StructureMap/Configuration/FamilyParser.cs trunk/Source/StructureMap/Configuration/ITypeReader.cs trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs trunk/Source/StructureMap/Configuration/ProfileBuilder.cs trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs trunk/Source/StructureMap/Configuration/XmlExtensions.cs trunk/Source/StructureMap/Diagnostics/BuildError.cs trunk/Source/StructureMap/Diagnostics/CharacterWidth.cs trunk/Source/StructureMap/Diagnostics/DividerLine.cs trunk/Source/StructureMap/Diagnostics/Doctor.cs trunk/Source/StructureMap/Diagnostics/DoctorReport.cs trunk/Source/StructureMap/Diagnostics/DoctorRunner.cs trunk/Source/StructureMap/Diagnostics/Error.cs trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs trunk/Source/StructureMap/Diagnostics/GraphLog.cs trunk/Source/StructureMap/Diagnostics/TextLine.cs trunk/Source/StructureMap/Diagnostics/TextReportWriter.cs trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Diagnostics/ValidationError.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/Emitting/ArgumentEmitter.cs trunk/Source/StructureMap/Emitting/BuildInstanceMethod.cs trunk/Source/StructureMap/Emitting/DynamicAssembly.cs trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs trunk/Source/StructureMap/Emitting/Method.cs trunk/Source/StructureMap/Emitting/Parameters/ChildArrayParameterEmitter.cs trunk/Source/StructureMap/Emitting/Parameters/Methods.cs trunk/Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs trunk/Source/StructureMap/Emitting/Parameters/PrimitiveParameterEmitter.cs trunk/Source/StructureMap/Emitting/Parameters/StringParameterEmitter.cs Modified: trunk/Source/StructureMap/Attributes/DefaultConstructorAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/DefaultConstructorAttribute.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Attributes/DefaultConstructorAttribute.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -10,10 +10,6 @@ [AttributeUsage(AttributeTargets.Constructor)] public class DefaultConstructorAttribute : Attribute { - public DefaultConstructorAttribute() - { - } - /// <summary> /// Examines a System.Type object and determines the ConstructorInfo to use in creating /// instances of the Type Modified: trunk/Source/StructureMap/Attributes/PluggableAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -8,22 +8,16 @@ [AttributeUsage(AttributeTargets.Class)] public class PluggableAttribute : Attribute { - private string _concreteKey; - public PluggableAttribute(string concreteKey) { - _concreteKey = concreteKey; + ConcreteKey = concreteKey; } /// <summary> /// The ConcreteKey alias of the Type /// </summary> - public string ConcreteKey - { - get { return _concreteKey; } - set { _concreteKey = value; } - } + public string ConcreteKey { get; set; } /// <summary> /// Gets an instance of PluggableAttribute from a Type object Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -9,9 +9,8 @@ /// </summary> public class PluginFamilyAttribute : Attribute { - private string _default = string.Empty; + private readonly string _default = string.Empty; private InstanceScope _scope = InstanceScope.PerRequest; - private Type _source = null; public PluginFamilyAttribute() { @@ -33,11 +32,7 @@ set { _scope = value; } } - public Type SourceType - { - get { return _source; } - set { _source = value; } - } + public Type SourceType { get; set; } /// <summary> /// InstanceKey of the default instance. Used to implicitly define the default without @@ -66,14 +61,14 @@ /// <returns></returns> public static bool MarkedAsPluginFamily(Type objectType) { - PluginFamilyAttribute att = + var att = GetCustomAttribute(objectType, typeof (PluginFamilyAttribute), false) as PluginFamilyAttribute; return (att != null); } public static void ConfigureFamily(IPluginFamily family) { - PluginFamilyAttribute att = + var att = GetCustomAttribute(family.PluginType, typeof (PluginFamilyAttribute), false) as PluginFamilyAttribute; @@ -89,7 +84,7 @@ { try { - MementoSource source = (MementoSource) Activator.CreateInstance(SourceType); + var source = (MementoSource) Activator.CreateInstance(SourceType); family.AddMementoSource(source); } catch (Exception ex) Modified: trunk/Source/StructureMap/Attributes/SetterPropertyAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/SetterPropertyAttribute.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Attributes/SetterPropertyAttribute.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -19,12 +19,12 @@ return new PropertyInfo[0]; } - ArrayList list = new ArrayList(); + var list = new ArrayList(); PropertyInfo[] properties = pluggedType.GetProperties(); foreach (PropertyInfo property in properties) { - SetterPropertyAttribute att = + var att = GetCustomAttribute(property, typeof (SetterPropertyAttribute)) as SetterPropertyAttribute; if (att != null) @@ -37,9 +37,5 @@ } #endregion - - public SetterPropertyAttribute() - { - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Attributes/ValidationMethodAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/ValidationMethodAttribute.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Attributes/ValidationMethodAttribute.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -12,10 +12,6 @@ [AttributeUsage(AttributeTargets.Method)] public class ValidationMethodAttribute : Attribute { - public ValidationMethodAttribute() - { - } - /// <summary> /// Returns an array of any MethodInfo's on a Type that are marked as ValidationMethod /// </summary> @@ -23,12 +19,12 @@ /// <returns></returns> public static MethodInfo[] GetValidationMethods(Type objectType) { - ArrayList methodList = new ArrayList(); + var methodList = new ArrayList(); MethodInfo[] methods = objectType.GetMethods(); foreach (MethodInfo method in methods) { - ValidationMethodAttribute att = + var att = (ValidationMethodAttribute) GetCustomAttribute(method, typeof (ValidationMethodAttribute)); if (att != null) @@ -46,7 +42,7 @@ } } - MethodInfo[] returnValue = new MethodInfo[methodList.Count]; + var returnValue = new MethodInfo[methodList.Count]; methodList.CopyTo(returnValue, 0); return returnValue; Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -2,7 +2,6 @@ using System.IO; using System.Xml; using StructureMap.Diagnostics; -using StructureMap.Graph; using StructureMap.Source; namespace StructureMap.Configuration @@ -40,10 +39,12 @@ _structureMapNode = structureMapNode; XmlMementoStyle mementoStyle = XmlMementoStyle.NodeNormalized; - _structureMapNode.ForAttributeValue(MEMENTO_STYLE, style => - { - if (style == ATTRIBUTE_STYLE) mementoStyle = XmlMementoStyle.AttributeNormalized; - }); + _structureMapNode.ForAttributeValue(MEMENTO_STYLE, + style => + { + if (style == ATTRIBUTE_STYLE) + mementoStyle = XmlMementoStyle.AttributeNormalized; + }); _mementoCreator = new XmlMementoCreator( mementoStyle, @@ -114,6 +115,5 @@ ParseProfilesAndMachines(builder); } - } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -29,6 +29,8 @@ _log = log; } + #region IConfigurationParserBuilder Members + public bool UseAndEnforceExistenceOfDefaultFile { get { return _useAndEnforceExistenceOfDefaultFile; } @@ -48,6 +50,22 @@ set { _pullConfigurationFromAppConfig = value; } } + public void IncludeFile(string filename) + { + _otherFiles.Add(filename); + } + + + public void IncludeNode(XmlNode node, string description) + { + var parser = new ConfigurationParser(node); + parser.Description = description; + + _parsers.Add(parser); + } + + #endregion + public ConfigurationParser[] GetParsers() { var list = new List<ConfigurationParser>(); @@ -126,20 +144,6 @@ } - public void IncludeFile(string filename) - { - _otherFiles.Add(filename); - } - - - public void IncludeNode(XmlNode node, string description) - { - var parser = new ConfigurationParser(node); - parser.Description = description; - - _parsers.Add(parser); - } - public static ConfigurationParser[] GetParsers(XmlNode node, GraphLog log) { var builder = new ConfigurationParserBuilder(log); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -44,10 +44,7 @@ { var instance = new ConfiguredInstance(concreteType); - alterAndContinue(family => - { - family.AddInstance(instance); - }); + alterAndContinue(family => { family.AddInstance(instance); }); return instance; } @@ -77,7 +74,7 @@ { _registry.addExpression(graph => { - PluginTypeInterceptor interceptor = new PluginTypeInterceptor(_pluginType, func); + var interceptor = new PluginTypeInterceptor(_pluginType, func); graph.InterceptorLibrary.AddInterceptor(interceptor); }); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,4 +1,4 @@ -using System; +using System; using StructureMap.Pipeline; namespace StructureMap.Configuration.DSL.Expressions @@ -38,6 +38,25 @@ _action = action; } + #region IsExpression<T> Members + + InstanceExpression<T> IsExpression<T>.Is + { + get { return this; } + } + + public void IsThis(Instance instance) + { + returnInstance(instance); + } + + public LiteralInstance IsThis(T obj) + { + return returnInstance(new LiteralInstance(obj)); + } + + #endregion + public void Instance(Instance instance) { _action(instance); @@ -64,21 +83,6 @@ return returnInstance(new LiteralInstance(theObject)); } - InstanceExpression<T> IsExpression<T>.Is - { - get { return this; } - } - - public void IsThis(Instance instance) - { - returnInstance(instance); - } - - public LiteralInstance IsThis(T obj) - { - return returnInstance(new LiteralInstance(obj)); - } - public ReferencedInstance References(string key) { return returnInstance(new ReferencedInstance(key)); @@ -114,4 +118,4 @@ return returnInstance(new UserControlInstance(url)); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,5 +1,4 @@ using System; -using StructureMap.Graph; using StructureMap.Pipeline; namespace StructureMap.Configuration.DSL.Expressions @@ -39,6 +38,43 @@ return new GenericDefaultExpression(this, pluginType); } + #region Nested type: GenericDefaultExpression + + public class GenericDefaultExpression + { + private readonly ProfileExpression _parent; + private readonly Type _pluginType; + private readonly Registry _registry; + + internal GenericDefaultExpression(ProfileExpression parent, Type pluginType) + { + _parent = parent; + _registry = parent._registry; + _pluginType = pluginType; + } + + public ProfileExpression UseConcreteType(Type concreteType) + { + var instance = new ConfiguredInstance(concreteType); + return Use(instance); + } + + public ProfileExpression Use(Instance instance) + { + _registry.addExpression(graph => graph.SetDefault(_parent._profileName, _pluginType, instance)); + + return _parent; + } + + public ProfileExpression UseNamedInstance(string name) + { + var instance = new ReferencedInstance(name); + return Use(instance); + } + } + + #endregion + #region Nested type: InstanceDefaultExpression public class InstanceDefaultExpression<T> @@ -61,7 +97,8 @@ /// <returns></returns> public ProfileExpression UseNamedInstance(string instanceKey) { - _registry.addExpression(graph => graph.SetDefault(_profileName, typeof (T), new ReferencedInstance(instanceKey))); + _registry.addExpression( + graph => graph.SetDefault(_profileName, typeof (T), new ReferencedInstance(instanceKey))); return _parent; } @@ -82,62 +119,29 @@ public ProfileExpression Use(Func<T> func) { - ConstructorInstance<T> instance = new ConstructorInstance<T>(func); + var instance = new ConstructorInstance<T>(func); return Use(instance); } public ProfileExpression Use(T t) { - LiteralInstance instance = new LiteralInstance(t); + var instance = new LiteralInstance(t); return Use(instance); } public ProfileExpression UseConcreteType<CONCRETETYPE>() { - ConfiguredInstance instance = new ConfiguredInstance(typeof(CONCRETETYPE)); + var instance = new ConfiguredInstance(typeof (CONCRETETYPE)); return Use(instance); } public ProfileExpression UsePrototypeOf(T template) { - PrototypeInstance instance = new PrototypeInstance((ICloneable) template); + var instance = new PrototypeInstance((ICloneable) template); return Use(instance); } } #endregion - - public class GenericDefaultExpression - { - private readonly ProfileExpression _parent; - private readonly Type _pluginType; - private readonly Registry _registry; - - internal GenericDefaultExpression(ProfileExpression parent, Type pluginType) - { - _parent = parent; - _registry = parent._registry; - _pluginType = pluginType; - } - - public ProfileExpression UseConcreteType(Type concreteType) - { - ConfiguredInstance instance = new ConfiguredInstance(concreteType); - return Use(instance); - } - - public ProfileExpression Use(Instance instance) - { - _registry.addExpression(graph => graph.SetDefault(_parent._profileName, _pluginType, instance)); - - return _parent; - } - - public ProfileExpression UseNamedInstance(string name) - { - ReferencedInstance instance = new ReferencedInstance(name); - return Use(instance); - } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -9,8 +9,8 @@ { public class Registry { - private readonly List<Action> _basicActions = new List<Action>(); private readonly List<Action<PluginGraph>> _actions = new List<Action<PluginGraph>>(); + private readonly List<Action> _basicActions = new List<Action>(); public Registry() { @@ -65,27 +65,9 @@ return new GenericFamilyExpression(pluginType, this); } - public class BuildWithExpression<T> - { - private SmartInstance<T> _instance; - - public BuildWithExpression(SmartInstance<T> instance) - { - _instance = instance; - } - - public SmartInstance<T> Configure - { - get - { - return _instance; - } - } - } - public BuildWithExpression<T> ForConcreteType<T>() { - var instance = ForRequestedType<T>().TheDefault.Is.OfConcreteType<T>(); + SmartInstance<T> instance = ForRequestedType<T>().TheDefault.Is.OfConcreteType<T>(); return new BuildWithExpression<T>(instance); } @@ -104,7 +86,7 @@ public PluginGraph Build() { - PluginGraph graph = new PluginGraph(); + var graph = new PluginGraph(); ConfigurePluginGraph(graph); graph.Seal(); @@ -122,13 +104,9 @@ public GenericIsExpression InstanceOf(Type pluginType) { - return new GenericIsExpression(instance => - { - _actions.Add(graph => - { - graph.FindFamily(pluginType).AddInstance(instance); - }); - }); + return + new GenericIsExpression( + instance => { _actions.Add(graph => { graph.FindFamily(pluginType).AddInstance(instance); }); }); } /// <summary> @@ -138,7 +116,7 @@ /// <returns></returns> public ProfileExpression CreateProfile(string profileName) { - ProfileExpression expression = new ProfileExpression(profileName, this); + var expression = new ProfileExpression(profileName, this); return expression; } @@ -165,7 +143,7 @@ public MatchedTypeInterceptor IfTypeMatches(Predicate<Type> match) { - MatchedTypeInterceptor interceptor = new MatchedTypeInterceptor(match); + var interceptor = new MatchedTypeInterceptor(match); _actions.Add(graph => graph.InterceptorLibrary.AddInterceptor(interceptor)); return interceptor; @@ -209,10 +187,27 @@ public CreatePluginFamilyExpression<PLUGINTYPE> FillAllPropertiesOfType<PLUGINTYPE>() { - PluginCache.AddFilledType(typeof(PLUGINTYPE)); + PluginCache.AddFilledType(typeof (PLUGINTYPE)); return ForRequestedType<PLUGINTYPE>(); } + #region Nested type: BuildWithExpression + public class BuildWithExpression<T> + { + private readonly SmartInstance<T> _instance; + + public BuildWithExpression(SmartInstance<T> instance) + { + _instance = instance; + } + + public SmartInstance<T> Configure + { + get { return _instance; } + } + } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DictionaryReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DictionaryReader.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/DictionaryReader.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -8,57 +8,89 @@ { public class DictionaryReader : ITypeReader { + #region ITypeReader Members + public bool CanProcess(Type pluginType) { - if (pluginType.Equals(typeof(NameValueCollection))) return true; + if (pluginType.Equals(typeof (NameValueCollection))) return true; if (!pluginType.IsGenericType) return false; - var definition = pluginType.GetGenericTypeDefinition(); + Type definition = pluginType.GetGenericTypeDefinition(); if (definition == null) return false; return definition.Equals(typeof (IDictionary<,>)) || definition.Equals(typeof (Dictionary<,>)); } + public Instance Read(XmlNode node, Type pluginType) + { + IBuilder builder = findBuilder(pluginType); + node.ForEachChild("Pair").Do( + element => builder.Read(element.GetAttribute("Key"), element.GetAttribute("Value"))); + + return new SerializedInstance(builder.Object); + } + + #endregion + private static IBuilder findBuilder(Type pluginType) { - if (pluginType.Equals(typeof(NameValueCollection))) return new NameValueCollectionBuilder(); + if (pluginType.Equals(typeof (NameValueCollection))) return new NameValueCollectionBuilder(); - var definition = pluginType.GetGenericTypeDefinition(); - if (definition.Equals(typeof(IDictionary<,>)) || definition.Equals(typeof(Dictionary<,>))) + Type definition = pluginType.GetGenericTypeDefinition(); + if (definition.Equals(typeof (IDictionary<,>)) || definition.Equals(typeof (Dictionary<,>))) { - var arguments = pluginType.GetGenericArguments(); - var builderType = typeof (DictionaryBuilder<,>).MakeGenericType(arguments); + Type[] arguments = pluginType.GetGenericArguments(); + Type builderType = typeof (DictionaryBuilder<,>).MakeGenericType(arguments); return (IBuilder) Activator.CreateInstance(builderType); } return null; } - public Instance Read(XmlNode node, Type pluginType) + #region Nested type: DictionaryBuilder + + internal class DictionaryBuilder<KEY, VALUE> : IBuilder { - var builder = findBuilder(pluginType); - node.ForEachChild("Pair").Do(element => builder.Read(element.GetAttribute("Key"), element.GetAttribute("Value"))); + private readonly Dictionary<KEY, VALUE> _dictionary = new Dictionary<KEY, VALUE>(); - return new SerializedInstance(builder.Object); - } + #region IBuilder Members - + public void Read(string name, string value) + { + var key = (KEY) Convert.ChangeType(name, typeof (KEY)); + var theValue = (VALUE) Convert.ChangeType(value, typeof (VALUE)); + _dictionary.Add(key, theValue); + } + public object Object + { + get { return _dictionary; } + } + #endregion + } + #endregion + #region Nested type: IBuilder internal interface IBuilder { + object Object { get; } void Read(string name, string value); - object Object { get; } } + #endregion + + #region Nested type: NameValueCollectionBuilder + internal class NameValueCollectionBuilder : IBuilder { private readonly NameValueCollection _collection = new NameValueCollection(); + #region IBuilder Members + public void Read(string name, string value) { _collection.Add(name, value); @@ -68,24 +100,10 @@ { get { return _collection; } } + + #endregion } - internal class DictionaryBuilder<KEY, VALUE> : IBuilder - { - private Dictionary<KEY, VALUE> _dictionary = new Dictionary<KEY, VALUE>(); - - public void Read(string name, string value) - { - KEY key = (KEY) Convert.ChangeType(name, typeof (KEY)); - VALUE theValue = (VALUE) Convert.ChangeType(value, typeof (VALUE)); - - _dictionary.Add(key, theValue); - } - - public object Object - { - get { return _dictionary; } - } - } + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -52,7 +52,7 @@ public void ParseDefaultElement(XmlElement element) { - TypePath pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); + var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); _builder.ConfigureFamily(pluginTypePath, family => @@ -67,7 +67,7 @@ public void ParseInstanceElement(XmlElement element) { - TypePath pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); + var pluginTypePath = new TypePath(element.GetAttribute(PLUGIN_TYPE)); _builder.ConfigureFamily(pluginTypePath, family => { @@ -81,10 +81,8 @@ { InstanceScope returnValue = InstanceScope.PerRequest; - familyElement.ForAttributeValue(SCOPE, scope => - { - returnValue = (InstanceScope)Enum.Parse(typeof(InstanceScope), scope); - }); + familyElement.ForAttributeValue(SCOPE, + scope => { returnValue = (InstanceScope) Enum.Parse(typeof (InstanceScope), scope); }); return returnValue; } @@ -95,7 +93,8 @@ { InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(node); - string context = string.Format("MementoSource for {0}\n{1}", TypePath.GetAssemblyQualifiedName(family.PluginType), node.OuterXml); + string context = string.Format("MementoSource for {0}\n{1}", + TypePath.GetAssemblyQualifiedName(family.PluginType), node.OuterXml); _builder.WithSystemObject<MementoSource>(sourceMemento, context, source => family.AddMementoSource(source)); }); @@ -122,13 +121,14 @@ private void attachInterceptors(PluginFamily family, XmlElement familyElement) { - string contextBase = string.Format("creating an InstanceInterceptor for {0}\n", TypePath.GetAssemblyQualifiedName(family.PluginType)); + string contextBase = string.Format("creating an InstanceInterceptor for {0}\n", + TypePath.GetAssemblyQualifiedName(family.PluginType)); familyElement.ForEachChild("*/Interceptor").Do(element => { var interceptorMemento = new XmlAttributeInstanceMemento(element); string context = contextBase + element.OuterXml; _builder.WithSystemObject<IBuildInterceptor>( - interceptorMemento, + interceptorMemento, context, interceptor => family.AddInterceptor(interceptor)); }); Modified: trunk/Source/StructureMap/Configuration/ITypeReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ITypeReader.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/ITypeReader.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,6 +1,4 @@ -using System; -using System.Linq; -using System.Text; +using System; using System.Xml; using StructureMap.Pipeline; @@ -11,4 +9,4 @@ bool CanProcess(Type pluginType); Instance Read(XmlNode node, Type pluginType); } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs =================================================================== --- trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,4 +1,4 @@ -using System; +using System; using System.Xml; using StructureMap.Graph; using StructureMap.Pipeline; @@ -19,11 +19,11 @@ Type elementType = pluginType.GetElementType(); char Delimiter = node.GetAttribute("Delimiter", ",").ToCharArray()[0]; - var valueString = node.GetAttribute("Values", string.Empty); - string[] rawValues = valueString.Split(new[]{Delimiter}, StringSplitOptions.RemoveEmptyEntries); + string valueString = node.GetAttribute("Values", string.Empty); + string[] rawValues = valueString.Split(new[] {Delimiter}, StringSplitOptions.RemoveEmptyEntries); - var array = Array.CreateInstance(elementType, rawValues.Length); + Array array = Array.CreateInstance(elementType, rawValues.Length); for (int i = 0; i < rawValues.Length; i++) { object convertedType = Convert.ChangeType(rawValues[i].Trim(), elementType); Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,4 +1,3 @@ -using System; using System.Xml; using StructureMap.Graph; using StructureMap.Pipeline; @@ -23,7 +22,8 @@ public void Parse() { - _structureMapNode.ForAttributeValue(DEFAULT_PROFILE, profileName => _profileBuilder.SetDefaultProfileName(profileName)); + _structureMapNode.ForAttributeValue(DEFAULT_PROFILE, + profileName => _profileBuilder.SetDefaultProfileName(profileName)); forEachNode(PROFILE_NODE).Do(element => { @@ -31,7 +31,8 @@ _profileBuilder.AddProfile(profileName); writeOverrides(element, - (fullName, defaultKey) => _profileBuilder.OverrideProfile(new TypePath(fullName), defaultKey), profileName); + (fullName, defaultKey) => + _profileBuilder.OverrideProfile(new TypePath(fullName), defaultKey), profileName); }); @@ -43,7 +44,8 @@ _profileBuilder.AddMachine(machineName, profileName); writeOverrides(element, - (fullName, defaultKey) => _profileBuilder.OverrideMachine(new TypePath(fullName), defaultKey), machineName); + (fullName, defaultKey) => + _profileBuilder.OverrideMachine(new TypePath(fullName), defaultKey), machineName); }); } @@ -73,7 +75,7 @@ InstanceMemento memento = _creator.CreateMemento(instanceElement); memento.InstanceKey = key; - TypePath familyPath = new TypePath(fullName); + var familyPath = new TypePath(fullName); _graphBuilder.ConfigureFamily(familyPath, family => { Modified: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -8,16 +8,6 @@ { private static string _overriden_machine_name; - public static void OverrideMachineName(string machineName) - { - _overriden_machine_name = machineName; - } - - public static void ResetMachineName() - { - _overriden_machine_name = string.Empty; - } - private readonly string _machineName; private readonly PluginGraph _pluginGraph; private readonly ProfileManager _profileManager; @@ -49,7 +39,7 @@ { _pluginGraph.Log.WithType(typePath, "while trying to add an override for a Profile", pluginType => { - ReferencedInstance instance = new ReferencedInstance(instanceKey); + var instance = new ReferencedInstance(instanceKey); _pluginGraph.SetDefault(_lastProfile, pluginType, instance); }); } @@ -71,11 +61,11 @@ return; } - _pluginGraph.Log.WithType(typePath, - "trying to configure a Machine Override", + _pluginGraph.Log.WithType(typePath, + "trying to configure a Machine Override", pluginType => { - ReferencedInstance instance = new ReferencedInstance(instanceKey); + var instance = new ReferencedInstance(instanceKey); _profileManager.SetMachineDefault(pluginType, instance); }); } @@ -87,6 +77,16 @@ #endregion + public static void OverrideMachineName(string machineName) + { + _overriden_machine_name = machineName; + } + + public static void ResetMachineName() + { + _overriden_machine_name = string.Empty; + } + public static string GetMachineName() { if (!string.IsNullOrEmpty(_overriden_machine_name)) Modified: trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs =================================================================== --- trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/StructureMapConfigurationSection.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -10,7 +10,7 @@ public object Create(object parent, object configContext, XmlNode section) { - IList<XmlNode> allNodes = parent as IList<XmlNode>; + var allNodes = parent as IList<XmlNode>; if (allNodes == null) { allNodes = new List<XmlNode>(); @@ -23,7 +23,7 @@ public static IList<XmlNode> GetStructureMapConfiguration() { - IList<XmlNode> nodes = ConfigurationSettings.GetConfig(XmlConstants.STRUCTUREMAP) as IList<XmlNode>; + var nodes = ConfigurationSettings.GetConfig(XmlConstants.STRUCTUREMAP) as IList<XmlNode>; if (nodes == null) { throw new StructureMapException(105, XmlConstants.STRUCTUREMAP); Modified: trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs =================================================================== --- trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/TypeReaderFactory.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -5,7 +5,7 @@ { public static class TypeReaderFactory { - private static List<ITypeReader> _readers = new List<ITypeReader>(); + private static readonly List<ITypeReader> _readers = new List<ITypeReader>(); static TypeReaderFactory() { @@ -15,7 +15,7 @@ public static ITypeReader GetReader(Type pluginType) { - foreach (var reader in _readers) + foreach (ITypeReader reader in _readers) { if (reader.CanProcess(pluginType)) { Modified: trunk/Source/StructureMap/Configuration/XmlExtensions.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -7,7 +7,7 @@ { public static string GetAttribute(this XmlNode node, string attributeName, string defaultValue) { - var attribute = node.Attributes.GetNamedItem(attributeName); + XmlNode attribute = node.Attributes.GetNamedItem(attributeName); return attribute == null ? defaultValue : attribute.InnerText; } @@ -35,13 +35,15 @@ return new HasXmlElementExpression(node, xpath); } + #region Nested type: HasXmlElementExpression + public class HasXmlElementExpression { - private XmlElement _element; + private readonly XmlElement _element; internal HasXmlElementExpression(XmlNode parent, string xpath) { - _element = (XmlElement)parent.SelectSingleNode(xpath); + _element = (XmlElement) parent.SelectSingleNode(xpath); } public HasXmlElementExpression Do(Action<XmlElement> action) @@ -63,10 +65,13 @@ } } + #endregion + #region Nested type: XmlNodeExpression + public class XmlNodeExpression { - private XmlNodeList _list; + private readonly XmlNodeList _list; internal XmlNodeExpression(XmlNode parent, string xpath) { @@ -79,11 +84,15 @@ foreach (XmlNode node in _list) { - action((XmlElement)node); + action((XmlElement) node); } } } + #endregion + + #region Nested type: XmlTextExpression + public class XmlTextExpression { private readonly XmlNodeList _list; @@ -104,6 +113,6 @@ } } - + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/BuildError.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/BuildError.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/BuildError.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using StructureMap.Graph; using StructureMap.Pipeline; namespace StructureMap.Diagnostics @@ -18,6 +17,7 @@ PluginType = pluginType; } + #region IEquatable<BuildDependency> Members public bool Equals(BuildDependency buildDependency) { @@ -25,6 +25,8 @@ return Equals(Instance, buildDependency.Instance) && Equals(PluginType, buildDependency.PluginType); } + #endregion + public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) return true; @@ -33,16 +35,16 @@ public override int GetHashCode() { - return (Instance != null ? Instance.GetHashCode() : 0) + 29*(PluginType != null ? PluginType.GetHashCode() : 0); + return (Instance != null ? Instance.GetHashCode() : 0) + + 29*(PluginType != null ? PluginType.GetHashCode() : 0); } } public class BuildError { + private readonly List<BuildDependency> _dependencies = new List<BuildDependency>(); private readonly Instance _instance; private readonly Type _pluginType; - private StructureMapException _exception; - private readonly List<BuildDependency> _dependencies = new List<BuildDependency>(); public BuildError(Type pluginType, Instance instance) { @@ -50,14 +52,6 @@ _pluginType = pluginType; } - public void AddDependency(BuildDependency dependency) - { - if (!_dependencies.Contains(dependency)) - { - _dependencies.Add(dependency); - } - } - public List<BuildDependency> Dependencies { get { return _dependencies; } @@ -73,21 +67,27 @@ get { return _pluginType; } } - public StructureMapException Exception + public StructureMapException Exception { get; set; } + + public void AddDependency(BuildDependency dependency) { - get { return _exception; } - set { _exception = value; } + if (!_dependencies.Contains(dependency)) + { + _dependencies.Add(dependency); + } } public void Write(StringWriter writer) { - string description = ((IDiagnosticInstance)Instance).CreateToken().Description; + string description = ((IDiagnosticInstance) Instance).CreateToken().Description; writer.WriteLine(); - writer.WriteLine("-----------------------------------------------------------------------------------------------------"); - writer.WriteLine("Build Error on Instance '{0}' ({1})\n for PluginType {2}", Instance.Name, description, PluginType.AssemblyQualifiedName); + writer.WriteLine( + "-----------------------------------------------------------------------------------------------------"); + writer.WriteLine("Build Error on Instance '{0}' ({1})\n for PluginType {2}", Instance.Name, description, + PluginType.AssemblyQualifiedName); writer.WriteLine(); - + if (Exception != null) writer.WriteLine(Exception.ToString()); writer.WriteLine(); } Modified: trunk/Source/StructureMap/Diagnostics/CharacterWidth.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/CharacterWidth.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/CharacterWidth.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -2,9 +2,16 @@ { internal class CharacterWidth { + private int _width; + + internal int Width + { + get { return _width; } + } + internal static CharacterWidth[] For(int count) { - CharacterWidth[] widths = new CharacterWidth[count]; + var widths = new CharacterWidth[count]; for (int i = 0; i < widths.Length; i++) { widths[i] = new CharacterWidth(); @@ -13,8 +20,6 @@ return widths; } - private int _width = 0; - internal void SetWidth(int width) { if (width > _width) @@ -27,13 +32,5 @@ { _width += add; } - - internal int Width - { - get - { - return _width; - } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/DividerLine.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/DividerLine.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/DividerLine.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -10,7 +10,9 @@ { _character = character; } - + + #region Line Members + public void OverwriteCounts(CharacterWidth[] widths) { // no-op @@ -23,5 +25,7 @@ writer.Write(string.Empty.PadRight(width.Width, _character)); } } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/Doctor.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Doctor.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/Doctor.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,37 +1,37 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Text; namespace StructureMap.Diagnostics { public class Doctor { + public Doctor() + { + BinaryPath = AppDomain.CurrentDomain.BaseDirectory; + } + public string ConfigFile { get; set; } public string BootstrapperType { get; set; } public string BinaryPath { get; set; } public string OutputFile { get; set; } - public Doctor() - { - BinaryPath = AppDomain.CurrentDomain.BaseDirectory; - } - public DoctorReport RunReport() { AppDomain domain = null; try { - var setup = new AppDomainSetup() { ApplicationBase = BinaryPath, ConfigurationFile = ConfigFile }; + var setup = new AppDomainSetup {ApplicationBase = BinaryPath, ConfigurationFile = ConfigFile}; if (BinaryPath != null) setup.PrivateBinPath = BinaryPath; domain = AppDomain.CreateDomain("StructureMap-Diagnostics", null, setup); - var doctor = (DoctorRunner)domain.CreateInstanceAndUnwrap(typeof(DoctorRunner).Assembly.FullName, typeof(DoctorRunner).FullName); + var doctor = + (DoctorRunner) + domain.CreateInstanceAndUnwrap(typeof (DoctorRunner).Assembly.FullName, + typeof (DoctorRunner).FullName); DoctorReport report = doctor.RunReport(BootstrapperType); writeReport(report); - writeResults(System.Console.Out, report); + writeResults(Console.Out, report); return report; } @@ -48,7 +48,7 @@ return; } - using (StreamWriter writer = new StreamWriter(OutputFile)) + using (var writer = new StreamWriter(OutputFile)) { writeResults(writer, report); } @@ -56,28 +56,32 @@ private void writeResults(TextWriter writer, DoctorReport report) { - writer.WriteLine("StructureMap Configuration Report written at " + DateTime.Now.ToString()); - writer.WriteLine("Result: " + report.Result.ToString()); + writer.WriteLine("StructureMap Configuration Report written at " + DateTime.Now); + writer.WriteLine("Result: " + report.Result); writer.WriteLine(); writer.WriteLine("BootStrapper: " + BootstrapperType); writer.WriteLine("ConfigFile: " + ConfigFile); writer.WriteLine("BinaryPath: " + BinaryPath); - writer.WriteLine("===================================================================================================="); - + writer.WriteLine( + "===================================================================================================="); + writer.WriteLine(); writer.WriteLine(); if (!string.IsNullOrEmpty(report.ErrorMessages)) { - writer.WriteLine("===================================================================================================="); - writer.WriteLine("= Error Messages ="); - writer.WriteLine("===================================================================================================="); + writer.WriteLine( + "===================================================================================================="); + writer.WriteLine( + "= Error Messages ="); + writer.WriteLine( + "===================================================================================================="); writer.WriteLine(report.ErrorMessages); writer.WriteLine(); writer.WriteLine(); } - if (!string.IsNullOrEmpty(report.WhatDoIHave)) + if (!string.IsNullOrEmpty(report.WhatDoIHave)) { writer.WriteLine(report.WhatDoIHave); writer.WriteLine(); @@ -85,4 +89,4 @@ } } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/DoctorReport.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/DoctorReport.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/DoctorReport.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -5,8 +5,8 @@ [Serializable] public class DoctorReport { + public string ErrorMessages; + public DoctorResult Result; public string WhatDoIHave = string.Empty; - public DoctorResult Result; - public string ErrorMessages; } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/DoctorRunner.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/DoctorRunner.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/DoctorRunner.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -64,8 +64,6 @@ return report; } - - } private void writeConfigurationAndValidate(DoctorReport report, PluginGraph graph) Modified: trunk/Source/StructureMap/Diagnostics/Error.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Error.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/Error.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Resources; namespace StructureMap.Diagnostics { @@ -28,7 +27,7 @@ public Error(int errorCode, Exception ex, params object[] args) : this(errorCode, args) { _message += "\n\n" + ex.Message; - + writeStackTrace(ex); } @@ -41,19 +40,7 @@ writeStackTrace(exception); } - private void writeStackTrace(Exception exception) - { - _stackTrace = string.Empty; - Exception ex = exception; - while (ex != null) - { - _stackTrace += exception.ToString(); - _stackTrace += "\n\n"; - ex = ex.InnerException; - } - } - public int Code { get { return _code; } @@ -73,6 +60,17 @@ #endregion + private void writeStackTrace(Exception exception) + { + _stackTrace = string.Empty; + Exception ex = exception; + while (ex != null) + { + _stackTrace += exception.ToString(); + _stackTrace += "\n\n"; + ex = ex.InnerException; + } + } public override bool Equals(object obj) { @@ -105,9 +103,9 @@ writer.WriteLine("Error: " + Code); if (Instance != null) writer.WriteLine(Instance.ToString()); writer.WriteLine("Source: " + Source); - + if (!string.IsNullOrEmpty(_message)) writer.WriteLine(_message); - if (!string.IsNullOrEmpty(_stackTrace)) writer.WriteLine(_stackTrace); + if (!string.IsNullOrEmpty(_stackTrace)) writer.WriteLine(_stackTrace); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/ErrorCollection.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -6,14 +6,25 @@ { public class ErrorCollection { + private readonly List<Instance> _brokenInstances = new List<Instance>(); private readonly Dictionary<Instance, BuildError> _buildErrors = new Dictionary<Instance, BuildError>(); - private readonly List<Instance> _brokenInstances = new List<Instance>(); + public BuildError[] BuildErrors + { + get + { + var errors = new BuildError[_buildErrors.Count]; + _buildErrors.Values.CopyTo(errors, 0); + return errors; + } + } + + public void LogError( - Instance instance, - Type pluginType, - StructureMapException ex, + Instance instance, + Type pluginType, + StructureMapException ex, IEnumerable<BuildDependency> dependencies) { if (_buildErrors.ContainsKey(instance)) @@ -27,8 +38,8 @@ return; } - InstanceToken token = ((IDiagnosticInstance)instance).CreateToken(); - BuildError error = new BuildError(pluginType, instance); + InstanceToken token = ((IDiagnosticInstance) instance).CreateToken(); + var error = new BuildError(pluginType, instance); error.Exception = ex; _buildErrors.Add(instance, error); @@ -36,7 +47,8 @@ addDependenciesToError(instance, dependencies, error); } - private void addDependenciesToError(Instance instance, IEnumerable<BuildDependency> dependencies, BuildError error) + private void addDependenciesToError(Instance instance, IEnumerable<BuildDependency> dependencies, + BuildError error) { foreach (BuildDependency dependency in dependencies) { @@ -50,20 +62,9 @@ } } - public BuildError[] BuildErrors - { - get - { - BuildError[] errors = new BuildError[_buildErrors.Count]; - _buildErrors.Values.CopyTo(errors, 0); - - return errors; - } - } - public BuildError Find(Type pluginType, string name) { - foreach (KeyValuePair<Instance, BuildError> pair in _buildErrors) + foreach (var pair in _buildErrors) { BuildError error = pair.Value; if (error.PluginType == pluginType && error.Instance.Name == name) @@ -82,6 +83,5 @@ action(pair.Value); } } - } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/GraphLog.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-10-05 02:35:54 UTC (rev 170) +++ trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2008-10-05 02:43:34 UTC (rev 171) @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; @@ -11,9 +10,9 @@ { public class GraphLog { + private readonly List<Error> _errors = new List<Error>(); + private readonly List<string... [truncated message content] |
From: <jer...@us...> - 2008-10-05 02:51:23
|
Revision: 172 http://structuremap.svn.sourceforge.net/structuremap/?rev=172&view=rev Author: jeremydmiller Date: 2008-10-05 02:50:36 +0000 (Sun, 05 Oct 2008) Log Message: ----------- More cleanup Modified Paths: -------------- trunk/Source/StructureMap/Exceptions/MissingPluginFamilyException.cs trunk/Source/StructureMap/Exceptions/StructureMapConfigurationException.cs trunk/Source/StructureMap/Exceptions/StructureMapException.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/Constructor.cs trunk/Source/StructureMap/Graph/FamilyAttributeScanner.cs trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs trunk/Source/StructureMap/Graph/FindRegistriesScanner.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap/Graph/PluggableAttributeScanner.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/Graph/PluginCache.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/Graph/SetterProperty.cs trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs trunk/Source/StructureMap/Graph/TypePath.cs trunk/Source/StructureMap/Graph/TypeRules.cs trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs trunk/Source/StructureMap/Pipeline/BuildFrame.cs trunk/Source/StructureMap/Pipeline/BuildStack.cs trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs trunk/Source/StructureMap/Pipeline/DefaultInstance.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs trunk/Source/StructureMap/Pipeline/LiteralInstance.cs trunk/Source/StructureMap/Pipeline/Profile.cs trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs trunk/Source/StructureMap/Pipeline/SerializedInstance.cs trunk/Source/StructureMap/Pipeline/SmartInstance.cs trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.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/Util/Cache.cs Modified: trunk/Source/StructureMap/Exceptions/MissingPluginFamilyException.cs =================================================================== --- trunk/Source/StructureMap/Exceptions/MissingPluginFamilyException.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Exceptions/MissingPluginFamilyException.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -6,27 +6,27 @@ [Serializable] public class MissingPluginFamilyException : ApplicationException { - private string _message; + private readonly string _message; - public MissingPluginFamilyException(string pluginTypeName) : base() + public MissingPluginFamilyException(string pluginTypeName) { _message = string.Format("Type {0} is not a configured PluginFamily", pluginTypeName); } - public override string Message - { - get { return _message; } - } - protected MissingPluginFamilyException(SerializationInfo info, StreamingContext context) : base(info, context) { _message = info.GetString("message"); } + public override string Message + { + get { return _message; } + } + public override void GetObjectData(SerializationInfo info, StreamingContext context) { - info.AddValue("message", _message, typeof(string)); + info.AddValue("message", _message, typeof (string)); base.GetObjectData(info, context); } Modified: trunk/Source/StructureMap/Exceptions/StructureMapConfigurationException.cs =================================================================== --- trunk/Source/StructureMap/Exceptions/StructureMapConfigurationException.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Exceptions/StructureMapConfigurationException.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -16,4 +16,4 @@ { } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Exceptions/StructureMapException.cs =================================================================== --- trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,5 +1,4 @@ using System; -using System.Resources; using System.Runtime.Serialization; namespace StructureMap @@ -11,8 +10,8 @@ [Serializable] public class StructureMapException : ApplicationException { - private int _errorCode; - private string _msg; + private readonly int _errorCode; + private readonly string _msg; protected StructureMapException(SerializationInfo info, StreamingContext context) : @@ -23,7 +22,7 @@ } - public StructureMapException(int ErrorCode, params object[] args) : base() + public StructureMapException(int ErrorCode, params object[] args) { _errorCode = ErrorCode; _msg = string.Format("StructureMap Exception Code: {0}\n", _errorCode); @@ -49,7 +48,6 @@ } - public override void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("errorCode", _errorCode, typeof (int)); Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -4,7 +4,6 @@ using System.Linq; using System.Reflection; using System.Threading; -using StructureMap.Diagnostics; namespace StructureMap.Graph { @@ -19,9 +18,9 @@ public class AssemblyScanner { private readonly List<Assembly> _assemblies = new List<Assembly>(); - private readonly List<ITypeScanner> _scanners = new List<ITypeScanner>(); - private readonly List<Predicate<Type>> _includes = new List<Predicate<Type>>(); private readonly List<Predicate<Type>> _excludes = new List<Predicate<Type>>(); + private readonly List<Predicate<Type>> _includes = new List<Predicate<Type>>(); + private readonly List<ITypeScanner> _scanners = new List<ITypeScanner>(); public AssemblyScanner() { @@ -35,7 +34,6 @@ } - public void ScanForAll(PluginGraph pluginGraph) { _assemblies.ForEach(assem => scanTypesInAssembly(assem, pluginGraph)); @@ -151,7 +149,7 @@ private static Assembly findTheCallingAssembly() { - StackTrace trace = new StackTrace(Thread.CurrentThread, false); + var trace = new StackTrace(Thread.CurrentThread, false); Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); Assembly callingAssembly = null; @@ -170,7 +168,7 @@ public void AssemblyContainingType<T>() { - _assemblies.Add(typeof(T).Assembly); + _assemblies.Add(typeof (T).Assembly); } public void AssemblyContainingType(Type type) @@ -180,7 +178,7 @@ public void AddAllTypesOf<PLUGINTYPE>() { - AddAllTypesOf(typeof(PLUGINTYPE)); + AddAllTypesOf(typeof (PLUGINTYPE)); } public void AddAllTypesOf(Type pluginType) @@ -207,7 +205,7 @@ public void ExcludeNamespaceContainingType<T>() { - ExcludeNamespace(typeof(T).Namespace); + ExcludeNamespace(typeof (T).Namespace); } public void Include(Predicate<Type> predicate) Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -5,8 +5,8 @@ { public class Constructor : TypeRules { + private readonly ConstructorInfo _ctor; private readonly Type _pluggedType; - private ConstructorInfo _ctor; public Constructor(Type pluggedType) { Modified: trunk/Source/StructureMap/Graph/FamilyAttributeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/FamilyAttributeScanner.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/FamilyAttributeScanner.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -4,6 +4,8 @@ { public class FamilyAttributeScanner : ITypeScanner { + #region ITypeScanner Members + public void Process(Type type, PluginGraph graph) { if (PluginFamilyAttribute.MarkedAsPluginFamily(type)) @@ -11,5 +13,7 @@ graph.CreateFamily(type); } } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs =================================================================== --- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -11,6 +11,8 @@ _pluginType = pluginType; } + #region ITypeScanner Members + public void Process(Type type, PluginGraph graph) { if (CanBeCast(_pluginType, type)) @@ -18,5 +20,7 @@ graph.AddType(_pluginType, type); } } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/FindRegistriesScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/FindRegistriesScanner.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/FindRegistriesScanner.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -5,11 +5,13 @@ { public class FindRegistriesScanner : ITypeScanner { + #region ITypeScanner Members + public void Process(Type type, PluginGraph graph) { if (!Registry.IsPublicRegistry(type)) return; - foreach (var previous in graph.Registries) + foreach (Registry previous in graph.Registries) { if (previous.GetType().Equals(type)) { @@ -17,8 +19,10 @@ } } - Registry registry = (Registry)Activator.CreateInstance(type); + var registry = (Registry) Activator.CreateInstance(type); registry.ConfigurePluginGraph(graph); } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using StructureMap.Pipeline; using StructureMap.Util; @@ -24,7 +23,7 @@ { get { - foreach (var family in _families) + foreach (PluginFamily family in _families) { yield return family.GetConfiguration(); } @@ -95,7 +94,6 @@ PluginFamily basicFamily = _families.Retrieve(basicType); Type[] templatedParameterTypes = templatedType.GetGenericArguments(); - PluginFamily family = CreateTemplatedClone(basicFamily, templatedParameterTypes); profileManager.CopyDefaults(basicType, templatedType, family); @@ -111,13 +109,11 @@ // TODO: This code sucks. What's going on here? public static PluginFamily CreateTemplatedClone(PluginFamily baseFamily, params Type[] templateTypes) { - PluginFamily templatedFamily = baseFamily.CreateTemplatedClone(templateTypes); return templatedFamily; } - public static bool CanBePluggedIntoGenericType(Type pluginType, Type pluggedType, params Type[] templateTypes) { bool isValid = true; Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; namespace StructureMap.Graph { Modified: trunk/Source/StructureMap/Graph/PluggableAttributeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluggableAttributeScanner.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/PluggableAttributeScanner.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -4,6 +4,8 @@ { public class PluggableAttributeScanner : ITypeScanner { + #region ITypeScanner Members + public void Process(Type type, PluginGraph graph) { if (PluggableAttribute.MarkedAsPluggable(type)) @@ -11,5 +13,7 @@ graph.AddType(type); } } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -144,8 +144,8 @@ { Type templatedType = _pluggedType.IsGenericType ? _pluggedType.MakeGenericType(types) : _pluggedType; - Plugin templatedPlugin = new Plugin(templatedType, ConcreteKey); - + var templatedPlugin = new Plugin(templatedType, ConcreteKey); + foreach (SetterProperty setter in Setters) { templatedPlugin.Setters.MarkSetterAsMandatory(setter.Name); Modified: trunk/Source/StructureMap/Graph/PluginCache.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCache.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/PluginCache.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using StructureMap.Emitting; @@ -9,8 +9,8 @@ public static class PluginCache { private static readonly Cache<Type, InstanceBuilder> _builders; + private static readonly List<Type> _filledTypes = new List<Type>(); private static readonly Cache<Type, Plugin> _plugins; - private static List<Type> _filledTypes = new List<Type>(); static PluginCache() { @@ -37,7 +37,8 @@ { lock (typeof (PluginCache)) { - IEnumerable<Plugin> plugins = _plugins.Where(plugin => pluginHasNoBuilder(plugin) && plugin.CanBeCreated()); + IEnumerable<Plugin> plugins = + _plugins.Where(plugin => pluginHasNoBuilder(plugin) && plugin.CanBeCreated()); createAndStoreBuilders(plugins); } } @@ -65,7 +66,7 @@ internal static void ResetAll() { - lock (typeof(PluginCache)) + lock (typeof (PluginCache)) { _builders.Clear(); _plugins.Clear(); Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -152,7 +152,7 @@ { if (plugin.CanBeAutoFilled && !hasInstanceWithPluggedType(plugin)) { - var instance = new ConfiguredInstance(plugin.PluggedType).WithName(key); + ConfiguredInstance instance = new ConfiguredInstance(plugin.PluggedType).WithName(key); AddInstance(instance); } }); @@ -216,54 +216,6 @@ return string.IsNullOrEmpty(_defaultKey) ? null : GetInstance(_defaultKey); } - #region properties - - - public bool IsGenericTemplate - { - get { return _pluginType.IsGenericTypeDefinition || _pluginType.ContainsGenericParameters; } - } - - public IBuildPolicy Policy - { - get { return _buildPolicy; } - set { _policy = value; } - } - - public int PluginCount - { - get { return _pluggedTypes.Count; } - } - - /// <summary> - /// The CLR Type that defines the "Plugin" interface for the PluginFamily - /// </summary> - public Type PluginType - { - get { return _pluginType; } - } - - /// <summary> - /// The InstanceKey of the default instance of the PluginFamily - /// </summary> - public string DefaultInstanceKey - { - get { return _defaultKey; } - set { _defaultKey = value ?? string.Empty; } - } - - public int InstanceCount - { - get { return _instances.Count; } - } - - public IEnumerable<IInstance> Instances - { - get { return _instances.GetAll(); } - } - - #endregion - public Plugin FindPlugin(Type pluggedType) { return _pluggedTypes.Find(p => p.PluggedType == pluggedType); @@ -325,16 +277,13 @@ public PluginFamily CreateTemplatedClone(Type[] templateTypes) { Type templatedType = _pluginType.MakeGenericType(templateTypes); - PluginFamily templatedFamily = new PluginFamily(templatedType, Parent); + var templatedFamily = new PluginFamily(templatedType, Parent); templatedFamily.DefaultInstanceKey = DefaultInstanceKey; templatedFamily.Policy = Policy.Clone(); // TODO -- Got a big problem here. Intances need to be copied over - EachInstance(i => - { - ((IDiagnosticInstance)i).AddTemplatedInstanceTo(templatedFamily, templateTypes); - }); + EachInstance(i => { ((IDiagnosticInstance) i).AddTemplatedInstanceTo(templatedFamily, templateTypes); }); // Need to attach the new PluginFamily to the old PluginGraph Parent.PluginFamilies.Add(templatedFamily); @@ -364,13 +313,60 @@ public PluginTypeConfiguration GetConfiguration() { - return new PluginTypeConfiguration() - { - Default = GetDefaultInstance(), - PluginType = PluginType, - Policy = _buildPolicy, - Instances = Instances - }; + return new PluginTypeConfiguration + { + Default = GetDefaultInstance(), + PluginType = PluginType, + Policy = _buildPolicy, + Instances = Instances + }; } + + #region properties + + public bool IsGenericTemplate + { + get { return _pluginType.IsGenericTypeDefinition || _pluginType.ContainsGenericParameters; } + } + + public IBuildPolicy Policy + { + get { return _buildPolicy; } + set { _policy = value; } + } + + public int PluginCount + { + get { return _pluggedTypes.Count; } + } + + public int InstanceCount + { + get { return _instances.Count; } + } + + public IEnumerable<IInstance> Instances + { + get { return _instances.GetAll(); } + } + + /// <summary> + /// The CLR Type that defines the "Plugin" interface for the PluginFamily + /// </summary> + public Type PluginType + { + get { return _pluginType; } + } + + /// <summary> + /// The InstanceKey of the default instance of the PluginFamily + /// </summary> + public string DefaultInstanceKey + { + get { return _defaultKey; } + set { _defaultKey = value ?? string.Empty; } + } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/PluginFamilyCollection.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -24,7 +24,7 @@ { if (!_pluginFamilies.ContainsKey(pluginType)) { - PluginFamily family = new PluginFamily(pluginType, _pluginGraph); + var family = new PluginFamily(pluginType, _pluginGraph); Add(family); } @@ -41,7 +41,7 @@ { get { - PluginFamily[] families = new PluginFamily[_pluginFamilies.Count]; + var families = new PluginFamily[_pluginFamilies.Count]; _pluginFamilies.Values.CopyTo(families, 0); return families; } @@ -95,7 +95,7 @@ public void Each(Action<PluginFamily> action) { - foreach (var family in All) + foreach (PluginFamily family in All) { action(family); } Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -40,19 +40,6 @@ _scanners.Add(assemblies); } - public void Scan(Action<AssemblyScanner> action) - { - var scanner = new AssemblyScanner(); - action(scanner); - - AddScanner(scanner); - } - - public void ScanThisAssembly() - { - Scan(x => x.TheCallingAssembly()); - } - public List<Registry> Registries { get { return _registries; } @@ -114,6 +101,19 @@ #endregion + public void Scan(Action<AssemblyScanner> action) + { + var scanner = new AssemblyScanner(); + action(scanner); + + AddScanner(scanner); + } + + public void ScanThisAssembly() + { + Scan(x => x.TheCallingAssembly()); + } + public void AddScanner(AssemblyScanner scanner) { _scanners.Add(scanner); Modified: trunk/Source/StructureMap/Graph/SetterProperty.cs =================================================================== --- trunk/Source/StructureMap/Graph/SetterProperty.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/SetterProperty.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -12,10 +12,10 @@ private readonly PropertyInfo _property; - public SetterProperty(PropertyInfo property) : base() + public SetterProperty(PropertyInfo property) { _property = property; - var att = Attribute.GetCustomAttribute(property, typeof (SetterPropertyAttribute)); + Attribute att = Attribute.GetCustomAttribute(property, typeof (SetterPropertyAttribute)); IsMandatory = att != null; } Modified: trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Reflection; -using StructureMap.Attributes; namespace StructureMap.Graph { @@ -12,7 +11,7 @@ public class SetterPropertyCollection : IEnumerable<SetterProperty> { private readonly Plugin _plugin; - private List<SetterProperty> _properties; + private readonly List<SetterProperty> _properties; public SetterPropertyCollection(Plugin plugin) { @@ -20,12 +19,11 @@ _plugin = plugin; - foreach (PropertyInfo property in plugin.PluggedType.GetProperties()) { if (property.CanWrite && property.GetSetMethod(false) != null) { - SetterProperty setter = new SetterProperty(property); + var setter = new SetterProperty(property); _properties.Add(setter); } } @@ -57,7 +55,7 @@ public SetterProperty MarkSetterAsMandatory(string propertyName) { - var setter = _properties.Find(p => p.Property.Name == propertyName); + SetterProperty setter = _properties.Find(p => p.Property.Name == propertyName); if (setter == null) { throw new StructureMapException(240, propertyName, _plugin.PluggedType); Modified: trunk/Source/StructureMap/Graph/TypePath.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypePath.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/TypePath.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -65,7 +65,7 @@ public static string GetAssemblyQualifiedName(Type type) { - TypePath path = new TypePath(type); + var path = new TypePath(type); return path.AssemblyQualifiedName; } @@ -84,7 +84,7 @@ public override bool Equals(object obj) { - TypePath peer = obj as TypePath; + var peer = obj as TypePath; if (peer == null) { return false; Modified: trunk/Source/StructureMap/Graph/TypeRules.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypeRules.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Graph/TypeRules.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -62,7 +62,7 @@ protected bool IsPrimitive(Type type) { - return type.IsPrimitive && !IsString(type) && type != typeof(IntPtr); + return type.IsPrimitive && !IsString(type) && type != typeof (IntPtr); } protected bool IsSimple(Type type) Modified: trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -32,7 +32,7 @@ public InstanceInterceptor Merge(InstanceInterceptor interceptor) { - InstanceInterceptor[] interceptors = new InstanceInterceptor[_interceptors.Length + 1]; + var interceptors = new InstanceInterceptor[_interceptors.Length + 1]; _interceptors.CopyTo(interceptors, 0); interceptors[interceptors.Length - 1] = interceptor; Modified: trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace StructureMap.Interceptors { @@ -33,4 +31,4 @@ _interception = interception; } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/BuildFrame.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildFrame.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/BuildFrame.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -4,9 +4,11 @@ { public class BuildFrame { - private readonly Type _requestedType; - private readonly string _name; private readonly Type _concreteType; + private readonly string _name; + private readonly Type _requestedType; + private BuildFrame _next; + private BuildFrame _parent; public BuildFrame(Type requestedType, string name, Type concreteType) { @@ -30,8 +32,10 @@ get { return _concreteType; } } - private BuildFrame _parent; - private BuildFrame _next; + internal BuildFrame Parent + { + get { return _parent; } + } internal void Attach(BuildFrame next) { @@ -45,24 +49,18 @@ return _parent; } - internal BuildFrame Parent - { - get - { - return _parent; - } - } - public override string ToString() { - return string.Format("RequestedType: {0}, Name: {1}, ConcreteType: {2}", _requestedType, _name, _concreteType); + return string.Format("RequestedType: {0}, Name: {1}, ConcreteType: {2}", _requestedType, _name, + _concreteType); } public bool Equals(BuildFrame obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - return Equals(obj._requestedType, _requestedType) && Equals(obj._name, _name) && Equals(obj._concreteType, _concreteType); + return Equals(obj._requestedType, _requestedType) && Equals(obj._name, _name) && + Equals(obj._concreteType, _concreteType); } public override bool Equals(object obj) Modified: trunk/Source/StructureMap/Pipeline/BuildStack.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildStack.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/BuildStack.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,15 +1,12 @@ -using System.Collections.Generic; - namespace StructureMap.Pipeline { public class BuildStack { - private BuildFrame _root; private BuildFrame _current; + private BuildFrame _root; internal BuildStack() { - } public BuildFrame Root @@ -24,10 +21,7 @@ public BuildFrame Parent { - get - { - return _current.Parent; - } + get { return _current.Parent; } } internal void Push(BuildFrame frame) Modified: trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -51,7 +51,7 @@ public override string ToString() { - return GetType().FullName + " / " + _innerPolicy.ToString(); + return GetType().FullName + " / " + _innerPolicy; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,6 +1,5 @@ using System; using StructureMap.Configuration.DSL; -using StructureMap.Graph; using StructureMap.Interceptors; namespace StructureMap.Pipeline @@ -15,7 +14,7 @@ public ConfiguredInstance OnCreation<TYPE>(Action<TYPE> handler) { - StartupInterceptor<TYPE> interceptor = new StartupInterceptor<TYPE>(handler); + var interceptor = new StartupInterceptor<TYPE>(handler); Interceptor = interceptor; return this; @@ -23,7 +22,7 @@ public ConfiguredInstance EnrichWith<TYPE>(EnrichmentHandler<TYPE> handler) { - EnrichmentInterceptor<TYPE> interceptor = new EnrichmentInterceptor<TYPE>(handler); + var interceptor = new EnrichmentInterceptor<TYPE>(handler); Interceptor = interceptor; return this; @@ -34,7 +33,7 @@ { validateTypeIsArray<PLUGINTYPE>(); - ChildArrayExpression expression = + var expression = new ChildArrayExpression(this, propertyName); return expression; @@ -84,7 +83,7 @@ /// <returns></returns> public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>(string propertyName) { - ChildInstanceExpression child = new ChildInstanceExpression(this, propertyName); + var child = new ChildInstanceExpression(this, propertyName); child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE); return child; @@ -161,7 +160,7 @@ /// <returns></returns> public ConfiguredInstance IsNamedInstance(string instanceKey) { - ReferencedInstance instance = new ReferencedInstance(instanceKey); + var instance = new ReferencedInstance(instanceKey); _instance.setChild(_propertyName, instance); return _instance; @@ -177,7 +176,7 @@ Type pluggedType = typeof (T); ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType); - ConfiguredInstance childInstance = new ConfiguredInstance(pluggedType); + var childInstance = new ConfiguredInstance(pluggedType); _instance.setChild(_propertyName, childInstance); return _instance; @@ -198,21 +197,17 @@ public ConfiguredInstance Is(object value) { - LiteralInstance instance = new LiteralInstance(value); + var instance = new LiteralInstance(value); return Is(instance); } public ConfiguredInstance IsAutoFilled() { - DefaultInstance instance = new DefaultInstance(); + var instance = new DefaultInstance(); return Is(instance); } } #endregion - - #region Nested type: PropertyExpression - - #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,20 +1,15 @@ using System; -using System.Collections.Generic; using StructureMap.Graph; namespace StructureMap.Pipeline { public partial class ConfiguredInstance : ConfiguredInstanceBase<ConfiguredInstance> { - public static Type GetGenericType(Type templateType, params Type[] types) + public ConfiguredInstance(InstanceMemento memento, PluginGraph graph, Type pluginType) + : base(memento, graph, pluginType) { - return templateType.MakeGenericType(types); } - public ConfiguredInstance(InstanceMemento memento, PluginGraph graph, Type pluginType) : base(memento, graph, pluginType) - { - } - public ConfiguredInstance(Type pluggedType, string name) : base(pluggedType, name) { } @@ -26,13 +21,13 @@ public ConfiguredInstance(Type templateType, params Type[] types) : base(GetGenericType(templateType, types)) { - } - #region IStructuredInstance Members + public static Type GetGenericType(Type templateType, params Type[] types) + { + return templateType.MakeGenericType(types); + } - #endregion - protected void setPluggedType(Type pluggedType) { _pluggedType = pluggedType; @@ -41,13 +36,12 @@ protected override void preprocess(PluginFamily family) { - } protected override string getDescription() { string typeName = _pluggedType.AssemblyQualifiedName; - Constructor ctor = new Constructor(_pluggedType); + var ctor = new Constructor(_pluggedType); if (ctor.HasArguments()) { return "Configured " + typeName; @@ -60,10 +54,12 @@ protected override void addTemplatedInstanceTo(PluginFamily family, Type[] templateTypes) { - Type specificType = _pluggedType.IsGenericTypeDefinition ? _pluggedType.MakeGenericType(templateTypes) : _pluggedType; + Type specificType = _pluggedType.IsGenericTypeDefinition + ? _pluggedType.MakeGenericType(templateTypes) + : _pluggedType; if (TypeRules.CanBeCast(family.PluginType, specificType)) { - ConfiguredInstance instance = new ConfiguredInstance(specificType); + var instance = new ConfiguredInstance(specificType); instance._arrays = _arrays; instance._children = _children; instance._properties = _properties; Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using StructureMap.Graph; @@ -16,10 +15,10 @@ public abstract class ConfiguredInstanceBase<T> : Instance, IConfiguredInstance, IStructuredInstance, Copyable { + protected Dictionary<string, Instance[]> _arrays = new Dictionary<string, Instance[]>(); protected Dictionary<string, Instance> _children = new Dictionary<string, Instance>(); + protected Type _pluggedType; protected Dictionary<string, string> _properties = new Dictionary<string, string>(); - protected Dictionary<string, Instance[]> _arrays = new Dictionary<string, Instance[]>(); - protected Type _pluggedType; protected ConfiguredInstanceBase(InstanceMemento memento, PluginGraph graph, Type pluginType) { @@ -41,14 +40,109 @@ } } + #region Copyable Members + Type Copyable.PluggedType + { + get { return _pluggedType; } + } + + Dictionary<string, string> Copyable.Properties + { + get { return _properties; } + } + + Dictionary<string, Instance> Copyable.Children + { + get { return _children; } + } + + Dictionary<string, Instance[]> Copyable.Arrays + { + get { return _arrays; } + } + + #endregion + + #region IConfiguredInstance Members + Type IConfiguredInstance.PluggedType { get { return _pluggedType; } } + Instance[] IConfiguredInstance.GetChildrenArray(string propertyName) + { + return _arrays.ContainsKey(propertyName) ? _arrays[propertyName] : null; + } + string IConfiguredInstance.GetProperty(string propertyName) + { + if (!_properties.ContainsKey(propertyName)) + { + throw new StructureMapException(205, propertyName, Name); + } + return _properties[propertyName]; + } + + object IConfiguredInstance.GetChild(string propertyName, Type pluginType, BuildSession buildSession) + { + return getChild(propertyName, pluginType, buildSession); + } + + object IConfiguredInstance.Build(Type pluginType, BuildSession session, InstanceBuilder builder) + { + if (builder == null) + { + throw new StructureMapException( + 201, _pluggedType.FullName, Name, pluginType); + } + + + try + { + return builder.BuildInstance(this, session); + } + catch (StructureMapException) + { + throw; + } + catch (InvalidCastException ex) + { + throw new StructureMapException(206, ex, Name); + } + catch (Exception ex) + { + throw new StructureMapException(207, ex, Name, pluginType.FullName); + } + } + + bool IConfiguredInstance.HasProperty(string propertyName) + { + return _properties.ContainsKey(propertyName) || _children.ContainsKey(propertyName) || + _arrays.ContainsKey(propertyName); + } + + void IConfiguredInstance.SetProperty(string propertyName, string propertyValue) + { + setProperty(propertyName, propertyValue); + } + + void IConfiguredInstance.SetChild(string name, Instance instance) + { + setChild(name, instance); + } + + void IConfiguredInstance.SetChildArray(string name, Type type, Instance[] children) + { + setChildArray(name, children); + } + + #endregion + + #region IStructuredInstance Members + Instance IStructuredInstance.GetChild(string name) { return _children[name]; @@ -64,6 +158,8 @@ _properties.Remove(name); } + #endregion + protected override object build(Type pluginType, BuildSession session) { InstanceBuilder builder = PluginCache.FindBuilder(_pluggedType); @@ -97,7 +193,7 @@ _pluggedType = plugin.PluggedType; - InstanceMementoPropertyReader reader = new InstanceMementoPropertyReader(this, memento, graph, pluginType); + var reader = new InstanceMementoPropertyReader(this, memento, graph, pluginType); plugin.VisitArguments(reader); } @@ -113,58 +209,6 @@ _arrays.Add(name, array); } - Instance[] IConfiguredInstance.GetChildrenArray(string propertyName) - { - return _arrays.ContainsKey(propertyName) ? _arrays[propertyName] : null; - } - - string IConfiguredInstance.GetProperty(string propertyName) - { - if (!_properties.ContainsKey(propertyName)) - { - throw new StructureMapException(205, propertyName, Name); - } - - return _properties[propertyName]; - } - - object IConfiguredInstance.GetChild(string propertyName, Type pluginType, BuildSession buildSession) - { - return getChild(propertyName, pluginType, buildSession); - } - - object IConfiguredInstance.Build(Type pluginType, BuildSession session, InstanceBuilder builder) - { - if (builder == null) - { - throw new StructureMapException( - 201, _pluggedType.FullName, Name, pluginType); - } - - - try - { - return builder.BuildInstance(this, session); - } - catch (StructureMapException) - { - throw; - } - catch (InvalidCastException ex) - { - throw new StructureMapException(206, ex, Name); - } - catch (Exception ex) - { - throw new StructureMapException(207, ex, Name, pluginType.FullName); - } - } - - bool IConfiguredInstance.HasProperty(string propertyName) - { - return _properties.ContainsKey(propertyName) || _children.ContainsKey(propertyName) || _arrays.ContainsKey(propertyName); - } - protected override Type getConcreteType(Type pluginType) { return _pluggedType; @@ -172,7 +216,7 @@ protected string findPropertyName<T>() { - Plugin plugin = new Plugin(_pluggedType); + var plugin = new Plugin(_pluggedType); string propertyName = plugin.FindArgumentNameForType<T>(); if (string.IsNullOrEmpty(propertyName)) @@ -191,32 +235,17 @@ } } - void IConfiguredInstance.SetProperty(string propertyName, string propertyValue) - { - setProperty(propertyName, propertyValue); - } - protected void setProperty(string propertyName, string propertyValue) { if (string.IsNullOrEmpty(propertyValue)) return; _properties[propertyName] = propertyValue; } - void IConfiguredInstance.SetChild(string name, Instance instance) - { - setChild(name, instance); - } - - void IConfiguredInstance.SetChildArray(string name, Type type, Instance[] children) - { - setChildArray(name, children); - } - protected void mergeIntoThis(Copyable instance) { _pluggedType = instance.PluggedType; - foreach (KeyValuePair<string, string> pair in instance.Properties) + foreach (var pair in instance.Properties) { if (!_properties.ContainsKey(pair.Key)) { @@ -224,7 +253,7 @@ } } - foreach (KeyValuePair<string, Instance> pair in instance.Children) + foreach (var pair in instance.Children) { if (!_children.ContainsKey(pair.Key)) { @@ -234,25 +263,5 @@ _arrays = instance.Arrays; } - - Type Copyable.PluggedType - { - get { return _pluggedType; } - } - - Dictionary<string, string> Copyable.Properties - { - get { return _properties; } - } - - Dictionary<string, Instance> Copyable.Children - { - get { return _children; } - } - - Dictionary<string, Instance[]> Copyable.Arrays - { - get { return _arrays; } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -2,8 +2,6 @@ namespace StructureMap.Pipeline { - - public class ConstructorInstance<T> : ExpressedInstance<ConstructorInstance<T>> { private readonly Func<IContext, T> _builder; @@ -37,7 +35,7 @@ protected override string getDescription() { - return "Instance is created by Func<object> function: " + _builder.ToString(); + return "Instance is created by Func<object> function: " + _builder; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/DefaultInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/DefaultInstance.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/DefaultInstance.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -9,6 +9,11 @@ int x = 1; } + protected override bool doesRecordOnTheStack + { + get { return false; } + } + protected override object build(Type pluginType, BuildSession session) { return session.CreateInstance(pluginType); @@ -18,10 +23,5 @@ { return "Default"; } - - protected override bool doesRecordOnTheStack - { - get { return false; } - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -44,7 +44,7 @@ public void Configure(IConfiguredInstance instance) { - foreach (KeyValuePair<string, object> arg in _args) + foreach (var arg in _args) { if (arg.Value == null) continue; @@ -81,7 +81,7 @@ args.Configure(this); _args = args; - Copyable defaultConfiguration = defaultInstance as Copyable; + var defaultConfiguration = defaultInstance as Copyable; if (defaultConfiguration != null) { mergeIntoThis(defaultConfiguration); Modified: trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -5,7 +5,7 @@ { public class HttpContextBuildPolicy : CacheInterceptor { - private string _prefix = Guid.NewGuid().ToString(); + private readonly string _prefix = Guid.NewGuid().ToString(); public static bool HasContext() { Modified: trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -29,7 +29,7 @@ public IBuildPolicy Clone() { - HybridBuildPolicy policy = new HybridBuildPolicy(); + var policy = new HybridBuildPolicy(); policy.InnerPolicy = InnerPolicy.Clone(); return policy; Modified: trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -15,6 +15,4 @@ void SetChild(string name, Instance instance); void SetChildArray(string name, Type type, Instance[] children); } - - } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Interceptors; @@ -13,7 +11,7 @@ { string key = PluginCache.GetPlugin(type).ConcreteKey; return new ReferencedInstance(key); - } + } } public interface IInstance @@ -44,69 +42,25 @@ _originalName = _name; } - public string Name - { - get { return _name; } - set { _name = value; } - } - - public virtual object Build(Type pluginType, BuildSession session) - { - markBuildStackStart(session, pluginType); - - object rawValue = createRawObject(pluginType, session); - var finalValue = applyInterception(rawValue, pluginType); - - markBuildStackFinish(session); - - return finalValue; - } - - protected virtual void markBuildStackFinish(BuildSession session) - { - if (!doesRecordOnTheStack) return; - - session.BuildStack.Pop(); - } - - protected virtual void markBuildStackStart(BuildSession session, Type pluginType) - { - if (!doesRecordOnTheStack) return; - - session.BuildStack.Push(new BuildFrame(pluginType, Name, getConcreteType(pluginType))); - } - protected virtual bool doesRecordOnTheStack { get { return true; } } - private object createRawObject(Type pluginType, BuildSession session) - { - try - { - return build(pluginType, session); - } - catch (StructureMapException ex) - { - throw; - } - catch (Exception ex) - { - throw new StructureMapException(400, ex); - } - } - public InstanceInterceptor Interceptor { get { return _interceptor; } set { _interceptor = value; } } - - #region IDiagnosticInstance Members + public string Name + { + get { return _name; } + set { _name = value; } + } + bool IDiagnosticInstance.CanBePartOfPluginFamily(PluginFamily family) { return canBePartOfPluginFamily(family); @@ -142,6 +96,50 @@ get { return getDescription(); } } + #endregion + + public virtual object Build(Type pluginType, BuildSession session) + { + markBuildStackStart(session, pluginType); + + object rawValue = createRawObject(pluginType, session); + object finalValue = applyInterception(rawValue, pluginType); + + markBuildStackFinish(session); + + return finalValue; + } + + protected virtual void markBuildStackFinish(BuildSession session) + { + if (!doesRecordOnTheStack) return; + + session.BuildStack.Pop(); + } + + protected virtual void markBuildStackStart(BuildSession session, Type pluginType) + { + if (!doesRecordOnTheStack) return; + + session.BuildStack.Push(new BuildFrame(pluginType, Name, getConcreteType(pluginType))); + } + + private object createRawObject(Type pluginType, BuildSession session) + { + try + { + return build(pluginType, session); + } + catch (StructureMapException ex) + { + throw; + } + catch (Exception ex) + { + throw new StructureMapException(400, ex); + } + } + protected virtual Type getConcreteType(Type pluginType) { return pluginType; @@ -162,8 +160,6 @@ protected abstract string getDescription(); - #endregion - protected void replaceNameIfNotAlreadySet(string name) { if (_name == _originalName) @@ -173,7 +169,6 @@ } - private object applyInterception(object rawValue, Type pluginType) { try @@ -200,7 +195,6 @@ } - internal virtual bool Matches(Plugin plugin) { return false; @@ -219,7 +213,7 @@ public T OnCreation<TYPE>(Action<TYPE> handler) { - StartupInterceptor<TYPE> interceptor = new StartupInterceptor<TYPE>(handler); + var interceptor = new StartupInterceptor<TYPE>(handler); Interceptor = interceptor; return thisInstance; @@ -227,11 +221,10 @@ public T EnrichWith<TYPE>(EnrichmentHandler<TYPE> handler) { - EnrichmentInterceptor<TYPE> interceptor = new EnrichmentInterceptor<TYPE>(handler); + var interceptor = new EnrichmentInterceptor<TYPE>(handler); Interceptor = interceptor; return thisInstance; } } - } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -82,7 +82,7 @@ { throw new StructureMapException(205, name, _memento.InstanceKey); } - + _instance.SetProperty(name, propertyValue); } @@ -97,7 +97,7 @@ { InstanceMemento[] mementoes = _memento.GetChildrenArray(name) ?? new InstanceMemento[0]; - Instance[] children = new Instance[mementoes.Length]; + var children = new Instance[mementoes.Length]; for (int i = 0; i < mementoes.Length; i++) { InstanceMemento memento = mementoes[i]; Modified: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-10-05 02:43:34 UTC (rev 171) +++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2008-10-05 02:50:36 UTC (rev 172) @@ -41,7 +41,7 @@ protected override string getDescription() { - return "Object: " + _object.ToString(); + return "Object: " + _object; } public override string ToString() Modified: trunk/Source/StructureMap/Pipeline/Profile.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Profile.cs 2008-10-05 02... [truncated message content] |
From: <jer...@us...> - 2008-10-05 03:23:12
|
Revision: 173 http://structuremap.svn.sourceforge.net/structuremap/?rev=173&view=rev Author: jeremydmiller Date: 2008-10-05 03:02:08 +0000 (Sun, 05 Oct 2008) Log Message: ----------- One big honking ReSharper cleanup Modified Paths: -------------- trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/ConfigurationExpression.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/Emitting/Parameters/Methods.cs trunk/Source/StructureMap/ErrorMessages.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/IBootstrapper.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/InstanceBuilder.cs trunk/Source/StructureMap/InstanceBuilderList.cs trunk/Source/StructureMap/InstanceCache.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/MementoSource.cs trunk/Source/StructureMap/MemoryInstanceMemento.cs trunk/Source/StructureMap/Model.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/Properties/AssemblyInfo.cs trunk/Source/StructureMap/ReflectionHelper.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/AssemblyInfo.cs trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ConstructorExpressionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.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/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryTester.cs trunk/Source/StructureMap.Testing/Configuration/DefaultInstanceNodeTester.cs trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs trunk/Source/StructureMap.Testing/Configuration/FamilyParserTester.cs trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs trunk/Source/StructureMap.Testing/Configuration/PrimitiveArrayReaderTester.cs trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs trunk/Source/StructureMap.Testing/Configuration/ShortcuttedInstanceNodeTester.cs trunk/Source/StructureMap.Testing/DataAccess/CommandCollectionTester.cs trunk/Source/StructureMap.Testing/DataAccess/CommandFactoryTester.cs trunk/Source/StructureMap.Testing/DataAccess/Commands/ParameterizedQueryFilterTester.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/Debugging.cs trunk/Source/StructureMap.Testing/DataAccess/ExecutionStates/AutoCommitExecutionStateTester.cs trunk/Source/StructureMap.Testing/DataAccess/ExecutionStates/TransactionalExecutionStateTester.cs trunk/Source/StructureMap.Testing/DataAccess/JSON/ArrayTester.cs trunk/Source/StructureMap.Testing/DataAccess/JSON/FieldTester.cs trunk/Source/StructureMap.Testing/DataAccess/JSON/ObjectTester.cs trunk/Source/StructureMap.Testing/DataAccess/MSSQL/MSSQLDatabaseEngineTester.cs trunk/Source/StructureMap.Testing/DataAccess/Parameterization/ParameterTemplateTester.cs trunk/Source/StructureMap.Testing/DataAccess/Parameterization/ParameterizedCommandBuilderTester.cs trunk/Source/StructureMap.Testing/DataAccess/Parameters/TemplateParameterTester.cs trunk/Source/StructureMap.Testing/DataAccess/ReaderSourceCollectionTester.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/MockDataSessionTester.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/Diagnostics/TextReportWriterSmokeTester.cs trunk/Source/StructureMap.Testing/Diagnostics/WriterExtensions.cs trunk/Source/StructureMap.Testing/Examples.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/EmittingTester.cs trunk/Source/StructureMap.Testing/Graph/EnumerationTester.cs trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/ImplicitDefaultTest.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/InterceptorLibraryTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyMergeTester.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/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlAttributeInstanceMementoTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlInstanceMementoTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlTemplaterTester.cs trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs trunk/Source/StructureMap.Testing/InstanceBuilderListTester.cs trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs trunk/Source/StructureMap.Testing/MementoTester.cs trunk/Source/StructureMap.Testing/ModelQueryTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs trunk/Source/StructureMap.Testing/Pipeline/BuildStackTester.cs trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.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/OptionalSetterInjectionTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/SerializedInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/StubBuildSession.cs trunk/Source/StructureMap.Testing/Pipeline/ThreadLocalStoragePolicyTester.cs trunk/Source/StructureMap.Testing/PipelineGraphTester.cs trunk/Source/StructureMap.Testing/SpecificationExtensions.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationDefensiveChecksTester.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/Source/StructureMap.Testing/TestData/DataMother.cs trunk/Source/StructureMap.Testing/TestUtility.cs trunk/Source/StructureMap.Testing/XmlWriting/ElementChecker.cs Removed Paths: ------------- trunk/Source/StructureMap/StructureMap.ndoc Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/BuildSession.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -1,6 +1,5 @@ using System; using System.Collections; -using System.Collections.Generic; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; @@ -10,20 +9,18 @@ { public interface IContext { - T GetInstance<T>(); - - BuildStack BuildStack { get; } Type ParentType { get; } + T GetInstance<T>(); } public class BuildSession : IContext { - private readonly InterceptorLibrary _interceptorLibrary; - private readonly PipelineGraph _pipelineGraph; + private readonly BuildStack _buildStack = new BuildStack(); private readonly InstanceCache _cache = new InstanceCache(); private readonly Cache<Type, object> _defaults; - private readonly BuildStack _buildStack = new BuildStack(); + private readonly InterceptorLibrary _interceptorLibrary; + private readonly PipelineGraph _pipelineGraph; public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) { @@ -46,12 +43,10 @@ public BuildSession(PluginGraph graph) : this(new PipelineGraph(graph), graph.InterceptorLibrary) { - } public BuildSession() : this(new PluginGraph()) { - } @@ -60,6 +55,25 @@ get { return _pipelineGraph; } } + #region IContext Members + + public BuildStack BuildStack + { + get { return _buildStack; } + } + + public Type ParentType + { + get { return _buildStack.Parent.ConcreteType; } + } + + T IContext.GetInstance<T>() + { + return (T) CreateInstance(typeof (T)); + } + + #endregion + public virtual object CreateInstance(Type pluginType, string name) { Instance instance = forType(pluginType).FindInstance(name); @@ -74,7 +88,7 @@ public virtual object CreateInstance(Type pluginType, Instance instance) { object result = _cache.Get(pluginType, instance); - + if (result == null) { result = forType(pluginType).Build(this, instance); @@ -107,7 +121,7 @@ object arrayValue = forType(pluginType).Build(this, instance); array.SetValue(arrayValue, i); - } + } } return array; @@ -129,25 +143,10 @@ _defaults.Store(pluginType, defaultObject); } - public BuildStack BuildStack - { - get { return _buildStack; } - } - public Type ParentType - { - get { return _buildStack.Parent.ConcreteType; } - } - - private IInstanceFactory forType(Type pluginType) { return _pipelineGraph.ForType(pluginType); } - - T IContext.GetInstance<T>() - { - return (T) CreateInstance(typeof (T)); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/ConfigurationExpression.cs =================================================================== --- trunk/Source/StructureMap/ConfigurationExpression.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/ConfigurationExpression.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -10,8 +10,8 @@ public class ConfigurationExpression : Registry { protected readonly GraphLog _log = new GraphLog(); - private readonly List<Registry> _registries = new List<Registry>(); protected readonly ConfigurationParserBuilder _parserBuilder; + private readonly List<Registry> _registries = new List<Registry>(); internal ConfigurationExpression() { @@ -20,9 +20,13 @@ _parserBuilder.PullConfigurationFromAppConfig = false; _registries.Add(this); - } + public bool IncludeConfigurationFromConfigFile + { + set { _parserBuilder.UseAndEnforceExistenceOfDefaultFile = value; } + } + public void AddRegistry<T>() where T : Registry, new() { AddRegistry(new T()); @@ -43,19 +47,10 @@ _parserBuilder.IncludeNode(node, "Xml configuration"); } - public bool IncludeConfigurationFromConfigFile - { - set - { - _parserBuilder.UseAndEnforceExistenceOfDefaultFile = value; - } - - } - internal PluginGraph BuildGraph() { - var parsers = _parserBuilder.GetParsers(); - PluginGraphBuilder builder = new PluginGraphBuilder(parsers, _registries.ToArray(), _log); + ConfigurationParser[] parsers = _parserBuilder.GetParsers(); + var builder = new PluginGraphBuilder(parsers, _registries.ToArray(), _log); return builder.Build(); } Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/Container.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -1,8 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Diagnostics; -using System.Text; using StructureMap.Configuration.DSL; using StructureMap.Diagnostics; using StructureMap.Exceptions; @@ -18,13 +16,13 @@ public class Container : TypeRules, IContainer { private InterceptorLibrary _interceptorLibrary; + private Model _model; private PipelineGraph _pipelineGraph; private PluginGraph _pluginGraph; - private Model _model; public Container(Action<ConfigurationExpression> action) { - ConfigurationExpression expression = new ConfigurationExpression(); + var expression = new ConfigurationExpression(); action(expression); construct(expression.BuildGraph()); @@ -38,11 +36,6 @@ { } - public PluginGraph PluginGraph - { - get { return _pluginGraph; } - } - /// <summary> /// Constructor to create an Container /// </summary> @@ -54,24 +47,6 @@ construct(pluginGraph); } - private void construct(PluginGraph pluginGraph) - { - _interceptorLibrary = pluginGraph.InterceptorLibrary; - - if (!pluginGraph.IsSealed) - { - pluginGraph.Seal(); - } - - _pluginGraph = pluginGraph; - pluginGraph.Log.AssertFailures(); - - _pipelineGraph = new PipelineGraph(pluginGraph); - _model = new Model(_pipelineGraph); - - PluginCache.Compile(); - } - protected MissingFactoryFunction onMissingFactory { set { _pipelineGraph.OnMissingFactory = value; } @@ -79,6 +54,11 @@ #region IContainer Members + public PluginGraph PluginGraph + { + get { return _pluginGraph; } + } + public IModel Model { get { return _model; } @@ -96,7 +76,7 @@ public PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args) { - return (PLUGINTYPE) GetInstance(typeof(PLUGINTYPE), args); + return (PLUGINTYPE) GetInstance(typeof (PLUGINTYPE), args); } public object GetInstance(Type type, ExplicitArguments args) @@ -148,17 +128,6 @@ return getListOfTypeWithSession<T>(session); } - private IList<T> getListOfTypeWithSession<T>(BuildSession session) - { - List<T> list = new List<T>(); - foreach (T instance in forType(typeof (T)).GetAllInstances(session)) - { - list.Add(instance); - } - - return list; - } - public void SetDefaultsToProfile(string profile) { _pipelineGraph.CurrentProfile = profile; @@ -176,8 +145,6 @@ } - - /// <summary> /// Creates a new object instance of the requested type /// </summary> @@ -205,20 +172,10 @@ /// Sets the default instance for the PluginType /// </summary> /// <param name="pluginType"></param> - /// <param name="instance"></param> - public void Inject(Type pluginType, Instance instance) - { - _pipelineGraph.SetDefault(pluginType, instance); - } - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> /// <param name="instanceKey"></param> public void SetDefault(Type pluginType, string instanceKey) { - ReferencedInstance reference = new ReferencedInstance(instanceKey); + var reference = new ReferencedInstance(instanceKey); _pipelineGraph.SetDefault(pluginType, reference); } @@ -229,12 +186,12 @@ public void SetDefault<T>(Instance instance) { - SetDefault(typeof(T), instance); + SetDefault(typeof (T), instance); } public void SetDefault<PLUGINTYPE, CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE { - SetDefault<PLUGINTYPE>(new ConfiguredInstance(typeof(CONCRETETYPE))); + SetDefault<PLUGINTYPE>(new ConfiguredInstance(typeof (CONCRETETYPE))); } @@ -251,7 +208,7 @@ throw new StructureMapException(230, type.FullName); } - Plugin plugin = new Plugin(type); + var plugin = new Plugin(type); if (!plugin.CanBeAutoFilled) { throw new StructureMapException(230, type.FullName); @@ -275,7 +232,7 @@ } - LiteralInstance instance = new LiteralInstance(stub); + var instance = new LiteralInstance(stub); _pipelineGraph.SetDefault(pluginType, instance); } @@ -288,7 +245,7 @@ { lock (this) { - ConfigurationExpression registry = new ConfigurationExpression(); + var registry = new ConfigurationExpression(); configure(registry); PluginGraph graph = registry.Build(); @@ -302,13 +259,13 @@ public string WhatDoIHave() { - WhatDoIHaveWriter writer = new WhatDoIHaveWriter(_pipelineGraph); + var writer = new WhatDoIHaveWriter(_pipelineGraph); return writer.GetText(); } public ExplicitArgsExpression With<T>(T arg) { - return new ExplicitArgsExpression(this).With<T>(arg); + return new ExplicitArgsExpression(this).With(arg); } public IExplicitProperty With(string argName) @@ -318,7 +275,7 @@ public void AssertConfigurationIsValid() { - ValidationBuildSession session = new ValidationBuildSession(_pipelineGraph, _interceptorLibrary); + var session = new ValidationBuildSession(_pipelineGraph, _interceptorLibrary); session.PerformValidations(); if (!session.Success) @@ -327,10 +284,52 @@ } } + public void EjectAllInstancesOf<T>() + { + _pipelineGraph.EjectAllInstancesOf<T>(); + } - #endregion + private void construct(PluginGraph pluginGraph) + { + _interceptorLibrary = pluginGraph.InterceptorLibrary; + + if (!pluginGraph.IsSealed) + { + pluginGraph.Seal(); + } + + _pluginGraph = pluginGraph; + pluginGraph.Log.AssertFailures(); + + _pipelineGraph = new PipelineGraph(pluginGraph); + _model = new Model(_pipelineGraph); + + PluginCache.Compile(); + } + + private IList<T> getListOfTypeWithSession<T>(BuildSession session) + { + var list = new List<T>(); + foreach (T instance in forType(typeof (T)).GetAllInstances(session)) + { + list.Add(instance); + } + + return list; + } + + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + public void Inject(Type pluginType, Instance instance) + { + _pipelineGraph.SetDefault(pluginType, instance); + } + private BuildSession withNewSession() { return new BuildSession(_pipelineGraph, _interceptorLibrary); @@ -341,10 +340,5 @@ { return _pipelineGraph.ForType(type); } - - public void EjectAllInstancesOf<T>() - { - _pipelineGraph.EjectAllInstancesOf<T>(); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -67,7 +67,8 @@ _writer.AddDivider('-'); var contents = new[] { - pluginType.PluginType.AssemblyQualifiedName ?? pluginType.PluginType.Name, string.Empty, + pluginType.PluginType.AssemblyQualifiedName ?? pluginType.PluginType.Name, + string.Empty, string.Empty }; Modified: trunk/Source/StructureMap/Emitting/Parameters/Methods.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/Methods.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/Emitting/Parameters/Methods.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -19,7 +19,8 @@ null, new[] { - typeof (Type), typeof (string), typeof (bool) + typeof (Type), typeof (string), + typeof (bool) }, null); public static MethodInfo GET_CHILD = Modified: trunk/Source/StructureMap/ErrorMessages.cs =================================================================== --- trunk/Source/StructureMap/ErrorMessages.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/ErrorMessages.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Resources; -using System.Text; namespace StructureMap { @@ -14,7 +12,7 @@ for (int i = 0; i < args.Length; i++) { object arg = args[i]; - Type type = arg as Type; + var type = arg as Type; if (type != null) { args[i] = type.AssemblyQualifiedName; @@ -32,8 +30,8 @@ private static string getMessage(int errorCode) { - ResourceManager resources = new ResourceManager(typeof(StructureMapException)); + var resources = new ResourceManager(typeof (StructureMapException)); return resources.GetString(errorCode.ToString()); } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/ExplicitArgsExpression.cs =================================================================== --- trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -38,7 +38,7 @@ /// <returns></returns> public ExplicitArgsExpression With<T>(T arg) { - _args.Set<T>(arg); + _args.Set(arg); return this; } Modified: trunk/Source/StructureMap/IBootstrapper.cs =================================================================== --- trunk/Source/StructureMap/IBootstrapper.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/IBootstrapper.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace StructureMap { public interface IBootstrapper { void BootstrapStructureMap(); } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/IContainer.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; @@ -10,15 +9,16 @@ public interface IContainer { IModel Model { get; } + PluginGraph PluginGraph { get; } T GetInstance<T>(string instanceKey); T GetInstance<T>(); T FillDependencies<T>(); object FillDependencies(Type type); - + IList<T> GetAllInstances<T>(); - + T GetInstance<T>(Instance instance); IList GetAllInstances(Type type); @@ -68,7 +68,6 @@ IExplicitProperty With(string argName); void AssertConfigurationIsValid(); object GetInstance(Type type, ExplicitArguments args); - PluginGraph PluginGraph { get; } void EjectAllInstancesOf<T>(); } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilder.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/InstanceBuilder.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -11,9 +11,7 @@ { private Container _manager; - public InstanceBuilder() - { - } + public InstanceBuilder(){} public abstract Type PluggedType { get; } Modified: trunk/Source/StructureMap/InstanceBuilderList.cs =================================================================== --- trunk/Source/StructureMap/InstanceBuilderList.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/InstanceBuilderList.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -7,9 +7,9 @@ { public class InstanceBuilderList { + private readonly Dictionary<string, Type> _aliases = new Dictionary<string, Type>(); private readonly Dictionary<Type, InstanceBuilder> _builders = new Dictionary<Type, InstanceBuilder>(); private readonly Type _pluginType; - private readonly Dictionary<string, Type> _aliases = new Dictionary<string, Type>(); public InstanceBuilderList(Type pluginType, IEnumerable<Plugin> plugins) @@ -44,7 +44,7 @@ // Add a missing PluggedType if we can if (TypeRules.CanBeCast(_pluginType, pluggedType)) { - Plugin plugin = new Plugin(pluggedType); + var plugin = new Plugin(pluggedType); processPlugin(plugin); return _builders[pluggedType]; @@ -66,7 +66,7 @@ private void processPlugin(Plugin plugin) { - processPlugins(new Plugin[] { plugin }); + processPlugins(new[] {plugin}); } private void processPlugins(IEnumerable<Plugin> plugins) @@ -90,7 +90,7 @@ private List<InstanceBuilder> createInstanceBuilders(IEnumerable<Plugin> plugins) { - List<Plugin> list = new List<Plugin>(); + var list = new List<Plugin>(); foreach (Plugin plugin in plugins) { if (!_builders.ContainsKey(plugin.PluggedType)) @@ -99,13 +99,13 @@ } } - InstanceBuilderAssembly builderAssembly = new InstanceBuilderAssembly(list); + var builderAssembly = new InstanceBuilderAssembly(list); return builderAssembly.Compile(); } public void Add(Plugin plugin) { - Add(new Plugin[] {plugin}); + Add(new[] {plugin}); } public void Add(IEnumerable<Plugin> plugins) Modified: trunk/Source/StructureMap/InstanceCache.cs =================================================================== --- trunk/Source/StructureMap/InstanceCache.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/InstanceCache.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -6,7 +6,8 @@ { internal class InstanceCache { - private Dictionary<Type, Dictionary<Instance, object>> _objects = new Dictionary<Type, Dictionary<Instance, object>>(); + private readonly Dictionary<Type, Dictionary<Instance, object>> _objects = + new Dictionary<Type, Dictionary<Instance, object>>(); private Dictionary<Instance, object> getCache(Type type) { @@ -16,7 +17,7 @@ } else { - Dictionary<Instance, object> cache = new Dictionary<Instance, object>(); + var cache = new Dictionary<Instance, object>(); _objects.Add(type, cache); return cache; } Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -56,10 +56,10 @@ public static InstanceFactory CreateFactoryForType(Type concreteType, ProfileManager profileManager) { - PluginFamily family = new PluginFamily(concreteType); + var family = new PluginFamily(concreteType); family.Seal(); - InstanceFactory factory = new InstanceFactory(family); + var factory = new InstanceFactory(family); Instance instance = family.GetDefaultInstance(); if (instance != null) @@ -134,8 +134,6 @@ return _instances.Retrieve(name); } - #endregion - public void ImportFrom(PluginFamily family) { family.EachInstance(instance => _instances.Fill(instance.Name, instance)); @@ -145,5 +143,7 @@ { _instances.Clear(); } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/InstanceMemento.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/InstanceMemento.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -84,8 +84,8 @@ public virtual Plugin FindPlugin(PluginFamily family) { - Plugin plugin = getPluginByType(family) ?? family.FindPlugin(innerConcreteKey ?? string.Empty) ?? - family.FindPlugin(Plugin.DEFAULT); + Plugin plugin = getPluginByType(family) ?? family.FindPlugin(innerConcreteKey ?? string.Empty) ?? + family.FindPlugin(Plugin.DEFAULT); if (plugin == null) { @@ -120,7 +120,6 @@ try { returnValue = getPropertyValue(Key); - } catch (Exception ex) { @@ -144,7 +143,6 @@ protected abstract string getPropertyValue(string Key); - /// <summary> /// Returns the named child InstanceMemento /// </summary> @@ -229,7 +227,5 @@ return new ConfiguredInstance(this, pluginGraph, pluginType); } - - } } \ No newline at end of file Modified: trunk/Source/StructureMap/MementoSource.cs =================================================================== --- trunk/Source/StructureMap/MementoSource.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/MementoSource.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -13,14 +13,11 @@ [PluginFamily] public abstract class MementoSource { + private readonly Dictionary<string, InstanceMemento> _externalMementos = + new Dictionary<string, InstanceMemento>(); + private InstanceMemento _defaultMemento; - private Dictionary<string, InstanceMemento> _externalMementos = new Dictionary<string, InstanceMemento>(); - private PluginFamily _family; - protected MementoSource() : base() - { - } - public InstanceMemento DefaultMemento { get { return _defaultMemento; } @@ -40,11 +37,7 @@ /// </summary> public abstract string Description { get; } - public PluginFamily Family - { - get { return _family; } - set { _family = value; } - } + public PluginFamily Family { get; set; } /// <summary> /// Retrieves the named InstanceMemento @@ -115,7 +108,7 @@ /// <returns></returns> public InstanceMemento[] GetAllMementos() { - ArrayList list = new ArrayList(); + var list = new ArrayList(); list.AddRange(fetchInternalMementos()); list.AddRange(_externalMementos.Values); Modified: trunk/Source/StructureMap/MemoryInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/MemoryInstanceMemento.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/MemoryInstanceMemento.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -18,7 +18,7 @@ /// <returns></returns> public static MemoryInstanceMemento CreateReferencedInstanceMemento(string referenceKey) { - MemoryInstanceMemento memento = new MemoryInstanceMemento(); + var memento = new MemoryInstanceMemento(); memento._referenceKey = referenceKey; memento._isReference = true; @@ -32,7 +32,7 @@ /// <returns></returns> public static MemoryInstanceMemento CreateDefaultInstanceMemento() { - MemoryInstanceMemento memento = new MemoryInstanceMemento(); + var memento = new MemoryInstanceMemento(); memento._referenceKey = string.Empty; memento._isReference = true; Modified: trunk/Source/StructureMap/Model.cs =================================================================== --- trunk/Source/StructureMap/Model.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/Model.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -8,9 +8,9 @@ { public interface IModel { + IEnumerable<PluginTypeConfiguration> PluginTypes { get; } bool HasDefaultImplementationFor(Type pluginType); bool HasDefaultImplementationFor<T>(); - IEnumerable<PluginTypeConfiguration> PluginTypes { get; } IEnumerable<IInstance> InstancesOf(Type pluginType); IEnumerable<IInstance> InstancesOf<T>(); bool HasImplementationsFor(Type pluginType); @@ -26,9 +26,11 @@ _graph = graph; } + #region IModel Members + public bool HasDefaultImplementationFor(Type pluginType) { - var family = PluginTypes.FirstOrDefault(x => x.PluginType == pluginType); + PluginTypeConfiguration family = PluginTypes.FirstOrDefault(x => x.PluginType == pluginType); return family == null ? false : family.Default != null; } @@ -39,10 +41,7 @@ public IEnumerable<PluginTypeConfiguration> PluginTypes { - get - { - return _graph.PluginTypes; - } + get { return _graph.PluginTypes; } } public IEnumerable<IInstance> InstancesOf(Type pluginType) @@ -52,7 +51,7 @@ public IEnumerable<IInstance> InstancesOf<T>() { - return _graph.InstancesOf(typeof(T)); + return _graph.InstancesOf(typeof (T)); } public bool HasImplementationsFor(Type pluginType) @@ -62,7 +61,9 @@ public bool HasImplementationsFor<T>() { - return HasImplementationsFor(typeof(T)); + return HasImplementationsFor(typeof (T)); } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -19,6 +19,11 @@ private static IContainer _container; private static string _profile = string.Empty; + public static IModel Model + { + get { return container.Model; } + } + private static event Notify _notify; /// <summary> @@ -105,14 +110,6 @@ container.Inject(name, instance); } - public static IModel Model - { - get - { - return container.Model; - } - } - [Obsolete("Please use Inject<PLUGINTYPE>(name) instead.")] public static void InjectStub<PLUGINTYPE>(string name, PLUGINTYPE stub) { Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -3,7 +3,6 @@ using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Pipeline; -using System.Linq; namespace StructureMap { @@ -25,13 +24,12 @@ = new Dictionary<Type, IInstanceFactory>(); private readonly GenericsPluginGraph _genericsGraph = new GenericsPluginGraph(); + private readonly GraphLog _log; private readonly ProfileManager _profileManager; private MissingFactoryFunction _missingFactory = (pluginType, profileManager) => null; - private GraphLog _log; - public PipelineGraph(PluginGraph graph) { _profileManager = graph.ProfileManager; @@ -45,7 +43,7 @@ } else { - InstanceFactory factory = new InstanceFactory(family); + var factory = new InstanceFactory(family); _factories.Add(family.PluginType, factory); } } @@ -56,6 +54,41 @@ get { return _log; } } + public MissingFactoryFunction OnMissingFactory + { + set { _missingFactory = value; } + } + + public string CurrentProfile + { + get { return _profileManager.CurrentProfile; } + set { _profileManager.CurrentProfile = value; } + } + + public IEnumerable<PluginTypeConfiguration> PluginTypes + { + get + { + foreach (PluginTypeConfiguration configuration in _genericsGraph.Families) + { + yield return configuration; + } + + foreach (var pair in _factories) + { + IInstanceFactory factory = pair.Value; + + yield return new PluginTypeConfiguration + { + Default = _profileManager.GetDefault(factory.PluginType), + PluginType = factory.PluginType, + Policy = factory.Policy, + Instances = factory.Instances + }; + } + } + } + public void ImportFrom(PluginGraph graph) { foreach (PluginFamily family in graph.PluginFamilies) @@ -73,17 +106,6 @@ _profileManager.ImportFrom(graph.ProfileManager); } - public MissingFactoryFunction OnMissingFactory - { - set { _missingFactory = value; } - } - - public string CurrentProfile - { - get { return _profileManager.CurrentProfile; } - set { _profileManager.CurrentProfile = value; } - } - public IInstanceFactory ForType(Type pluginType) { createFactoryIfMissing(pluginType); @@ -155,7 +177,7 @@ public void Inject<PLUGINTYPE>(PLUGINTYPE instance) { - LiteralInstance literalInstance = new LiteralInstance(instance); + var literalInstance = new LiteralInstance(instance); ForType(typeof (PLUGINTYPE)).AddInstance(literalInstance); SetDefault(typeof (PLUGINTYPE), literalInstance); } @@ -181,35 +203,9 @@ return new IInstance[0]; } - public IEnumerable<PluginTypeConfiguration> PluginTypes - { - get - { - foreach (PluginTypeConfiguration configuration in _genericsGraph.Families) - { - yield return configuration; - } - - foreach (var pair in _factories) - { - var factory = pair.Value; - - yield return new PluginTypeConfiguration() - { - Default = _profileManager.GetDefault(factory.PluginType), - PluginType = factory.PluginType, - Policy = factory.Policy, - Instances = factory.Instances - }; - } - } - - - } - public List<IInstance> GetAllInstances() { - List<IInstance> list = new List<IInstance>(); + var list = new List<IInstance>(); foreach (var pair in _factories) { Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -18,11 +18,11 @@ // Only used in testing public static PluginGraph BuildFromXml(XmlDocument document) { - GraphLog log = new GraphLog(); + var log = new GraphLog(); ConfigurationParser[] parsers = ConfigurationParserBuilder.GetParsers(document.DocumentElement, log); - PluginGraphBuilder builder = new PluginGraphBuilder(parsers, new Registry[0], log); - + var builder = new PluginGraphBuilder(parsers, new Registry[0], log); + return builder.Build(); } @@ -35,7 +35,7 @@ #region constructors public PluginGraphBuilder(ConfigurationParser parser) - : this(new ConfigurationParser[] {parser}, new Registry[0], new GraphLog()) + : this(new[] {parser}, new Registry[0], new GraphLog()) { } @@ -56,8 +56,8 @@ /// <returns></returns> public PluginGraph Build() { - GraphBuilder graphBuilder = new GraphBuilder(_registries, _graph); - + var graphBuilder = new GraphBuilder(_registries, _graph); + forAllParsers(p => { _graph.Log.StartSource(p.Description); @@ -80,6 +80,5 @@ action(parser); } } - } } \ No newline at end of file Modified: trunk/Source/StructureMap/Properties/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap/Properties/AssemblyInfo.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/Properties/AssemblyInfo.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -7,9 +7,9 @@ // associated with an assembly. // -[assembly : AssemblyTitle("StructureMap")] -[assembly : AssemblyDescription("Main Library")] -[assembly : +[assembly: AssemblyTitle("StructureMap")] +[assembly: AssemblyDescription("Main Library")] +[assembly: InternalsVisibleTo( "StructureMap.AutoMocking, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d9a2a76e43cd9b1b1944b1f3b489a046b33f0bcd755b25cc5d3ed7b18ded38240d6db7578cd986c72d3feb4f94a7ab26fcfa41e3e4f41cf2c029fba91159db05c44d63f0b2bfac24353a07f4a1230dd3d4240340adafa2275277fa083c75958062cd0e60016701db6af7ae718efdf1e802a840595b49c290964255b3c60c494" )] Modified: trunk/Source/StructureMap/ReflectionHelper.cs =================================================================== --- trunk/Source/StructureMap/ReflectionHelper.cs 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/ReflectionHelper.cs 2008-10-05 03:02:08 UTC (rev 173) @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System; using System.Linq.Expressions; using System.Reflection; -using System.Text; namespace StructureMap { @@ -12,13 +9,13 @@ public static PropertyInfo GetProperty<MODEL>(Expression<Func<MODEL, object>> expression) { MemberExpression memberExpression = getMemberExpression(expression); - return (PropertyInfo)memberExpression.Member; + return (PropertyInfo) memberExpression.Member; } public static PropertyInfo GetProperty<MODEL, T>(Expression<Func<MODEL, T>> expression) { MemberExpression memberExpression = getMemberExpression(expression); - return (PropertyInfo)memberExpression.Member; + return (PropertyInfo) memberExpression.Member; } private static MemberExpression getMemberExpression<MODEL, T>(Expression<Func<MODEL, T>> expression) @@ -26,7 +23,7 @@ MemberExpression memberExpression = null; if (expression.Body.NodeType == ExpressionType.Convert) { - var body = (UnaryExpression)expression.Body; + var body = (UnaryExpression) expression.Body; memberExpression = body.Operand as MemberExpression; } else if (expression.Body.NodeType == ExpressionType.MemberAccess) @@ -35,14 +32,12 @@ } - if (memberExpression == null) throw new ArgumentException("Not a member access", "member"); return memberExpression; } public static MethodInfo GetMethod<T>(Expression<Func<T, object>> expression) { - MethodCallExpression methodCall = expression.Body is UnaryExpression ? (MethodCallExpression) ((UnaryExpression) expression.Body).Operand @@ -53,15 +48,14 @@ public static MethodInfo GetMethod<T, U>(Expression<Func<T, U>> expression) { - MethodCallExpression methodCall = (MethodCallExpression)expression.Body; + var methodCall = (MethodCallExpression) expression.Body; return methodCall.Method; } public static MethodInfo GetMethod<T, U, V>(Expression<Func<T, U, V>> expression) { - MethodCallExpression methodCall = (MethodCallExpression)expression.Body; + var methodCall = (MethodCallExpression) expression.Body; return methodCall.Method; } - } -} +} \ No newline at end of file Deleted: trunk/Source/StructureMap/StructureMap.ndoc =================================================================== --- trunk/Source/StructureMap/StructureMap.ndoc 2008-10-05 02:50:36 UTC (rev 172) +++ trunk/Source/StructureMap/StructureMap.ndoc 2008-10-05 03:02:08 UTC (rev 173) @@ -1,299 +0,0 @@ -<project SchemaVersion="1.3"> - <assemblies> - <assembly location="C:\PIC\Code\Catalyst\Application\StructureMap\StructureMap\bin\Debug\StructureMap.dll" documentation="C:\PIC\Code\Catalyst\Application\StructureMap\StructureMap\StructureMap.xml" /> - </assemblies> - <namespaces> - <namespace name="StructureMap"></namespace> - <namespace name="StructureMap.Caching"></namespace> - <namespace name="StructureMap.Emitting"></namespace> - <namespace name="StructureMap.Emitting.Parameters"></namespace> - <namespace name="StructureMap.Logging"></namespace> - <namespace name="StructureMap.Source"></namespace> - <namespace name="StructureMap.Verification"></namespace> - </namespaces> - <documenters> - <documenter name="JavaDoc"> - <property name="OutputDirectory" value=".\doc\" /> - <property name="ShowMissingSummaries" value="False" /> - <property name="ShowMissingRemarks" value="False" /> - <property name="ShowMissingParams" value="False" /> - <property name="ShowMissingReturns" value="False" /> - <property name="ShowMissingValues" value="False" /> - <property name="DocumentExplicitInterfaceImplementations" value="False" /> - <property name="DocumentInternals" value="False" /> - <property name="DocumentProtected" value="True" /> - <property name="DocumentSealedProtected" value="False" /> - <property name="DocumentPrivates" value="False" /> - <property name="DocumentProtectedInternalAsProtected" value="False" /> - <property name="DocumentEmptyNamespaces" value="False" /> - <property name="SkipNamespacesWithoutSummaries" value="False" /> - <property name="EditorBrowsableFilter" value="Off" /> - <property name="IncludeAssemblyVersion" value="False" /> - <property name="CopyrightText" value="" /> - <property name="CopyrightHref" value="" /> - <property name="ReferencesPath" value="" /> - <property name="FeedbackEmailAddress" value="" /> - <property name="UseNamespaceDocSummaries" value="False" /> - <property name="AutoPropertyBackerSummaries" value="False" /> - <property name="AutoDocumentConstructors" value="True" /> - <property name="GetExternalSummaries" value="True" /> - <property name="Preliminary" value="False" /> - <property name="UseNDocXmlFile" value="" /> - <property name="CleanIntermediates" value="False" /> - <property name="DocumentAttributes" value="False" /> - <property name="ShowTypeIdInAttributes" value="False" /> - <property name="DocumentedAttributes" value="" /> - <property name="InheritPlatformSupport" value="True" /> - <property name="DefaultOSSupport" value="all" /> - <property name="SupportCompactFrameworkByDefault" value="False" /> - <property name="SupportMONOFrameworkByDefault" value="False" /> - <property name="AdditionalFrameworkList" value="" /> - <property name="AdditionalOSList" value="" /> - </documenter> - <documenter name="LaTeX"> - <property name="OutputDirectory" value=".\doc\" /> - <property name="TextFileFullName" value="Documentation.tex" /> - <property name="TexFileBaseName" value="Documentation" /> - <property name="LatexCompiler" value="latex" /> - <property name="TexFileFullPath" value=".\doc\Documentation.tex" /> - <property name="ShowMissingSummaries" value="False" /> - <property name="ShowMissingRemarks" value="False" /> - <property name="ShowMissingParams" value="False" /> - <property name="ShowMissingReturns" value="False" /> - <property name="ShowMissingValues" value="False" /> - <property name="DocumentExplicitInterfaceImplementations" value="False" /> - <property name="DocumentInternals" value="False" /> - <property name="DocumentProtected" value="True" /> - <property name="DocumentSealedProtected" value="False" /> - <property name="DocumentPrivates" value="False" /> - <property name="DocumentProtectedInternalAsProtected" value="False" /> - <property name="DocumentEmptyNamespaces" value="False" /> - <property name="SkipNamespacesWithoutSummaries" value="False" /> - <property name="EditorBrowsableFilter" value="Off" /> - <property name="IncludeAssemblyVersion" value="False" /> - <property name="CopyrightText" value="" /> - <property name="CopyrightHref" value="" /> - <property name="ReferencesPath" value="" /> - <property name="FeedbackEmailAddress" value="" /> - <property name="UseNamespaceDocSummaries" value="False" /> - <property name="AutoPropertyBackerSummaries" value="False" /> - <property name="AutoDocumentConstructors" value="True" /> - <property name="GetExternalSummaries" value="True" /> - <property name="Preliminary" value="False" /> - <property name="UseNDocXmlFile" value="" /> - <property name="CleanIntermediates" value="False" /> - <property name="DocumentAttributes" value="False" /> - <property name="ShowTypeIdInAttributes" value="False" /> - <property name="DocumentedAttributes" value="" /> - <property name="InheritPlatformSupport" value="True" /> - <property name="DefaultOSSupport" value="all" /> - <property name="SupportCompactFrameworkByDefault" value="False" /> - <property name="SupportMONOFrameworkByDefault" value="False" /> - <property name="AdditionalFrameworkList" value="" /> - <property name="AdditionalOSList" value="" /> - </documenter> - <documenter name="LinearHtml"> - <property name="IncludeTypeMemberDetails" value="False" /> - <property name="OutputDirectory" value=".\doc\" /> - <property name="MethodParametersInTable" value="False" /> - <property name="TypeIncludeRegexp" value="" /> - <property name="NamespaceExcludeRegexp" value="" /> - <property name="Title" value="An NDoc Documented Class Library" /> - <property name="IncludeHierarchy" value="False" /> - <property name="SortTOCByNamespace" value="True" /> - <property name="HeaderHtml" value="" /> - <property name="FooterHtml" value="" /> - <property name="FilesToInclude" value="" /> - <property name="ShowMissingSummaries" value="False" /> - <property name="ShowMissingRemarks" value="False" /> - <property name="ShowMissingParams" value="False" /> - <property name="ShowMissingReturns" value="False" /> - <property name="ShowMissingValues" value="False" /> - <property name="DocumentExplicitInterfaceImplementations" value="False" /> - <property name="DocumentInternals" value="False" /> - <property name="DocumentProtected" value="True" /> - <property name="DocumentSealedProtected" value="False" /> - <property name="DocumentPrivates" value="False" /> - <property name="DocumentProtectedInternalAsProtected" value="False" /> - <property name="DocumentEmptyNamespaces" value="False" /> - <property name="SkipNamespacesWithoutSummaries" value="False" /> - <property name="EditorBrowsableFilter" value="Off" /> - <property name="IncludeAssemblyVersion" value="False" /> - <property name="CopyrightText" value="" /> - <property name="CopyrightHref" value="" /> - <property name="ReferencesPath" value="" /> - <property name="FeedbackEmailAddress" value="" /> - <property name="UseNamespaceDocSummaries" value="False" /> - <property name="AutoPropertyBackerSummaries" value="False" /> - <property name="AutoDocumentConstructors" value="True" /> - <property name="GetExternalSummaries" value="True" /> - <property name="Preliminary" value="False" /> - <property name="UseNDocXmlFile" value="" /> - <property name="CleanIntermediates" value="False" /> - <property name="DocumentAttributes" value="False" /> - <property name="ShowTypeIdInAttributes" value="False" /> - <property name="DocumentedAttributes" value="" /> - <property name="InheritPlatformSupport" value="True" /> - <property name="DefaultOSSupport" value="all" /> - <property name="SupportCompactFrameworkByDefault" value="False" /> - <property name="SupportMONOFrameworkByDefault" value="False" /> - <property name="AdditionalFrameworkList" value="" /> - <property name="AdditionalOSList" value="" /> - </documenter> - <documenter name="MSDN"> - <property name="OutputDirectory" value=".\doc\" /> - <property name="HtmlHelpName" value="Documentation" /> - <property name="IncludeFavorites" value="False" /> - <property name="Title" value="An NDoc Documented Class Library" /> - <property name="DefaultTOC" value="" /> - <property name=... [truncated message content] |
From: <jer...@us...> - 2008-10-05 03:33:33
|
Revision: 174 http://structuremap.svn.sourceforge.net/structuremap/?rev=174&view=rev Author: jeremydmiller Date: 2008-10-05 03:29:12 +0000 (Sun, 05 Oct 2008) Log Message: ----------- convenience method for configuring Profiles Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-10-05 03:02:08 UTC (rev 173) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-10-05 03:29:12 UTC (rev 174) @@ -3,6 +3,8 @@ namespace StructureMap.Configuration.DSL.Expressions { + + /// <summary> /// Expression class to help define a runtime Profile /// </summary> @@ -28,6 +30,17 @@ return new InstanceDefaultExpression<T>(this); } + public IsExpression<T> Type<T>() + { + return new InstanceExpression<T>(instance => + { + _registry.addExpression(graph => + { + graph.SetDefault(_profileName, typeof(T), instance); + }); + }); + } + /// <summary> /// Use statement to define the Profile defaults for a Generic type /// </summary> Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-05 03:02:08 UTC (rev 173) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-05 03:29:12 UTC (rev 174) @@ -121,6 +121,12 @@ return expression; } + public void CreateProfile(string profileName, Action<ProfileExpression> action) + { + var expression = new ProfileExpression(profileName, this); + action(expression); + } + public static bool IsPublicRegistry(Type type) { if (!typeof (Registry).IsAssignableFrom(type)) Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2008-10-05 03:02:08 UTC (rev 173) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2008-10-05 03:29:12 UTC (rev 174) @@ -89,6 +89,16 @@ return child; } + public ChildInstanceExpression CtorDependency<CONSTRUCTORARGUMENTTYPE>(string propertyName) + { + return Child(propertyName); + } + + public ChildInstanceExpression SetterDependency<CONSTRUCTORARGUMENTTYPE>(string propertyName) + { + return Child(propertyName); + } + /// <summary> /// Start the definition of a primitive argument to a constructor argument /// </summary> @@ -99,6 +109,11 @@ return new PropertyExpression<ConfiguredInstance>(this, propertyName); } + public PropertyExpression<ConfiguredInstance> WithCtorArg(string propertyName) + { + return new PropertyExpression<ConfiguredInstance>(this, propertyName); + } + #region Nested type: ChildArrayExpression public class ChildArrayExpression Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-10-05 03:02:08 UTC (rev 173) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-10-05 03:29:12 UTC (rev 174) @@ -34,7 +34,28 @@ Assert.IsInstanceOfType(typeof (DefaultRule), manager.GetInstance<Rule>()); } + [Test] + public void Add_default_instance_by_lambda2() + { + string theProfileName = "something"; + + IContainer manager = new Container(registry => + { + registry.CreateProfile(theProfileName, x => + { + x.Type<IWidget>().Is.ConstructedBy(() => new AWidget()); + x.Type<Rule>().Is.ConstructedBy(() => new DefaultRule()); + }); + }); + + manager.SetDefaultsToProfile(theProfileName); + + Assert.IsInstanceOfType(typeof(AWidget), manager.GetInstance<IWidget>()); + Assert.IsInstanceOfType(typeof(DefaultRule), manager.GetInstance<Rule>()); + } + + [Test] public void Add_default_instance_by_prototype() { string theProfileName = "something"; Modified: trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs 2008-10-05 03:02:08 UTC (rev 173) +++ trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs 2008-10-05 03:29:12 UTC (rev 174) @@ -1,10 +1,22 @@ using NUnit.Framework; +using StructureMap.Configuration.DSL; using StructureMap.Testing.GenericWidgets; using StructureMap.Testing.TestData; +using StructureMap.Testing.Widget; using StructureMap.Testing.Widget3; +using StructureMap.Testing.Widget5; namespace StructureMap.Testing { + public class InitializeRegistry : Registry + { + public InitializeRegistry() + { + InstanceOf<IWidget>().Is.OfConcreteType<ColorWidget>().WithCtorArg("color").EqualTo("Green").WithName( + "Green"); + } + } + [TestFixture] public class ObjectFactoryInitializeTester { @@ -23,6 +35,18 @@ [Test] + public void Add_a_registry_by_generic_signature() + { + ObjectFactory.Initialize(x => + { + x.IgnoreStructureMapConfig = true; + x.AddRegistry<InitializeRegistry>(); + }); + + ObjectFactory.GetNamedInstance<IWidget>("Green").ShouldBeOfType<ColorWidget>().Color.ShouldEqual("Green"); + } + + [Test] public void StructureMap_functions_without_StructureMapconfig_file_in_the_default_mode() { DataMother.RemoveStructureMapConfig(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-08 19:29:46
|
Revision: 178 http://structuremap.svn.sourceforge.net/structuremap/?rev=178&view=rev Author: jeremydmiller Date: 2008-10-08 19:29:40 +0000 (Wed, 08 Oct 2008) Log Message: ----------- little fix for Kevin Modified Paths: -------------- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs trunk/Source/StructureMap/Configuration/XmlExtensions.cs trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Interceptors/Interceptors.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-10-08 18:14:10 UTC (rev 177) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2008-10-08 19:29:40 UTC (rev 178) @@ -71,6 +71,9 @@ public void ForEachFile(GraphLog log, Action<string> action) { string includePath = getIncludePath(); + + // Find the text in every child node of _structureMapNode and + // perform an action with that text _structureMapNode.ForTextInChild("Include/@File").Do(fileName => { string includedFile = Path.Combine(includePath, fileName); Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-10-08 18:14:10 UTC (rev 177) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-10-08 19:29:40 UTC (rev 178) @@ -85,12 +85,12 @@ { foreach (ConfigurationParser parser in list.ToArray()) { - parser.ForEachFile(_log, - filename => _log.Try(() => - { - ConfigurationParser childParser = ConfigurationParser.FromFile(filename); - list.Add(childParser); - }).AndReportErrorAs(150, filename)); + parser.ForEachFile(_log, filename => _log.Try(() => + { + ConfigurationParser childParser = ConfigurationParser.FromFile(filename); + list.Add(childParser); + }) + .AndReportErrorAs(150, filename)); } } Modified: trunk/Source/StructureMap/Configuration/XmlExtensions.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-10-08 18:14:10 UTC (rev 177) +++ trunk/Source/StructureMap/Configuration/XmlExtensions.cs 2008-10-08 19:29:40 UTC (rev 178) @@ -16,6 +16,26 @@ return new XmlTextExpression(node, xpath); } + public class XmlTextExpression + { + private readonly XmlNodeList _list; + + internal XmlTextExpression(XmlNode parent, string attributePath) + { + _list = parent.SelectNodes(attributePath); + } + + public void Do(Action<string> action) + { + if (_list == null) return; + + foreach (XmlNode node in _list) + { + action(node.InnerText); + } + } + } + public static XmlNodeExpression ForEachChild(this XmlNode node, string xpath) { return new XmlNodeExpression(node, xpath); @@ -93,26 +113,8 @@ #region Nested type: XmlTextExpression - public class XmlTextExpression - { - private readonly XmlNodeList _list; - internal XmlTextExpression(XmlNode parent, string attributePath) - { - _list = parent.SelectNodes(attributePath); - } - public void Do(Action<string> action) - { - if (_list == null) return; - - foreach (XmlNode node in _list) - { - action(node.InnerText); - } - } - } - #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2008-10-08 18:14:10 UTC (rev 177) +++ trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2008-10-08 19:29:40 UTC (rev 178) @@ -134,6 +134,7 @@ writer.WriteLine(); + writer.WriteLine("StructureMap Failures: {0} Build/Configuration Failures and {1} Validation Errors", _errors.BuildErrors.Length, _validationErrors.Count); Modified: trunk/Source/StructureMap/Interceptors/Interceptors.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/Interceptors.cs 2008-10-08 18:14:10 UTC (rev 177) +++ trunk/Source/StructureMap/Interceptors/Interceptors.cs 2008-10-08 19:29:40 UTC (rev 178) @@ -1,4 +1,4 @@ namespace StructureMap.Interceptors { - public delegate T EnrichmentHandler<T>(T target); + public delegate object EnrichmentHandler<T>(T target); } \ No newline at end of file Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-10-08 18:14:10 UTC (rev 177) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-10-08 19:29:40 UTC (rev 178) @@ -11,7 +11,7 @@ public delegate void VoidMethod(); - public enum MockMode { Record, Replay } + public enum MockMode { RecordAndReplay, AAA } // Note that it subclasses the RhinoMocks.MockRepository class /// <summary> @@ -23,7 +23,7 @@ private readonly AutoMockedContainer _container; private TARGETCLASS _classUnderTest; - public RhinoAutoMocker() : this(MockMode.Record) {} + public RhinoAutoMocker() : this(MockMode.RecordAndReplay) {} public RhinoAutoMocker(MockMode mockMode) { @@ -37,9 +37,9 @@ { switch (mockMode) { - case MockMode.Record: + case MockMode.RecordAndReplay: return MockCreationStrategy.RecordMode; - case MockMode.Replay: + case MockMode.AAA: return MockCreationStrategy.ReplayMode; default: throw new InvalidOperationException("Unsupported MockMode " + mockMode); Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-10-08 18:14:10 UTC (rev 177) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-10-08 19:29:40 UTC (rev 178) @@ -335,7 +335,7 @@ [Test] public void TheAutoMockerOptionallyPushesInMocksInReplayModeToAllowForAAAsyntax() { - var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.Replay); + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.AAA); autoMocker.ClassUnderTest.CallService(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2008-10-10 21:11:07
|
Revision: 181 http://structuremap.svn.sourceforge.net/structuremap/?rev=181&view=rev Author: flimflan Date: 2008-10-10 21:11:00 +0000 (Fri, 10 Oct 2008) Log Message: ----------- Enabled non-generic GetAllInstances with explicit arguments. Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs Removed Paths: ------------- trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-10-08 20:38:53 UTC (rev 180) +++ trunk/Source/StructureMap/Container.cs 2008-10-10 21:11:00 UTC (rev 181) @@ -91,6 +91,15 @@ return session.CreateInstance(type, instance); } + public IList GetAllInstances(Type type, ExplicitArguments args) + { + BuildSession session = withNewSession(); + + args.RegisterDefaults(session); + + return forType(type).GetAllInstances(session); + } + public IList<T> GetAllInstances<T>(ExplicitArguments args) { BuildSession session = withNewSession(); Modified: trunk/Source/StructureMap/ExplicitArgsExpression.cs =================================================================== --- trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-10-08 20:38:53 UTC (rev 180) +++ trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-10-10 21:11:00 UTC (rev 181) @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using StructureMap.Pipeline; @@ -77,5 +78,11 @@ { return _container.GetAllInstances<T>(_args); } + + public IList GetAllInstances(Type type) + { + return _container.GetAllInstances(type, _args); + } + } } \ No newline at end of file Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-10-08 20:38:53 UTC (rev 180) +++ trunk/Source/StructureMap/IContainer.cs 2008-10-10 21:11:00 UTC (rev 181) @@ -61,6 +61,7 @@ /// <returns></returns> object GetInstance(Type pluginType, string instanceKey); + IList GetAllInstances(Type type, ExplicitArguments args); IList<T> GetAllInstances<T>(ExplicitArguments args); T GetInstance<T>(ExplicitArguments args); Deleted: trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs 2008-10-08 20:38:53 UTC (rev 180) +++ trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs 2008-10-10 21:11:00 UTC (rev 181) @@ -1,415 +0,0 @@ -using System.Collections.Generic; -using NUnit.Framework; -using StructureMap.Pipeline; -using StructureMap.Testing.Pipeline; - -namespace StructureMap.Testing.Graph -{ - [TestFixture] - public class ExplicitArgumentTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - ObjectFactory.Initialize(x => { x.UseDefaultStructureMapConfigFile = false; }); - } - - #endregion - - 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 Example() - { - IContainer container = new Container(); - var theTrade = new Trade(); - - var view = container.With(theTrade).GetInstance<TradeView>(); - - view.Trade.ShouldBeTheSameAs(theTrade); - } - - [Test] - public void Explicit_services_are_used_throughout_the_object_graph() - { - var theTrade = new Trade(); - - IContainer container = new Container(r => - { - r.ForRequestedType<IView>().TheDefaultIsConcreteType<TradeView>(); - r.ForRequestedType<Node>().TheDefaultIsConcreteType<TradeNode>(); - }); - - var command = container.With(theTrade).GetInstance<Command>(); - - command.Trade.ShouldBeTheSameAs(theTrade); - command.Node.IsType<TradeNode>().Trade.ShouldBeTheSameAs(theTrade); - command.View.IsType<TradeView>().Trade.ShouldBeTheSameAs(theTrade); - } - - [Test] - public void ExplicitArguments_can_return_child_by_name() - { - var args = new ExplicitArguments(); - var theNode = new Node(); - args.SetArg("node", theNode); - - IConfiguredInstance instance = new ExplicitInstance(typeof (Command), args, null); - - Assert.AreSame(theNode, instance.GetChild("node", typeof (Node), new StubBuildSession())); - } - - [Test] - public void Fill_in_argument_by_name() - { - var container = new Container(); - container.SetDefault<IView, View>(); - - var theNode = new Node(); - var theTrade = new Trade(); - - var command = container - .With("node").EqualTo(theNode) - .With(theTrade) - .GetInstance<Command>(); - - Assert.IsInstanceOfType(typeof (View), command.View); - Assert.AreSame(theNode, command.Node); - Assert.AreSame(theTrade, command.Trade); - } - - [Test] - public void NowDoItWithObjectFactoryItself() - { - ObjectFactory.Initialize(x => - { - x.ForConcreteType<ExplicitTarget>().Configure - .CtorDependency<IProvider>().Is<RedProvider>() - .WithCtorArg("name").EqualTo("Jeremy"); - }); - - // Get the ExplicitTarget without setting an explicit arg for IProvider - var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); - Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); - - // Now, set the explicit arg for IProvider - var theBlueProvider = new BlueProvider(); - var secondTarget = ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>(); - Assert.AreSame(theBlueProvider, secondTarget.Provider); - } - - [Test] - public void NowDoItWithObjectFactoryItself_with_new_API() - { - ObjectFactory.Initialize(x => - { - x.ForRequestedType<ExplicitTarget>().TheDefault.Is.OfConcreteType<ExplicitTarget>() - .CtorDependency<IProvider>().Is(child => child.OfConcreteType<RedProvider>()) - .WithCtorArg("name").EqualTo("Jeremy"); - }); - - // Get the ExplicitTarget without setting an explicit arg for IProvider - ObjectFactory.GetInstance<ExplicitTarget>().Provider.IsType<RedProvider>(); - - // Now, set the explicit arg for IProvider - var theBlueProvider = new BlueProvider(); - ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>() - .Provider.ShouldBeTheSameAs(theBlueProvider); - } - - [Test] - public void OverrideAPrimitiveWithObjectFactory() - { - ObjectFactory.Initialize(x => - { - x.ForConcreteType<ExplicitTarget>().Configure - .CtorDependency<IProvider>().Is<RedProvider>() - .WithCtorArg("name").EqualTo("Jeremy"); - }); - - // Get the ExplicitTarget without setting an explicit arg for IProvider - var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); - Assert.AreEqual("Jeremy", firstTarget.Name); - - // Now, set the explicit arg for IProvider - var secondTarget = ObjectFactory.With("name").EqualTo("Julia").GetInstance<ExplicitTarget>(); - Assert.AreEqual("Julia", secondTarget.Name); - } - - [Test] - public void pass_explicit_service_into_all_instances() - { - // The Container is constructed with 2 instances - // of TradeView - var container = new Container(r => - { - r.ForRequestedType<TradeView>() - .TheDefaultIsConcreteType<TradeView>() - .AddConcreteType<SecuredTradeView>(); - }); - - var theTrade = new Trade(); - - IList<TradeView> views = container.With(theTrade).GetAllInstances<TradeView>(); - - views[0].Trade.ShouldBeTheSameAs(theTrade); - views[1].Trade.ShouldBeTheSameAs(theTrade); - } - - [Test] - public void Pass_in_arguments_as_dictionary() - { - var manager = new Container(); - manager.SetDefault<IView, View>(); - - var theNode = new Node(); - var theTrade = new Trade(); - - var args = new ExplicitArguments(); - args.Set(theNode); - args.SetArg("trade", theTrade); - - var command = manager.GetInstance<Command>(args); - - Assert.IsInstanceOfType(typeof (View), command.View); - Assert.AreSame(theNode, command.Node); - Assert.AreSame(theTrade, command.Trade); - } - - - [Test] - public void PassAnArgumentIntoExplicitArgumentsForARequestedInterface() - { - IContainer manager = - new Container( - registry => registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<LumpProvider>()); - - var args = new ExplicitArguments(); - var theLump = new Lump(); - args.Set(theLump); - - var instance = (LumpProvider) manager.GetInstance<IProvider>(args); - Assert.AreSame(theLump, instance.Lump); - } - - [Test] - public void PassAnArgumentIntoExplicitArgumentsForARequestedInterfaceUsingObjectFactory() - { - ObjectFactory.Initialize(x => { x.ForRequestedType<IProvider>().TheDefaultIsConcreteType<LumpProvider>(); }); - - - var theLump = new Lump(); - - var provider = (LumpProvider) ObjectFactory.With(theLump).GetInstance<IProvider>(); - Assert.AreSame(theLump, provider.Lump); - } - - [Test] - public void PassAnArgumentIntoExplicitArgumentsThatMightNotAlreadyBeRegistered() - { - var theLump = new Lump(); - var provider = ObjectFactory.With(theLump).GetInstance<LumpProvider>(); - Assert.AreSame(theLump, provider.Lump); - } - - [Test] - public void PassExplicitArgsIntoInstanceManager() - { - var container = new Container(r => - { - r.ForConcreteType<ExplicitTarget>().Configure - .CtorDependency<IProvider>().Is<RedProvider>() - .WithCtorArg("name").EqualTo("Jeremy"); - }); - - var args = new ExplicitArguments(); - - // Get the ExplicitTarget without setting an explicit arg for IProvider - var firstTarget = container.GetInstance<ExplicitTarget>(args); - Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); - - // Now, set the explicit arg for IProvider - args.Set<IProvider>(new BlueProvider()); - var secondTarget = container.GetInstance<ExplicitTarget>(args); - Assert.IsInstanceOfType(typeof (BlueProvider), secondTarget.Provider); - } - - [Test] - public void RegisterAndFindServicesOnTheExplicitArgument() - { - var args = new ExplicitArguments(); - Assert.IsNull(args.Get<IProvider>()); - - var 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() - { - var 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")); - } - } - - public class Lump - { - } - - public class LumpProvider : ExplicitArgumentTester.IProvider - { - private readonly Lump _lump; - - public LumpProvider(Lump lump) - { - _lump = lump; - } - - - public Lump Lump - { - get { return _lump; } - } - } - - - public class Trade - { - } - - public class TradeView : IView - { - private readonly Trade _trade; - - public TradeView(Trade trade) - { - _trade = trade; - } - - public Trade Trade - { - get { return _trade; } - } - } - - public class SecuredTradeView : TradeView - { - public SecuredTradeView(Trade trade) : base(trade) - { - } - } - - public class Node - { - } - - public interface IView - { - } - - public class View : IView - { - } - - public class Command - { - private readonly Node _node; - private readonly Trade _trade; - private readonly IView _view; - - public Command(Trade trade, Node node, IView view) - { - _trade = trade; - _node = node; - _view = view; - } - - public Trade Trade - { - get { return _trade; } - } - - public Node Node - { - get { return _node; } - } - - public IView View - { - get { return _view; } - } - } - - public class TradeNode : Node - { - private readonly Trade _trade; - - public TradeNode(Trade trade) - { - _trade = trade; - } - - public Trade Trade - { - get { return _trade; } - } - } -} \ No newline at end of file Copied: trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs (from rev 180, trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs) =================================================================== --- trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs 2008-10-10 21:11:00 UTC (rev 181) @@ -0,0 +1,437 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; +using StructureMap.Pipeline; +using StructureMap.Testing.Pipeline; + +namespace StructureMap.Testing.Graph +{ + [TestFixture] + public class TestExplicitArguments + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + ObjectFactory.Initialize(x => { x.UseDefaultStructureMapConfigFile = false; }); + } + + #endregion + + 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 Example() + { + IContainer container = new Container(); + var theTrade = new Trade(); + + var view = container.With(theTrade).GetInstance<TradeView>(); + + view.Trade.ShouldBeTheSameAs(theTrade); + } + + [Test] + public void Explicit_services_are_used_throughout_the_object_graph() + { + var theTrade = new Trade(); + + IContainer container = new Container(r => + { + r.ForRequestedType<IView>().TheDefaultIsConcreteType<TradeView>(); + r.ForRequestedType<Node>().TheDefaultIsConcreteType<TradeNode>(); + }); + + var command = container.With(theTrade).GetInstance<Command>(); + + command.Trade.ShouldBeTheSameAs(theTrade); + command.Node.IsType<TradeNode>().Trade.ShouldBeTheSameAs(theTrade); + command.View.IsType<TradeView>().Trade.ShouldBeTheSameAs(theTrade); + } + + [Test] + public void ExplicitArguments_can_return_child_by_name() + { + var args = new ExplicitArguments(); + var theNode = new Node(); + args.SetArg("node", theNode); + + IConfiguredInstance instance = new ExplicitInstance(typeof (Command), args, null); + + Assert.AreSame(theNode, instance.GetChild("node", typeof (Node), new StubBuildSession())); + } + + [Test] + public void Fill_in_argument_by_name() + { + var container = new Container(); + container.SetDefault<IView, View>(); + + var theNode = new Node(); + var theTrade = new Trade(); + + var command = container + .With("node").EqualTo(theNode) + .With(theTrade) + .GetInstance<Command>(); + + Assert.IsInstanceOfType(typeof (View), command.View); + Assert.AreSame(theNode, command.Node); + Assert.AreSame(theTrade, command.Trade); + } + + [Test] + public void NowDoItWithObjectFactoryItself() + { + ObjectFactory.Initialize(x => + { + x.ForConcreteType<ExplicitTarget>().Configure + .CtorDependency<IProvider>().Is<RedProvider>() + .WithCtorArg("name").EqualTo("Jeremy"); + }); + + // Get the ExplicitTarget without setting an explicit arg for IProvider + var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); + Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); + + // Now, set the explicit arg for IProvider + var theBlueProvider = new BlueProvider(); + var secondTarget = ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>(); + Assert.AreSame(theBlueProvider, secondTarget.Provider); + } + + [Test] + public void NowDoItWithObjectFactoryItself_with_new_API() + { + ObjectFactory.Initialize(x => + { + x.ForRequestedType<ExplicitTarget>().TheDefault.Is.OfConcreteType<ExplicitTarget>() + .CtorDependency<IProvider>().Is(child => child.OfConcreteType<RedProvider>()) + .WithCtorArg("name").EqualTo("Jeremy"); + }); + + // Get the ExplicitTarget without setting an explicit arg for IProvider + ObjectFactory.GetInstance<ExplicitTarget>().Provider.IsType<RedProvider>(); + + // Now, set the explicit arg for IProvider + var theBlueProvider = new BlueProvider(); + ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>() + .Provider.ShouldBeTheSameAs(theBlueProvider); + } + + [Test] + public void OverrideAPrimitiveWithObjectFactory() + { + ObjectFactory.Initialize(x => + { + x.ForConcreteType<ExplicitTarget>().Configure + .CtorDependency<IProvider>().Is<RedProvider>() + .WithCtorArg("name").EqualTo("Jeremy"); + }); + + // Get the ExplicitTarget without setting an explicit arg for IProvider + var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); + Assert.AreEqual("Jeremy", firstTarget.Name); + + // Now, set the explicit arg for IProvider + var secondTarget = ObjectFactory.With("name").EqualTo("Julia").GetInstance<ExplicitTarget>(); + Assert.AreEqual("Julia", secondTarget.Name); + } + + [Test] + public void pass_explicit_service_into_all_instances() + { + // The Container is constructed with 2 instances + // of TradeView + var container = new Container(r => + { + r.ForRequestedType<TradeView>() + .TheDefaultIsConcreteType<TradeView>() + .AddConcreteType<SecuredTradeView>(); + }); + + var theTrade = new Trade(); + + IList<TradeView> views = container.With(theTrade).GetAllInstances<TradeView>(); + + views[0].Trade.ShouldBeTheSameAs(theTrade); + views[1].Trade.ShouldBeTheSameAs(theTrade); + } + + [Test] + public void pass_explicit_service_into_all_instances_and_retrieve_without_generics() + { + // The Container is constructed with 2 instances + // of TradeView + var container = new Container(r => + { + r.ForRequestedType<TradeView>() + .TheDefaultIsConcreteType<TradeView>() + .AddConcreteType<SecuredTradeView>(); + }); + + var theTrade = new Trade(); + + IList views = container.With(theTrade).GetAllInstances(typeof(TradeView)); + + ((TradeView)views[0]).Trade.ShouldBeTheSameAs(theTrade); + ((TradeView)views[1]).Trade.ShouldBeTheSameAs(theTrade); + } + + + [Test] + public void Pass_in_arguments_as_dictionary() + { + var manager = new Container(); + manager.SetDefault<IView, View>(); + + var theNode = new Node(); + var theTrade = new Trade(); + + var args = new ExplicitArguments(); + args.Set(theNode); + args.SetArg("trade", theTrade); + + var command = manager.GetInstance<Command>(args); + + Assert.IsInstanceOfType(typeof (View), command.View); + Assert.AreSame(theNode, command.Node); + Assert.AreSame(theTrade, command.Trade); + } + + + [Test] + public void PassAnArgumentIntoExplicitArgumentsForARequestedInterface() + { + IContainer manager = + new Container( + registry => registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<LumpProvider>()); + + var args = new ExplicitArguments(); + var theLump = new Lump(); + args.Set(theLump); + + var instance = (LumpProvider) manager.GetInstance<IProvider>(args); + Assert.AreSame(theLump, instance.Lump); + } + + [Test] + public void PassAnArgumentIntoExplicitArgumentsForARequestedInterfaceUsingObjectFactory() + { + ObjectFactory.Initialize(x => { x.ForRequestedType<IProvider>().TheDefaultIsConcreteType<LumpProvider>(); }); + + + var theLump = new Lump(); + + var provider = (LumpProvider) ObjectFactory.With(theLump).GetInstance<IProvider>(); + Assert.AreSame(theLump, provider.Lump); + } + + [Test] + public void PassAnArgumentIntoExplicitArgumentsThatMightNotAlreadyBeRegistered() + { + var theLump = new Lump(); + var provider = ObjectFactory.With(theLump).GetInstance<LumpProvider>(); + Assert.AreSame(theLump, provider.Lump); + } + + [Test] + public void PassExplicitArgsIntoInstanceManager() + { + var container = new Container(r => + { + r.ForConcreteType<ExplicitTarget>().Configure + .CtorDependency<IProvider>().Is<RedProvider>() + .WithCtorArg("name").EqualTo("Jeremy"); + }); + + var args = new ExplicitArguments(); + + // Get the ExplicitTarget without setting an explicit arg for IProvider + var firstTarget = container.GetInstance<ExplicitTarget>(args); + Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); + + // Now, set the explicit arg for IProvider + args.Set<IProvider>(new BlueProvider()); + var secondTarget = container.GetInstance<ExplicitTarget>(args); + Assert.IsInstanceOfType(typeof (BlueProvider), secondTarget.Provider); + } + + [Test] + public void RegisterAndFindServicesOnTheExplicitArgument() + { + var args = new ExplicitArguments(); + Assert.IsNull(args.Get<IProvider>()); + + var 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() + { + var 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")); + } + } + + public class Lump + { + } + + public class LumpProvider : TestExplicitArguments.IProvider + { + private readonly Lump _lump; + + public LumpProvider(Lump lump) + { + _lump = lump; + } + + + public Lump Lump + { + get { return _lump; } + } + } + + + public class Trade + { + } + + public class TradeView : IView + { + private readonly Trade _trade; + + public TradeView(Trade trade) + { + _trade = trade; + } + + public Trade Trade + { + get { return _trade; } + } + } + + public class SecuredTradeView : TradeView + { + public SecuredTradeView(Trade trade) : base(trade) + { + } + } + + public class Node + { + } + + public interface IView + { + } + + public class View : IView + { + } + + public class Command + { + private readonly Node _node; + private readonly Trade _trade; + private readonly IView _view; + + public Command(Trade trade, Node node, IView view) + { + _trade = trade; + _node = node; + _view = view; + } + + public Trade Trade + { + get { return _trade; } + } + + public Node Node + { + get { return _node; } + } + + public IView View + { + get { return _view; } + } + } + + public class TradeNode : Node + { + private readonly Trade _trade; + + public TradeNode(Trade trade) + { + _trade = trade; + } + + public Trade Trade + { + get { return _trade; } + } + } +} \ No newline at end of file Property changes on: trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-08 20:38:53 UTC (rev 180) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-10 21:11:00 UTC (rev 181) @@ -224,7 +224,7 @@ <Compile Include="Graph\ExceptionHandling\StructureMapExceptionTester.cs"> <SubType>Code</SubType> </Compile> - <Compile Include="Graph\ExplicitArgumentTester.cs" /> + <Compile Include="Graph\TestExplicitArguments.cs" /> <Compile Include="Graph\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: <fli...@us...> - 2008-10-17 19:00:42
|
Revision: 183 http://structuremap.svn.sourceforge.net/structuremap/?rev=183&view=rev Author: flimflan Date: 2008-10-17 19:00:37 +0000 (Fri, 17 Oct 2008) Log Message: ----------- Added ability to provide a default value to EqualToAppSetting if the appSetting key does not exist Modified Paths: -------------- trunk/Source/StructureMap/Pipeline/PropertyExpression.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs Modified: trunk/Source/StructureMap/Pipeline/PropertyExpression.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2008-10-17 14:40:26 UTC (rev 182) +++ trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2008-10-17 19:00:37 UTC (rev 183) @@ -31,13 +31,26 @@ /// Sets the value of the constructor argument to the key/value in the /// AppSettings /// </summary> - /// <param name="appSettingKey"></param> + /// <param name="appSettingKey">The key in appSettings for the value to use.</param> /// <returns></returns> public T EqualToAppSetting(string appSettingKey) { + return EqualToAppSetting(appSettingKey, null); + } + + /// <summary> + /// Sets the value of the constructor argument to the key/value in the + /// AppSettings when it exists. Otherwise uses the provided default value. + /// </summary> + /// <param name="appSettingKey">The key in appSettings for the value to use.</param> + /// <param name="defaultValue">The value to use if an entry for <paramref name="appSettingKey"/> does not exist in the appSettings section.</param> + /// <returns></returns> + public T EqualToAppSetting(string appSettingKey, string defaultValue) + { string propertyValue = ConfigurationManager.AppSettings[appSettingKey]; + if (propertyValue == null) propertyValue = defaultValue; _instance.SetProperty(_propertyName, propertyValue); - return (T) _instance; + return (T)_instance; } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-10-17 14:40:26 UTC (rev 182) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-10-17 19:00:37 UTC (rev 183) @@ -35,7 +35,13 @@ .WithName("AppSetting") .WithProperty("color").EqualToAppSetting("Color"); + // Pull a property from the App config + registry.InstanceOf<IWidget>() + .Is.OfConcreteType<NotPluggableWidget>() + .WithName("UsesDefaultValue") + .WithProperty("name").EqualToAppSetting("WidgetName", "TheDefaultValue"); + registry.InstanceOf<IWidget>().Is.OfConcreteType<AWidget>(); }); } @@ -71,7 +77,7 @@ .Widget.IsType<AWidget>(); } - [Test, Explicit] + [Test] public void CreateAnInstancePullAPropertyFromTheApplicationConfig() { Assert.AreEqual("Blue", ConfigurationManager.AppSettings["Color"]); @@ -80,6 +86,14 @@ } [Test] + public void CreateAnInstanceUsingDefaultPropertyValueWhenSettingDoesNotExistInApplicationConfig() + { + Assert.AreEqual(null, ConfigurationManager.AppSettings["WidgetName"]); + var widget = (NotPluggableWidget)container.GetInstance<IWidget>("UsesDefaultValue"); + Assert.AreEqual("TheDefaultValue", widget.Name); + } + + [Test] public void SimpleCaseWithNamedInstance() { container = new Container( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-18 13:26:17
|
Revision: 186 http://structuremap.svn.sourceforge.net/structuremap/?rev=186&view=rev Author: jeremydmiller Date: 2008-10-18 13:26:11 +0000 (Sat, 18 Oct 2008) Log Message: ----------- Added a last minute defensive programming check on TheDefaultInstanceIsConcreteType Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-10-18 13:13:17 UTC (rev 185) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-10-18 13:26:11 UTC (rev 186) @@ -71,6 +71,11 @@ ExpressionValidator.ValidatePluggabilityOf(concreteType).IntoPluginType(_pluginType); + if (!PluginCache.GetPlugin(concreteType).CanBeAutoFilled) + { + throw new StructureMapException(231); + } + return alterAndContinue(family => { ConfiguredInstance instance = Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2008-10-18 13:13:17 UTC (rev 185) +++ trunk/Source/StructureMap/StructureMapException.resx 2008-10-18 13:26:11 UTC (rev 186) @@ -262,4 +262,7 @@ <data name="125" xml:space="preserve"> <value>Cannot plug an abstract class or an interface</value> </data> + <data name="231" xml:space="preserve"> + <value>Cannot use the "TheDefaultIsConcreteType" method with an object that has primitive constructor arguments. Use the "TheDefault.Is.OfConcreteType<T>()" method instead and specify the primitive constructor arguments</value> + </data> </root> \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-10-18 13:13:17 UTC (rev 185) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-10-18 13:26:11 UTC (rev 186) @@ -35,7 +35,30 @@ { } + public class ClassWithStringInConstructor + { + public ClassWithStringInConstructor(string name){} + } + [Test] + public void cannot_use_a_class_with_a_primitive_constructor_in_the_TheDefaultIsConcreteType_shortcut() + { + try + { + var container = new Container(x => + { + x.ForRequestedType<ClassWithStringInConstructor>().TheDefaultIsConcreteType + <ClassWithStringInConstructor>(); + }); + Assert.Fail("Should have thrown exception 231"); + } + catch (StructureMapException e) + { + e.ErrorCode.ShouldEqual(231); + } + } + + [Test] public void Add_an_instance_by_lambda() { var manager = This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2008-10-21 22:02:28
|
Revision: 188 http://structuremap.svn.sourceforge.net/structuremap/?rev=188&view=rev Author: flimflan Date: 2008-10-21 22:02:21 +0000 (Tue, 21 Oct 2008) Log Message: ----------- - Added TryGetInstance to container Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap.Testing/Examples.cs trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-10-18 20:49:21 UTC (rev 187) +++ trunk/Source/StructureMap/Container.cs 2008-10-21 22:02:21 UTC (rev 188) @@ -7,6 +7,7 @@ using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; +using System.Linq; namespace StructureMap { @@ -215,8 +216,56 @@ return withNewSession().CreateInstance(pluginType, instanceKey); } + /// <summary> + /// Creates or finds the named instance of the pluginType. Returns null if the named instance is not known to the container. + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + /// <param name="instance"></param> + /// <returns></returns> + public object TryGetInstance(Type pluginType, string instanceKey) + { + return _pipelineGraph.ForType(pluginType).FindInstance(instanceKey) == null + ? null + : GetInstance(pluginType, instanceKey); + } /// <summary> + /// Creates or finds the default instance of the pluginType. Returns null if the pluginType is not known to the container. + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + /// <returns></returns> + public object TryGetInstance(Type pluginType) + { + return !_pipelineGraph.PluginTypes.Any(p => p.PluginType == pluginType) + ? null + : GetInstance(pluginType); + } + + /// <summary> + /// Creates or finds the default instance of type T. Returns the default value of T if it is not known to the container. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="instance"></param> + /// <returns></returns> + public T TryGetInstance<T>() + { + return (T)(TryGetInstance(typeof (T)) ?? default(T)); + } + + /// <summary> + /// Creates or finds the named instance of type T. Returns the default value of T if the named instance is not known to the container. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="instance"></param> + /// <returns></returns> + public T TryGetInstance<T>(string instanceKey) + { + return (T)(TryGetInstance(typeof(T), instanceKey) ?? default(T)); + } + + /// <summary> /// Creates or finds the default instance of the pluginType /// </summary> /// <param name="pluginType"></param> Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2008-10-18 20:49:21 UTC (rev 187) +++ trunk/Source/StructureMap/IContainer.cs 2008-10-21 22:02:21 UTC (rev 188) @@ -76,6 +76,40 @@ /// <returns></returns> IList GetAllInstances(Type pluginType); + /// <summary> + /// Creates or finds the named instance of the pluginType. Returns null if the named instance is not known to the container. + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instanceKey"></param> + /// <param name="instance"></param> + /// <returns></returns> + object TryGetInstance(Type pluginType, string instanceKey); + + /// <summary> + /// Creates or finds the default instance of the pluginType. Returns null if the pluginType is not known to the container. + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + /// <returns></returns> + object TryGetInstance(Type pluginType); + + /// <summary> + /// Creates or finds the default instance of type T. Returns the default value of T if it is not known to the container. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="instance"></param> + /// <returns></returns> + T TryGetInstance<T>(); + + /// <summary> + /// Creates or finds the named instance of type T. Returns the default value of T if the named instance is not known to the container. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="instance"></param> + /// <returns></returns> + T TryGetInstance<T>(string instanceKey); + + [Obsolete("Please use GetInstance<T>() instead.")] T FillDependencies<T>(); @@ -188,6 +222,5 @@ /// </summary> /// <typeparam name="T"></typeparam> void EjectAllInstancesOf<T>(); - } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Examples.cs =================================================================== --- trunk/Source/StructureMap.Testing/Examples.cs 2008-10-18 20:49:21 UTC (rev 187) +++ trunk/Source/StructureMap.Testing/Examples.cs 2008-10-21 22:02:21 UTC (rev 188) @@ -7,7 +7,7 @@ using StructureMap.Configuration.DSL; using StructureMap.Testing.Widget3; -namespace StructureMap.Testing +namespace StructureMap.Testing.DocumentationExamples { public interface IDataProvider { Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2008-10-18 20:49:21 UTC (rev 187) +++ trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2008-10-21 22:02:21 UTC (rev 188) @@ -63,7 +63,9 @@ var scanner = new AssemblyScanner(); action(scanner); theGraph = new PluginGraph(); + scanner.ExcludeNamespaceContainingType<DocumentationExamples.ScanningRegistry>(); scanner.ScanForAll(theGraph); + theGraph.Log.AssertFailures(); } @@ -129,7 +131,7 @@ } [Test] - public void Search_for_registries_by_default() + public void Search_for_registries_when_explicitly_told() { Scan(x => { Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-10-18 20:49:21 UTC (rev 187) +++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-10-21 22:02:21 UTC (rev 188) @@ -195,6 +195,82 @@ Assert.AreEqual("Orange", maker.Color); } + [Test] + public void TryGetInstanceViaName_ReturnsNull_WhenNotFound() + { + addColorInstance("Red"); + addColorInstance("Orange"); + addColorInstance("Blue"); + + var rule = _container.TryGetInstance(typeof(Rule), "Yellow"); + rule.ShouldBeNull(); + } + + [Test] + public void TryGetInstanceViaName_ReturnsTheOutInstance_WhenFound() + { + addColorInstance("Red"); + addColorInstance("Orange"); + addColorInstance("Blue"); + + var rule = _container.TryGetInstance(typeof(Rule), "Orange"); + rule.ShouldBeOfType(typeof(ColorRule)); + } + + [Test] + public void TryGetInstance_ReturnsNull_WhenTypeNotFound() + { + var instance = _container.TryGetInstance(typeof(IProvider)); + instance.ShouldBeNull(); + } + + [Test] + public void TryGetInstance_ReturnsInstance_WhenTypeFound() + { + _container.Configure(c => c.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>()); + var instance = _container.TryGetInstance(typeof(IProvider)); + instance.ShouldBeOfType(typeof(Provider)); + } + + [Test] + public void TryGetInstanceViaGeneric_ReturnsNull_WhenTypeNotFound() + { + var instance = _container.TryGetInstance<IProvider>(); + instance.ShouldBeNull(); + } + + [Test] + public void TryGetInstanceViaGeneric_ReturnsInstance_WhenTypeFound() + { + _container.Configure(c => c.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>()); + var instance = _container.TryGetInstance<IProvider>(); + instance.ShouldBeOfType(typeof(Provider)); + } + + [Test] + public void TryGetInstanceViaNameAndGeneric_ReturnsNull_WhenTypeNotFound() + { + addColorInstance("Red"); + addColorInstance("Orange"); + addColorInstance("Blue"); + + var instance = _container.TryGetInstance<Rule>("Yellow"); + instance.ShouldBeNull(); + } + + [Test] + public void TryGetInstanceViaNameAndGeneric_ReturnsInstance_WhenTypeFound() + { + addColorInstance("Red"); + addColorInstance("Orange"); + addColorInstance("Blue"); + + var instance = _container.TryGetInstance<Rule>("Orange"); + instance.ShouldBeOfType(typeof(ColorRule)); + } + + + [Test, ExpectedException(typeof (StructureMapException))] public void GetMissingType() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-22 14:45:29
|
Revision: 191 http://structuremap.svn.sourceforge.net/structuremap/?rev=191&view=rev Author: jeremydmiller Date: 2008-10-22 14:45:15 +0000 (Wed, 22 Oct 2008) Log Message: ----------- fixing the HybridBuildPolicy and adding a method on ObjectFactory for pushing in a dictionary of arguments Modified Paths: -------------- trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Pipeline/HybridBuildPolicyTester.cs Modified: trunk/Source/StructureMap/ObjectFactory.cs =================================================================== --- trunk/Source/StructureMap/ObjectFactory.cs 2008-10-21 22:15:42 UTC (rev 190) +++ trunk/Source/StructureMap/ObjectFactory.cs 2008-10-22 14:45:15 UTC (rev 191) @@ -366,5 +366,10 @@ } #endregion + + public static T GetInstance<T>(ExplicitArguments args) + { + return container.GetInstance<T>(args); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-10-21 22:15:42 UTC (rev 190) +++ trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-10-22 14:45:15 UTC (rev 191) @@ -5,10 +5,10 @@ { public class ExplicitArguments { - private readonly Dictionary<string, object> _args; - private readonly Dictionary<Type, object> _children = new Dictionary<Type, object>(); + private readonly IDictionary<string, object> _args; + private readonly IDictionary<Type, object> _children = new Dictionary<Type, object>(); - public ExplicitArguments(Dictionary<string, object> args) + public ExplicitArguments(IDictionary<string, object> args) { _args = args; } Modified: trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-10-21 22:15:42 UTC (rev 190) +++ trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-10-22 14:45:15 UTC (rev 191) @@ -4,33 +4,35 @@ { public class HybridBuildPolicy : IBuildInterceptor { - private readonly IBuildInterceptor _innerInterceptor; + private IBuildPolicy _innerPolicy; - - public HybridBuildPolicy() + private IBuildInterceptor interceptor { - _innerInterceptor = HttpContextBuildPolicy.HasContext() - ? (IBuildInterceptor) new HttpContextBuildPolicy() - : new ThreadLocalStoragePolicy(); + get + { + return HttpContextBuildPolicy.HasContext() + ? (IBuildInterceptor)new HttpContextBuildPolicy(){InnerPolicy = _innerPolicy} + : new ThreadLocalStoragePolicy(){InnerPolicy = _innerPolicy}; + } } #region IBuildInterceptor Members public IBuildPolicy InnerPolicy { - get { return _innerInterceptor.InnerPolicy; } - set { _innerInterceptor.InnerPolicy = value; } + get { return _innerPolicy; } + set { _innerPolicy = value; } } public object Build(BuildSession buildSession, Type pluginType, Instance instance) { - return _innerInterceptor.Build(buildSession, pluginType, instance); + return interceptor.Build(buildSession, pluginType, instance); } public IBuildPolicy Clone() { var policy = new HybridBuildPolicy(); - policy.InnerPolicy = InnerPolicy.Clone(); + policy.InnerPolicy = _innerPolicy.Clone(); return policy; } Modified: trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs 2008-10-21 22:15:42 UTC (rev 190) +++ trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs 2008-10-22 14:45:15 UTC (rev 191) @@ -2,6 +2,8 @@ using System.Diagnostics; using System.Linq; using NUnit.Framework; +using StructureMap.Pipeline; +using StructureMap.Testing.Graph; using StructureMap.Testing.TestData; using StructureMap.Testing.Widget; using IList=System.Collections.IList; @@ -22,7 +24,30 @@ #endregion + [Test] + public void Pass_in_arguments_as_dictionary() + { + ObjectFactory.Initialize(x => + { + x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); + }); + + var theNode = new Node(); + var theTrade = new Trade(); + + var args = new ExplicitArguments(); + args.Set(theNode); + args.SetArg("trade", theTrade); + + var command = ObjectFactory.GetInstance<Command>(args); + + Assert.IsInstanceOfType(typeof(View), command.View); + Assert.AreSame(theNode, command.Node); + Assert.AreSame(theTrade, command.Trade); + } + + [Test] public void SmokeTestGetAllInstances() { IList list = ObjectFactory.GetAllInstances(typeof (GrandChild)); Modified: trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2008-10-21 22:15:42 UTC (rev 190) +++ trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2008-10-22 14:45:15 UTC (rev 191) @@ -85,7 +85,7 @@ [Test] public void CloneHybrid() { - var policy = new HybridBuildPolicy(); + var policy = new HybridBuildPolicy(){InnerPolicy = new BuildPolicy()}; var clone = (HybridBuildPolicy) policy.Clone(); Assert.AreNotSame(policy, clone); Added: trunk/Source/StructureMap.Testing/Pipeline/HybridBuildPolicyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/HybridBuildPolicyTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/HybridBuildPolicyTester.cs 2008-10-22 14:45:15 UTC (rev 191) @@ -0,0 +1,35 @@ +using System; +using System.IO; +using System.Text; +using System.Web; +using System.Web.Hosting; +using NUnit.Framework; +using StructureMap.Pipeline; +using StructureMap.Testing.DocumentationExamples; +using StructureMap.Testing.Widget3; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class HybridBuildPolicyTester + { + [Test] + public void run_without_an_httpcontext() + { + var policy = new HybridBuildPolicy(){InnerPolicy = new BuildPolicy()}; + var instance = new SmartInstance<RemoteService>(); + var object1 = policy.Build(new BuildSession(), typeof (IService), instance); + var object2 = policy.Build(new BuildSession(), typeof(IService), instance); + var object3 = policy.Build(new BuildSession(), typeof(IService), instance); + + object1.ShouldNotBeNull(); + object2.ShouldNotBeNull(); + object3.ShouldNotBeNull(); + + object1.ShouldBeTheSameAs(object2).ShouldBeTheSameAs(object3); + } + + } + + +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-21 22:15:42 UTC (rev 190) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-22 14:45:15 UTC (rev 191) @@ -110,6 +110,7 @@ <Name>System.Data</Name> </Reference> <Reference Include="System.Drawing" /> + <Reference Include="System.Web" /> <Reference Include="System.Web.Services" /> <Reference Include="System.Windows.Forms"> <Name>System.Windows.Forms</Name> @@ -322,6 +323,7 @@ <Compile Include="Pipeline\ConfiguredInstanceTester.cs" /> <Compile Include="Pipeline\ConstructorInstanceTester.cs" /> <Compile Include="Pipeline\DefaultInstanceTester.cs" /> + <Compile Include="Pipeline\HybridBuildPolicyTester.cs" /> <Compile Include="Pipeline\InstanceTester.cs" /> <Compile Include="Pipeline\LiteralInstanceTester.cs" /> <Compile Include="Pipeline\OptionalSetterInjectionTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2008-10-23 23:02:19
|
Revision: 192 http://structuremap.svn.sourceforge.net/structuremap/?rev=192&view=rev Author: flimflan Date: 2008-10-23 23:02:07 +0000 (Thu, 23 Oct 2008) Log Message: ----------- - Container.Configure() can now load load configuration from an xml file - configuration file paths are now automatically resolved to an absolute path related to the appdomain (instead of defaulting to the working directory) - GetStructureMapConfigurationPath() has been moved to ConfigurationParserBuilder Modified Paths: -------------- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs trunk/Source/StructureMap.Testing/TestData/Config2.xml Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-10-22 14:45:15 UTC (rev 191) +++ trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2008-10-23 23:02:07 UTC (rev 192) @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.IO; using System.Xml; @@ -103,29 +104,30 @@ IList<XmlNode> appConfigNodes = StructureMapConfigurationSection.GetStructureMapConfiguration(); foreach (XmlNode appConfigNode in appConfigNodes) { - IncludeNode(appConfigNode, string.Empty); + IncludeNode(appConfigNode, String.Empty); } }).AndLogAnyErrors(); } } - private void addConfigurationFromExplicitlyAddedFiles(List<ConfigurationParser> list) + private void addConfigurationFromExplicitlyAddedFiles(ICollection<ConfigurationParser> list) { foreach (string filename in _otherFiles) { + var absolutePath = locateFileAsAbsolutePath(filename); _log.Try(() => { - ConfigurationParser parser = ConfigurationParser.FromFile(filename); - parser.Description = filename; + ConfigurationParser parser = ConfigurationParser.FromFile(absolutePath); + parser.Description = absolutePath; list.Add(parser); - }).AndReportErrorAs(160, filename); + }).AndReportErrorAs(160, absolutePath); } } - private void addConfigurationFromStructureMapConfig(List<ConfigurationParser> list) + private void addConfigurationFromStructureMapConfig(ICollection<ConfigurationParser> list) { // Pick up the configuration in the default StructureMap.config - string pathToStructureMapConfig = StructureMapConfiguration.GetStructureMapConfigurationPath(); + string pathToStructureMapConfig = GetStructureMapConfigurationPath(); if (shouldUseStructureMapConfigFileAt(pathToStructureMapConfig)) { _log.Try(() => @@ -147,10 +149,45 @@ public static ConfigurationParser[] GetParsers(XmlNode node, GraphLog log) { var builder = new ConfigurationParserBuilder(log); - builder.IncludeNode(node, string.Empty); + builder.IncludeNode(node, String.Empty); builder.IgnoreDefaultFile = true; return builder.GetParsers(); } + + /// <summary> + /// The name of the default configuration file. The value is always <c>StructurMap.config</c> + /// </summary> + public static readonly string DefaultConfigurationFilename = "StructureMap.config"; + + /// <summary> + /// Returns the absolute path to the StructureMap.config file + /// </summary> + /// <returns></returns> + public static string GetStructureMapConfigurationPath() + { + return locateFileAsAbsolutePath(DefaultConfigurationFilename); + } + + private static string locateFileAsAbsolutePath(string filename) + { + if (Path.IsPathRooted(filename)) return filename; + var basePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; + var configPath = Path.Combine(basePath, filename); + + if (!File.Exists(configPath)) + { + configPath = Path.Combine(basePath, "bin"); + configPath = Path.Combine(configPath, filename); + + if (!File.Exists(configPath)) + { + configPath = Path.Combine(basePath, ".."); + configPath = Path.Combine(configPath, filename); + } + } + + return configPath; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-10-22 14:45:15 UTC (rev 191) +++ trunk/Source/StructureMap/Container.cs 2008-10-23 23:02:07 UTC (rev 192) @@ -350,7 +350,7 @@ var registry = new ConfigurationExpression(); configure(registry); - PluginGraph graph = registry.Build(); + PluginGraph graph = registry.BuildGraph(); graph.Log.AssertFailures(); Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-10-22 14:45:15 UTC (rev 191) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-10-23 23:02:07 UTC (rev 192) @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Xml; using StructureMap.Configuration; using StructureMap.Configuration.DSL; @@ -16,7 +15,6 @@ )] public static class StructureMapConfiguration { - private const string CONFIG_FILE_NAME = "StructureMap.config"; private static GraphLog _log; private static ConfigurationParserBuilder _parserBuilder; private static List<Registry> _registries; @@ -93,24 +91,10 @@ /// Returns the path to the StructureMap.config file /// </summary> /// <returns></returns> + [Obsolete("Use ConfigurationParserBuilder.GetStructureMapConfigurationPath() instead.")] public static string GetStructureMapConfigurationPath() { - string basePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; - string configPath = Path.Combine(basePath, CONFIG_FILE_NAME); - - if (!File.Exists(configPath)) - { - configPath = Path.Combine(basePath, "bin"); - configPath = Path.Combine(configPath, CONFIG_FILE_NAME); - - if (!File.Exists(configPath)) - { - configPath = Path.Combine(basePath, ".."); - configPath = Path.Combine(configPath, CONFIG_FILE_NAME); - } - } - - return configPath; + return ConfigurationParserBuilder.GetStructureMapConfigurationPath(); } /// <summary> Modified: trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2008-10-22 14:45:15 UTC (rev 191) +++ trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs 2008-10-23 23:02:07 UTC (rev 192) @@ -73,5 +73,15 @@ ObjectFactory.GetInstance<IWidget>().ShouldBeOfType<ColorWidget>().Color.ShouldEqual("Red"); } + + [Test] + public void Load_configuration_file_after_the_container_has_already_been_initialized() + { + var container = new Container(x => x.AddConfigurationFromXmlFile("Config1.xml")); + + container.GetInstance<IWidget>().ShouldBeOfType<ColorWidget>().Color.ShouldEqual("Orange"); + container.Configure(x => x.AddConfigurationFromXmlFile("Config2.xml")); + container.GetInstance<IWidget>().ShouldBeOfType<ColorWidget>().Color.ShouldEqual("Green"); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-10-22 14:45:15 UTC (rev 191) +++ trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserBuilderTester.cs 2008-10-23 23:02:07 UTC (rev 192) @@ -59,7 +59,7 @@ } [Test] - public void Do_NOT_Log_exception_100_if_StructureMap_config_is_required_and_missing() + public void Do_NOT_Log_exception_100_if_StructureMap_config_is_missing_but_not_required() { assertNoErrorIsLogged(100, delegate { @@ -169,10 +169,24 @@ builder.IncludeFile("GenericsTesting.xml"); ConfigurationParser[] parsers = builder.GetParsers(); - Assert.AreEqual("GenericsTesting.xml", parsers[0].Description); + Assert.AreEqual("GenericsTesting.xml", Path.GetFileName(parsers[0].Description)); } + [Test] + public void Always_resolve_files_to_an_absolute_path_before_giving_to_configuration_parser() + { + builder.UseAndEnforceExistenceOfDefaultFile = false; + builder.IgnoreDefaultFile = true; + DataMother.WriteDocument("GenericsTesting.xml"); + + builder.IncludeFile("GenericsTesting.xml"); + + ConfigurationParser[] parsers = builder.GetParsers(); + Assert.IsTrue(Path.IsPathRooted(parsers[0].Description)); + } + + [Test] public void SimpleDefaultConfigurationParser() { Modified: trunk/Source/StructureMap.Testing/TestData/Config2.xml =================================================================== --- trunk/Source/StructureMap.Testing/TestData/Config2.xml 2008-10-22 14:45:15 UTC (rev 191) +++ trunk/Source/StructureMap.Testing/TestData/Config2.xml 2008-10-23 23:02:07 UTC (rev 192) @@ -4,7 +4,7 @@ <PluginFamily Type="StructureMap.Testing.Widget.IWidget" Assembly="StructureMap.Testing.Widget" DefaultKey="Green"> <Instance Type="Color" Key="Green"> - <Property Name="Color" Value="Green" /> + <Property Name="color" Value="Green" /> </Instance> </PluginFamily> </StructureMap> \ 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-11-19 19:10:28
|
Revision: 195 http://structuremap.svn.sourceforge.net/structuremap/?rev=195&view=rev Author: jeremydmiller Date: 2008-11-19 19:10:25 +0000 (Wed, 19 Nov 2008) Log Message: ----------- Mild fix for a production issue with auto scanning open generic types Modified Paths: -------------- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs trunk/Source/StructureMap/Graph/TypeRules.cs trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs trunk/Source/StructureMap.Testing/ModelQueryTester.cs Modified: trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs =================================================================== --- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2008-10-27 02:13:42 UTC (rev 194) +++ trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2008-11-19 19:10:25 UTC (rev 195) @@ -15,6 +15,8 @@ public void Process(Type type, PluginGraph graph) { + + if (CanBeCast(_pluginType, type)) { graph.AddType(_pluginType, type); Modified: trunk/Source/StructureMap/Graph/TypeRules.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypeRules.cs 2008-10-27 02:13:42 UTC (rev 194) +++ trunk/Source/StructureMap/Graph/TypeRules.cs 2008-11-19 19:10:25 UTC (rev 195) @@ -22,14 +22,25 @@ return false; } - if (GenericsPluginGraph.CanBeCast(pluginType, pluggedType)) + if (IsGeneric(pluginType)) { - return true; + return GenericsPluginGraph.CanBeCast(pluginType, pluggedType); } + if (IsGeneric(pluggedType)) + { + return false; + } + + return pluginType.IsAssignableFrom(pluggedType); } + public static bool IsGeneric(Type pluggedType) + { + return pluggedType.IsGenericTypeDefinition || pluggedType.ContainsGenericParameters; + } + /// <summary> /// Determines if the PluggedType is a valid Plugin into the /// PluginType Modified: trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-10-27 02:13:42 UTC (rev 194) +++ trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-11-19 19:10:25 UTC (rev 195) @@ -5,8 +5,9 @@ { public class HttpContextBuildPolicy : CacheInterceptor { - private readonly string _prefix = Guid.NewGuid().ToString(); + private string _prefix = Guid.NewGuid().ToString(); + public static bool HasContext() { return HttpContext.Current != null; Modified: trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-10-27 02:13:42 UTC (rev 194) +++ trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-11-19 19:10:25 UTC (rev 195) @@ -4,15 +4,25 @@ { public class HybridBuildPolicy : IBuildInterceptor { + private readonly IBuildInterceptor _http; + private readonly IBuildInterceptor _threadLocal; + + public HybridBuildPolicy() + { + _http = new HttpContextBuildPolicy(); + _threadLocal = new ThreadLocalStoragePolicy(); + } + private IBuildPolicy _innerPolicy; + private IBuildInterceptor interceptor { get { return HttpContextBuildPolicy.HasContext() - ? (IBuildInterceptor)new HttpContextBuildPolicy(){InnerPolicy = _innerPolicy} - : new ThreadLocalStoragePolicy(){InnerPolicy = _innerPolicy}; + ? _http + : _threadLocal; } } @@ -21,7 +31,12 @@ public IBuildPolicy InnerPolicy { get { return _innerPolicy; } - set { _innerPolicy = value; } + set + { + _http.InnerPolicy = value; + _threadLocal.InnerPolicy = value; + _innerPolicy = value; + } } public object Build(BuildSession buildSession, Type pluginType, Instance instance) Modified: trunk/Source/StructureMap.Testing/ModelQueryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ModelQueryTester.cs 2008-10-27 02:13:42 UTC (rev 194) +++ trunk/Source/StructureMap.Testing/ModelQueryTester.cs 2008-11-19 19:10:25 UTC (rev 195) @@ -1,5 +1,6 @@ using System; using System.Data; +using System.Data.SqlClient; using System.Linq; using NUnit.Framework; using StructureMap.Configuration.DSL; @@ -31,6 +32,7 @@ } + [SetUp] public void SetUp() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-12-19 19:04:51
|
Revision: 203 http://structuremap.svn.sourceforge.net/structuremap/?rev=203&view=rev Author: jeremydmiller Date: 2008-12-19 19:04:47 +0000 (Fri, 19 Dec 2008) Log Message: ----------- fixing a bug reported in: http://groups.google.com/group/structuremap-users/browse_thread/thread/1ab08ef6c3ac6bf1?hl=en Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-12-19 15:46:37 UTC (rev 202) +++ trunk/Source/StructureMap/Container.cs 2008-12-19 19:04:47 UTC (rev 203) @@ -109,7 +109,9 @@ { Instance defaultInstance = _pipelineGraph.GetDefault(pluginType); - Instance instance = new ExplicitInstance(pluginType, args, defaultInstance); + BasicInstance basicInstance = defaultInstance as BasicInstance; + + Instance instance = basicInstance == null ? defaultInstance : new ExplicitInstance(pluginType, args, basicInstance); BuildSession session = withNewSession(); args.RegisterDefaults(session); Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2008-12-19 15:46:37 UTC (rev 202) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2008-12-19 19:04:47 UTC (rev 203) @@ -4,7 +4,7 @@ namespace StructureMap.Pipeline { - public interface Copyable + public interface BasicInstance { Type PluggedType { get; } Dictionary<string, string> Properties { get; } @@ -13,7 +13,7 @@ } - public abstract class ConfiguredInstanceBase<T> : Instance, IConfiguredInstance, IStructuredInstance, Copyable + public abstract class ConfiguredInstanceBase<T> : Instance, IConfiguredInstance, IStructuredInstance, BasicInstance { protected Dictionary<string, Instance[]> _arrays = new Dictionary<string, Instance[]>(); protected Dictionary<string, Instance> _children = new Dictionary<string, Instance>(); @@ -42,22 +42,22 @@ #region Copyable Members - Type Copyable.PluggedType + Type BasicInstance.PluggedType { get { return _pluggedType; } } - Dictionary<string, string> Copyable.Properties + Dictionary<string, string> BasicInstance.Properties { get { return _properties; } } - Dictionary<string, Instance> Copyable.Children + Dictionary<string, Instance> BasicInstance.Children { get { return _children; } } - Dictionary<string, Instance[]> Copyable.Arrays + Dictionary<string, Instance[]> BasicInstance.Arrays { get { return _arrays; } } @@ -241,7 +241,7 @@ _properties[propertyName] = propertyValue; } - protected void mergeIntoThis(Copyable instance) + protected void mergeIntoThis(BasicInstance instance) { _pluggedType = instance.PluggedType; Modified: trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-12-19 15:46:37 UTC (rev 202) +++ trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-12-19 19:04:47 UTC (rev 203) @@ -76,20 +76,11 @@ { private readonly ExplicitArguments _args; - public ExplicitInstance(Type pluginType, ExplicitArguments args, Instance defaultInstance) : base(null) + public ExplicitInstance(Type pluginType, ExplicitArguments args, BasicInstance defaultInstance) : base(null) { args.Configure(this); _args = args; - - var defaultConfiguration = defaultInstance as Copyable; - if (defaultConfiguration != null) - { - mergeIntoThis(defaultConfiguration); - } - else - { - setPluggedType(pluginType); - } + mergeIntoThis(defaultInstance); } Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-12-19 15:46:37 UTC (rev 202) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2008-12-19 19:04:47 UTC (rev 203) @@ -40,7 +40,7 @@ { string theProfileName = "something"; - IContainer manager = new Container(registry => + IContainer container = new Container(registry => { registry.CreateProfile(theProfileName, x => { @@ -49,10 +49,10 @@ }); }); - manager.SetDefaultsToProfile(theProfileName); + container.SetDefaultsToProfile(theProfileName); - Assert.IsInstanceOfType(typeof(AWidget), manager.GetInstance<IWidget>()); - Assert.IsInstanceOfType(typeof(DefaultRule), manager.GetInstance<Rule>()); + Assert.IsInstanceOfType(typeof(AWidget), container.GetInstance<IWidget>()); + Assert.IsInstanceOfType(typeof(DefaultRule), container.GetInstance<Rule>()); } Modified: trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs 2008-12-19 15:46:37 UTC (rev 202) +++ trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs 2008-12-19 19:04:47 UTC (rev 203) @@ -1,5 +1,6 @@ using System.Collections; using NUnit.Framework; +using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Testing.GenericWidgets; using StructureMap.Testing.TestData; @@ -74,6 +75,20 @@ (IService<double>) manager.GetInstance(typeof (IService<double>), "Default"); } + + + + + + + + + + + + + + [Test] public void PicksUpAnExplicitlyDefinedGenericPluginFamilyFromConfiguration() { Modified: trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs 2008-12-19 15:46:37 UTC (rev 202) +++ trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs 2008-12-19 19:04:47 UTC (rev 203) @@ -1,5 +1,7 @@ +using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using NUnit.Framework; using StructureMap.Pipeline; using StructureMap.Testing.Pipeline; @@ -96,13 +98,58 @@ } [Test] + public void use_a_type_that_is_not_part_of_the_constructor_in_the_with() + { + var container = new Container(); + container.With(new Address()).GetInstance<ClassWithNoArgs>() + .ShouldBeOfType<ClassWithNoArgs>(); + } + + [Test] + public void use_explicit_type_arguments_with_custom_instance() + { + var container = new Container(x => + { + x.ForRequestedType<ClassWithNoArgs>().TheDefault.IsThis(new SpecialInstance()); + }); + + Debug.WriteLine(container.WhatDoIHave()); + + var address = new Address(); + + + container.With(address).GetInstance<ClassWithNoArgs>() + .TheAddress.ShouldBeTheSameAs(address); + + } + + public class ClassWithNoArgs + { + public Address TheAddress { get; set;} + } + public class Address{} + + public class SpecialInstance : Instance + { + protected override string getDescription() + { + return string.Empty; + } + + protected override object build(Type pluginType, BuildSession session) + { + return new ClassWithNoArgs() {TheAddress = (Address)session.CreateInstance(typeof (Address))}; + } + } + + [Test] public void ExplicitArguments_can_return_child_by_name() { var args = new ExplicitArguments(); var theNode = new Node(); args.SetArg("node", theNode); - IConfiguredInstance instance = new ExplicitInstance(typeof (Command), args, null); + IConfiguredInstance instance = new ExplicitInstance(typeof (Command), args, new SmartInstance<Command>()); Assert.AreSame(theNode, instance.GetChild("node", typeof (Node), new StubBuildSession())); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-12-20 18:17:03
|
Revision: 205 http://structuremap.svn.sourceforge.net/structuremap/?rev=205&view=rev Author: jeremydmiller Date: 2008-12-20 18:16:59 +0000 (Sat, 20 Dec 2008) Log Message: ----------- added a new caching strategy for Session Modified Paths: -------------- trunk/Source/StructureMap/Attributes/InstanceScope.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Pipeline/HttpContextBuildStorage.cs Modified: trunk/Source/StructureMap/Attributes/InstanceScope.cs =================================================================== --- trunk/Source/StructureMap/Attributes/InstanceScope.cs 2008-12-20 17:59:45 UTC (rev 204) +++ trunk/Source/StructureMap/Attributes/InstanceScope.cs 2008-12-20 18:16:59 UTC (rev 205) @@ -6,6 +6,7 @@ Singleton, ThreadLocal, HttpContext, - Hybrid + Hybrid, + HttpSession } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-12-20 17:59:45 UTC (rev 204) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-12-20 18:16:59 UTC (rev 205) @@ -77,6 +77,10 @@ case InstanceScope.Hybrid: AddInterceptor(new HybridBuildPolicy()); break; + + case InstanceScope.HttpSession: + AddInterceptor(new HttpSessionBuildPolicy()); + break; } } Deleted: trunk/Source/StructureMap/Pipeline/HttpContextBuildStorage.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpContextBuildStorage.cs 2008-12-20 17:59:45 UTC (rev 204) +++ trunk/Source/StructureMap/Pipeline/HttpContextBuildStorage.cs 2008-12-20 18:16:59 UTC (rev 205) @@ -1,41 +0,0 @@ -using System.Collections; -using System.Web; - -namespace StructureMap.Pipeline -{ - public class HttpContextBuildPolicy : CacheInterceptor - { - public static readonly string ITEM_NAME = "STRUCTUREMAP-INSTANCES"; - - public static bool HasContext() - { - return HttpContext.Current != null; - } - - protected override InstanceCache findCache() - { - IDictionary items = HttpContext.Current.Items; - - if (!items.Contains(ITEM_NAME)) - { - lock (items.SyncRoot) - { - if (!items.Contains(ITEM_NAME)) - { - InstanceCache cache = buildNewCache(); - items.Add(ITEM_NAME, cache); - - return cache; - } - } - } - - return (InstanceCache) items[ITEM_NAME]; - } - - protected override CacheInterceptor clone() - { - return this; - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-12-20 17:59:45 UTC (rev 204) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-12-20 18:16:59 UTC (rev 205) @@ -411,7 +411,7 @@ <Compile Include="Pipeline\BuildFrame.cs" /> <Compile Include="Pipeline\BuildStack.cs" /> <Compile Include="Pipeline\ConfiguredInstanceBase.cs" /> - <Compile Include="Pipeline\HttpContextBuildStorage.cs" /> + <Compile Include="Pipeline\HttpContextBuildPolicy.cs" /> <Compile Include="Pipeline\InstanceKey.cs" /> <Compile Include="Pipeline\IStructuredInstance.cs" /> <Compile Include="Pipeline\PropertyExpression.cs" /> Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-12-20 17:59:45 UTC (rev 204) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-12-20 18:16:59 UTC (rev 205) @@ -260,6 +260,15 @@ } [Test] + public void set_the_scope_to_session() + { + var family = new PluginFamily(typeof(IServiceProvider)); + family.SetScopeTo(InstanceScope.HttpSession); + + family.Policy.ShouldBeOfType<HttpSessionBuildPolicy>(); + } + + [Test] public void SetScopeToSingleton() { var family = new PluginFamily(typeof (IServiceProvider)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-12-20 18:50:31
|
Revision: 206 http://structuremap.svn.sourceforge.net/structuremap/?rev=206&view=rev Author: jeremydmiller Date: 2008-12-20 18:50:25 +0000 (Sat, 20 Dec 2008) Log Message: ----------- Fixed the problem with missing dictionary data in Xml configuration for non-mandatory setters Modified Paths: -------------- trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/DataMother.cs Added Paths: ----------- trunk/Source/StructureMap/Extensions.cs trunk/Source/StructureMap.Testing/Bugs/IDictionaryAndXmlBugTester.cs Added: trunk/Source/StructureMap/Extensions.cs =================================================================== --- trunk/Source/StructureMap/Extensions.cs (rev 0) +++ trunk/Source/StructureMap/Extensions.cs 2008-12-20 18:50:25 UTC (rev 206) @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace StructureMap +{ + public static class StringExtensions + { + public static string ToFormat(this string template, params object[] parameters) + { + return string.Format(template, parameters); + } + + public static string[] ToDelimitedArray(this string content) + { + string[] array = content.Split(','); + for (int i = 0; i < array.Length; i++) + { + array[i] = array[i].Trim(); + } + + return array; + } + } +} Modified: trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs 2008-12-20 18:16:59 UTC (rev 205) +++ trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs 2008-12-20 18:50:25 UTC (rev 206) @@ -123,7 +123,7 @@ } XmlElement element = _element[name]; - return reader.Read(element, childType); + return element == null ? null : reader.Read(element, childType); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs 2008-12-20 18:16:59 UTC (rev 205) +++ trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs 2008-12-20 18:50:25 UTC (rev 206) @@ -110,7 +110,7 @@ } XmlElement element = getChildNode(name); - return reader.Read(element, childType); + return element == null ? null : reader.Read(element, childType); } protected override InstanceMemento getChild(string Key) Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-12-20 18:16:59 UTC (rev 205) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-12-20 18:50:25 UTC (rev 206) @@ -399,6 +399,7 @@ <Compile Include="Diagnostics\ValidationError.cs" /> <Compile Include="Emitting\Parameters\Methods.cs" /> <Compile Include="ErrorMessages.cs" /> + <Compile Include="Extensions.cs" /> <Compile Include="Graph\FamilyAttributeScanner.cs" /> <Compile Include="Graph\FindAllTypesFilter.cs" /> <Compile Include="Graph\FindRegistriesScanner.cs" /> Added: trunk/Source/StructureMap.Testing/Bugs/IDictionaryAndXmlBugTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Bugs/IDictionaryAndXmlBugTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Bugs/IDictionaryAndXmlBugTester.cs 2008-12-20 18:50:25 UTC (rev 206) @@ -0,0 +1,132 @@ +using System.Collections.Generic; +using NUnit.Framework; +using StructureMap.Attributes; +using StructureMap.Testing.TestData; + +namespace StructureMap.Testing.Bugs +{ + [TestFixture] + public class IDictionaryAndXmlBugTester + { + [Test] + public void read_a_dictionary_from_configuration() + { + string className = typeof (ClassWithDictionaryInCtor).AssemblyQualifiedName; + string xml = + @" +<StructureMap> + <DefaultInstance PluginType='{0}' PluggedType='{0}'> + <Property Name='values'> + <Pair Key='color' Value='red'/> + <Pair Key='state' Value='texas'/> + <Pair Key='direction' Value='north'/> + </Property> + </DefaultInstance> +</StructureMap> +" + .ToFormat(className); + + Container container = DataMother.BuildContainerForXml(xml); + + var dict = container.GetInstance<ClassWithDictionaryInCtor>(); + dict.Values["color"].ShouldEqual("red"); + } + + + [Test] + public void + read_a_dictionary_from_configuration_in_attribute_style_that_is_missing_a_dictionary_and_blow_up_with_good_message + () + { + string className = typeof (ClassWithDictionaryInCtor).AssemblyQualifiedName; + string xml = + @" +<StructureMap MementoStyle='Attribute'> + <DefaultInstance PluginType='{0}' PluggedType='{0}'></DefaultInstance> +</StructureMap> +" + .ToFormat(className); + + + try + { + Container container = DataMother.BuildContainerForXml(xml); + container.GetInstance<ClassWithDictionaryInCtor>(); + } + catch (StructureMapException e) + { + e.ErrorCode.ShouldEqual(202); + } + } + + + [Test] + public void + read_a_dictionary_from_configuration_in_attribute_style_that_is_missing_a_dictionary_for_an_optional_setter() + { + string className = typeof (ClassWithDictionaryProperty).AssemblyQualifiedName; + string xml = + @" +<StructureMap MementoStyle='Attribute'> + <DefaultInstance PluginType='{0}' PluggedType='{0}'></DefaultInstance> +</StructureMap> +" + .ToFormat(className); + + + Container container = DataMother.BuildContainerForXml(xml); + container.GetInstance<ClassWithDictionaryProperty>().ShouldNotBeNull(); + } + + [Test] + public void read_a_dictionary_from_configuration_when_the_property_is_missing_on_mandatory_setter() + { + string className = typeof (ClassWithDictionaryProperty2).AssemblyQualifiedName; + string xml = + @" +<StructureMap> + <DefaultInstance PluginType='{0}' PluggedType='{0}'></DefaultInstance> +</StructureMap> +" + .ToFormat(className); + + + try + { + Container container = DataMother.BuildContainerForXml(xml); + container.GetInstance<ClassWithDictionaryProperty2>(); + } + catch (StructureMapException e) + { + e.ErrorCode.ShouldEqual(202); + } + } + + } + + public class ClassWithDictionaryInCtor + { + private readonly IDictionary<string, string> _values; + + public ClassWithDictionaryInCtor(IDictionary<string, string> values) + { + _values = values; + } + + public IDictionary<string, string> Values + { + get { return _values; } + } + } + + public class ClassWithDictionaryProperty + { + public IDictionary<string, string> Values { get; set; } + } + + public class ClassWithDictionaryProperty2 + { + [SetterProperty] + public IDictionary<string, string> Values { get; set; } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-12-20 18:16:59 UTC (rev 205) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-12-20 18:50:25 UTC (rev 206) @@ -178,6 +178,7 @@ <Compile Include="AutoMocking\MoqFactoryTester.cs" /> <Compile Include="AutoMocking\RhinoAutoMockerTester.cs" /> <Compile Include="AutoMocking\RhinoMockRepositoryProxyTester.cs" /> + <Compile Include="Bugs\IDictionaryAndXmlBugTester.cs" /> <Compile Include="Bugs\ScanIndexerBugTester.cs" /> <Compile Include="BuildSessionTester.cs" /> <Compile Include="Configuration\ConfigurationParserBuilderTester.cs" /> Modified: trunk/Source/StructureMap.Testing/TestData/DataMother.cs =================================================================== --- trunk/Source/StructureMap.Testing/TestData/DataMother.cs 2008-12-20 18:16:59 UTC (rev 205) +++ trunk/Source/StructureMap.Testing/TestData/DataMother.cs 2008-12-20 18:50:25 UTC (rev 206) @@ -17,6 +17,12 @@ { } + public static Container BuildContainerForXml(string xml) + { + var graph = BuildPluginGraphFromXml(xml); + return new Container(graph); + } + public static PluginGraph BuildPluginGraphFromXml(string xml) { XmlDocument document = BuildDocument(xml); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-12-20 19:44:09
|
Revision: 207 http://structuremap.svn.sourceforge.net/structuremap/?rev=207&view=rev Author: jeremydmiller Date: 2008-12-20 19:44:05 +0000 (Sat, 20 Dec 2008) Log Message: ----------- allowing users to specify object scope in the Container.Configure() method Modified Paths: -------------- trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/PluginTypeConfiguration.cs trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeInConfigureTester.cs Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-12-20 18:50:25 UTC (rev 206) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-12-20 19:44:05 UTC (rev 207) @@ -16,7 +16,7 @@ new Cache<string, Instance>(delegate { return null; }); private readonly Type _pluginType; - private readonly IBuildPolicy _policy = new BuildPolicy(); + private IBuildPolicy _policy = new BuildPolicy(); #region constructor functions @@ -136,6 +136,12 @@ public void ImportFrom(PluginFamily family) { + if (!_policy.GetType().Equals(family.Policy.GetType())) + { + // TODO: Might need to clear out the existing policy when it's ejected + _policy = family.Policy; + } + family.EachInstance(instance => _instances.Fill(instance.Name, instance)); } Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-12-20 18:50:25 UTC (rev 206) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-12-20 19:44:05 UTC (rev 207) @@ -9,31 +9,6 @@ public delegate InstanceFactory MissingFactoryFunction(Type pluginType, ProfileManager profileManager); - /// <summary> - /// Metadata describing the registration of a PluginType - /// </summary> - public class PluginTypeConfiguration - { - public Type PluginType { get; set; } - - /// <summary> - /// The "instance" that will be used when Container.GetInstance(PluginType) is called. - /// See <see cref="StructureMap.Pipeline.IInstance">IInstance</see> for more information - /// </summary> - public IInstance Default { get; set; } - - /// <summary> - /// The build "policy" for this PluginType. Used by the WhatDoIHave() diagnostics methods - /// </summary> - public IBuildPolicy Policy { get; set; } - - /// <summary> - /// All of the <see cref="StructureMap.Pipeline.IInstance">IInstance</see>'s registered - /// for this PluginType - /// </summary> - public IEnumerable<IInstance> Instances { get; set; } - } - public class PipelineGraph { private readonly Dictionary<Type, IInstanceFactory> _factories Added: trunk/Source/StructureMap/PluginTypeConfiguration.cs =================================================================== --- trunk/Source/StructureMap/PluginTypeConfiguration.cs (rev 0) +++ trunk/Source/StructureMap/PluginTypeConfiguration.cs 2008-12-20 19:44:05 UTC (rev 207) @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using StructureMap.Pipeline; + +namespace StructureMap +{ + /// <summary> + /// Metadata describing the registration of a PluginType + /// </summary> + public class PluginTypeConfiguration + { + public Type PluginType { get; set; } + + /// <summary> + /// The "instance" that will be used when Container.GetInstance(PluginType) is called. + /// See <see cref="StructureMap.Pipeline.IInstance">IInstance</see> for more information + /// </summary> + public IInstance Default { get; set; } + + /// <summary> + /// The build "policy" for this PluginType. Used by the WhatDoIHave() diagnostics methods + /// </summary> + public IBuildPolicy Policy { get; set; } + + /// <summary> + /// All of the <see cref="StructureMap.Pipeline.IInstance">IInstance</see>'s registered + /// for this PluginType + /// </summary> + public IEnumerable<IInstance> Instances { get; set; } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-12-20 18:50:25 UTC (rev 206) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-12-20 19:44:05 UTC (rev 207) @@ -418,6 +418,7 @@ <Compile Include="Pipeline\PropertyExpression.cs" /> <Compile Include="Pipeline\SerializedInstance.cs" /> <Compile Include="Pipeline\SmartInstance.cs" /> + <Compile Include="PluginTypeConfiguration.cs" /> <Compile Include="ReflectionHelper.cs" /> <Compile Include="Util\Cache.cs" /> </ItemGroup> Added: trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeInConfigureTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeInConfigureTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeInConfigureTester.cs 2008-12-20 19:44:05 UTC (rev 207) @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using StructureMap.Attributes; +using StructureMap.Testing.Widget3; + +namespace StructureMap.Testing.Bugs +{ + [TestFixture] + public class SpecifyScopeInConfigureTester + { + [Test] + public void specify_the_scope_in_a_Configure_if_it_is_not_already_set() + { + var container = new Container(x => { }); + container.Configure(x => + { + x.ForRequestedType<IGateway>().CacheBy(InstanceScope.Singleton) + .TheDefaultIsConcreteType<DefaultGateway>(); + + }); + + var gateway1 = container.GetInstance<IGateway>(); + var gateway2 = container.GetInstance<IGateway>(); + var gateway3 = container.GetInstance<IGateway>(); + + gateway1.ShouldBeTheSameAs(gateway2); + gateway1.ShouldBeTheSameAs(gateway3); + } + } +} Modified: trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2008-12-20 18:50:25 UTC (rev 206) +++ trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2008-12-20 19:44:05 UTC (rev 207) @@ -1,4 +1,5 @@ using NUnit.Framework; +using StructureMap.Attributes; using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; @@ -74,6 +75,39 @@ } [Test] + public void import_from_another_family_will_override_the_build_policy_if_the_initial_policy_is_the_default() + { + var factory = new InstanceFactory(typeof(IWidget)); + + var family = new PluginFamily(typeof(IWidget)); + family.SetScopeTo(InstanceScope.Singleton); + + factory.ImportFrom(family); + + factory.Policy.ShouldBeOfType<SingletonPolicy>(); + } + + [Test] + public void do_not_replace_the_build_policy_if_it_is_the_same_type_as_the_imported_family() + { + PluginFamily originalFamily = new PluginFamily(typeof(IWidget)); + originalFamily.SetScopeTo(InstanceScope.Singleton); + var factory = new InstanceFactory(originalFamily); + + var originalPolicy = factory.Policy; + + + var family = new PluginFamily(typeof(IWidget)); + family.SetScopeTo(InstanceScope.Singleton); + + factory.ImportFrom(family); + + factory.Policy.ShouldBeTheSameAs(originalPolicy); + } + + + + [Test] public void Merge_from_PluginFamily_will_not_replace_an_existing_instance() { var factory = new InstanceFactory(typeof (IWidget)); Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-12-20 18:50:25 UTC (rev 206) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-12-20 19:44:05 UTC (rev 207) @@ -180,6 +180,7 @@ <Compile Include="AutoMocking\RhinoMockRepositoryProxyTester.cs" /> <Compile Include="Bugs\IDictionaryAndXmlBugTester.cs" /> <Compile Include="Bugs\ScanIndexerBugTester.cs" /> + <Compile Include="Bugs\SpecifyScopeInConfigureTester.cs" /> <Compile Include="BuildSessionTester.cs" /> <Compile Include="Configuration\ConfigurationParserBuilderTester.cs" /> <Compile Include="Configuration\ConfigurationParserTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-12-21 00:34:38
|
Revision: 209 http://structuremap.svn.sourceforge.net/structuremap/?rev=209&view=rev Author: jeremydmiller Date: 2008-12-21 00:34:36 +0000 (Sun, 21 Dec 2008) Log Message: ----------- making "EjectAll" work for singletons Modified Paths: -------------- trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/Pipeline/BuildPolicy.cs trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs trunk/Source/StructureMap/Pipeline/IBuildPolicy.cs trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -87,6 +87,7 @@ public IBuildPolicy Policy { get { return _policy; } + set { _policy = value; } } public void ForEachInstance(Action<Instance> action) @@ -147,6 +148,7 @@ public void EjectAllInstances() { + _policy.EjectAll(); _instances.Clear(); } Modified: trunk/Source/StructureMap/Pipeline/BuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -30,6 +30,12 @@ return this; } + public void EjectAll() + { + // no-op. Unlike other Container's, StructureMap doesn't hang on to + // objects it created as "Transients" + } + #endregion public bool Equals(BuildPolicy obj) Modified: trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -44,6 +44,16 @@ return clonedCache; } + public void EjectAll() + { + ejectAll(); + _innerPolicy.EjectAll(); + } + + protected virtual void ejectAll() + { + } + #endregion protected abstract CacheInterceptor clone(); Modified: trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -45,6 +45,11 @@ } public abstract IBuildPolicy Clone(); + public void EjectAll() + { + _http.EjectAll(); + _nonHttp.EjectAll(); + } } Modified: trunk/Source/StructureMap/Pipeline/IBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IBuildPolicy.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap/Pipeline/IBuildPolicy.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -9,5 +9,6 @@ { object Build(BuildSession buildSession, Type pluginType, Instance instance); IBuildPolicy Clone(); + void EjectAll(); } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -1,3 +1,5 @@ +using System; + namespace StructureMap.Pipeline { [Pluggable("Singleton")] @@ -22,6 +24,35 @@ return _cache; } + public InstanceCache Cache + { + get + { + return findCache(); + } + } + + protected override void ejectAll() + { + lock (_locker) + { + _cache.Each(o => + { + IDisposable disposable = o as IDisposable; + if (disposable != null) + { + try + { + disposable.Dispose(); + } + catch (Exception){} + } + }); + + _cache.Clear(); + } + } + protected override CacheInterceptor clone() { return new SingletonPolicy(); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -289,6 +289,11 @@ throw new NotImplementedException(); } + public void EjectAll() + { + throw new System.NotImplementedException(); + } + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -61,6 +61,11 @@ throw new NotImplementedException(); } + public void EjectAll() + { + throw new System.NotImplementedException(); + } + #endregion } Modified: trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -364,6 +364,11 @@ throw new NotImplementedException(); } + public void EjectAll() + { + throw new System.NotImplementedException(); + } + #endregion } Modified: trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -1,10 +1,12 @@ using NUnit.Framework; +using Rhino.Mocks; using StructureMap.Attributes; using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; using StructureMap.Testing.Widget; using StructureMap.Testing.Widget3; +using System.Linq; namespace StructureMap.Testing.Graph { @@ -58,6 +60,23 @@ } [Test] + public void eject_all_instances_removes_all_instances_and_ejects_from_the_build_policy() + { + var factory = new InstanceFactory(typeof (IGateway)); + factory.AddInstance(new SmartInstance<DefaultGateway>()); + factory.AddInstance(new SmartInstance<DefaultGateway>()); + + var policy = MockRepository.GenerateMock<IBuildPolicy>(); + factory.Policy = policy; + + factory.EjectAllInstances(); + + factory.Instances.Count().ShouldEqual(0); + + policy.AssertWasCalled(x => x.EjectAll()); + } + + [Test] public void Import_from_family_picks_up_new_instances() { var factory = new InstanceFactory(typeof (IWidget)); Modified: trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2008-12-20 20:50:53 UTC (rev 208) +++ trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2008-12-21 00:34:36 UTC (rev 209) @@ -102,6 +102,7 @@ Assert.IsInstanceOfType(typeof (BuildPolicy), clone.InnerPolicy); } + [Test] public void Singleton_build_policy() { @@ -124,4 +125,81 @@ Assert.AreSame(green1, green3); } } + + [TestFixture] + public class when_the_singleton_policy_ejects_all + { + private SingletonPolicy policy; + private StubBuildPolicy inner; + private StubDisposable disposable1; + private StubDisposable disposable2; + + + [SetUp] + public void SetUp() + { + policy = new SingletonPolicy(); + inner = new StubBuildPolicy(); + policy.InnerPolicy = inner; + + disposable1 = new StubDisposable(); + disposable2 = new StubDisposable(); + + policy.Cache[new InstanceKey() { Name = "a", PluginType = typeof(IGateway) }] = disposable1; + policy.Cache[new InstanceKey() {Name = "b", PluginType = typeof (IGateway)}] = disposable2; + policy.Cache[new InstanceKey() {Name = "c", PluginType = typeof (IGateway)}] = new object(); + + policy.EjectAll(); + } + + [Test] + public void the_count_should_be_zero() + { + policy.Cache.Count.ShouldEqual(0); + } + + [Test] + public void should_have_called_dispose_if_it_was_there() + { + disposable1.DisposedWasCalled.ShouldBeTrue(); + disposable2.DisposedWasCalled.ShouldBeTrue(); + } + + [Test] + public void inner_policy_was_ejected() + { + inner.WasEjected.ShouldBeTrue(); + } + + } + + public class StubDisposable : IDisposable + { + public bool DisposedWasCalled; + + public void Dispose() + { + DisposedWasCalled = true; + } + } + + public class StubBuildPolicy : IBuildPolicy + { + public bool WasEjected; + + public object Build(BuildSession buildSession, Type pluginType, Instance instance) + { + throw new System.NotImplementedException(); + } + + public IBuildPolicy Clone() + { + throw new System.NotImplementedException(); + } + + public void EjectAll() + { + WasEjected = true; + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |