|
From: <jer...@us...> - 2010-02-03 23:16:39
|
Revision: 328
http://structuremap.svn.sourceforge.net/structuremap/?rev=328&view=rev
Author: jeremydmiller
Date: 2010-02-03 23:16:32 +0000 (Wed, 03 Feb 2010)
Log Message:
-----------
Applied a patch from Frank Quednau related to applying closed types to a generic interface
Modified Paths:
--------------
branches/2.5.4/Source/StructureMap/Graph/PluginFamily.cs
branches/2.5.4/Source/StructureMap/Pipeline/ConstructorInstance.cs
branches/2.5.4/Source/StructureMap/TypeExtensions.cs
branches/2.5.4/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
branches/2.5.4/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs
Modified: branches/2.5.4/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- branches/2.5.4/Source/StructureMap/Graph/PluginFamily.cs 2010-01-30 22:08:48 UTC (rev 327)
+++ branches/2.5.4/Source/StructureMap/Graph/PluginFamily.cs 2010-02-03 23:16:32 UTC (rev 328)
@@ -288,9 +288,15 @@
return clone;
}).Where(x => x != null).Each(templatedFamily.AddInstance);
+ //Are there instances that close the templatedtype straight away?
+ _instances.GetAll()
+ .Where(x => x.ConcreteType.CanBeCastTo(templatedType))
+ .Each(templatedFamily.AddInstance);
+
// Need to attach the new PluginFamily to the old PluginGraph
Parent.PluginFamilies.Add(templatedFamily);
+
return templatedFamily;
}
@@ -363,4 +369,4 @@
#endregion
}
-}
\ No newline at end of file
+}
Modified: branches/2.5.4/Source/StructureMap/Pipeline/ConstructorInstance.cs
===================================================================
--- branches/2.5.4/Source/StructureMap/Pipeline/ConstructorInstance.cs 2010-01-30 22:08:48 UTC (rev 327)
+++ branches/2.5.4/Source/StructureMap/Pipeline/ConstructorInstance.cs 2010-02-03 23:16:32 UTC (rev 328)
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Globalization;
using System.Linq;
using StructureMap.Construction;
using StructureMap.Graph;
@@ -198,7 +199,7 @@
if (value.GetType() == dependencyType) return new ObjectInstance(value);
TypeConverter converter = TypeDescriptor.GetConverter(dependencyType);
- object convertedValue = converter.ConvertFrom(value);
+ object convertedValue = converter.ConvertFrom(null, CultureInfo.InvariantCulture, value);
return new ObjectInstance(convertedValue);
}
catch (Exception e)
@@ -276,4 +277,4 @@
return "'{0}' -> {1}".ToFormat(Name, _plugin.PluggedType.FullName);
}
}
-}
\ No newline at end of file
+}
Modified: branches/2.5.4/Source/StructureMap/TypeExtensions.cs
===================================================================
--- branches/2.5.4/Source/StructureMap/TypeExtensions.cs 2010-01-30 22:08:48 UTC (rev 327)
+++ branches/2.5.4/Source/StructureMap/TypeExtensions.cs 2010-02-03 23:16:32 UTC (rev 328)
@@ -181,7 +181,7 @@
return false;
}
- if (pluginType.IsOpenGeneric() && pluggedType.IsGenericType)
+ if (pluginType.IsOpenGeneric())
{
return GenericsPluginGraph.CanBeCast(pluginType, pluggedType);
}
@@ -257,4 +257,4 @@
}
}
}
-}
\ No newline at end of file
+}
Modified: branches/2.5.4/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
===================================================================
--- branches/2.5.4/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2010-01-30 22:08:48 UTC (rev 327)
+++ branches/2.5.4/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2010-02-03 23:16:32 UTC (rev 328)
@@ -157,6 +157,13 @@
}
[Test]
+ public void CanPlugConcreteNonGenericClassIntoGenericInterface()
+ {
+ typeof(NotSoGenericService).CanBeCastTo(typeof(IGenericService<>))
+ .ShouldBeTrue();
+ }
+
+ [Test]
public void Define_profile_with_generics_and_concrete_type()
{
var container = new Container(registry =>
@@ -306,4 +313,9 @@
return typeof (T);
}
}
-}
\ No newline at end of file
+
+ public class NotSoGenericService : IGenericService<string>
+ {
+ public void DoSomething(string thing) { }
+ }
+}
Modified: branches/2.5.4/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs
===================================================================
--- branches/2.5.4/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2010-01-30 22:08:48 UTC (rev 327)
+++ branches/2.5.4/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2010-02-03 23:16:32 UTC (rev 328)
@@ -47,7 +47,15 @@
public class Service3<T> : IService<T>
{
}
+
+ public interface IOtherService<T>
+ {
+ }
+ public class Service4 : IOtherService<string>
+ {
+ }
+
[PluginFamily("Default")]
public interface IThingy
{
@@ -151,6 +159,22 @@
}
[Test]
+ public void Add_an_assembly_on_the_fly_and_pick_up_plugins4()
+ {
+ var container = new Container();
+ container.Configure(
+ registry => registry.Scan(
+ x =>
+ {
+ x.AssemblyContainingType(typeof (IOtherService<>));
+ x.AddAllTypesOf(typeof (IOtherService<>));
+ }));
+
+ var instances = container.GetAllInstances<IOtherService<string>>();
+ instances.Any(s=> s is Service4).ShouldBeTrue();
+ }
+
+ [Test]
public void Add_generic_stuff_in_configure()
{
var container = new Container();
@@ -346,4 +370,4 @@
throw new NotImplementedException();
}
}
-}
\ No newline at end of file
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|