From: <jer...@us...> - 2008-12-22 14:58:19
|
Revision: 212 http://structuremap.svn.sourceforge.net/structuremap/?rev=212&view=rev Author: jeremydmiller Date: 2008-12-22 14:57:59 +0000 (Mon, 22 Dec 2008) Log Message: ----------- Fixed a minor problem with explicit arguments and concrete classes Modified Paths: -------------- trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Extensions.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/TypeRules.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs Added Paths: ----------- trunk/Source/StructureMap/TypeExtensions.cs Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-12-21 16:31:48 UTC (rev 211) +++ trunk/Source/StructureMap/Container.cs 2008-12-22 14:57:59 UTC (rev 212) @@ -109,6 +109,11 @@ { Instance defaultInstance = _pipelineGraph.GetDefault(pluginType); + if (defaultInstance == null && pluginType.IsConcrete()) + { + defaultInstance = new ConfiguredInstance(pluginType); + } + BasicInstance basicInstance = defaultInstance as BasicInstance; Instance instance = basicInstance == null ? defaultInstance : new ExplicitInstance(pluginType, args, basicInstance); Modified: trunk/Source/StructureMap/Extensions.cs =================================================================== --- trunk/Source/StructureMap/Extensions.cs 2008-12-21 16:31:48 UTC (rev 211) +++ trunk/Source/StructureMap/Extensions.cs 2008-12-22 14:57:59 UTC (rev 212) @@ -5,7 +5,7 @@ namespace StructureMap { - public static class StringExtensions + internal static class StringExtensions { public static string ToFormat(this string template, params object[] parameters) { Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-12-21 16:31:48 UTC (rev 211) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-12-22 14:57:59 UTC (rev 212) @@ -7,14 +7,6 @@ namespace StructureMap.Graph { - public static class TypeExtensions - { - public static bool IsInNamespace(this Type type, string nameSpace) - { - return type.Namespace.StartsWith(nameSpace); - } - } - public interface IAssemblyScanner { #region Designating Assemblies Modified: trunk/Source/StructureMap/Graph/TypeRules.cs =================================================================== --- trunk/Source/StructureMap/Graph/TypeRules.cs 2008-12-21 16:31:48 UTC (rev 211) +++ trunk/Source/StructureMap/Graph/TypeRules.cs 2008-12-22 14:57:59 UTC (rev 212) @@ -76,7 +76,7 @@ return type.IsPrimitive && !IsString(type) && type != typeof (IntPtr); } - protected bool IsSimple(Type type) + protected internal bool IsSimple(Type type) { return type.IsPrimitive || IsString(type) || IsEnum(type); } @@ -101,7 +101,7 @@ return type.IsArray && IsSimple(type.GetElementType()); } - protected bool IsConcrete(Type type) + protected internal bool IsConcrete(Type type) { return !type.IsInterface && !type.IsAbstract; } @@ -112,4 +112,6 @@ return IsChild(type) || IsChildArray(type); } } + + } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-12-21 16:31:48 UTC (rev 211) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-12-22 14:57:59 UTC (rev 212) @@ -5,14 +5,6 @@ namespace StructureMap.Pipeline { - public static class TypeExtensions - { - public static ReferencedInstance GetReferenceTo(this Type type) - { - string key = PluginCache.GetPlugin(type).ConcreteKey; - return new ReferencedInstance(key); - } - } public interface IInstance { Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-12-21 16:31:48 UTC (rev 211) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-12-22 14:57:59 UTC (rev 212) @@ -406,6 +406,7 @@ <Compile Include="Graph\ITypeScanner.cs" /> <Compile Include="Graph\PluggableAttributeScanner.cs" /> <Compile Include="Graph\PluginCache.cs" /> + <Compile Include="TypeExtensions.cs" /> <Compile Include="IBootstrapper.cs" /> <Compile Include="InitializationExpression.cs" /> <Compile Include="Model.cs" /> Added: trunk/Source/StructureMap/TypeExtensions.cs =================================================================== --- trunk/Source/StructureMap/TypeExtensions.cs (rev 0) +++ trunk/Source/StructureMap/TypeExtensions.cs 2008-12-22 14:57:59 UTC (rev 212) @@ -0,0 +1,25 @@ +using System; +using StructureMap.Graph; +using StructureMap.Pipeline; + +namespace StructureMap +{ + public static class TypeExtensions + { + public static bool IsInNamespace(this Type type, string nameSpace) + { + return type.Namespace.StartsWith(nameSpace); + } + + public static ReferencedInstance GetReferenceTo(this Type type) + { + string key = PluginCache.GetPlugin(type).ConcreteKey; + return new ReferencedInstance(key); + } + + public static bool IsConcrete(this Type type) + { + return new TypeRules().IsConcrete(type); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs 2008-12-21 16:31:48 UTC (rev 211) +++ trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs 2008-12-22 14:57:59 UTC (rev 212) @@ -16,7 +16,10 @@ [SetUp] public void SetUp() { - ObjectFactory.Initialize(x => { x.UseDefaultStructureMapConfigFile = false; }); + ObjectFactory.Initialize(x => + { + x.UseDefaultStructureMapConfigFile = false; + }); } #endregion @@ -381,6 +384,14 @@ args.SetArg("age", 34); Assert.AreEqual(34, args.GetArg("age")); } + + [Test] + public void can_build_a_concrete_class_with_constructor_args_that_is_not_previously_registered() + { + var container = new Container(); + container.With("name").EqualTo("Jeremy").GetInstance<ConcreteThatNeedsString>() + .Name.ShouldEqual("Jeremy"); + } } public class Lump @@ -485,4 +496,19 @@ get { return _trade; } } } + + public class ConcreteThatNeedsString + { + private string _name; + + public ConcreteThatNeedsString(string name) + { + _name = name; + } + + public string Name + { + get { return _name; } + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |