From: <jer...@us...> - 2010-02-04 02:35:31
|
Revision: 332 http://structuremap.svn.sourceforge.net/structuremap/?rev=332&view=rev Author: jeremydmiller Date: 2010-02-04 00:56:59 +0000 (Thu, 04 Feb 2010) Log Message: ----------- patch from Kyle Malloy that adds IContext.BuildUp() and fixes a bug where Lifecycle was not correctly set from a Configure() block Modified Paths: -------------- trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/IContext.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2010-02-04 00:52:26 UTC (rev 331) +++ trunk/Source/StructureMap/BuildSession.cs 2010-02-04 00:56:59 UTC (rev 332) @@ -5,6 +5,7 @@ using StructureMap.Interceptors; using StructureMap.Pipeline; using StructureMap.Util; +using StructureMap.Construction; namespace StructureMap { @@ -61,6 +62,17 @@ } } + public void BuildUp(object target) + { + Type pluggedType = target.GetType(); + IConfiguredInstance instance = _pipelineGraph.GetDefault(pluggedType) as IConfiguredInstance + ?? new ConfiguredInstance(pluggedType); + + IInstanceBuilder builder = PluginCache.FindBuilder(pluggedType); + var arguments = new Arguments(instance, this); + builder.BuildUp(arguments, target); + } + public T GetInstance<T>() { return (T) CreateInstance(typeof (T)); @@ -186,4 +198,4 @@ return _pipelineGraph.ForType(pluginType); } } -} \ No newline at end of file +} Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2010-02-04 00:52:26 UTC (rev 331) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2010-02-04 00:56:59 UTC (rev 332) @@ -242,6 +242,11 @@ public void ImportFrom(PluginFamily source) { + if (source.Lifecycle != null) + { + SetScopeTo(source.Lifecycle); + } + source.Instances.Each(instance => _instances.Fill(instance.Name, instance)); source._pluggedTypes.Each((key, plugin) => _pluggedTypes.Fill(key, plugin)); Modified: trunk/Source/StructureMap/IContext.cs =================================================================== --- trunk/Source/StructureMap/IContext.cs 2010-02-04 00:52:26 UTC (rev 331) +++ trunk/Source/StructureMap/IContext.cs 2010-02-04 00:56:59 UTC (rev 332) @@ -27,6 +27,14 @@ string RequestedName { get; } /// <summary> + /// The "BuildUp" method takes in an already constructed object + /// and uses Setter Injection to push in configured dependencies + /// of that object + /// </summary> + /// <param name="target"></param> + void BuildUp(object target); + + /// <summary> /// Get the object of type T that is valid for this build session. /// </summary> /// <typeparam name="T"></typeparam> @@ -81,4 +89,4 @@ /// <returns></returns> IEnumerable<T> GetAllInstances<T>(); } -} \ No newline at end of file +} Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2010-02-04 00:52:26 UTC (rev 331) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2010-02-04 00:56:59 UTC (rev 332) @@ -281,6 +281,18 @@ family.SetScopeTo(InstanceScope.ThreadLocal); Assert.IsInstanceOfType(typeof (ThreadLocalStorageLifecycle), family.Lifecycle); } + + [Test] + public void Lifecycle_is_imported_from_the_source_when_merging_PluginFamilies() + { + var source = new PluginFamily(typeof(GenericType<>)); + source.SetScopeTo(InstanceScope.Unique); + var importInto = new PluginFamily(typeof(GenericType<>)); + + importInto.ImportFrom(source); + + importInto.Lifecycle.ShouldBeOfType(source.Lifecycle.GetType()); + } } @@ -313,4 +325,6 @@ public interface IDevice { } -} \ No newline at end of file + + public class GenericType<T> { } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |