|
From: <jer...@us...> - 2008-05-27 22:12:36
|
Revision: 103
http://structuremap.svn.sourceforge.net/structuremap/?rev=103&view=rev
Author: jeremydmiller
Date: 2008-05-27 15:12:33 -0700 (Tue, 27 May 2008)
Log Message:
-----------
little refactoring of ProfileManager and PluginFamily to move misplaced code
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Pipeline/ProfileManager.cs
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 17:50:51 UTC (rev 102)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-05-27 22:12:33 UTC (rev 103)
@@ -297,5 +297,21 @@
AddInstance(memento);
DefaultInstanceKey = memento.InstanceKey;
}
+
+ public void FillDefault(Profile profile)
+ {
+ if (string.IsNullOrEmpty(DefaultInstanceKey))
+ {
+ return;
+ }
+
+ Instance defaultInstance = GetInstance(DefaultInstanceKey);
+ if (defaultInstance == null)
+ {
+ Parent.Log.RegisterError(210, DefaultInstanceKey, PluginType);
+ }
+
+ profile.FillTypeInto(PluginType, defaultInstance);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 17:50:51 UTC (rev 102)
+++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2008-05-27 22:12:33 UTC (rev 103)
@@ -133,7 +133,7 @@
{
foreach (PluginFamily family in graph.PluginFamilies)
{
- findDefaultFromPluginFamily(family);
+ family.FillDefault(_default);
}
}
@@ -158,19 +158,6 @@
}
}
- private void findDefaultFromPluginFamily(PluginFamily family)
- {
- // TODO: Sad path here if the default instance key cannot be found
- // TODO: Pull inside of PluginFamily itself
- if (string.IsNullOrEmpty(family.DefaultInstanceKey))
- {
- return;
- }
-
- Instance defaultInstance = family.GetInstance(family.DefaultInstanceKey);
- _default.FillTypeInto(family.PluginType, defaultInstance);
- }
-
public void CopyDefaults(Type basicType, Type templatedType)
{
_default.CopyDefault(basicType, templatedType);
Modified: trunk/Source/StructureMap/StructureMapException.resx
===================================================================
--- trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 17:50:51 UTC (rev 102)
+++ trunk/Source/StructureMap/StructureMapException.resx 2008-05-27 22:12:33 UTC (rev 103)
@@ -256,4 +256,7 @@
<data name="270" xml:space="preserve">
<value>Instance specific interception failed for {0} of PluginType {1}</value>
</data>
+ <data name="210" xml:space="preserve">
+ <value>The designated default instance '{0}' for PluginType {1} cannot be found</value>
+ </data>
</root>
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-27 17:50:51 UTC (rev 102)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-05-27 22:12:33 UTC (rev 103)
@@ -112,6 +112,32 @@
}
[Test]
+ public void FillDefault_happy_path()
+ {
+ PluginFamily family = new PluginFamily(typeof (IWidget));
+ family.Parent = new PluginGraph();
+ family.AddInstance(new ConfiguredInstance().WithName("Default"));
+ family.DefaultInstanceKey = "Default";
+
+
+ family.FillDefault(new Profile("theProfile"));
+
+ family.Parent.Log.AssertHasNoError(210);
+ }
+
+ [Test]
+ public void FillDefault_sad_path_when_the_default_instance_key_does_not_exist_throws_210()
+ {
+ PluginFamily family = new PluginFamily(typeof (IWidget));
+ family.Parent = new PluginGraph();
+
+ family.DefaultInstanceKey = "something that cannot be found";
+ family.FillDefault(new Profile("theProfile"));
+
+ family.Parent.Log.AssertHasError(210);
+ }
+
+ [Test]
public void If_PluginFamily_only_has_one_instance_make_that_the_default()
{
PluginFamily family = new PluginFamily(typeof (IGateway));
@@ -259,7 +285,7 @@
[Pluggable("Default")]
public class SingletonRepositoryWithAttribute : ISingletonRepository
{
- private Guid _id = Guid.NewGuid();
+ private readonly Guid _id = Guid.NewGuid();
public Guid Id
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|