|
From: <jer...@us...> - 2009-12-28 05:05:01
|
Revision: 311
http://structuremap.svn.sourceforge.net/structuremap/?rev=311&view=rev
Author: jeremydmiller
Date: 2009-12-28 05:04:44 +0000 (Mon, 28 Dec 2009)
Log Message:
-----------
added the FirstInterfaceConvention (I think it's a bad idea, but other people wanted it), deleted some obsolete code hiding out leftover from the data access crap
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/AssemblyScanner.cs
trunk/Source/StructureMap/Graph/IAssemblyScanner.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs
trunk/Source/StructureMap.Testing/SpecificationExtensions.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap/Graph/FirstInterfaceConvention.cs
trunk/Source/StructureMap.Testing/Graph/FirstInterfaceConventionTester.cs
Removed Paths:
-------------
trunk/Source/StructureMap.Testing/DataAccess/
Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-12-28 04:19:45 UTC (rev 310)
+++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-12-28 05:04:44 UTC (rev 311)
@@ -80,6 +80,11 @@
Convention<DefaultConventionScanner>();
}
+ public void RegisterConcreteTypesAgainstTheFirstInterface()
+ {
+ Convention<FirstInterfaceConvention>();
+ }
+
[Obsolete("Replace ITypeScanner with IRegistrationConvention")]
public void With<T>() where T : ITypeScanner, new()
{
Added: trunk/Source/StructureMap/Graph/FirstInterfaceConvention.cs
===================================================================
--- trunk/Source/StructureMap/Graph/FirstInterfaceConvention.cs (rev 0)
+++ trunk/Source/StructureMap/Graph/FirstInterfaceConvention.cs 2009-12-28 05:04:44 UTC (rev 311)
@@ -0,0 +1,24 @@
+using System;
+using System.Diagnostics;
+using StructureMap.Configuration.DSL;
+using StructureMap.TypeRules;
+using System.Linq;
+
+namespace StructureMap.Graph
+{
+ public class FirstInterfaceConvention : IRegistrationConvention
+ {
+ public void Process(Type type, Registry registry)
+ {
+ if (!type.IsConcrete() || !type.CanBeCreated()) return;
+
+
+ var interfaceType = type.AllInterfaces().FirstOrDefault();
+ if (interfaceType != null)
+ {
+ Debug.WriteLine("Plugging {0} into {1}".ToFormat(type.Name, interfaceType.Name));
+ registry.AddType(interfaceType, type);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/IAssemblyScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/IAssemblyScanner.cs 2009-12-28 04:19:45 UTC (rev 310)
+++ trunk/Source/StructureMap/Graph/IAssemblyScanner.cs 2009-12-28 05:04:44 UTC (rev 311)
@@ -83,6 +83,13 @@
void WithDefaultConventions();
/// <summary>
+ /// Automatically registers all concrete types without primitive arguments
+ /// against its first interface, if any
+ /// </summary>
+ void RegisterConcreteTypesAgainstTheFirstInterface();
+
+
+ /// <summary>
/// Creates and adds a new ITypeScanner of type T to this scanning operation
/// </summary>
/// <typeparam name="T"></typeparam>
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-12-28 04:19:45 UTC (rev 310)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-12-28 05:04:44 UTC (rev 311)
@@ -348,7 +348,11 @@
/// The InstanceKey of the default instance of the PluginFamily
/// </summary>
[Obsolete]
- public string DefaultInstanceKey { get { return _defaultKey; } set { _defaultKey = value ?? string.Empty; } }
+ public string DefaultInstanceKey
+ {
+ get { return _defaultKey; }
+ set { _defaultKey = value ?? string.Empty; }
+ }
#endregion
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2009-12-28 04:19:45 UTC (rev 310)
+++ trunk/Source/StructureMap/StructureMap.csproj 2009-12-28 05:04:44 UTC (rev 311)
@@ -361,6 +361,7 @@
<Compile Include="Graph\FamilyAttributeScanner.cs" />
<Compile Include="Graph\FindAllTypesFilter.cs" />
<Compile Include="Graph\FindRegistriesScanner.cs" />
+ <Compile Include="Graph\FirstInterfaceConvention.cs" />
<Compile Include="Graph\IAssemblyScanner.cs" />
<Compile Include="Graph\ImplementationMap.cs" />
<Compile Include="Graph\ITypeScanner.cs" />
Modified: trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2009-12-28 04:19:45 UTC (rev 310)
+++ trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2009-12-28 05:04:44 UTC (rev 311)
@@ -58,7 +58,6 @@
{
}
-
[TestFixture]
public class DefaultConventionScanningTester
{
Added: trunk/Source/StructureMap.Testing/Graph/FirstInterfaceConventionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/FirstInterfaceConventionTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Graph/FirstInterfaceConventionTester.cs 2009-12-28 05:04:44 UTC (rev 311)
@@ -0,0 +1,79 @@
+using System.Diagnostics;
+using NUnit.Framework;
+using System.Linq;
+using StructureMap.Testing.Widget;
+using StructureMap.Testing.Widget3;
+using StructureMap.TypeRules;
+
+namespace StructureMap.Testing.Graph
+{
+ [TestFixture]
+ public class FirstInterfaceConventionTester
+ {
+ private Container container;
+
+ [SetUp]
+ public void SetUp()
+ {
+ container = new Container(x =>
+ {
+ x.Scan(o =>
+ {
+ o.TheCallingAssembly();
+ o.RegisterConcreteTypesAgainstTheFirstInterface();
+
+ o.Exclude(t => t.CanBeCastTo(typeof(IGateway)));
+ });
+ });
+ }
+
+ [Test]
+ public void simple_case()
+ {
+ container.Model.For<I1>().Instances.Select(x => x.ConcreteType).ShouldHaveTheSameElementsAs(typeof(C1), typeof(C2));
+ container.Model.For<I2>().Instances.Select(x => x.ConcreteType).Any().ShouldBeFalse();
+ }
+
+ [Test]
+ public void do_not_register_type_if_there_are_primitive_arguments()
+ {
+ container.Model.HasImplementationsFor<I3>().ShouldBeFalse();
+ }
+
+
+ public interface I1 { }
+ public interface I2 { }
+ public interface I3 { }
+
+ public class C1 : I1 { }
+ public class C2 : C1, I2 { }
+ public class C3 : C2, I3
+ {
+ public C3(string name)
+ {
+ }
+ }
+
+ public class C4
+ {
+
+ }
+
+ public class C5 : I1
+ {
+ private C5(){}
+ }
+
+ public interface I1<T> { }
+ public interface I2<T> { }
+ public interface I3<T> { }
+
+ public class C1<T> : I1<T> { }
+ public class C2<T> : C1<T>, I2<T> { }
+ public class C3<T> : C2<T>, I3<T> { }
+
+ }
+
+
+}
+
Modified: trunk/Source/StructureMap.Testing/SpecificationExtensions.cs
===================================================================
--- trunk/Source/StructureMap.Testing/SpecificationExtensions.cs 2009-12-28 04:19:45 UTC (rev 310)
+++ trunk/Source/StructureMap.Testing/SpecificationExtensions.cs 2009-12-28 05:04:44 UTC (rev 311)
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
@@ -31,11 +32,23 @@
actual.ShouldNotBeNull();
expected.ShouldNotBeNull();
- actual.Count.ShouldEqual(expected.Count);
+ try
+ {
+ actual.Count.ShouldEqual(expected.Count);
- for (int i = 0; i < actual.Count; i++)
+ for (int i = 0; i < actual.Count; i++)
+ {
+ actual[i].ShouldEqual(expected[i]);
+ }
+ }
+ catch (Exception)
{
- actual[i].ShouldEqual(expected[i]);
+ Debug.WriteLine("ACTUAL:");
+ foreach (var o in actual)
+ {
+ Debug.WriteLine(o);
+ }
+ throw;
}
}
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-12-28 04:19:45 UTC (rev 310)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-12-28 05:04:44 UTC (rev 311)
@@ -257,6 +257,7 @@
<Compile Include="Graph\ExceptionHandling\StructureMapExceptionTester.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Graph\FirstInterfaceConventionTester.cs" />
<Compile Include="Graph\SingleImplementationScannerTester.cs" />
<Compile Include="Graph\TestExplicitArguments.cs" />
<Compile Include="Graph\FillDependenciesTester.cs">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|