Permalink
Browse files

Missing Instance, BuildUp, documentation, conditional instance

  • Loading branch information...
1 parent 75d6a6f commit 214b371888cac6104941ac62e6db400d2d694d7b @jeremydmiller jeremydmiller committed Jan 3, 2009
Showing with 1,953 additions and 119 deletions.
  1. +2 −1 Docs/style.css
  2. +1 −1 Source/CommonAssemblyInfo.cs
  3. +7 −0 Source/StructureMap.Testing.Widget/BuilderSamples.cs
  4. +5 −1 Source/StructureMap.Testing.Widget3/IService.cs
  5. +87 −0 Source/StructureMap.Testing/AutoWiringExamples.cs
  6. +114 −0 Source/StructureMap.Testing/Bugs/SingletonShouldBeLazy.cs
  7. +78 −0 Source/StructureMap.Testing/BuildUpIntegratedTester.cs
  8. +106 −0 Source/StructureMap.Testing/BuildUpTester.cs
  9. +19 −18 Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs
  10. +1 −0 Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
  11. +9 −7 Source/StructureMap.Testing/Configuration/DSL/GenericFamilyExpressionTester.cs
  12. +42 −0 Source/StructureMap.Testing/Configuration/DSL/ProgrammaticConstructorSelectionTester.cs
  13. +103 −0 Source/StructureMap.Testing/Examples.cs
  14. +44 −0 Source/StructureMap.Testing/Examples/CustomInstance.cs
  15. +62 −0 Source/StructureMap.Testing/Examples/RegisteringWithTheAPI.cs
  16. +2 −0 Source/StructureMap.Testing/Graph/ContainerTester.cs
  17. +121 −0 Source/StructureMap.Testing/Graph/ConventionBasedSetterInjectionTester.cs
  18. +5 −3 Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs
  19. +14 −6 Source/StructureMap.Testing/Graph/PluginTester.cs
  20. +0 −1 Source/StructureMap.Testing/Graph/TestExplicitArguments.cs
  21. +135 −0 Source/StructureMap.Testing/Pipeline/ConditionalInstanceTester.cs
  22. +42 −0 Source/StructureMap.Testing/Pipeline/MissingInstanceTester.cs
  23. +4 −1 Source/StructureMap.Testing/Pipeline/OptionalSetterInjectionTester.cs
  24. +26 −0 Source/StructureMap.Testing/PrimitiveArrayTester.cs
  25. +11 −1 Source/StructureMap.Testing/StructureMap.Testing.csproj
  26. +26 −0 Source/StructureMap/BuildSession.cs
  27. +8 −0 Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
  28. +24 −1 Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs
  29. +48 −2 Source/StructureMap/Configuration/DSL/Registry.cs
  30. +63 −0 Source/StructureMap/Configuration/DSL/SetterConvention.cs
  31. +17 −0 Source/StructureMap/ConfigurationExpression.cs
  32. +30 −19 Source/StructureMap/Container.cs
  33. +4 −2 Source/StructureMap/Emitting/ArgumentEmitter.cs
  34. +1 −1 Source/StructureMap/Emitting/BuildInstanceMethod.cs
  35. +54 −0 Source/StructureMap/Emitting/BuildUpMethod.cs
  36. +5 −2 Source/StructureMap/Emitting/InstanceBuilderAssembly.cs
  37. +13 −7 Source/StructureMap/Emitting/Parameters/ParameterEmitter.cs
  38. +0 −1 Source/StructureMap/ExplicitArgsExpression.cs
  39. +16 −1 Source/StructureMap/Graph/Constructor.cs
  40. +8 −8 Source/StructureMap/Graph/Plugin.cs
  41. +24 −9 Source/StructureMap/Graph/PluginCache.cs
  42. +2 −0 Source/StructureMap/Graph/PluginFamily.cs
  43. +5 −0 Source/StructureMap/Graph/SetterPropertyCollection.cs
  44. +11 −8 Source/StructureMap/IContainer.cs
  45. +1 −0 Source/StructureMap/IInstanceFactory.cs
  46. +16 −1 Source/StructureMap/InitializationExpression.cs
  47. +3 −0 Source/StructureMap/InstanceBuilder.cs
  48. +5 −2 Source/StructureMap/InstanceFactory.cs
  49. +11 −0 Source/StructureMap/ObjectFactory.cs
  50. +20 −1 Source/StructureMap/Pipeline/BuildFrame.cs
  51. +83 −0 Source/StructureMap/Pipeline/ConditionalInstance.cs
  52. +406 −0 Source/StructureMap/ReflectionHelper.cs
  53. +6 −2 Source/StructureMap/StructureMap.csproj
  54. +1 −1 Source/StructureMap/SystemRegistry.cs
  55. +2 −11 cruise.build
View
@@ -16,7 +16,8 @@ H1
}
H2
{
- COLOR: #316592;
+ BACKGROUND-COLOR: #316592;
+ COLOR: white;
FONT-FAMILY: Arial;
FONT-SIZE: large;
FONT-WEIGHT: bold;
@@ -5,7 +5,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
-// Runtime Version:2.0.50727.1434
+// Runtime Version:2.0.50727.3053
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -64,5 +64,12 @@ public override object BuildInstance(IConfiguredInstance instance, BuildSession
if (instance.HasProperty("Name2")) target.Name = instance.GetProperty("Name2");
return target;
}
+
+ public override void BuildUp(IConfiguredInstance instance, BuildSession session, object target)
+ {
+ SetterTarget x = (SetterTarget) target;
+ if (instance.HasProperty("Name")) x.Name = instance.GetProperty("Name");
+ if (instance.HasProperty("Name2")) x.Name = instance.GetProperty("Name2");
+ }
}
}
@@ -1,6 +1,10 @@
namespace StructureMap.Testing.Widget3
{
- public interface IService
+ public interface IService : IBasicService
+ {
+ }
+
+ public interface IBasicService
{
}
@@ -0,0 +1,87 @@
+using System.Diagnostics;
+using NUnit.Framework;
+
+namespace StructureMap.Testing
+{
+ public interface IValidator
+ {
+ }
+
+ public class Validator : IValidator
+ {
+ private readonly string _name;
+
+ public Validator(string name)
+ {
+ _name = name;
+ }
+
+ public override string ToString()
+ {
+ return string.Format("Name: {0}", _name);
+ }
+ }
+
+ public class ClassThatUsesValidators
+ {
+ private readonly IValidator[] _validators;
+
+ public ClassThatUsesValidators(IValidator[] validators)
+ {
+ _validators = validators;
+ }
+
+ public void Write()
+ {
+ foreach (IValidator validator in _validators)
+ {
+ Debug.WriteLine(validator);
+ }
+ }
+ }
+
+ [TestFixture]
+ public class ValidatorExamples
+ {
+ private Container container;
+
+ [SetUp]
+ public void SetUp()
+ {
+ container = new Container(x =>
+ {
+ x.ForRequestedType<IValidator>().AddInstances(o =>
+ {
+ o.OfConcreteType<Validator>().WithCtorArg("name").EqualTo("Red").WithName("Red");
+ o.OfConcreteType<Validator>().WithCtorArg("name").EqualTo("Blue").WithName("Blue");
+ o.OfConcreteType<Validator>().WithCtorArg("name").EqualTo("Purple").WithName("Purple");
+ o.OfConcreteType<Validator>().WithCtorArg("name").EqualTo("Green").WithName("Green");
+ });
+
+ x.ForRequestedType<ClassThatUsesValidators>().AddInstances(o =>
+ {
+ // Define an Instance of ClassThatUsesValidators that depends on AutoWiring
+ o.OfConcreteType<ClassThatUsesValidators>().WithName("WithAutoWiring");
+
+ // Define an Instance of ClassThatUsesValidators that overrides AutoWiring
+ o.OfConcreteType<ClassThatUsesValidators>().WithName("ExplicitArray")
+ .TheArrayOf<IValidator>().Contains(y =>
+ {
+ y.TheInstanceNamed("Red");
+ y.TheInstanceNamed("Green");
+ });
+ });
+ });
+ }
+
+ [Test]
+ public void what_are_the_validators()
+ {
+ Debug.WriteLine("With Auto Wiring");
+ container.GetInstance<ClassThatUsesValidators>("WithAutoWiring").Write();
+ Debug.WriteLine("=================================");
+ Debug.WriteLine("With Explicit Configuration");
+ container.GetInstance<ClassThatUsesValidators>("ExplicitArray").Write();
+ }
+ }
+}
@@ -0,0 +1,114 @@
+using System;
+using System.Diagnostics;
+using NUnit.Framework;
+using StructureMap.Attributes;
+using StructureMap.Testing.Widget3;
+
+namespace StructureMap.Testing.Bugs
+{
+ public class SingletonShouldBeLazy : IGateway
+ {
+ public SingletonShouldBeLazy()
+ {
+ Assert.Fail("I should not be called");
+ }
+
+ #region IGateway Members
+
+ public string WhoAmI
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public void DoSomething()
+ {
+ throw new NotImplementedException();
+ }
+
+ #endregion
+ }
+
+ [TestFixture]
+ public class Singleton_should_be_lazy
+ {
+ [Test]
+ public void test_it()
+ {
+ var container = new Container(x =>
+ {
+ x.ForRequestedType<IGateway>().CacheBy(InstanceScope.Singleton).TheDefaultIsConcreteType
+ <SingletonShouldBeLazy>();
+ });
+ }
+
+ [Test]
+ public void TESTNAME()
+ {
+ CrmService.Main(new string[0]);
+ }
+ }
+
+
+ public class CrmService
+ {
+ private readonly ICrm _crm;
+
+ public CrmService() : this(ObjectFactory.GetInstance<ICrm>())
+ {
+ }
+
+ public CrmService(ICrm crm)
+ {
+ _crm = crm;
+ }
+
+ public static void Main(string[] args)
+ {
+ Initialise();
+
+ var svc = new CrmService();
+ svc.Run(args);
+ }
+
+ public void Run(string[] args)
+ {
+ Trace.WriteLine("Starting service");
+ _crm.Message("Running CRM");
+ }
+
+ private static void Initialise()
+ {
+ ObjectFactory.Initialize(registry =>
+ registry.UseDefaultStructureMapConfigFile = false);
+ ObjectFactory.Configure(registry =>
+ registry.ForRequestedType<ICrm>().TheDefaultIsConcreteType<Crm>
+ ().CacheBy(InstanceScope.Singleton));
+ }
+ }
+
+
+
+ public interface ICrm
+ {
+ void Message(string arg);
+ }
+
+
+ public class Crm : ICrm
+ {
+ public Crm()
+ {
+ Trace.WriteLine("Initialising CRM");
+ }
+
+ public void Message(string message)
+ {
+ Trace.WriteLine(message);
+ }
+}
+
+
+
+
+
+}
@@ -0,0 +1,78 @@
+using NUnit.Framework;
+using StructureMap.Graph;
+using StructureMap.Testing.Widget3;
+
+namespace StructureMap.Testing
+{
+ [TestFixture]
+ public class BuildUpIntegratedTester
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ PluginCache.ResetAll();
+ }
+
+ [Test]
+ public void create_a_setter_rule_and_see_it_applied_in_BuildUp()
+ {
+ var theGateway = new DefaultGateway();
+ var container = new Container(x =>
+ {
+ x.ForRequestedType<IGateway>().TheDefault.IsThis(theGateway);
+ x.SetAllProperties(y =>
+ {
+ y.OfType<IGateway>();
+ });
+ });
+
+ var target = new BuildUpTarget1();
+ container.BuildUp(target);
+
+ target.Gateway.ShouldBeTheSameAs(theGateway);
+ target.Service.ShouldBeNull();
+ }
+
+ [Test]
+ public void use_predefined_setter_values_for_buildup()
+ {
+ var theGateway = new DefaultGateway();
+ var container = new Container(x =>
+ {
+ x.ForConcreteType<BuildUpTarget1>().Configure
+ .SetterDependency(y => y.Gateway).Is(theGateway);
+ });
+
+ var target = new BuildUpTarget1();
+ container.BuildUp(target);
+
+ target.Gateway.ShouldBeTheSameAs(theGateway);
+ }
+
+ [Test]
+ public void create_a_setter_rule_and_see_it_applied_in_BuildUp_through_ObjectFactory()
+ {
+ var theGateway = new DefaultGateway();
+ ObjectFactory.Initialize(x =>
+ {
+ x.IgnoreStructureMapConfig = true;
+ x.ForRequestedType<IGateway>().TheDefault.IsThis(theGateway);
+ x.SetAllProperties(y =>
+ {
+ y.OfType<IGateway>();
+ });
+ });
+
+ var target = new BuildUpTarget1();
+ ObjectFactory.BuildUp(target);
+
+ target.Gateway.ShouldBeTheSameAs(theGateway);
+ }
+ }
+
+ public class BuildUpTarget1
+ {
+ public IGateway Gateway { get; set; }
+ public IService Service { get; set; }
+ }
+}
Oops, something went wrong.

0 comments on commit 214b371

Please sign in to comment.