From: <jer...@us...> - 2009-12-24 04:53:31
|
Revision: 285 http://structuremap.svn.sourceforge.net/structuremap/?rev=285&view=rev Author: jeremydmiller Date: 2009-12-24 04:53:19 +0000 (Thu, 24 Dec 2009) Log Message: ----------- Work on the new ConstructorInstance, EnumerableInstance Modified Paths: -------------- trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/CloseGenericTypeExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Emitting/Parameters/Methods.cs trunk/Source/StructureMap/Graph/Constructor.cs trunk/Source/StructureMap/Graph/ITypeScanner.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs trunk/Source/StructureMap/Pipeline/PropertyExpression.cs trunk/Source/StructureMap/Pipeline/SmartInstance.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/TypeExtensions.cs trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyMergeTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs trunk/Source/StructureMap.Testing/Pipeline/MissingInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerMergeTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs Added Paths: ----------- trunk/Source/StructureMap/Pipeline/ArrayCoercion.cs trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs trunk/Source/StructureMap/Pipeline/EnumerableInstance.cs trunk/Source/StructureMap/Pipeline/IEnumerableCoercion.cs trunk/Source/StructureMap/Pipeline/LambdaInstance.cs trunk/Source/StructureMap/Pipeline/ListCoercion.cs trunk/Source/StructureMap/Pipeline/ObjectInstance.cs trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/EnumerableInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/LambdaInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ObjectInstanceTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs trunk/Source/StructureMap/Pipeline/HttpSessionBuildPolicy.cs trunk/Source/StructureMap/Pipeline/Lifecycle.cs trunk/Source/StructureMap/Pipeline/LiteralInstance.cs trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/LiteralInstanceTester.cs Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/BuildSession.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -153,7 +153,7 @@ return result; } - + [Obsolete("Move all of this into the new EnumerableInstance")] public virtual Array CreateInstanceArray(Type pluginType, Instance[] instances) { if (instances == null) Modified: trunk/Source/StructureMap/CloseGenericTypeExpression.cs =================================================================== --- trunk/Source/StructureMap/CloseGenericTypeExpression.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/CloseGenericTypeExpression.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -40,7 +40,7 @@ private void closeType(Type type) { - if (!type.IsGeneric()) + if (!type.IsOpenGeneric()) { throw new StructureMapException(285); } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -124,7 +124,7 @@ /// </summary> /// <param name="func"></param> /// <returns></returns> - public ConstructorInstance<PLUGINTYPE> Use(Func<IContext, PLUGINTYPE> func) + public LambdaInstance<PLUGINTYPE> Use(Func<IContext, PLUGINTYPE> func) { return TheDefault.Is.ConstructedBy(func); } @@ -134,7 +134,7 @@ /// </summary> /// <param name="object"></param> /// <returns></returns> - public LiteralInstance Use(PLUGINTYPE @object) + public ObjectInstance Use(PLUGINTYPE @object) { return TheDefault.IsThis(@object); } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -72,9 +72,9 @@ /// </summary> /// <param name="value"></param> /// <returns></returns> - public LiteralInstance Use(object value) + public ObjectInstance Use(object value) { - var instance = new LiteralInstance(value); + var instance = new ObjectInstance(value); Use(instance); return instance; @@ -105,7 +105,7 @@ public GenericFamilyExpression Add(object instance) { - return Add(new LiteralInstance(instance)); + return Add(new ObjectInstance(instance)); } Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -26,7 +26,7 @@ /// </summary> /// <param name="obj"></param> /// <returns></returns> - LiteralInstance IsThis(T obj); + ObjectInstance IsThis(T obj); } public interface ThenItExpression<T> @@ -95,7 +95,7 @@ /// </summary> /// <param name="theObject"></param> /// <returns></returns> - LiteralInstance Object(T theObject); + ObjectInstance Object(T theObject); /// <summary> /// Build the Instance with the constructor function and setter arguments. Starts @@ -123,7 +123,7 @@ /// <param name="func"></param> /// <returns></returns> [Obsolete("Prefer For<T>().Use(Func<T> func) or For<T>().Add(Func<T> func)")] - ConstructorInstance<T> ConstructedBy(Func<T> func); + LambdaInstance<T> ConstructedBy(Func<T> func); /// <summary> /// Create an Instance that builds an object by calling a Lambda or @@ -132,7 +132,7 @@ /// </summary> /// <param name="func"></param> /// <returns></returns> - ConstructorInstance<T> ConstructedBy(Func<IContext, T> func); + LambdaInstance<T> ConstructedBy(Func<IContext, T> func); /// <summary> /// Use the Instance of this PluginType with the specified name. This is @@ -204,9 +204,9 @@ returnInstance(instance); } - public LiteralInstance IsThis(T obj) + public ObjectInstance IsThis(T obj) { - return returnInstance(new LiteralInstance(obj)); + return returnInstance(new ObjectInstance(obj)); } #endregion @@ -232,9 +232,9 @@ return returnInstance(new ConfiguredInstance(type)); } - public LiteralInstance Object(T theObject) + public ObjectInstance Object(T theObject) { - return returnInstance(new LiteralInstance(theObject)); + return returnInstance(new ObjectInstance(theObject)); } public ReferencedInstance TheInstanceNamed(string name) @@ -247,14 +247,14 @@ return returnInstance(new DefaultInstance()); } - public ConstructorInstance<T> ConstructedBy(Func<T> func) + public LambdaInstance<T> ConstructedBy(Func<T> func) { - return returnInstance(new ConstructorInstance<T>(func)); + return returnInstance(new LambdaInstance<T>(func)); } - public ConstructorInstance<T> ConstructedBy(Func<IContext, T> func) + public LambdaInstance<T> ConstructedBy(Func<IContext, T> func) { - return returnInstance(new ConstructorInstance<T>(func)); + return returnInstance(new LambdaInstance<T>(func)); } public PrototypeInstance PrototypeOf(T template) Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -169,7 +169,7 @@ /// <returns></returns> public ProfileExpression Use(Func<T> func) { - var instance = new ConstructorInstance<T>(func); + var instance = new LambdaInstance<T>(func); return Use(instance); } @@ -180,7 +180,7 @@ /// <returns></returns> public ProfileExpression Use(T t) { - var instance = new LiteralInstance(t); + var instance = new ObjectInstance(t); return Use(instance); } Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -395,7 +395,7 @@ /// <typeparam name="T"></typeparam> /// <typeparam name="U"></typeparam> /// <returns></returns> - public ConstructorInstance<T> Redirect<T, U>() where T : class where U : class + public LambdaInstance<T> Redirect<T, U>() where T : class where U : class { return For<T>().TheDefault.Is.ConstructedBy(c => { Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Container.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -561,7 +561,7 @@ public OpenGenericTypeExpression(Type templateType, Container container) { - if (!templateType.IsGeneric()) + if (!templateType.IsOpenGeneric()) { throw new StructureMapException(285); } @@ -599,7 +599,7 @@ /// <param name="object"></param> public void Inject<T>(string name, T @object) { - LiteralInstance instance = new LiteralInstance(@object).WithName(name); + ObjectInstance instance = new ObjectInstance(@object).WithName(name); _transientCache.Set(typeof(T), instance, @object); _pipelineGraph.AddInstance<T>(instance); } @@ -630,7 +630,7 @@ } - var instance = new LiteralInstance(@object); + var instance = new ObjectInstance(@object); _transientCache.Set(pluginType, instance, @object); _pipelineGraph.SetDefault(pluginType, instance); } Modified: trunk/Source/StructureMap/Emitting/Parameters/Methods.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/Methods.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Emitting/Parameters/Methods.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -24,7 +24,7 @@ }, null); public static MethodInfo GET_CHILD = - ReflectionHelper.GetMethod<IConfiguredInstance>(i => i.GetChild(null, null, null)); + ReflectionHelper.GetMethod<IConfiguredInstance>(i => i.Get(null, null, null)); public static MethodInfo GET_CHILDREN_ARRAY = ReflectionHelper.GetMethod<IConfiguredInstance>(i => i.GetChildrenArray(null)); Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Linq.Expressions; using System.Reflection; using StructureMap.TypeRules; @@ -81,15 +82,9 @@ public string FindFirstConstructorArgumentOfType(Type type) { - foreach (ParameterInfo info in _ctor.GetParameters()) - { - if (info.ParameterType.Equals(type)) - { - return info.Name; - } - } - - return null; + return _ctor.GetParameters() + .Where(x => x.ParameterType == type) + .Select(x => x.Name).FirstOrDefault(); } @@ -157,5 +152,12 @@ _ctor = ctor; } + + public Type FindArgumentType(string name) + { + return _ctor.GetParameters() + .Where(x => x.Name == name) + .Select(x => x.ParameterType).FirstOrDefault(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -41,7 +41,7 @@ { _openType = openType; - if (!_openType.IsGeneric()) + if (!_openType.IsOpenGeneric()) { throw new ApplicationException("This scanning convention can only be used with open generic types"); } Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -169,7 +169,12 @@ public bool IsNotOpenGeneric() { - return !_pluggedType.IsGeneric(); + return !_pluggedType.IsOpenGeneric(); } + + public Type FindArgumentType(string argumentName) + { + return _constructor.FindArgumentType(argumentName) ?? _setters.FindArgumentType(argumentName); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs =================================================================== --- trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Reflection; +using System.Linq; namespace StructureMap.Graph { @@ -129,5 +130,12 @@ { _properties.FindAll(setter => rule(setter.Property)).ForEach(setter => setter.IsMandatory = true); } + + public Type FindArgumentType(string name) + { + return _properties + .Where(x => x.Name == name) + .Select(x => x.Property.PropertyType).FirstOrDefault(); + } } } \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/ArrayCoercion.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ArrayCoercion.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ArrayCoercion.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Linq; + +namespace StructureMap.Pipeline +{ + public class ArrayCoercion<T> : IEnumerableCoercion where T : class + { + public object Convert(IEnumerable<object> enumerable) + { + return enumerable.Select(x => x as T).ToArray(); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -322,7 +322,7 @@ public ConfiguredInstance Is(object value) { - var instance = new LiteralInstance(value); + var instance = new ObjectInstance(value); return Is(instance); } Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -87,7 +87,7 @@ return _properties[propertyName]; } - object IConfiguredInstance.GetChild(string propertyName, Type pluginType, BuildSession buildSession) + object IConfiguredInstance.Get(string propertyName, Type pluginType, BuildSession buildSession) { return getChild(propertyName, pluginType, buildSession); } @@ -130,7 +130,7 @@ setProperty(propertyName, propertyValue); } - void IConfiguredInstance.SetChild(string name, Instance instance) + void IConfiguredInstance.Set(string name, Instance instance) { setChild(name, instance); } Deleted: trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -1,41 +0,0 @@ -using System; - -namespace StructureMap.Pipeline -{ - public class ConstructorInstance<T> : ExpressedInstance<ConstructorInstance<T>> - { - private readonly Func<IContext, T> _builder; - - public ConstructorInstance(Func<IContext, T> builder) - { - _builder = builder; - } - - public ConstructorInstance(Func<T> func) - { - _builder = s => func(); - } - - protected override ConstructorInstance<T> thisInstance - { - get { return this; } - } - - protected override object build(Type pluginType, BuildSession session) - { - try - { - return _builder(session); - } - catch (Exception ex) - { - throw new StructureMapException(207, ex, Name, pluginType); - } - } - - protected override string getDescription() - { - return "Instance is created by Func<object> function: " + _builder; - } - } -} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using StructureMap.Graph; +using StructureMap.TypeRules; +using StructureMap.Util; + +namespace StructureMap.Pipeline +{ + public class ConstructorInstance : Instance + { + private readonly Cache<string, Instance> _dependencies = new Cache<string, Instance>(); + private readonly Plugin _plugin; + + public ConstructorInstance(Type pluggedType) + { + _plugin = PluginCache.GetPlugin(pluggedType); + } + + protected override string getDescription() + { + return "Configured Instance of " + _plugin.PluggedType.AssemblyQualifiedName; + } + + public void SetChild(string name, Instance instance) + { + _dependencies[name] = instance; + } + + public void SetValue(string name, object value) + { + var dependencyType = _plugin.FindArgumentType(name); + var instance = buildInstanceForType(dependencyType, value); + _dependencies[name] = instance; + } + + public void SetCollection(string name, IEnumerable<Instance> children) + { + var dependencyType = _plugin.FindArgumentType(name); + var instance = new EnumerableInstance(dependencyType, children); + _dependencies[name] = instance; + } + + private static Instance buildInstanceForType(Type dependencyType, object value) + { + if (value == null) return new NullInstance(); + + + if (dependencyType.IsSimple() || dependencyType.IsNullable() || dependencyType == typeof(Guid) || dependencyType == typeof(DateTime)) + { + var converter = TypeDescriptor.GetConverter(dependencyType); + var convertedValue = converter.ConvertFrom(value); + return new ObjectInstance(convertedValue); + } + + + return new ObjectInstance(value); + } + + public object Get(string propertyName, Type pluginType, BuildSession session) + { + return _dependencies[propertyName].Build(pluginType, session); + } + + protected override object build(Type pluginType, BuildSession session) + { + throw new NotImplementedException(); + } + + public object Build(Type pluginType, BuildSession session, InstanceBuilder builder) + { + throw new NotImplementedException(); + } + + public static ConstructorInstance For<T>() + { + return new ConstructorInstance(typeof(T)); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/EnumerableInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/EnumerableInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/EnumerableInstance.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace StructureMap.Pipeline +{ + public class EnumerableInstance : Instance + { + private readonly IEnumerable<Instance> _children; + private readonly IEnumerableCoercion _coercion; + private readonly string _description; + + public EnumerableInstance(Type propertyType, IEnumerable<Instance> children) + { + _description = propertyType.FullName; + + _children = children; + _coercion = DetermineCoercion(propertyType); + } + + public static IEnumerableCoercion DetermineCoercion(Type propertyType) + { + var coercionType = determineCoercionType(propertyType); + return (IEnumerableCoercion) Activator.CreateInstance(coercionType); + } + + private static readonly List<Type> _enumerableTypes = new List<Type>(){typeof(IEnumerable<>), typeof(IList<>), typeof(List<>)}; + private static Type determineCoercionType(Type propertyType) + { + if (propertyType.IsArray) + { + return typeof (ArrayCoercion<>).MakeGenericType(propertyType.GetElementType()); + } + + if (propertyType.IsGenericType ) + { + var templateType = propertyType.GetGenericTypeDefinition(); + if (_enumerableTypes.Contains(templateType)) + { + return typeof (ListCoercion<>).MakeGenericType(propertyType.GetGenericArguments().First()); + } + } + + throw new ArgumentException("Only IEnumerable<T> types can be passed to this constructor. {0} is invalid".ToFormat(propertyType.AssemblyQualifiedName)); + } + + protected override string getDescription() + { + return _description; + } + + protected override object build(Type pluginType, BuildSession session) + { + var objects = _children.Select(x => x.Build(pluginType, session)); + return _coercion.Convert(objects); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -54,7 +54,7 @@ if (arg.Value == null) continue; instance.SetProperty(arg.Key, arg.Value.ToString()); - instance.SetChild(arg.Key, new LiteralInstance(arg.Value)); + instance.Set(arg.Key, new ObjectInstance(arg.Value)); } } Deleted: trunk/Source/StructureMap/Pipeline/HttpSessionBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpSessionBuildPolicy.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/HttpSessionBuildPolicy.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -1,47 +0,0 @@ -using System; -using System.Collections; -using System.Web; -using StructureMap.Attributes; - -namespace StructureMap.Pipeline -{ - public class HttpSessionBuildPolicy : HttpContextBuildPolicy - { - protected override IDictionary findHttpDictionary() - { - return new SessionWrapper(HttpContext.Current.Session); - } - - public override string ToString() - { - return InstanceScope.HttpSession.ToString(); - } - } - - - public class HttpSessionLifecycle : HttpContextLifecycle - { - protected override IDictionary findHttpDictionary() - { - return new SessionWrapper(HttpContext.Current.Session); - } - } - - public class HybridSessionLifecycle : HttpLifecycleBase<HttpSessionLifecycle, ThreadLocalStorageLifecycle> - { - - } - - public class HybridSessionBuildPolicy : HttpBuildPolicyBase<HttpSessionBuildPolicy, ThreadLocalStoragePolicy> - { - public override IBuildPolicy Clone() - { - return new HybridSessionBuildPolicy() { InnerPolicy = InnerPolicy.Clone() }; - } - - public override string ToString() - { - return InstanceScope.HybridHttpSession.ToString(); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/IConfiguredInstance.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -6,13 +6,29 @@ { string Name { get; } Type PluggedType { get; } + + + + [Obsolete] Instance[] GetChildrenArray(string propertyName); + + [Obsolete] string GetProperty(string propertyName); - object GetChild(string propertyName, Type pluginType, BuildSession buildSession); + + + object Get(string propertyName, Type pluginType, BuildSession buildSession); + object Build(Type pluginType, BuildSession session, InstanceBuilder builder); + bool HasProperty(string propertyName); + + [Obsolete] void SetProperty(string name, string value); - void SetChild(string name, Instance instance); + + + void Set(string name, Instance instance); + + [Obsolete] void SetChildArray(string name, Type type, Instance[] children); } } \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/IEnumerableCoercion.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IEnumerableCoercion.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/IEnumerableCoercion.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace StructureMap.Pipeline +{ + public interface IEnumerableCoercion + { + object Convert(IEnumerable<object> enumerable); + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/InstanceMementoPropertyReader.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -90,7 +90,7 @@ { Instance childInstance = _memento.ReadChildInstance(name, _pluginGraph, childType); - _instance.SetChild(name, childInstance); + _instance.Set(name, childInstance); } private void copyChildArray(string name, Type childType) Copied: trunk/Source/StructureMap/Pipeline/LambdaInstance.cs (from rev 282, trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs) =================================================================== --- trunk/Source/StructureMap/Pipeline/LambdaInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/LambdaInstance.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -0,0 +1,41 @@ +using System; + +namespace StructureMap.Pipeline +{ + public class LambdaInstance<T> : ExpressedInstance<LambdaInstance<T>> + { + private readonly Func<IContext, T> _builder; + + public LambdaInstance(Func<IContext, T> builder) + { + _builder = builder; + } + + public LambdaInstance(Func<T> func) + { + _builder = s => func(); + } + + protected override LambdaInstance<T> thisInstance + { + get { return this; } + } + + protected override object build(Type pluginType, BuildSession session) + { + try + { + return _builder(session); + } + catch (Exception ex) + { + throw new StructureMapException(207, ex, Name, pluginType); + } + } + + protected override string getDescription() + { + return "Instance is created by Func<object> function: " + _builder; + } + } +} \ No newline at end of file Deleted: trunk/Source/StructureMap/Pipeline/Lifecycle.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Lifecycle.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/Lifecycle.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -1,201 +0,0 @@ -using System; -using System.Collections.Generic; -using StructureMap.Attributes; -using StructureMap.Interceptors; -using StructureMap.Util; - -namespace StructureMap.Pipeline -{ - public interface IObjectCache - { - object Locker { get; } - - int Count - { - get; - } - - object Get(Type pluginType, Instance instance); - void Set(Type pluginType, Instance instance, object value); - void DisposeAndClear(); - } - - public class NulloObjectCache : IObjectCache - { - public object Locker - { - get { return new object(); } - } - - public int Count - { - get { return 0; } - } - - public object Get(Type pluginType, Instance instance) - { - return null; - } - - public void Set(Type pluginType, Instance instance, object value) - { - // no-op - } - - public void DisposeAndClear() - { - // no-op - } - } - - public class MainObjectCache : IObjectCache - { - private readonly IDictionary<InstanceKey, object> _objects = new Dictionary<InstanceKey,object>(); - private readonly object _locker = new object(); - - public object Locker - { - get { return _locker; } - } - - public int Count - { - get { return _objects.Count; } - } - - public object Get(Type pluginType, Instance instance) - { - var key = new InstanceKey(instance, pluginType); - return _objects.ContainsKey(key) ? _objects[key] : null; - } - - public void Set(Type pluginType, Instance instance, object value) - { - var key = new InstanceKey(instance, pluginType); - _objects.Add(key, value); - } - - public void DisposeAndClear() - { - - lock (Locker) - { - foreach (var @object in _objects.Values) - { - IDisposable disposable = @object as IDisposable; - if (disposable != null) - { - try - { - disposable.Dispose(); - } - catch (Exception) { } - } - } - - _objects.Clear(); - } - } - } - - - public interface ILifecycle - { - void EjectAll(); - IObjectCache FindCache(); - } - - public static class Lifecycles - { - public static ILifecycle GetLifecycle(InstanceScope scope) - { - switch (scope) - { - case InstanceScope.PerRequest: - return null; - - case InstanceScope.Singleton: - return new SingletonLifecycle(); - - case InstanceScope.HttpContext: - return new HttpContextLifecycle(); - - case InstanceScope.ThreadLocal: - return new ThreadLocalStorageLifecycle(); - - case InstanceScope.Hybrid: - return new HybridLifecycle(); - - case InstanceScope.HttpSession: - return new HttpSessionLifecycle(); - - case InstanceScope.HybridHttpSession: - return new HybridSessionLifecycle(); - } - - throw new ArgumentOutOfRangeException("scope"); - } - } - - public class ObjectBuilder - { - private readonly PipelineGraph _pipeline; - private readonly InterceptorLibrary _library; - private readonly IObjectCache _defaultCache; - - public ObjectBuilder(PipelineGraph pipeline, InterceptorLibrary library, IObjectCache defaultCache) - { - _pipeline = pipeline; - _library = library; - _defaultCache = defaultCache; - } - - public object Resolve(Type pluginType, Instance instance, BuildSession session) - { - var cache = FindCache(pluginType, instance, session); - lock (cache.Locker) - { - var returnValue = cache.Get(pluginType, instance); - if (returnValue == null) - { - returnValue = ConstructNew(pluginType, instance, session); - - - cache.Set(pluginType, instance, returnValue); - } - - return returnValue; - } - } - - public object ConstructNew(Type pluginType, Instance instance, BuildSession session) - { - object returnValue = instance.Build(pluginType, session); - return ApplyInterception(pluginType, returnValue, session, instance); - } - - public virtual object ApplyInterception(Type pluginType, object actualValue, BuildSession session, Instance instance) - { - if (actualValue == null) return null; - - try - { - return _library.FindInterceptor(actualValue.GetType()).Process(actualValue, session); - } - catch (Exception e) - { - throw new StructureMapException(308, e, instance.Name, actualValue.GetType()); - } - - - } - - public IObjectCache FindCache(Type pluginType, Instance instance, BuildSession session) - { - var lifecycle = _pipeline.ForType(pluginType).Lifecycle; - return lifecycle == null - ? _defaultCache - : lifecycle.FindCache(); - } - } -} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/ListCoercion.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ListCoercion.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ListCoercion.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Linq; + +namespace StructureMap.Pipeline +{ + public class ListCoercion<T> : IEnumerableCoercion where T : class + { + public object Convert(IEnumerable<object> enumerable) + { + return enumerable.Select(x => x as T).ToList(); + } + } +} \ No newline at end of file Deleted: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -1,58 +0,0 @@ -using System; -using StructureMap.Graph; -using StructureMap.TypeRules; - -namespace StructureMap.Pipeline -{ - public class LiteralInstance : ExpressedInstance<LiteralInstance>, IDisposable - { - private object _object; - - public LiteralInstance(object anObject) - { - if (anObject == null) - { - throw new ArgumentNullException("anObject"); - } - - _object = anObject; - } - - - protected override LiteralInstance thisInstance - { - get { return this; } - } - - public object Object - { - get { return _object; } - } - - protected override object build(Type pluginType, BuildSession session) - { - return _object; - } - - - protected override bool canBePartOfPluginFamily(PluginFamily family) - { - return _object.GetType().CanBeCastTo(family.PluginType); - } - - protected override string getDescription() - { - return "Object: " + _object; - } - - public override string ToString() - { - return string.Format("LiteralInstance: {0}", _object); - } - - public void Dispose() - { - _object = null; - } - } -} \ No newline at end of file Copied: trunk/Source/StructureMap/Pipeline/ObjectInstance.cs (from rev 282, trunk/Source/StructureMap/Pipeline/LiteralInstance.cs) =================================================================== --- trunk/Source/StructureMap/Pipeline/ObjectInstance.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ObjectInstance.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -0,0 +1,71 @@ +using System; +using StructureMap.Graph; +using StructureMap.TypeRules; + +namespace StructureMap.Pipeline +{ + public class NullInstance : Instance + { + protected override string getDescription() + { + return "NULL"; + } + + protected override object build(Type pluginType, BuildSession session) + { + return null; + } + } + + public class ObjectInstance : ExpressedInstance<ObjectInstance>, IDisposable + { + private object _object; + + public ObjectInstance(object anObject) + { + if (anObject == null) + { + throw new ArgumentNullException("anObject"); + } + + _object = anObject; + } + + + protected override ObjectInstance thisInstance + { + get { return this; } + } + + public object Object + { + get { return _object; } + } + + protected override object build(Type pluginType, BuildSession session) + { + return _object; + } + + + protected override bool canBePartOfPluginFamily(PluginFamily family) + { + return _object.GetType().CanBeCastTo(family.PluginType); + } + + protected override string getDescription() + { + return "Object: " + _object; + } + + public override string ToString() + { + return string.Format("LiteralInstance: {0}", _object); + } + + public void Dispose() + { + _object = null; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/PropertyExpression.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -28,7 +28,7 @@ _instance.SetProperty(_propertyName, propertyValue.ToString()); else { - _instance.SetChild(_propertyName,new LiteralInstance(propertyValue)); + _instance.Set(_propertyName,new ObjectInstance(propertyValue)); } return (T) _instance; } Modified: trunk/Source/StructureMap/Pipeline/SmartInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SmartInstance.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/Pipeline/SmartInstance.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -366,7 +366,7 @@ /// <returns></returns> public SmartInstance<T> Is(CHILD value) { - return Is(new LiteralInstance(value)); + return Is(new ObjectInstance(value)); } /// <summary> Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/PipelineGraph.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -187,7 +187,7 @@ public Instance Inject<PLUGINTYPE>(PLUGINTYPE instance) { - var literalInstance = new LiteralInstance(instance); + var literalInstance = new ObjectInstance(instance); ForType(typeof (PLUGINTYPE)).AddInstance(literalInstance); SetDefault(typeof (PLUGINTYPE), literalInstance); Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/StructureMap.csproj 2009-12-24 04:53:19 UTC (rev 285) @@ -158,13 +158,13 @@ <Compile Include="PipelineGraph.cs" /> <Compile Include="Pipeline\ConfiguredInstance.cs" /> <Compile Include="Pipeline\ConfiguredInstance.Expressions.cs" /> - <Compile Include="Pipeline\ConstructorInstance.cs" /> + <Compile Include="Pipeline\LambdaInstance.cs" /> <Compile Include="Pipeline\DefaultInstance.cs" /> <Compile Include="Pipeline\IConfiguredInstance.cs" /> <Compile Include="Pipeline\ILocationPolicy.cs" /> <Compile Include="Pipeline\Instance.cs" /> <Compile Include="Pipeline\InstanceMementoPropertyReader.cs" /> - <Compile Include="Pipeline\LiteralInstance.cs" /> + <Compile Include="Pipeline\ObjectInstance.cs" /> <Compile Include="Pipeline\Profile.cs" /> <Compile Include="Pipeline\ProfileManager.cs" /> <Compile Include="Pipeline\PrototypeInstance.cs" /> @@ -401,14 +401,19 @@ <Compile Include="Graph\PluginCache.cs" /> <Compile Include="Graph\SingleImplementationScanner.cs" /> <Compile Include="IContext.cs" /> + <Compile Include="Pipeline\ArrayCoercion.cs" /> <Compile Include="Pipeline\ConditionalInstance.cs" /> + <Compile Include="Pipeline\ConstructorInstance.cs" /> + <Compile Include="Pipeline\EnumerableInstance.cs" /> <Compile Include="Pipeline\HttpContextLifecycle.cs" /> <Compile Include="Pipeline\HttpLifecycleBase.cs" /> <Compile Include="Pipeline\HttpSessionLifecycle.cs" /> <Compile Include="Pipeline\HybridSessionLifecycle.cs" /> + <Compile Include="Pipeline\IEnumerableCoercion.cs" /> <Compile Include="Pipeline\ILifecycle.cs" /> <Compile Include="Pipeline\IObjectCache.cs" /> <Compile Include="Pipeline\Lifecycles.cs" /> + <Compile Include="Pipeline\ListCoercion.cs" /> <Compile Include="Pipeline\MainObjectCache.cs" /> <Compile Include="Pipeline\NulloObjectCache.cs" /> <Compile Include="Pipeline\ObjectBuilder.cs" /> Modified: trunk/Source/StructureMap/TypeExtensions.cs =================================================================== --- trunk/Source/StructureMap/TypeExtensions.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap/TypeExtensions.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -30,11 +30,12 @@ return new ReferencedInstance(key); } - public static bool IsGeneric(this Type type) + public static bool IsOpenGeneric(this Type type) { return type.IsGenericTypeDefinition || type.ContainsGenericParameters; } + public static bool IsConcreteAndAssignableTo(this Type pluggedType, Type pluginType) { return pluggedType.IsConcrete() && pluginType.IsAssignableFrom(pluggedType); @@ -124,12 +125,12 @@ return false; } - if (IsGeneric(pluginType)) + if (IsOpenGeneric(pluginType)) { return GenericsPluginGraph.CanBeCast(pluginType, pluggedType); } - if (IsGeneric(pluggedType)) + if (IsOpenGeneric(pluggedType)) { return false; } Modified: trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -29,7 +29,7 @@ { object service = _locator.Service(pluginType); - var instance = new LiteralInstance(service); + var instance = new ObjectInstance(service); profileManager.SetDefault(pluginType, instance); } Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -57,7 +57,7 @@ var session = new BuildSession(new PluginGraph()); var session2 = new BuildSession(new PluginGraph()); - var instance = new ConstructorInstance<ColorRule>(() => + var instance = new LambdaInstance<ColorRule>(() => { count++; return new ColorRule("Red"); @@ -98,7 +98,7 @@ int count = 0; var session = new BuildSession(new PluginGraph()); - var instance = new ConstructorInstance<ColorRule>(() => + var instance = new LambdaInstance<ColorRule>(() => { count++; return new ColorRule("Red"); @@ -121,7 +121,7 @@ { int count = 0; - var instance = new ConstructorInstance<ColorRule>(() => + var instance = new LambdaInstance<ColorRule>(() => { count++; return new ColorRule("Red"); @@ -221,8 +221,8 @@ PluginGraph graph = new PluginGraph(); PluginFamily family = graph.FindFamily(typeof(IService)); - family.AddInstance(new LiteralInstance(red).WithName("red")); - family.AddInstance(new LiteralInstance(green).WithName("green")); + family.AddInstance(new ObjectInstance(red).WithName("red")); + family.AddInstance(new ObjectInstance(green).WithName("green")); var session = new BuildSession(graph); session.TryGetInstance<IService>("red").ShouldBeTheSameAs(red); @@ -237,8 +237,8 @@ PluginGraph graph = new PluginGraph(); PluginFamily family = graph.FindFamily(typeof(IService)); - family.AddInstance(new LiteralInstance(red).WithName("red")); - family.AddInstance(new LiteralInstance(green).WithName("green")); + family.AddInstance(new ObjectInstance(red).WithName("red")); + family.AddInstance(new ObjectInstance(green).WithName("green")); var session = new BuildSession(graph); session.GetInstance<IService>("red").ShouldBeTheSameAs(red); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -82,7 +82,7 @@ .For<IWidget>().Use(theWidget); PluginGraph graph = registry.Build(); - var instance = (LiteralInstance) graph.ProfileManager.GetDefault(typeof (IWidget), "something"); + var instance = (ObjectInstance) graph.ProfileManager.GetDefault(typeof (IWidget), "something"); Assert.AreSame(theWidget, instance.Object); } @@ -98,7 +98,7 @@ .For<IWidget>().UseNamedInstance(theDefaultName) .For<Rule>().UseNamedInstance("DefaultRule"); - LiteralInstance masterInstance = + ObjectInstance masterInstance = registry.InstanceOf<IWidget>().Is.Object(new AWidget()).WithName(theDefaultName); ProfileManager manager = registry.Build().ProfileManager; Modified: trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -31,10 +31,10 @@ return session.BuildErrors[0]; } - private ConstructorInstance<IWidget> errorInstance() + private LambdaInstance<IWidget> errorInstance() { return - new ConstructorInstance<IWidget>(delegate() { throw new NotSupportedException("You can't make me!"); }); + new LambdaInstance<IWidget>(delegate() { throw new NotSupportedException("You can't make me!"); }); } [Test] @@ -157,7 +157,7 @@ { var session = new ValidationBuildSession(new PluginGraph()); - var instance = new LiteralInstance(new ColorWidget("Red")); + var instance = new ObjectInstance(new ColorWidget("Red")); object widget1 = session.CreateInstance(typeof (IWidget), instance); object widget2 = session.CreateInstance(typeof (IWidget), instance); @@ -177,7 +177,7 @@ [Test] public void Validate_a_single_object_with_both_a_passing_validation_method_and_a_failing_validation_method() { - var instance = new LiteralInstance(new WidgetWithOneValidationFailure()); + var instance = new ObjectInstance(new WidgetWithOneValidationFailure()); ValidationBuildSession session = validatedSession(registry => registry.InstanceOf<IWidget>().IsThis(instance)); Modified: trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -289,8 +289,8 @@ { IInstanceFactory factory = getISomethingFactory(); - factory.AddInstance(new LiteralInstance(_red).WithName("Red")); - factory.AddInstance(new LiteralInstance(_blue).WithName("Blue")); + factory.AddInstance(new ObjectInstance(_red).WithName("Red")); + factory.AddInstance(new ObjectInstance(_blue).WithName("Blue")); factory.FindInstance("Red").ShouldNotBeNull(); @@ -324,12 +324,12 @@ { IInstanceFactory factory = getISomethingFactory(); - factory.AddInstance(new LiteralInstance(_red).WithName("Red")); - var oldBlue = new LiteralInstance(_blue).WithName("Blue"); + factory.AddInstance(new ObjectInstance(_red).WithName("Red")); + var oldBlue = new ObjectInstance(_blue).WithName("Blue"); factory.AddInstance(oldBlue); // Replace Blue - var newBlue = new LiteralInstance(_orange).WithName("Blue"); + var newBlue = new ObjectInstance(_orange).WithName("Blue"); factory.AddInstance(newBlue); factory.FindInstance("Blue").ShouldBeTheSameAs(newBlue); Modified: trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -82,9 +82,9 @@ var factory = new InstanceFactory(typeof (IWidget)); var family = new PluginFamily(typeof (IWidget)); - family.AddInstance(new LiteralInstance(new AWidget()).WithName("New")); - family.AddInstance(new LiteralInstance(new AWidget()).WithName("New2")); - family.AddInstance(new LiteralInstance(new AWidget()).WithName("New3")); + family.AddInstance(new ObjectInstance(new AWidget()).WithName("New")); + family.AddInstance(new ObjectInstance(new AWidget()).WithName("New2")); + family.AddInstance(new ObjectInstance(new AWidget()).WithName("New3")); factory.ImportFrom(family); @@ -130,11 +130,11 @@ public void Merge_from_PluginFamily_will_not_replace_an_existing_instance() { var factory = new InstanceFactory(typeof (IWidget)); - LiteralInstance instance1 = new LiteralInstance(new AWidget()).WithName("New"); + ObjectInstance instance1 = new ObjectInstance(new AWidget()).WithName("New"); factory.AddInstance(instance1); var family = new PluginFamily(typeof (IWidget)); - family.AddInstance(new LiteralInstance(new AWidget()).WithName("New")); + family.AddInstance(new ObjectInstance(new AWidget()).WithName("New")); factory.ImportFrom(family); @@ -191,7 +191,7 @@ [Test] public void the_instances_are_cloned_so_that_new_instances_are_NOT_injected_into_() { - clone.AddInstance(new LiteralInstance(new DefaultGateway())); + clone.AddInstance(new ObjectInstance(new DefaultGateway())); factory.AllInstances.Count().ShouldEqual(2); clone.AllInstances.Count().ShouldEqual(3); Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyMergeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/PluginFamilyMergeTester.cs 2009-12-23 19:54:52 UTC (rev 284) +++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyMergeTester.cs 2009-12-24 04:53:19 UTC (rev 285) @@ -12,7 +12,7 @@ public void Add_instance_that_does_not_exist_in_destination() { var source = new PluginFamily(typeof (IWidget)); - var sourceInstance = new LiteralInstance(new AWidget()); + var sourceInstance = new ObjectInstance(new AWidget()); source.AddInstance(sourceInstance); var destination = new PluginFamily(typeof (IWidget)); @@ -25,11 +25,11 @@ public void Do_not_override_named_instance() { var source = new PluginFamily(typeof (IWidget)); - LiteralInstance sourceInstance = new LiteralInstance(new AWidget()).WithName("New"); + ObjectInstance sourceInstance = new ObjectInstance(new AWidget()).WithName("New"); source.AddInstance(sourceInstance); var destination = new PluginFamily(typeof (IWidget)); - LiteralInstance destinationInstance = new LiteralInstance(new AWidget()).WithName("New"); + ObjectInstance destinationInstance = new ObjectInstance(new AWidget()).WithName("New"); destination.AddInstance(destinationInstance); destination.ImportFrom(source); Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs =================================================================== --- tru... [truncated message content] |