|
From: <jer...@us...> - 2008-04-29 04:19:22
|
Revision: 84
http://structuremap.svn.sourceforge.net/structuremap/?rev=84&view=rev
Author: jeremydmiller
Date: 2008-04-28 21:19:20 -0700 (Mon, 28 Apr 2008)
Log Message:
-----------
BIG REFACTORING. Rewrote the Profile/Machine/Defaults functionality. Simplified NormalGraphBuilder and InstanceFactory. Using the BuildPolicy now. Killed off the InstanceFactoryInterceptor
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/PluginGraph.cs
trunk/Source/StructureMap/Graph/TypePath.cs
trunk/Source/StructureMap/IInstanceFactory.cs
trunk/Source/StructureMap/IInstanceManager.cs
trunk/Source/StructureMap/IPluginGraphSource.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/InstanceMemento.cs
trunk/Source/StructureMap/ObjectFactory.cs
trunk/Source/StructureMap/Pipeline/Instance.cs
trunk/Source/StructureMap/Pipeline/Profile.cs
trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs
trunk/Source/StructureMap/PluginGraphBuilder.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapConfiguration.cs
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.AutoMocking/AutoMockedInstanceManager.cs
trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs
trunk/Source/StructureMap.Testing/Configuration/ConfigurationParserTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs
trunk/Source/StructureMap.Testing/Configuration/InlineInstanceDefinitionInProfileAndMachineNodesTester.cs
trunk/Source/StructureMap.Testing/Container/ArrayConstructorTester.cs
trunk/Source/StructureMap.Testing/Container/FullStackFacadeTester.cs
trunk/Source/StructureMap.Testing/Container/ImplicitDefaultTest.cs
trunk/Source/StructureMap.Testing/Container/InstanceFactoryTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
trunk/Source/StructureMap.Testing/Container/IntegratedTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs
trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs
trunk/Source/StructureMap.Testing/ObjectMother.cs
trunk/Source/StructureMap.Testing/Pipeline/ReferencedInstanceTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing/StructureMap.config
trunk/Source/StructureMap.Testing/TestData/DefaultProfileConfig.xml
trunk/Source/StructureMap.Testing/TestData/InlineInstanceInProfileAndMachine.xml
trunk/Source/StructureMap.Testing/TestData/ObjectMother.config
trunk/Source/StructureMap.Testing/TestData/SampleConfig.xml
trunk/Source/StructureMap.Testing/TestData/StructureMap.config
Added Paths:
-----------
trunk/Source/StructureMap/Configuration/ProfileBuilder.cs
trunk/Source/StructureMap/Pipeline/ProfileManager.cs
trunk/Source/StructureMap.Testing/Configuration/ProfileBuilderTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ProfileTester.cs
Removed Paths:
-------------
trunk/Source/StructureMap/Graph/InstanceDefault.cs
trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs
trunk/Source/StructureMap/Graph/MachineOverride.cs
trunk/Source/StructureMap/Graph/Profile.cs
trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Graph/OverrideGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/OverrideTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceDefaultExpression.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -31,22 +31,22 @@
return _parent;
}
- internal void Configure(Profile profile, PluginGraph graph)
+ internal void Configure(string profileName, PluginGraph pluginGraph)
{
- if (!string.IsNullOrEmpty(_instanceKey))
+ if (_instance != null)
{
- InstanceDefault instanceDefault = new InstanceDefault(_pluginType, _instanceKey);
- profile.AddOverride(instanceDefault);
+ _instanceKey = Profile.InstanceKeyForProfile(profileName);
+ _instance.Name = _instanceKey;
+ pluginGraph.LocateOrCreateFamilyForType(_pluginType).AddInstance(_instance);
}
- else if (_instance != null)
+ else if (!string.IsNullOrEmpty(_instanceKey))
{
- string defaultKey = Profile.InstanceKeyForProfile(profile.ProfileName);
-
- _instance.Name = defaultKey;
- graph.LocateOrCreateFamilyForType(_pluginType).AddInstance(_instance);
+ _instance = new ReferencedInstance(_instanceKey);
+ }
- InstanceDefault instanceDefault = new InstanceDefault(_pluginType, defaultKey);
- profile.AddOverride(instanceDefault);
+ if (_instance != null)
+ {
+ pluginGraph.ProfileManager.SetDefault(profileName, _pluginType, _instance);
}
else
{
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using StructureMap.Graph;
@@ -20,16 +21,9 @@
void IExpression.Configure(PluginGraph graph)
{
- Profile profile = graph.DefaultManager.GetProfile(_profileName);
- if (profile == null)
- {
- profile = new Profile(_profileName);
- graph.DefaultManager.AddProfile(profile);
- }
-
foreach (InstanceDefaultExpression expression in _defaults)
{
- expression.Configure(profile, graph);
+ expression.Configure(_profileName, graph);
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -94,7 +94,6 @@
public IInstanceManager BuildInstanceManager()
{
ConfigurePluginGraph(_graph);
- _graph.ReadDefaults();
return new InstanceManager(_graph);
}
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -34,7 +34,7 @@
public void ParseDefaultElement(XmlElement element)
{
- TypePath pluginTypePath = TypePath.GetTypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
+ TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
InstanceScope scope = findScope(element);
string name = element.GetAttribute(XmlConstants.NAME);
if (string.IsNullOrEmpty(name))
@@ -51,7 +51,7 @@
public void ParseInstanceElement(XmlElement element)
{
- TypePath pluginTypePath = TypePath.GetTypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
+ TypePath pluginTypePath = new TypePath(element.GetAttribute(XmlConstants.PLUGIN_TYPE));
InstanceScope scope = findScope(element);
InstanceMemento memento = _mementoCreator.CreateMemento(element);
Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,3 +1,4 @@
+using System;
using StructureMap.Attributes;
using StructureMap.Graph;
@@ -3,12 +4,23 @@
namespace StructureMap.Configuration
{
+ public interface IProfileBuilder
+ {
+ void AddProfile(string profileName);
+ void OverrideProfile(TypePath typePath, string instanceKey);
+ void AddMachine(string machineName, string profileName);
+ void OverrideMachine(TypePath typePath, string instanceKey);
+ void SetDefaultProfileName(string profileName);
+ }
+
+
public interface IGraphBuilder
{
PluginGraph SystemGraph { get; }
- InstanceDefaultManager DefaultManager { get; }
PluginGraph PluginGraph { get; }
void AddAssembly(string assemblyName);
void StartFamilies();
+ void FinishFamilies();
+ PluginGraph CreatePluginGraph();
void AddPluginFamily(TypePath typePath, string defaultKey, InstanceScope scope);
@@ -19,17 +31,8 @@
SetterProperty AddSetter(TypePath pluginTypePath, string concreteKey, string setterName);
void AddInterceptor(TypePath pluginTypePath, InstanceMemento interceptorMemento);
- void FinishFamilies();
-
- PluginGraph CreatePluginGraph();
-
void RegisterMemento(TypePath pluginTypePath, InstanceMemento memento);
- void AddProfile(string profileName);
- void OverrideProfile(string fullTypeName, string instanceKey);
- void AddMachine(string machineName, string profileName);
- void OverrideMachine(string fullTypeName, string instanceKey);
-
- TypePath LocateOrCreateFamilyForType(string fullName);
+ IProfileBuilder GetProfileBuilder();
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,22 +1,20 @@
using System;
-using System.Diagnostics;
using System.Reflection;
using StructureMap.Attributes;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
-using StructureMap.Interceptors;
using StructureMap.Pipeline;
namespace StructureMap.Configuration
{
public class NormalGraphBuilder : IGraphBuilder
{
- private MachineOverride _machine;
- private PluginGraph _pluginGraph;
+ private readonly PluginGraph _pluginGraph;
+ private readonly PluginGraph _systemGraph;
private Profile _profile;
- private PluginGraph _systemGraph;
private InstanceManager _systemInstanceManager;
+
public NormalGraphBuilder(Registry[] registries)
{
_pluginGraph = new PluginGraph();
@@ -36,9 +34,8 @@
_pluginGraph.Seal();
}
- public PluginGraph CreatePluginGraph()
+ [Obsolete("Do away?")] public PluginGraph CreatePluginGraph()
{
- _pluginGraph.ReadDefaults();
return _pluginGraph;
}
@@ -52,50 +49,6 @@
get { return _pluginGraph; }
}
- public void AddProfile(string profileName)
- {
- _profile = new Profile(profileName);
- _pluginGraph.DefaultManager.AddProfile(_profile);
- }
-
- public void OverrideProfile(string fullTypeName, string instanceKey)
- {
- _profile.AddOverride(fullTypeName, instanceKey);
- }
-
- public void AddMachine(string machineName, string profileName)
- {
- if (string.IsNullOrEmpty(profileName))
- {
- _machine = new MachineOverride(machineName, null);
- }
- else
- {
- Profile profile = _pluginGraph.DefaultManager.GetProfile(profileName);
-
- if (profile == null)
- {
- _pluginGraph.Log.RegisterError(195, profileName, machineName);
- return;
- }
-
- _machine = new MachineOverride(machineName, profile);
- }
-
-
- _pluginGraph.DefaultManager.AddMachineOverride(_machine);
- }
-
- public void OverrideMachine(string fullTypeName, string instanceKey)
- {
- _machine.AddMachineOverride(fullTypeName, instanceKey);
- }
-
- public TypePath LocateOrCreateFamilyForType(string fullName)
- {
- return _pluginGraph.LocateOrCreateFamilyForType(fullName);
- }
-
public void AddAssembly(string assemblyName)
{
AssemblyGraph assemblyGraph = new AssemblyGraph(assemblyName);
@@ -181,7 +134,7 @@
{
IInstanceInterceptor interceptor =
(IInstanceInterceptor)
- buildSystemObject(typeof(IInstanceInterceptor), interceptorMemento);
+ buildSystemObject(typeof (IInstanceInterceptor), interceptorMemento);
family.AddInterceptor(interceptor);
}
@@ -191,17 +144,17 @@
}
}
- public InstanceDefaultManager DefaultManager
- {
- get { return _pluginGraph.DefaultManager; }
- }
-
public void RegisterMemento(TypePath pluginTypePath, InstanceMemento memento)
{
PluginFamily family = _pluginGraph.LocateOrCreateFamilyForType(pluginTypePath.FindType());
family.AddInstance(memento);
}
+ public IProfileBuilder GetProfileBuilder()
+ {
+ return new ProfileBuilder(_pluginGraph);
+ }
+
#endregion
private object buildSystemObject(Type type, InstanceMemento memento)
Modified: trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Configuration/ProfileAndMachineParser.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,20 +1,22 @@
using System;
using System.Xml;
using StructureMap.Graph;
+using StructureMap.Pipeline;
using StructureMap.Source;
namespace StructureMap.Configuration
{
- [Obsolete("This puppy needs to be rewritten")]
public class ProfileAndMachineParser
{
- private readonly IGraphBuilder _builder;
+ private readonly IProfileBuilder _profileBuilder;
+ private readonly IGraphBuilder _graphBuilder;
private readonly XmlMementoCreator _creator;
private readonly XmlNode _structureMapNode;
- public ProfileAndMachineParser(IGraphBuilder builder, XmlNode structureMapNode, XmlMementoCreator creator)
+ public ProfileAndMachineParser(IGraphBuilder graphBuilder, XmlNode structureMapNode, XmlMementoCreator creator)
{
- _builder = builder;
+ _profileBuilder = graphBuilder.GetProfileBuilder();
+ _graphBuilder = graphBuilder;
_structureMapNode = structureMapNode;
_creator = creator;
}
@@ -24,16 +26,16 @@
XmlNode defaultProfileNode = _structureMapNode.Attributes.GetNamedItem(XmlConstants.DEFAULT_PROFILE);
if (defaultProfileNode != null)
{
- _builder.DefaultManager.DefaultProfileName = defaultProfileNode.InnerText;
+ _profileBuilder.SetDefaultProfileName(defaultProfileNode.InnerText);
}
foreach (XmlElement profileElement in findNodes(XmlConstants.PROFILE_NODE))
{
string profileName = profileElement.GetAttribute(XmlConstants.NAME);
- _builder.AddProfile(profileName);
+ _profileBuilder.AddProfile(profileName);
writeOverrides(profileElement,
- delegate(string fullName, string defaultKey) { _builder.OverrideProfile(fullName, defaultKey); }, profileName);
+ delegate(string fullName, string defaultKey) { _profileBuilder.OverrideProfile(new TypePath(fullName), defaultKey); }, profileName);
}
foreach (XmlElement machineElement in findNodes(XmlConstants.MACHINE_NODE))
@@ -41,10 +43,10 @@
string machineName = machineElement.GetAttribute(XmlConstants.NAME);
string profileName = machineElement.GetAttribute(XmlConstants.PROFILE_NODE);
- _builder.AddMachine(machineName, profileName);
+ _profileBuilder.AddMachine(machineName, profileName);
writeOverrides(machineElement,
- delegate(string fullName, string defaultKey) { _builder.OverrideMachine(fullName, defaultKey); }, machineName);
+ delegate(string fullName, string defaultKey) { _profileBuilder.OverrideMachine(new TypePath(fullName), defaultKey); }, machineName);
}
}
@@ -80,8 +82,8 @@
InstanceMemento memento = _creator.CreateMemento(instanceElement);
memento.InstanceKey = key;
- TypePath familyPath = _builder.LocateOrCreateFamilyForType(fullName);
- _builder.RegisterMemento(familyPath, memento);
+ TypePath familyPath = new TypePath(fullName);
+ _graphBuilder.RegisterMemento(familyPath, memento);
function(fullName, key);
}
Added: trunk/Source/StructureMap/Configuration/ProfileBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ProfileBuilder.cs (rev 0)
+++ trunk/Source/StructureMap/Configuration/ProfileBuilder.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using StructureMap.Graph;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Configuration
+{
+ public class ProfileBuilder : IProfileBuilder
+ {
+ public static string GetMachineName()
+ {
+ string machineName = string.Empty;
+ try
+ {
+ machineName = Environment.MachineName.ToUpper();
+ }
+ finally
+ {
+ }
+
+ return machineName;
+ }
+
+ private readonly PluginGraph _pluginGraph;
+ private readonly string _machineName;
+ private string _lastProfile;
+ private bool _useMachineOverrides;
+ private readonly ProfileManager _profileManager;
+
+
+ public ProfileBuilder(PluginGraph pluginGraph, string machineName)
+ {
+ _pluginGraph = pluginGraph;
+ _profileManager = pluginGraph.ProfileManager;
+ _machineName = machineName;
+ }
+
+
+ public ProfileBuilder(PluginGraph pluginGraph)
+ : this(pluginGraph, GetMachineName())
+ {
+ }
+
+ public void AddProfile(string profileName)
+ {
+ _lastProfile = profileName;
+ }
+
+ public void OverrideProfile(TypePath typePath, string instanceKey)
+ {
+ // TODO: what if the Type cannot be found?
+
+ ReferencedInstance instance = new ReferencedInstance(instanceKey);
+ _profileManager.SetDefault(_lastProfile, typePath.FindType(), instance);
+ }
+
+ public void AddMachine(string machineName, string profileName)
+ {
+ _useMachineOverrides = machineName == _machineName;
+
+ if (_useMachineOverrides)
+ {
+ _profileManager.DefaultMachineProfileName = profileName;
+ }
+ }
+
+ public void OverrideMachine(TypePath typePath, string instanceKey)
+ {
+ if (!_useMachineOverrides)
+ {
+ return;
+ }
+
+ // TODO: what if the Type cannot be found?
+ ReferencedInstance instance = new ReferencedInstance(instanceKey);
+ _profileManager.SetMachineDefault(typePath.FindType(), instance);
+ }
+
+ public void SetDefaultProfileName(string profileName)
+ {
+ _profileManager.DefaultProfileName = profileName;
+ }
+ }
+}
Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using StructureMap.Pipeline;
namespace StructureMap.Graph
{
@@ -86,7 +87,7 @@
}
- public PluginFamily CreateTemplatedFamily(Type templatedType)
+ public PluginFamily CreateTemplatedFamily(Type templatedType, ProfileManager profileManager)
{
Type basicType = templatedType.GetGenericTypeDefinition();
@@ -95,6 +96,8 @@
PluginFamily basicFamily = _families[basicType];
Type[] templatedParameterTypes = templatedType.GetGenericArguments();
+ profileManager.CopyDefaults(basicType, templatedType);
+
return basicFamily.CreateTemplatedClone(templatedParameterTypes);
}
else
@@ -102,17 +105,5 @@
return null;
}
}
-
- public PluginFamily CreateTemplatedFamily(string pluginTypeName)
- {
- Type type = Type.GetType(pluginTypeName, true);
-
- if (!type.IsGenericType)
- {
- return null;
- }
-
- return CreateTemplatedFamily(type);
- }
}
}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Graph/InstanceDefault.cs
===================================================================
--- trunk/Source/StructureMap/Graph/InstanceDefault.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/InstanceDefault.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,66 +0,0 @@
-using System;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// Stores the default instance key for a PluginType. Member of the <see cref="Profile"/>
- /// and <see cref="MachineOverride"/> classes
- /// </summary>
- [Serializable]
- public class InstanceDefault : ICloneable
- {
- private string _defaultKey;
- private string _pluginTypeName;
-
- public InstanceDefault(string pluginTypeName, string defaultKey) : base()
- {
- _pluginTypeName = pluginTypeName;
- _defaultKey = defaultKey;
- }
-
- public InstanceDefault(Type pluginType, string defaultKey) : this(pluginType.FullName, defaultKey)
- {
- }
-
- public string PluginTypeName
- {
- get { return _pluginTypeName; }
- }
-
- /// <summary>
- /// Default instance key
- /// </summary>
- public string DefaultKey
- {
- get { return _defaultKey; }
- set { _defaultKey = value; }
- }
-
- #region ICloneable Members
-
- public object Clone()
- {
- object clone = MemberwiseClone();
- return clone;
- }
-
- #endregion
-
- public override bool Equals(object obj)
- {
- if (this == obj) return true;
- InstanceDefault instanceDefault = obj as InstanceDefault;
- if (instanceDefault == null) return false;
- return
- Equals(_pluginTypeName, instanceDefault._pluginTypeName) &&
- Equals(_defaultKey, instanceDefault._defaultKey);
- }
-
- public override int GetHashCode()
- {
- return
- (_pluginTypeName != null ? _pluginTypeName.GetHashCode() : 0) +
- 29*(_defaultKey != null ? _defaultKey.GetHashCode() : 0);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs
===================================================================
--- trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/InstanceDefaultManager.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,231 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// Contains the logic rules to determine the default instances for a PluginGraph and/or
- /// InstanceManager for any combination of profile and machine name.
- /// </summary>
- [Serializable]
- [Obsolete] public class InstanceDefaultManager
- {
- private string _defaultProfileName = string.Empty;
- private List<InstanceDefault> _defaults;
- private Dictionary<string, MachineOverride> _machineOverrides;
- private Dictionary<string, Profile> _profiles;
-
- public InstanceDefaultManager() : base()
- {
- _defaults = new List<InstanceDefault>();
- _machineOverrides = new Dictionary<string, MachineOverride>();
- _profiles = new Dictionary<string, Profile>();
- }
-
- /// <summary>
- /// If defined, sets the default Profile to be used if no other profile
- /// is requested
- /// </summary>
- public string DefaultProfileName
- {
- get { return _defaultProfileName; }
- set { _defaultProfileName = value == null ? string.Empty : value; }
- }
-
- public Profile[] Profiles
- {
- get
- {
- Profile[] returnValue = new Profile[_profiles.Count];
- _profiles.Values.CopyTo(returnValue, 0);
- Array.Sort(returnValue);
- return returnValue;
- }
- }
-
- public MachineOverride[] MachineOverrides
- {
- get
- {
- MachineOverride[] returnValue = new MachineOverride[_machineOverrides.Count];
- _machineOverrides.Values.CopyTo(returnValue, 0);
- Array.Sort(returnValue);
- return returnValue;
- }
- }
-
- public static string GetMachineName()
- {
- string machineName = string.Empty;
- try
- {
- machineName = Environment.MachineName.ToUpper();
- }
- finally
- {
- }
-
- return machineName;
- }
-
- public void ReadDefaultsFromPluginGraph(PluginGraph graph)
- {
- _defaults = new List<InstanceDefault>();
-
- foreach (PluginFamily family in graph.PluginFamilies)
- {
- InstanceDefault instanceDefault = new InstanceDefault(family.PluginType, family.DefaultInstanceKey);
- _defaults.Add(instanceDefault);
- }
- }
-
-
- /// <summary>
- /// Adds the InstanceDefault from a PluginFamily
- /// </summary>
- /// <param name="instanceDefault"></param>
- public void AddPluginFamilyDefault(InstanceDefault instanceDefault)
- {
- _defaults.Add(instanceDefault);
- }
-
- /// <summary>
- /// Adds the InstanceDefault from a PluginFamily
- /// </summary>
- /// <param name="pluginTypeName"></param>
- /// <param name="defaultKey"></param>
- public void AddPluginFamilyDefault(string pluginTypeName, string defaultKey)
- {
- if (defaultKey == null)
- {
- defaultKey = string.Empty;
- }
-
- AddPluginFamilyDefault(new InstanceDefault(pluginTypeName, defaultKey));
- }
-
-
- /// <summary>
- /// Register a MachineOverride
- /// </summary>
- /// <param name="machine"></param>
- public void AddMachineOverride(MachineOverride machine)
- {
- _machineOverrides.Add(machine.MachineName, machine);
- }
-
- /// <summary>
- /// Register a Profile
- /// </summary>
- /// <param name="profile"></param>
- public void AddProfile(Profile profile)
- {
- _profiles.Add(profile.ProfileName, profile);
- }
-
- /// <summary>
- /// Fetches the named Profile
- /// </summary>
- /// <param name="profileName"></param>
- /// <returns></returns>
- public Profile GetProfile(string profileName)
- {
- if (!_profiles.ContainsKey(profileName))
- {
- return null;
- }
-
- return _profiles[profileName];
- }
-
- /// <summary>
- /// Fetches the named MachineOverride
- /// </summary>
- /// <param name="machineName"></param>
- /// <returns></returns>
- public MachineOverride GetMachineOverride(string machineName)
- {
- if (_machineOverrides.ContainsKey(machineName))
- {
- return _machineOverrides[machineName];
- }
- else
- {
- return new MachineOverride(machineName);
- }
- }
-
- private Profile findCurrentProfile(string profileName)
- {
- bool profileNameIsBlank = profileName == string.Empty || profileName == null;
- string profileToFind = profileNameIsBlank ? _defaultProfileName : profileName;
-
- if (_profiles.ContainsKey(profileToFind))
- {
- return _profiles[profileToFind];
- }
- else
- {
- return new Profile(profileToFind);
- }
- }
-
- /// <summary>
- /// Determines the default instance key for each plugin type using machine and/or
- /// profile overrides. Used internally by <see cref="ObjectFactory"/> to set instance
- /// defaults at runtime
- /// </summary>
- /// <param name="machineName">The machine (computer) name.</param>
- /// <param name="profileName"></param>
- /// <returns></returns>
- public Profile CalculateDefaults(string machineName, string profileName)
- {
- Profile answer = new Profile("Defaults");
- MachineOverride machine = GetMachineOverride(machineName);
- Profile profile = findCurrentProfile(profileName);
-
- foreach (InstanceDefault instance in _defaults)
- {
- answer.AddOverride((InstanceDefault) instance.Clone());
-
- // Machine specific override
- if (machine.HasOverride(instance.PluginTypeName))
- {
- answer.AddOverride(instance.PluginTypeName, machine[instance.PluginTypeName]);
- }
-
- // Profile specific override
- if (profile.HasOverride(instance.PluginTypeName))
- {
- answer.AddOverride(instance.PluginTypeName, profile[instance.PluginTypeName]);
- }
- }
-
- return answer;
- }
-
- public string[] GetMachineNames()
- {
- string[] names = new string[_machineOverrides.Count];
- int i = 0;
- foreach (MachineOverride machine in _machineOverrides.Values)
- {
- names[i++] = machine.MachineName;
- }
-
- return names;
- }
-
- public string[] GetProfileNames()
- {
- string[] names = new string[_profiles.Count];
- int i = 0;
- foreach (Profile profile in _profiles.Values)
- {
- names[i++] = profile.ProfileName;
- }
-
- return names;
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Graph/MachineOverride.cs
===================================================================
--- trunk/Source/StructureMap/Graph/MachineOverride.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/MachineOverride.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,125 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// Models the machine-level overrides for default instances per plugin type.
- /// </summary>
- [Serializable]
- public class MachineOverride
- {
- private Dictionary<string, InstanceDefault> _defaults;
- private string _machineName;
- private Profile _profile = new Profile(string.Empty);
-
- public MachineOverride(string machineName, Profile profile)
- : this(machineName)
- {
- if (profile != null)
- {
- _profile = profile;
- }
- }
-
- public MachineOverride(string machineName) : base()
- {
- _machineName = machineName;
- _defaults = new Dictionary<string, InstanceDefault>();
- }
-
- public string MachineName
- {
- get { return _machineName; }
- }
-
- /// <summary>
- /// Finds the default key for a plugin type
- /// </summary>
- [IndexerName("DefaultKey")]
- public string this[string pluginTypeName]
- {
- get
- {
- if (_profile.HasOverride(pluginTypeName))
- {
- return _profile[pluginTypeName];
- }
- else
- {
- return _defaults[pluginTypeName].DefaultKey;
- }
- }
- }
-
- /// <summary>
- /// If the MachineOverride has a Profile, returns the profile name
- /// </summary>
- public string ProfileName
- {
- get { return _profile == null ? string.Empty : _profile.ProfileName; }
- }
-
-
- public InstanceDefault[] Defaults
- {
- get
- {
- InstanceDefault[] profileDefaults = _profile.Defaults;
- Hashtable defaultHash = new Hashtable();
- foreach (InstanceDefault instance in profileDefaults)
- {
- defaultHash.Add(instance.PluginTypeName, instance);
- }
-
- foreach (InstanceDefault instance in _defaults.Values)
- {
- if (!defaultHash.ContainsKey(instance.PluginTypeName))
- {
- defaultHash.Add(instance.PluginTypeName, instance);
- }
- }
-
- InstanceDefault[] returnValue = new InstanceDefault[defaultHash.Count];
- defaultHash.Values.CopyTo(returnValue, 0);
- Array.Sort(returnValue);
-
- return returnValue;
- }
- }
-
-
- public InstanceDefault[] InnerDefaults
- {
- get
- {
- InstanceDefault[] returnValue = new InstanceDefault[_defaults.Count];
- _defaults.Values.CopyTo(returnValue, 0);
- return returnValue;
- }
- }
-
- /// <summary>
- /// Registers an override for the default instance of a certain plugin type.
- /// </summary>
- /// <param name="pluginTypeName"></param>
- /// <param name="defaultKey"></param>
- public void AddMachineOverride(string pluginTypeName, string defaultKey)
- {
- InstanceDefault instanceDefault = new InstanceDefault(pluginTypeName, defaultKey);
- _defaults.Add(pluginTypeName, instanceDefault);
- }
-
- /// <summary>
- /// Determines if the MachineOverride instance has an overriden default for the plugin type
- /// </summary>
- /// <param name="pluginTypeName"></param>
- /// <returns></returns>
- public bool HasOverride(string pluginTypeName)
- {
- return (_defaults.ContainsKey(pluginTypeName) || _profile.HasOverride(pluginTypeName));
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -267,18 +267,18 @@
#endregion
- public Instance[] GetAllInstances()
+ public void Seal()
{
- List<Instance> list = new List<Instance>();
foreach (InstanceMemento memento in _mementoList)
{
Instance instance = memento.ReadInstance(Parent, _pluginType);
- list.Add(instance);
+ _instances.Add(instance);
}
+ }
- list.AddRange(_instances);
-
- return list.ToArray();
+ public Instance[] GetAllInstances()
+ {
+ return _instances.ToArray();
}
public Instance GetInstance(string name)
@@ -313,5 +313,7 @@
interceptor.InnerPolicy = _buildPolicy;
_buildPolicy = interceptor;
}
+
+
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -6,6 +6,7 @@
using StructureMap.Configuration.DSL;
using StructureMap.Diagnostics;
using StructureMap.Interceptors;
+using StructureMap.Pipeline;
namespace StructureMap.Graph
{
@@ -18,12 +19,12 @@
public class PluginGraph
{
private readonly AssemblyGraphCollection _assemblies;
- private readonly InstanceDefaultManager _defaultManager = new InstanceDefaultManager();
private readonly InterceptorLibrary _interceptorLibrary = new InterceptorLibrary();
private readonly PluginFamilyCollection _pluginFamilies;
private bool _sealed = false;
private readonly bool _useExternalRegistries = true;
private readonly GraphLog _log = new GraphLog();
+ private readonly ProfileManager _profileManager = new ProfileManager();
/// <summary>
/// Default constructor
@@ -50,6 +51,10 @@
get { return _pluginFamilies; }
}
+ public ProfileManager ProfileManager
+ {
+ get { return _profileManager; }
+ }
public GraphLog Log
{
@@ -63,11 +68,6 @@
get { return _sealed; }
}
- public InstanceDefaultManager DefaultManager
- {
- get { return _defaultManager; }
- }
-
public InterceptorLibrary InterceptorLibrary
{
get { return _interceptorLibrary; }
@@ -100,6 +100,13 @@
family.DiscoverImplicitInstances();
}
+ foreach (PluginFamily family in _pluginFamilies)
+ {
+ family.Seal();
+ }
+
+ _profileManager.Seal(this);
+
_sealed = true;
}
@@ -154,14 +161,7 @@
return pluginGraph;
}
- public TypePath LocateOrCreateFamilyForType(string fullName)
- {
- Type pluginType = findTypeByFullName(fullName);
- buildFamilyIfMissing(pluginType);
- return new TypePath(pluginType);
- }
-
private void buildFamilyIfMissing(Type pluginType)
{
if (!_pluginFamilies.Contains(pluginType))
@@ -177,24 +177,5 @@
return PluginFamilies[pluginType];
}
- private Type findTypeByFullName(string fullName)
- {
- foreach (AssemblyGraph assembly in _assemblies)
- {
- Type type = assembly.FindTypeByFullName(fullName);
- if (type != null)
- {
- return type;
- }
- }
-
- throw new StructureMapException(300, fullName);
- }
-
- [Obsolete]
- public void ReadDefaults()
- {
- _defaultManager.ReadDefaultsFromPluginGraph(this);
- }
}
}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Graph/Profile.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Profile.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/Profile.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,115 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// A collection of InstanceDefault's overriding the default instances
- /// </summary>
- [Serializable]
- public class Profile
- {
- private readonly Dictionary<string, InstanceDefault> _defaults;
- private string _profileName;
-
- public Profile(string profileName)
- {
- _profileName = profileName;
- _defaults = new Dictionary<string, InstanceDefault>();
- }
-
- public string ProfileName
- {
- get { return _profileName; }
- set { _profileName = value; }
- }
-
- [IndexerName("DefaultInstanceKey")]
- public string this[string pluginTypeName]
- {
- get
- {
- if (_defaults.ContainsKey(pluginTypeName))
- {
- return (_defaults[pluginTypeName]).DefaultKey;
- }
- else
- {
- return string.Empty;
- }
- }
- }
-
- public int Count
- {
- get { return _defaults.Count; }
- }
-
- public InstanceDefault[] Defaults
- {
- get
- {
- InstanceDefault[] defaults = getDefaultArray();
- return defaults;
- }
- }
-
-
- public bool OverridesPluginType(string pluginTypeName)
- {
- return _defaults.ContainsKey(pluginTypeName);
- }
-
- public void AddOverride(InstanceDefault instanceDefault)
- {
- if (_defaults.ContainsKey(instanceDefault.PluginTypeName))
- {
- _defaults[instanceDefault.PluginTypeName] = instanceDefault;
- }
- else
- {
- _defaults.Add(instanceDefault.PluginTypeName, instanceDefault);
- }
- }
-
- public void AddOverride(string pluginTypeName, string defaultKey)
- {
- AddOverride(new InstanceDefault(pluginTypeName, defaultKey));
- }
-
- public void RemoveOverride(string pluginTypeName)
- {
- _defaults.Remove(pluginTypeName);
- }
-
- public bool HasOverride(string pluginTypeName)
- {
- return _defaults.ContainsKey(pluginTypeName);
- }
-
-
- private InstanceDefault[] getDefaultArray()
- {
- InstanceDefault[] defaults = new InstanceDefault[_defaults.Count];
- _defaults.Values.CopyTo(defaults, 0);
- return defaults;
- }
-
- public void FilterBlanks()
- {
- foreach (InstanceDefault instanceDefault in getDefaultArray())
- {
- if (instanceDefault.DefaultKey == string.Empty)
- {
- _defaults.Remove(instanceDefault.PluginTypeName);
- }
- }
- }
-
- public static string InstanceKeyForProfile(string profileName)
- {
- return profileName + "-Instance";
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/TypePath.cs
===================================================================
--- trunk/Source/StructureMap/Graph/TypePath.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/Graph/TypePath.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -26,6 +26,18 @@
_assemblyName = type.Assembly.GetName().Name;
}
+ public TypePath(string assemblyQualifiedName)
+ {
+ string[] parts = assemblyQualifiedName.Split(',');
+ if (parts.Length < 2)
+ {
+ throw new StructureMapException(107, assemblyQualifiedName);
+ }
+
+ _className = parts[0].Trim();
+ _assemblyName = parts[1].Trim();
+ }
+
public string AssemblyQualifiedName
{
get { return _className + "," + _assemblyName; }
@@ -128,23 +140,5 @@
{
return AssemblyQualifiedName;
}
-
- public static TypePath GetTypePath(string name)
- {
- try
- {
- Type type = Type.GetType(name);
- if (type != null)
- {
- return new TypePath(type);
- }
- }
- catch (Exception ex)
- {
- Debug.WriteLine("here!");
- }
-
- return TypePathForFullName(name);
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/IInstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/IInstanceFactory.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/IInstanceFactory.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -16,11 +16,6 @@
Type PluginType { get; }
/// <summary>
- /// The InstanceKey of the default instance built by this IInstanceFactory
- /// </summary>
- string DefaultInstanceKey { get; }
-
- /// <summary>
/// Establishes a reference to the parent InstanceManager
/// </summary>
/// <param name="instanceManager"></param>
@@ -41,25 +36,6 @@
object GetInstance(IConfiguredInstance instance, IInstanceCreator instanceCreator);
/// <summary>
- /// Creates a new object instance of the default instance memento
- /// </summary>
- /// <returns></returns>
- object GetInstance();
-
- /// <summary>
- /// Sets the default instance
- /// </summary>
- /// <param name="InstanceKey"></param>
- void SetDefault(string InstanceKey);
-
- /// <summary>
- /// Makes the InstanceMemento the basis of the default instance
- /// </summary>
- /// <param name="instance"></param>
- void SetDefault(Instance instance);
-
-
- /// <summary>
/// Returns an IList of all of the configured instances
/// </summary>
/// <returns></returns>
@@ -67,7 +43,8 @@
void AddInstance(Instance instance);
Instance AddType<T>();
- Instance GetDefault();
+
object ApplyInterception(object rawValue);
+ object Build(Instance instance);
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/IInstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/IInstanceManager.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/IInstanceManager.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -9,7 +9,6 @@
{
public interface IInstanceManager
{
- InstanceDefaultManager DefaultManager { get; }
T CreateInstance<T>(string instanceKey);
T CreateInstance<T>();
T FillDependencies<T>();
@@ -49,13 +48,6 @@
void SetDefault(Type pluginType, string instanceKey);
/// <summary>
- /// Sets the default instance for the PluginType
- /// </summary>
- /// <param name="pluginTypeName"></param>
- /// <param name="instanceKey"></param>
- void SetDefault(string pluginTypeName, string instanceKey);
-
- /// <summary>
/// Creates a new object instance of the requested type
/// </summary>
/// <param name="pluginType"></param>
Modified: trunk/Source/StructureMap/IPluginGraphSource.cs
===================================================================
--- trunk/Source/StructureMap/IPluginGraphSource.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/IPluginGraphSource.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -1,3 +1,4 @@
+using System;
using StructureMap.Graph;
namespace StructureMap
@@ -2,6 +3,4 @@
{
- public interface IPluginGraphSource
+ [Obsolete] public interface IPluginGraphSource
{
- InstanceDefaultManager DefaultManager { get; }
-
/// <summary>
Modified: trunk/Source/StructureMap/InstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFactory.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/InstanceFactory.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -17,25 +17,9 @@
private readonly Dictionary<string, Instance> _instances = new Dictionary<string, Instance>();
private readonly InstanceInterceptor _interceptor = new NulloInterceptor();
private readonly Type _pluginType;
- private Instance _defaultInstance;
private InstanceManager _manager = new InstanceManager();
- private IBuildPolicy _policy = new BuildPolicy();
+ private readonly IBuildPolicy _policy = new BuildPolicy();
- #region static constructors
-
- public static InstanceFactory CreateFactoryWithDefault(Type pluginType, object defaultInstance)
- {
- PluginFamily family = new PluginFamily(pluginType);
- InstanceFactory factory = new InstanceFactory(family, true);
-
- LiteralInstance instance = new LiteralInstance(defaultInstance);
- factory.SetDefault(instance);
-
- return factory;
- }
-
- #endregion
-
#region constructor functions
/// <summary>
@@ -62,8 +46,6 @@
{
AddInstance(instance);
}
-
- determineDefaultKey(family, failOnException);
}
catch (StructureMapException)
{
@@ -75,7 +57,7 @@
}
}
- private InstanceFactory(Type concreteType)
+ private InstanceFactory(Type concreteType, ProfileManager profileManager)
{
_interceptor = new NulloInterceptor();
_pluginType = concreteType;
@@ -97,54 +79,16 @@
_instances.Add(instance.Name, instance);
- _defaultInstance = instance;
+ profileManager.SetDefault(concreteType, instance);
}
}
- public static InstanceFactory CreateInstanceFactoryForType(Type concreteType)
+ public static InstanceFactory CreateInstanceFactoryForType(Type concreteType, ProfileManager profileManager)
{
- return new InstanceFactory(concreteType);
+ return new InstanceFactory(concreteType, profileManager);
}
- private void determineDefaultKey(PluginFamily family, bool failOnException)
- {
- if (family.DefaultInstanceKey != null && family.DefaultInstanceKey != string.Empty)
- {
- try
- {
- SetDefault(family.DefaultInstanceKey);
- }
- catch (Exception)
- {
- if (failOnException)
- {
- throw;
- }
- }
- }
- else
- {
- setDefaultFromAttribute();
- }
- }
-
- private void setDefaultFromAttribute()
- {
- string defaultKey = PluginFamilyAttribute.GetDefaultKey(PluginType);
- if (defaultKey != string.Empty)
- {
- try
- {
- SetDefault(defaultKey);
- }
- catch (Exception ex)
- {
- throw new StructureMapException(10, ex, defaultKey, PluginType.FullName);
- }
- }
- }
-
#endregion
#region IInstanceFactory Members
@@ -181,6 +125,11 @@
Instance instance = _instances[instanceKey];
+ return Build(instance);
+ }
+
+ public object Build(Instance instance)
+ {
return _policy.Build(_manager, PluginType, instance);
}
@@ -217,61 +166,6 @@
}
}
-
- /// <summary>
- /// Builds a new instance of the default instance of the PluginType
- /// </summary>
- /// <returns></returns>
- [Obsolete("Want to remove this eventually")] public object GetInstance()
- {
- if (_defaultInstance == null)
- {
- throw new StructureMapException(202, PluginType.FullName);
- }
-
- object builtObject = _policy.Build(_manager, PluginType, _defaultInstance);
- return _interceptor.Process(builtObject);
- }
-
-
- /// <summary>
- /// Sets the default InstanceMemento
- /// </summary>
- /// <param name="instanceKey"></param>
- public void SetDefault(string instanceKey)
- {
- if (instanceKey == string.Empty || instanceKey == null)
- {
- _defaultInstance = null;
- }
- else
- {
- if (!_instances.ContainsKey(instanceKey))
- {
- throw new StructureMapException(215, instanceKey, _pluginType.FullName);
- }
-
- _defaultInstance = _instances[instanceKey];
- }
- }
-
- /// <summary>
- /// Sets the default InstanceMemento
- /// </summary>
- /// <param name="instance"></param>
- public void SetDefault(Instance instance)
- {
- _defaultInstance = instance;
- }
-
- /// <summary>
- /// The default instanceKey
- /// </summary>
- public string DefaultInstanceKey
- {
- get { return _defaultInstance == null ? string.Empty : _defaultInstance.Name; }
- }
-
public IList GetAllInstances()
{
IList list = new ArrayList();
@@ -309,17 +203,13 @@
return instance;
}
- public Instance GetDefault()
- {
- return _defaultInstance;
- }
-
-
public object ApplyInterception(object rawValue)
{
return _interceptor.Process(rawValue);
}
+
+
#endregion
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-04-26 01:57:25 UTC (rev 83)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-04-29 04:19:20 UTC (rev 84)
@@ -15,11 +15,11 @@
/// </summary>
public class InstanceManager : IInstanceManager, IEnumerable, IInstanceCreator
{
- private readonly InstanceDefaultManager _defaultManager;
private readonly Dictionary<Type, IInstanceFactory> _factories;
private readonly bool _failOnException = true;
private readonly GenericsPluginGraph _genericsGraph;
private readonly InterceptorLibrary _interceptorLibrary;
+ private readonly ProfileManager _profileManager;
/// <summary>
/// Default constructor
@@ -29,6 +29,7 @@
_factories = new Dictionary<Type, IInstanceFactory>();
_genericsGraph = new GenericsPluginGraph();
_interceptorLibrary = new InterceptorLibrary();
+ _profileManager = new ProfileManager();
}
/// <summary>
@@ -50,8 +51,8 @@
public InstanceManager(PluginGraph pluginGraph, bool failOnException) : this()
{
_failOnException = failOnException;
- _defaultManager = pluginGraph.DefaultManager;
_interceptorLibrary = pluginGraph.InterceptorLibrary;
+ _profileManager = pluginGraph.ProfileManager;
if (!pluginGraph.IsSealed)
{
@@ -78,7 +79,7 @@
// Preprocess a GenericType
if (pluginType.IsGenericType && !_factories.ContainsKey(pluginType))
{
- PluginFamily family = _genericsGraph.CreateTemplatedFamily(pluginType);
+ PluginFamily family = _genericsGraph.CreateTemplatedFamily(pluginType, _profileManager);
return registerPluginFamily(family);
}
@@ -136,11 +137,6 @@
#region IInstanceManager Members
- public InstanceDefaultManager DefaultManager
- {
- get { return _defaultManager; }
- }
-
public T CreateInstance<T>(string instanceKey)
{
return (T) CreateInstance(typeof (T), instanceKey);
@@ -153,8 +149,9 @@
public PLUGINTYPE CreateInstance<PLUGINTYPE>(ExplicitArguments args)
{
+ // Gotta get the factory first
IInstanceFactory factory = getOrCreateFactory(typeof (PLUGINTYPE));
- Instance defaultInstance = factory.GetDefault();
+ Instance defaultInstance = _profileManager.GetDefault(typeof (PLUGINTYPE));
ExplicitInstance<PLUGINTYPE> instance = new ExplicitInstance<PLUGINTYPE>(args, defaultInstance);
return CreateInstance<PLUGINTYPE>(instance);
@@ -196,10 +193,7 @@
public void SetDefaultsToProfile(string profile)
{
- // The authenticated user may not have required privileges to read from Environment
- string machineName = InstanceDefaultManager.GetMachineName();
- Profile defaultProfile = _defaultManager.CalculateDefaults(machineName, profile);
- SetDefaults(defaultProfile);
+ _profileManager.CurrentProfile = profile;
}
/// <summary>
@@ -222,8 +216,17 @@
/// <returns></returns>
public object CreateInstance(Type pluginType)
{
- IInstanceFactory instanceFactory = this[pluginType];
- return instanceFactory.GetInstance();
+ // Need to fetch Factory first to make sure that the Type is "known"
+ IInstanceFactory factory = getOrCreateFactory(pluginType);
+
+ Instance instance = _profileManager.GetDefault(pluginType);
+
+ if (instance == null)
+ {
+ throw ...
[truncated message content] |