From: <jer...@us...> - 2007-03-25 02:56:21
|
Revision: 28 http://structuremap.svn.sourceforge.net/structuremap/?rev=28&view=rev Author: jeremydmiller Date: 2007-03-24 19:56:13 -0700 (Sat, 24 Mar 2007) Log Message: ----------- Pulling out the IInstanceManager interface Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Graph/AssemblyGraph.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/InstanceManager.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs Added Paths: ----------- trunk/Source/StructureMap/IInstanceManager.cs Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/CommonAssemblyInfo.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -1,5 +1,7 @@ +using System; using System.Reflection; using System.Runtime.InteropServices; + //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. @@ -10,10 +12,11 @@ // </auto-generated> //------------------------------------------------------------------------------ -[assembly : ComVisible(false)] -[assembly : AssemblyVersion("1.0.0.0000")] -[assembly : AssemblyCopyrightAttribute("Copyright (c) 2005, Jeremy D. Miller, Jeffrey Palermo")] -[assembly : AssemblyProductAttribute("StructureMap")] -[assembly : AssemblyCompanyAttribute("")] -[assembly : AssemblyConfigurationAttribute("release")] -[assembly : AssemblyInformationalVersionAttribute("1.0.0.0000")] \ No newline at end of file +[assembly: ComVisibleAttribute(false)] +[assembly: AssemblyVersionAttribute("1.0.0.0000")] +[assembly: AssemblyCopyrightAttribute("Copyright (c) 2005, Jeremy D. Miller, Jeffrey Palermo")] +[assembly: AssemblyProductAttribute("StructureMap")] +[assembly: AssemblyCompanyAttribute("")] +[assembly: AssemblyConfigurationAttribute("release")] +[assembly: AssemblyInformationalVersionAttribute("1.0.0.0000")] + Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -63,7 +63,7 @@ return expression; } - public InstanceManager BuildInstanceManager() + public IInstanceManager BuildInstanceManager() { configurePluginGraph(_graph); _graph.ReadDefaults(); Modified: trunk/Source/StructureMap/Graph/AssemblyGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap/Graph/AssemblyGraph.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -158,7 +158,7 @@ public static AssemblyGraph ContainingType<T>() { - return new AssemblyGraph(typeof(T).Assembly); + return new AssemblyGraph(typeof (T).Assembly); } public Type FindTypeByFullName(string fullName) Modified: trunk/Source/StructureMap/Graph/Plugin.cs =================================================================== --- trunk/Source/StructureMap/Graph/Plugin.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap/Graph/Plugin.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -102,7 +102,8 @@ PluggableAttribute att = PluggableAttribute.InstanceOf(pluggedType); if (att == null) { - return new Plugin(pluggedType, TypePath.GetAssemblyQualifiedName(pluggedType), Graph.DefinitionSource.Implicit); + return + new Plugin(pluggedType, TypePath.GetAssemblyQualifiedName(pluggedType), DefinitionSource.Implicit); } else { @@ -396,15 +397,17 @@ public override int GetHashCode() { - return (_pluggedType != null ? _pluggedType.GetHashCode() : 0) + 29*(_concreteKey != null ? _concreteKey.GetHashCode() : 0); + return + (_pluggedType != null ? _pluggedType.GetHashCode() : 0) + + 29*(_concreteKey != null ? _concreteKey.GetHashCode() : 0); } public string FindFirstConstructorArgumentOfType<T>() { - ConstructorInfo ctor = this.GetConstructor(); + ConstructorInfo ctor = GetConstructor(); foreach (ParameterInfo info in ctor.GetParameters()) { - if (info.ParameterType.Equals(typeof(T))) + if (info.ParameterType.Equals(typeof (T))) { return info.Name; } Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -160,7 +160,7 @@ public PluginFamily LocateOrCreateFamilyForType(Type pluginType) { buildFamilyIfMissing(pluginType); - return this.PluginFamilies[pluginType]; + return PluginFamilies[pluginType]; } private Type findTypeByFullName(string fullName) @@ -181,7 +181,5 @@ { _defaultManager.ReadDefaultsFromPluginGraph(this); } - - } } \ No newline at end of file Added: trunk/Source/StructureMap/IInstanceManager.cs =================================================================== --- trunk/Source/StructureMap/IInstanceManager.cs (rev 0) +++ trunk/Source/StructureMap/IInstanceManager.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using StructureMap.Graph; + +namespace StructureMap +{ + public interface IInstanceManager + { + T CreateInstance<T>(string instanceKey); + T CreateInstance<T>(); + T FillDependencies<T>(); + void Inject<T>(T instance); + IList<T> GetAllInstances<T>(); + void SetDefaultsToProfile(string profile); + + InstanceDefaultManager DefaultManager + { + get; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceManager.cs =================================================================== --- trunk/Source/StructureMap/InstanceManager.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap/InstanceManager.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; using NMock; using StructureMap.Exceptions; using StructureMap.Graph; @@ -12,10 +11,10 @@ /// <summary> /// A collection of IInstanceFactory's. /// </summary> - public class InstanceManager : IEnumerable + public class InstanceManager : IInstanceManager, IEnumerable { private Dictionary<Type, IInstanceFactory> _factories; - private HybridDictionary _filledTypeFactories; + private Dictionary<Type, InstanceFactory> _filledTypeFactories; private bool _failOnException = true; private GenericsPluginGraph _genericsGraph; private InstanceDefaultManager _defaultManager; @@ -26,7 +25,7 @@ public InstanceManager() { _factories = new Dictionary<Type, IInstanceFactory>(); - _filledTypeFactories = new HybridDictionary(); + _filledTypeFactories = new Dictionary<Type, InstanceFactory>(); _genericsGraph = new GenericsPluginGraph(); } @@ -174,7 +173,7 @@ public T CreateInstance<T>() { - return (T)CreateInstance(typeof(T)); + return (T) CreateInstance(typeof (T)); } /// <summary> @@ -202,7 +201,6 @@ } - /// <summary> /// Creates a new instance of the requested type using the InstanceMemento. Mostly used from other /// classes to link children members @@ -338,11 +336,11 @@ private InstanceFactory getFilledTypeFactory(Type type) { - if (!_filledTypeFactories.Contains(type)) + if (!_filledTypeFactories.ContainsKey(type)) { lock (this) { - if (!_filledTypeFactories.Contains(type)) + if (!_filledTypeFactories.ContainsKey(type)) { PluginFamily family = PluginFamily.CreateAutoFilledPluginFamily(type); InstanceFactory factory = new InstanceFactory(family, true); @@ -352,7 +350,7 @@ } } - return (InstanceFactory) _filledTypeFactories[type]; + return _filledTypeFactories[type]; } #region mocking @@ -390,14 +388,10 @@ /// <returns></returns> public bool IsMocked(Type TargetType) { - bool returnValue = false; - - returnValue = isInstanceFamilyMocked(this[TargetType]); - - return returnValue; + return isInstanceFamilyMocked(this[TargetType]); } - private bool isInstanceFamilyMocked(IInstanceFactory instanceFactory) + private static bool isInstanceFamilyMocked(IInstanceFactory instanceFactory) { bool returnValue = false; @@ -473,6 +467,11 @@ } } + public void Inject<T>(T instance) + { + InjectStub(typeof(T), instance); + } + #endregion public IEnumerator GetEnumerator() @@ -489,7 +488,7 @@ { List<T> list = new List<T>(); - foreach (T instance in this[typeof(T)].GetAllInstances()) + foreach (T instance in this[typeof (T)].GetAllInstances()) { list.Add(instance); } Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap/StructureMap.csproj 2007-03-25 02:56:13 UTC (rev 28) @@ -450,6 +450,7 @@ <Compile Include="IInstanceFactory.cs"> <SubType>Code</SubType> </Compile> + <Compile Include="IInstanceManager.cs" /> <Compile Include="InstanceBuilder.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -10,7 +10,7 @@ [TestFixture] public class AddInstanceTester { - private InstanceManager manager; + private IInstanceManager manager; private PluginGraph pluginGraph; [SetUp] @@ -104,7 +104,7 @@ .WithName("Orange") ); - InstanceManager mgr = registry.BuildInstanceManager(); + IInstanceManager mgr = registry.BuildInstanceManager(); ColorWidget orange = (ColorWidget) mgr.CreateInstance<IWidget>("Orange"); Assert.IsNotNull(orange); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -25,7 +25,7 @@ // Needs to blow up if the concrete type can't be used registry.BuildInstancesOf<Rule>().TheDefaultIsConcreteType<ARule>(); - InstanceManager manager = registry.BuildInstanceManager(); + IInstanceManager manager = registry.BuildInstanceManager(); Assert.IsInstanceOfType(typeof(ARule), manager.CreateInstance<Rule>()); } @@ -85,7 +85,7 @@ Registry.Instance<IWidget>().UsingConcreteType<ColorWidget>().WithProperty("Color").EqualTo("Red") ); - InstanceManager manager = registry.BuildInstanceManager(); + IInstanceManager manager = registry.BuildInstanceManager(); ColorWidget widget = (ColorWidget) manager.CreateInstance<IWidget>(); Assert.AreEqual("Red", widget.Color); Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2007-03-25 02:43:09 UTC (rev 27) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs 2007-03-25 02:56:13 UTC (rev 28) @@ -46,7 +46,7 @@ Registry.Instance<IWidget>().UsingConcreteType<AWidget>() ); - InstanceManager manager = registry.BuildInstanceManager(); + IInstanceManager manager = registry.BuildInstanceManager(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |