|
From: <jer...@us...> - 2010-02-11 02:44:07
|
Revision: 347
http://structuremap.svn.sourceforge.net/structuremap/?rev=347&view=rev
Author: jeremydmiller
Date: 2010-02-11 02:43:57 +0000 (Thu, 11 Feb 2010)
Log Message:
-----------
Fixing a bug with IContext.GetAllInstances<T>()
Modified Paths:
--------------
trunk/Source/StructureMap/BuildSession.cs
trunk/Source/StructureMap.Testing/BuildSessionTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs
trunk/Source/StructureMap.Testing/Examples.cs
trunk/Source/StructureMap.Testing/Pipeline/ContainerDisposalTester.cs
trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing.Widget3/IService.cs
trunk/cruise.build
Added Paths:
-----------
trunk/Source/StructureMap.Testing/Bugs/EnumerableShouldGetAllValuesTester.cs
Modified: trunk/Source/StructureMap/BuildSession.cs
===================================================================
--- trunk/Source/StructureMap/BuildSession.cs 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/Source/StructureMap/BuildSession.cs 2010-02-11 02:43:57 UTC (rev 347)
@@ -119,7 +119,7 @@
public IEnumerable<T> GetAllInstances<T>()
{
- return forType(typeof (T)).AllInstances.Select(x => GetInstance<T>());
+ return (IEnumerable<T>) forType(typeof (T)).AllInstances.Select(x => (T)CreateInstance(typeof(T), x));
}
protected void clearBuildStack()
Added: trunk/Source/StructureMap.Testing/Bugs/EnumerableShouldGetAllValuesTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Bugs/EnumerableShouldGetAllValuesTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Bugs/EnumerableShouldGetAllValuesTester.cs 2010-02-11 02:43:57 UTC (rev 347)
@@ -0,0 +1,44 @@
+using System.Collections.Generic;
+using NUnit.Framework;
+using StructureMap.Testing.Widget;
+using System.Linq;
+
+namespace StructureMap.Testing.Bugs
+{
+ [TestFixture]
+ public class EnumerableShouldGetAllValuesTester
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ }
+
+ [Test]
+ public void ienumerable_arg_should_get_all_registered()
+ {
+ var container = new Container(x =>
+ {
+ x.For<IWidget>().AddInstances(o =>
+ {
+ o.Type<ColorWidget>().Ctor<string>("color").Is("red");
+ o.Type<ColorWidget>().Ctor<string>("color").Is("blue");
+ o.Type<ColorWidget>().Ctor<string>("color").Is("green");
+ });
+ });
+
+ container.GetInstance<ClassWithEnumerable>().Widgets.Count().ShouldEqual(3);
+ }
+
+ public class ClassWithEnumerable
+ {
+ private readonly IEnumerable<IWidget> _widgets;
+
+ public ClassWithEnumerable(IEnumerable<IWidget> widgets)
+ {
+ _widgets = widgets;
+ }
+
+ public IEnumerable<IWidget> Widgets { get { return _widgets; } }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2010-02-11 02:43:57 UTC (rev 347)
@@ -67,7 +67,49 @@
container.GetInstance<TopClass>().Widgets.Count().ShouldEqual(4);
}
+
[Test]
+ public void can_get_all_of_a_type_during_object_creation_as_generic_type()
+ {
+ var container = new Container(x =>
+ {
+ x.For<IWidget>().AddInstances(o =>
+ {
+ o.OfConcreteType<AWidget>();
+ o.ConstructedBy(() => new ColorWidget("red"));
+ o.ConstructedBy(() => new ColorWidget("blue"));
+ o.ConstructedBy(() => new ColorWidget("green"));
+ });
+
+ x.ForConcreteType<TopClass>().Configure.OnCreation(
+ (c, top) => { top.Widgets = c.All<IWidget>().ToArray(); });
+ });
+
+ container.GetInstance<TopClass>().Widgets.Count().ShouldEqual(4);
+ }
+
+
+ [Test]
+ public void can_get_all_of_a_type_by_GetAllInstances_during_object_creation_as_generic_type()
+ {
+ var container = new Container(x =>
+ {
+ x.For<IWidget>().AddInstances(o =>
+ {
+ o.OfConcreteType<AWidget>();
+ o.ConstructedBy(() => new ColorWidget("red"));
+ o.ConstructedBy(() => new ColorWidget("blue"));
+ o.ConstructedBy(() => new ColorWidget("green"));
+ });
+
+ x.ForConcreteType<TopClass>().Configure.OnCreation(
+ (c, top) => { top.Widgets = c.GetAllInstances<IWidget>().ToArray(); });
+ });
+
+ container.GetInstance<TopClass>().Widgets.Count().ShouldEqual(4);
+ }
+
+ [Test]
public void Get_a_unique_value_for_each_individual_buildsession()
{
int count = 0;
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2010-02-11 02:43:57 UTC (rev 347)
@@ -150,6 +150,10 @@
public IService Inner { get { return _inner; } }
+ public void DoSomething()
+ {
+ throw new NotImplementedException();
+ }
}
public class ContextRecorder
Modified: trunk/Source/StructureMap.Testing/Examples.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Examples.cs 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/Source/StructureMap.Testing/Examples.cs 2010-02-11 02:43:57 UTC (rev 347)
@@ -403,6 +403,10 @@
public class RemoteService : IService
{
+ public void DoSomething()
+ {
+ throw new NotImplementedException();
+ }
}
public class InstanceExampleRegistry : Registry
Modified: trunk/Source/StructureMap.Testing/Pipeline/ContainerDisposalTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/ContainerDisposalTester.cs 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/Source/StructureMap.Testing/Pipeline/ContainerDisposalTester.cs 2010-02-11 02:43:57 UTC (rev 347)
@@ -1,5 +1,6 @@
using System;
using NUnit.Framework;
+using StructureMap.Testing.Widget3;
namespace StructureMap.Testing.Pipeline
{
Modified: trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs 2010-02-11 02:43:57 UTC (rev 347)
@@ -206,7 +206,11 @@
[Test]
public void transient_service_in_the_parent_container_is_effectively_a_singleton_for_the_nested_container()
{
- var parent = new Container(x => { x.For<IWidget>().Use<AWidget>(); });
+ var parent = new Container(x =>
+ {
+ // IWidget is a "transient"
+ x.For<IWidget>().Use<AWidget>();
+ });
IContainer child = parent.GetNestedContainer();
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2010-02-11 02:43:57 UTC (rev 347)
@@ -180,6 +180,7 @@
<Compile Include="BidirectionalDependencies.cs" />
<Compile Include="Bugs\AddValueDirectlyWithGenericUsage.cs" />
<Compile Include="Bugs\BuildUpBug.cs" />
+ <Compile Include="Bugs\EnumerableShouldGetAllValuesTester.cs" />
<Compile Include="Bugs\FillAllPropertiesShouldWorkForAlreadyConfiguredPluginsBug.cs" />
<Compile Include="Bugs\HttpSessionNullRefBug.cs" />
<Compile Include="Bugs\IDictionaryAndXmlBugTester.cs" />
Modified: trunk/Source/StructureMap.Testing.Widget3/IService.cs
===================================================================
--- trunk/Source/StructureMap.Testing.Widget3/IService.cs 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/Source/StructureMap.Testing.Widget3/IService.cs 2010-02-11 02:43:57 UTC (rev 347)
@@ -1,3 +1,5 @@
+using System;
+
namespace StructureMap.Testing.Widget3
{
public interface IService : IBasicService
@@ -2,2 +4,3 @@
{
+ void DoSomething();
}
@@ -25,5 +28,10 @@
{
return "ColorService: " + _color;
}
+
+ public void DoSomething()
+ {
+ throw new NotImplementedException();
+ }
}
}
\ No newline at end of file
Modified: trunk/cruise.build
===================================================================
--- trunk/cruise.build 2010-02-10 00:14:42 UTC (rev 346)
+++ trunk/cruise.build 2010-02-11 02:43:57 UTC (rev 347)
@@ -4,7 +4,7 @@
<property name="deployment.dir" value="source\StructureMap.Testing.DeploymentTasks\"/>
<property name="results.dir" value="results" />
<property name="nant.dir" value="bin\nant" />
- <property name="project.version" value="2.6.2" />
+ <property name="project.version" value="2.6.1" />
<property name="project.config" value="release" />
<property name="archive.dir" value="archive"/>
<target name="all" depends="compile, unit-test, post-clean"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|