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