|
From: <jer...@us...> - 2008-08-10 21:38:57
|
Revision: 136
http://structuremap.svn.sourceforge.net/structuremap/?rev=136&view=rev
Author: jeremydmiller
Date: 2008-08-10 21:38:45 +0000 (Sun, 10 Aug 2008)
Log Message:
-----------
Big refactoring of the Plugin model
Modified Paths:
--------------
trunk/Source/StructureMap/BuildSession.cs
trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Graph/Constructor.cs
trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
trunk/Source/StructureMap/Graph/ITypeScanner.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/IInstanceFactory.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/InstanceMemento.cs
trunk/Source/StructureMap/ObjectFactory.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/IBuildSession.cs
trunk/Source/StructureMap/Pipeline/Instance.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapConfiguration.cs
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap/Util/Cache.cs
trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs
trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
Removed Paths:
-------------
trunk/Source/StructureMap/Graph/PluginCollection.cs
Modified: trunk/Source/StructureMap/BuildSession.cs
===================================================================
--- trunk/Source/StructureMap/BuildSession.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/BuildSession.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -109,16 +109,6 @@
return _interceptorLibrary.FindInterceptor(actualValue.GetType()).Process(actualValue);
}
- public InstanceBuilder FindBuilderByType(Type pluginType, Type pluggedType)
- {
- return forType(pluginType).FindBuilderByType(pluggedType);
- }
-
- public InstanceBuilder FindBuilderByConcreteKey(Type pluginType, string concreteKey)
- {
- return forType(pluginType).FindBuilderByConcreteKey(concreteKey);
- }
-
public void RegisterDefault(Type pluginType, object defaultObject)
{
_defaults.Store(pluginType, defaultObject);
Modified: trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -23,6 +23,11 @@
public void IntoPluginType(Type pluginType)
{
+ if (!Constructor.HasConstructors(_pluggedType))
+ {
+ throw new StructureMapException(180, _pluggedType.AssemblyQualifiedName);
+ }
+
if (!TypeRules.CanBeCast(pluginType, _pluggedType))
{
throw new StructureMapException(
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -78,12 +78,15 @@
public CreatePluginFamilyExpression<PLUGINTYPE> TheDefaultIsConcreteType<CONCRETETYPE>()
where CONCRETETYPE : PLUGINTYPE
{
- ExpressionValidator.ValidatePluggabilityOf(typeof (CONCRETETYPE)).IntoPluginType(_pluginType);
+ var concreteType = typeof(CONCRETETYPE);
+ ExpressionValidator.ValidatePluggabilityOf(concreteType).IntoPluginType(_pluginType);
+
return alterAndContinue(family =>
{
- Plugin plugin = family.FindPlugin(typeof (CONCRETETYPE));
- family.DefaultInstanceKey = plugin.ConcreteKey;
+ ConfiguredInstance instance = new ConfiguredInstance(concreteType).WithName(concreteType.AssemblyQualifiedName);
+ family.AddInstance(instance);
+ family.DefaultInstanceKey = instance.Name;
});
return this;
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -109,6 +109,11 @@
string context = "creating a Plugin for " + family.PluginType.AssemblyQualifiedName;
_builder.WithType(pluginPath, context, pluggedType =>
{
+ if (concreteKey == string.Empty)
+ {
+ throw new StructureMapException(112, pluggedType.FullName);
+ }
+
Plugin plugin = family.AddPlugin(pluggedType, concreteKey);
pluginElement.ForTextInChild("Setter/@Name").Do(prop => plugin.Setters.MarkSetterAsMandatory(prop));
Modified: trunk/Source/StructureMap/Graph/Constructor.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Constructor.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -35,11 +35,6 @@
returnValue = GetGreediestConstructor(pluggedType);
}
- if (returnValue == null)
- {
- throw new StructureMapException(180, pluggedType.Name);
- }
-
return returnValue;
}
Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -99,31 +99,11 @@
// TODO: This code sucks. What's going on here?
public static PluginFamily CreateTemplatedClone(PluginFamily baseFamily, params Type[] templateTypes)
{
- Type templatedType = baseFamily.PluginType.MakeGenericType(templateTypes);
- PluginFamily templatedFamily = new PluginFamily(templatedType, baseFamily.Parent);
- templatedFamily.DefaultInstanceKey = baseFamily.DefaultInstanceKey;
- templatedFamily.Policy = baseFamily.Policy.Clone();
+
+ PluginFamily templatedFamily = baseFamily.CreateTemplatedClone(templateTypes);
+
- // Add Plugins
- baseFamily.EachPlugin(plugin =>
- {
- if (CanBePluggedIntoGenericType(baseFamily.PluginType, plugin.PluggedType, templateTypes))
- {
- Plugin templatedPlugin = plugin.CreateTemplatedClone(templateTypes);
- templatedFamily.AddPlugin(templatedPlugin);
- }
- });
-
- // TODO -- Got a big problem here. Intances need to be copied over
- baseFamily.EachInstance(i =>
- {
- ((IDiagnosticInstance)i).AddTemplatedInstanceTo(templatedFamily, templateTypes);
- });
-
- // Need to attach the new PluginFamily to the old PluginGraph
- baseFamily.Parent.PluginFamilies.Add(templatedFamily);
-
return templatedFamily;
}
Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -20,7 +20,7 @@
Type pluginType = FindPluginType(type);
- if (pluginType != null && Plugin.CreateForConcreteType(type) != null)
+ if (pluginType != null && Constructor.HasConstructors(type))
{
registry.ForRequestedType(pluginType).AddInstance(new ConfiguredInstance(type));
}
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -22,11 +22,6 @@
public Plugin(Type pluggedType, string concreteKey) : this(pluggedType)
{
- if (concreteKey == string.Empty)
- {
- throw new StructureMapException(112, pluggedType.FullName);
- }
-
_concreteKey = concreteKey;
}
@@ -129,11 +124,9 @@
return _constructor.IsValid();
}
- public static Plugin CreateForConcreteType(Type type)
+ public bool CanBeCreated()
{
- if (!Constructor.HasConstructors(type)) return null;
-
- return new Plugin(type, DEFAULT);
+ return Constructor.HasConstructors(_pluggedType);
}
public bool HasOptionalSetters()
Deleted: trunk/Source/StructureMap/Graph/PluginCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Graph/PluginCollection.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -1,134 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using StructureMap.Util;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// Custom collection for Plugin objects
- /// </summary>
- public class PluginCollection : IEnumerable<Plugin>
- {
- private readonly PluginFamily _family;
- private readonly Cache<Type, Plugin> _plugins;
-
- public PluginCollection(PluginFamily family)
- {
- _family = family;
- _plugins = new Cache<Type, Plugin>(t =>
- {
- // Reject if the PluggedType cannot be upcast to the PluginType
- if (!TypeRules.CanBeCast(_family.PluginType, t))
- {
- throw new StructureMapException(104, t, _family.PluginType);
- }
-
- return new Plugin(t);
- });
- }
-
- public Plugin[] All
- {
- get
- {
- return _plugins.GetAll();
- }
- }
-
- public int Count
- {
- get { return _plugins.Count; }
- }
-
- /// <summary>
- /// Gets a Plugin by its pluggedType
- /// </summary>
- /// <param name="pluggedType"></param>
- /// <returns></returns>
- public Plugin this[Type pluggedType]
- {
- get { return _plugins.Retrieve(pluggedType); }
- }
-
- /// <summary>
- /// Retrieves a Plugin by its ConcreteKey
- /// </summary>
- /// <param name="concreteKey"></param>
- /// <returns></returns>
- public Plugin this[string concreteKey]
- {
- get
- {
- return _plugins.Find(plugin => plugin.ConcreteKey == concreteKey);
- }
- }
-
- #region IEnumerable<Plugin> Members
-
- IEnumerator<Plugin> IEnumerable<Plugin>.GetEnumerator()
- {
- return _plugins.GetEnumerator();
- }
-
- public IEnumerator GetEnumerator()
- {
- return ((IEnumerable<Plugin>) this).GetEnumerator();
- }
-
- #endregion
-
-
- public void Add(Plugin plugin)
- {
- // Reject if the PluggedType cannot be upcast to the PluginType
- if (!TypeRules.CanBeCast(_family.PluginType, plugin.PluggedType))
- {
- throw new StructureMapException(104, plugin.PluggedType, _family.PluginType);
- }
-
- _plugins.Store(plugin.PluggedType, plugin);
- }
-
- /// <summary>
- /// Does the PluginFamily contain a Plugin
- /// </summary>
- /// <param name="concreteKey"></param>
- /// <returns></returns>
- public bool HasPlugin(string concreteKey)
- {
- return this[concreteKey] != null;
- }
-
-
- public void Remove(string concreteKey)
- {
- Plugin plugin = this[concreteKey];
- _plugins.Remove(plugin.PluggedType);
- }
-
- public List<Plugin> FindAutoFillablePlugins()
- {
- List<Plugin> list = new List<Plugin>();
- _plugins.Each(plugin =>
- {
- if (plugin.CanBeAutoFilled)
- {
- list.Add(plugin);
- }
- });
-
- return list;
- }
-
- public bool HasPlugin(Type pluggedType)
- {
- return _plugins.Has(pluggedType);
- }
-
- public void Fill(Plugin plugin)
- {
- _plugins.Fill(plugin.PluggedType, plugin);
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -17,7 +17,7 @@
private readonly Predicate<Type> _implicitPluginFilter;
private readonly Cache<string, Instance> _instances = new Cache<string, Instance>(delegate { return null; });
private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>();
- private readonly PluginCollection _plugins;
+ private Cache<string, Plugin> _pluggedTypes = new Cache<string, Plugin>();
private readonly Type _pluginType;
private IBuildPolicy _buildPolicy = new BuildPolicy();
private string _defaultKey = string.Empty;
@@ -34,7 +34,6 @@
{
_parent = parent;
_pluginType = pluginType;
- _plugins = new PluginCollection(this);
PluginFamilyAttribute.ConfigureFamily(this);
@@ -44,10 +43,10 @@
if (IsConcrete(pluginType))
{
- Plugin plugin = Plugin.CreateForConcreteType(pluginType);
- if (plugin != null)
+ Plugin plugin = PluginCache.GetPlugin(pluginType);
+ if (plugin.CanBeCreated())
{
- _plugins.Add(plugin);
+ AddPlugin(pluginType, Plugin.DEFAULT);
}
}
}
@@ -151,16 +150,21 @@
private void discoverImplicitInstances()
{
- List<Plugin> list = _plugins.FindAutoFillablePlugins();
- list.RemoveAll(
- plugin => _instances.Exists(instance => instance.Matches(plugin)));
-
- foreach (Plugin plugin in list)
+ _pluggedTypes.Each((key, plugin) =>
{
- AddInstance(plugin.CreateImplicitInstance());
- }
+ if (plugin.CanBeAutoFilled && !hasInstanceWithPluggedType(plugin))
+ {
+ var instance = new ConfiguredInstance(plugin.PluggedType).WithName(key);
+ AddInstance(instance);
+ }
+ });
}
+ private bool hasInstanceWithPluggedType(Plugin plugin)
+ {
+ return _instances.Exists(instance => instance.Matches(plugin));
+ }
+
public void EachInstance(Action<Instance> action)
{
_instances.Each(action);
@@ -178,40 +182,47 @@
{
if (!HasPlugin(pluggedType))
{
- Plugin plugin = new Plugin(pluggedType);
- _plugins.Add(plugin);
+ AddPlugin(pluggedType);
}
}
}
public bool HasPlugin(Type pluggedType)
{
- return _plugins.HasPlugin(pluggedType);
+ return _pluggedTypes.Exists(plugin => plugin.PluggedType == pluggedType);
}
- public Plugin AddPlugin(Type pluggedType)
+ private void assertPluggability(Type pluggedType)
{
- return _plugins[pluggedType];
+ if (!CanBeCast(_pluginType, pluggedType))
+ {
+ throw new StructureMapException(104, pluggedType, _pluginType);
+ }
+
+ if (!Constructor.HasConstructors(pluggedType))
+ {
+ throw new StructureMapException(180, pluggedType.AssemblyQualifiedName);
+ }
}
- public Plugin AddPlugin(Type pluggedType, string key)
+ public Plugin AddPlugin(Type pluggedType)
{
- Plugin plugin = new Plugin(pluggedType, key);
- AddPlugin(plugin);
+ assertPluggability(pluggedType);
+ Plugin plugin = PluginCache.GetPlugin(pluggedType);
+ _pluggedTypes.Store(plugin.ConcreteKey, plugin);
+
return plugin;
}
- [Obsolete("Wanna make private")]
- public void AddPlugin(Plugin plugin)
+ public Plugin AddPlugin(Type pluggedType, string key)
{
- if (_plugins.HasPlugin(plugin.ConcreteKey))
- {
- _parent.Log.RegisterError(113, plugin.ConcreteKey, _pluginType);
- }
+ assertPluggability(pluggedType);
+ Plugin plugin = PluginCache.GetPlugin(pluggedType);
+ _pluggedTypes.Store(key, plugin);
- _plugins.Add(plugin);
+ return plugin;
}
public Instance GetDefaultInstance()
@@ -241,7 +252,7 @@
public int PluginCount
{
- get { return _plugins.Count; }
+ get { return _pluggedTypes.Count; }
}
/// <summary>
@@ -268,9 +279,10 @@
#endregion
+ [Obsolete("is this really important?")]
public Plugin FindPlugin(Type pluggedType)
{
- return _plugins[pluggedType];
+ return _pluggedTypes.Find(p => p.PluggedType == pluggedType);
}
public void AddDefaultMemento(InstanceMemento memento)
@@ -303,11 +315,7 @@
public void ImportFrom(PluginFamily source)
{
source.EachInstance(instance => _instances.Fill(instance.Name, instance));
-
- foreach (Plugin plugin in source._plugins)
- {
- _plugins.Fill(plugin);
- }
+ source._pluggedTypes.Each((key, plugin) => _pluggedTypes.Fill(key, plugin));
}
public Instance FirstInstance()
@@ -317,25 +325,37 @@
public Plugin FindPlugin(string concreteKey)
{
- return _plugins[concreteKey];
+ if (_pluggedTypes.Has(concreteKey))
+ {
+ return _pluggedTypes.Retrieve(concreteKey);
+ }
+
+ return null;
}
public bool HasPlugin(string concreteKey)
{
- return _plugins.HasPlugin(concreteKey);
+ return _pluggedTypes.Has(concreteKey);
}
- public void EachPlugin(Action<Plugin> action)
+ public PluginFamily CreateTemplatedClone(Type[] templateTypes)
{
- foreach (Plugin plugin in _plugins)
+ Type templatedType = _pluginType.MakeGenericType(templateTypes);
+ PluginFamily templatedFamily = new PluginFamily(templatedType, Parent);
+ templatedFamily.DefaultInstanceKey = DefaultInstanceKey;
+ templatedFamily.Policy = Policy.Clone();
+
+
+ // TODO -- Got a big problem here. Intances need to be copied over
+ EachInstance(i =>
{
- action(plugin);
- }
- }
+ ((IDiagnosticInstance)i).AddTemplatedInstanceTo(templatedFamily, templateTypes);
+ });
- public IEnumerable<Plugin> GetAllPlugins()
- {
- return _plugins.All;
+ // Need to attach the new PluginFamily to the old PluginGraph
+ Parent.PluginFamilies.Add(templatedFamily);
+
+ return templatedFamily;
}
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/IInstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/IInstanceFactory.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/IInstanceFactory.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -19,8 +19,6 @@
object Build(IBuildSession session, Instance instance);
Instance FindInstance(string name);
- InstanceBuilder FindBuilderByType(Type pluggedType);
- InstanceBuilder FindBuilderByConcreteKey(string concreteKey);
void ForEachInstance(Action<Instance> action);
void ImportFrom(PluginFamily family);
void AcceptVisitor(IPipelineGraphVisitor visitor, Instance defaultInstance);
Modified: trunk/Source/StructureMap/InstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFactory.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/InstanceFactory.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -11,8 +11,6 @@
/// </summary>
public class InstanceFactory : IInstanceFactory
{
- private readonly InstanceBuilderList _instanceBuilders;
-
private readonly Cache<string, Instance> _instances =
new Cache<string, Instance>(delegate { return null; });
@@ -41,7 +39,6 @@
_policy = family.Policy;
_pluginType = family.PluginType;
- _instanceBuilders = new InstanceBuilderList(family.PluginType, family.GetAllPlugins());
family.EachInstance(AddInstance);
@@ -81,16 +78,6 @@
get { return _pluginType; }
}
- public InstanceBuilder FindBuilderByType(Type pluggedType)
- {
- return _instanceBuilders.FindByType(pluggedType);
- }
-
- public InstanceBuilder FindBuilderByConcreteKey(string concreteKey)
- {
- return _instanceBuilders.FindByConcreteKey(concreteKey);
- }
-
public void ForEachInstance(Action<Instance> action)
{
_instances.Each(action);
@@ -105,7 +92,6 @@
[Obsolete]
public Instance AddType<T>()
{
- InstanceBuilder builder = _instanceBuilders.FindByType(typeof (T));
ConfiguredInstance instance =
new ConfiguredInstance(typeof (T)).WithName(TypePath.GetAssemblyQualifiedName(typeof (T)));
@@ -141,7 +127,6 @@
public void ImportFrom(PluginFamily family)
{
- _instanceBuilders.Add(family.GetAllPlugins());
family.EachInstance(instance => _instances.Fill(instance.Name, instance));
}
Modified: trunk/Source/StructureMap/InstanceMemento.cs
===================================================================
--- trunk/Source/StructureMap/InstanceMemento.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/InstanceMemento.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -84,7 +84,7 @@
public virtual Plugin FindPlugin(PluginFamily family)
{
- Plugin plugin = family.FindPlugin(innerConcreteKey) ?? getPluginByType(family) ??
+ Plugin plugin = getPluginByType(family) ?? family.FindPlugin(innerConcreteKey ?? string.Empty) ??
family.FindPlugin(Plugin.DEFAULT);
if (plugin == null)
@@ -105,8 +105,7 @@
}
Type pluggedType = new TypePath(pluggedTypeName).FindType();
-
- return family.FindPlugin(pluggedType);
+ return PluginCache.GetPlugin(pluggedType);
}
/// <summary>
Modified: trunk/Source/StructureMap/ObjectFactory.cs
===================================================================
--- trunk/Source/StructureMap/ObjectFactory.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/ObjectFactory.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -218,6 +218,8 @@
Container container = new Container(graph);
container.SetDefaultsToProfile(_profile);
+ PluginCache.Compile();
+
return container;
}
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -87,8 +87,7 @@
protected override object build(Type pluginType, IBuildSession session)
{
- InstanceBuilder builder = session.FindBuilderByType(pluginType, _pluggedType);
-
+ InstanceBuilder builder = PluginCache.FindBuilder(_pluggedType);
return ((IConfiguredInstance) this).Build(pluginType, session, builder);
}
Modified: trunk/Source/StructureMap/Pipeline/IBuildSession.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/IBuildSession.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Pipeline/IBuildSession.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -9,8 +9,6 @@
Array CreateInstanceArray(Type pluginType, Instance[] instances);
object CreateInstance(Type pluginType);
object ApplyInterception(Type pluginType, object actualValue);
- InstanceBuilder FindBuilderByType(Type pluginType, Type pluggedType);
- InstanceBuilder FindBuilderByConcreteKey(Type pluginType, string concreteKey);
void RegisterDefault(Type pluginType, object defaultObject);
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/Instance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/Instance.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Pipeline/Instance.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -133,11 +133,6 @@
protected abstract object build(Type pluginType, IBuildSession session);
- protected virtual Plugin findPlugin(PluginCollection plugins)
- {
- return null;
- }
-
protected virtual Instance findMasterInstance(PluginFamily family, string profileName, GraphLog log)
{
return this;
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/StructureMap.csproj 2008-08-10 21:38:45 UTC (rev 136)
@@ -280,9 +280,6 @@
<Compile Include="Graph\Plugin.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Graph\PluginCollection.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Graph\PluginFamily.cs">
<SubType>Code</SubType>
</Compile>
Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs
===================================================================
--- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -85,6 +85,8 @@
_registries.Add(_registry);
UseDefaultStructureMapConfigFile = false;
IgnoreStructureMapConfig = false;
+
+ PluginCache.ResetAll();
}
public static void RegisterInterceptor(TypeInterceptor interceptor)
Modified: trunk/Source/StructureMap/StructureMapException.resx
===================================================================
--- trunk/Source/StructureMap/StructureMapException.resx 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/StructureMapException.resx 2008-08-10 21:38:45 UTC (rev 136)
@@ -135,9 +135,6 @@
<value>Missing a mandatory "ConcreteKey" attribute in a <Plugin> node for Type "{0}"</value>
<comment>change wording</comment>
</data>
- <data name="113" xml:space="preserve">
- <value>Duplicate ConcreteKey ({0}) values in PluginType "{1}"</value>
- </data>
<data name="200" xml:space="preserve">
<value>Could not find an Instance named "{0}" for PluginType {1}</value>
</data>
@@ -188,7 +185,7 @@
<value>Could not create the type {0} specified in the [PluginFamily] attribute on PluginFamily {1}</value>
</data>
<data name="180" xml:space="preserve">
- <value>Cannot construct a Plugin for Class {0}, No public constructor found.</value>
+ <value>StructureMap cannot construct objects of Class {0} because there is no public constructor found.</value>
</data>
<data name="115" xml:space="preserve">
<value>An exception occurred while trying to create an InstanceFactory for PluginType {0}</value>
Modified: trunk/Source/StructureMap/Util/Cache.cs
===================================================================
--- trunk/Source/StructureMap/Util/Cache.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap/Util/Cache.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -26,6 +26,11 @@
_onMissing = onMissing;
}
+ public void Clear()
+ {
+ _values.Clear();
+ }
+
public Func<VALUE, KEY> GetKey
{
get { return _getKey; }
@@ -94,6 +99,14 @@
}
}
+ public void Each(Action<KEY, VALUE> action)
+ {
+ foreach (var pair in _values)
+ {
+ action(pair.Key, pair.Value);
+ }
+ }
+
public bool Has(KEY key)
{
return _values.ContainsKey(key);
@@ -146,5 +159,6 @@
_values.Remove(key);
}
}
+
}
}
Modified: trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap.Testing/Graph/ExceptionHandling/StructureMapExceptionTester.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -153,24 +153,7 @@
");
}
- [Test]
- public void Log_113_if_a_duplicate_Plugin_ConcreteKey_is_detected()
- {
- assertErrorIsLogged(113,
- @"
- <StructureMap>
- <Assembly Name='StructureMap.Testing.Widget'/>
-
- <PluginFamily Type='StructureMap.Testing.Widget.IWidget' Assembly='StructureMap.Testing.Widget' DefaultKey=''>
- <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='Dup'/>
- <Plugin Assembly='StructureMap.Testing.Widget' Type='StructureMap.Testing.Widget.NotPluggableWidget' ConcreteKey='Dup'/>
- </PluginFamily>
- </StructureMap>
-
-");
- }
-
[Test]
public void Log_130_if_an_error_occurs_when_trying_to_create_an_interceptor_configured_in_xml()
{
Modified: trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -76,37 +76,10 @@
Assert.IsNotNull(templatedFamily);
Assert.AreEqual(typeof (IGenericService<int>), templatedFamily.PluginType);
- Assert.AreEqual(3, templatedFamily.PluginCount);
- Assert.IsNotNull(templatedFamily.FindPlugin(typeof (GenericService<int>)));
- Assert.IsNotNull(templatedFamily.FindPlugin(typeof (SecondGenericService<int>)));
- Assert.IsNotNull(templatedFamily.FindPlugin(typeof (ThirdGenericService<int>)));
}
- [Test]
- public void BuildTemplatedFamilyWithThreeTemplateParameters()
- {
- PluginGraph pluginGraph = new PluginGraph();
- PluginFamily family = pluginGraph.FindFamily(typeof (IGenericService3<,,>));
- family.AddPlugin(typeof (GenericService3<,,>), "Default");
- family.AddPlugin(typeof (SecondGenericService3<,,>), "Second");
- family.AddPlugin(typeof (ThirdGenericService3<,,>), "Third");
- PluginFamily templatedFamily = GenericsPluginGraph.CreateTemplatedClone(family, typeof (int), typeof (bool),
- typeof (string));
- Assert.IsNotNull(templatedFamily);
- Assert.AreEqual(typeof (IGenericService3<int, bool, string>), templatedFamily.PluginType);
-
- Assert.AreEqual(3, templatedFamily.PluginCount);
-
- Assert.AreEqual(typeof (GenericService3<int, bool, string>), templatedFamily.FindPlugin("Default").PluggedType);
- Assert.AreEqual(typeof (SecondGenericService3<int, bool, string>),
- templatedFamily.FindPlugin("Second").PluggedType);
- Assert.AreEqual(typeof (ThirdGenericService3<int, bool, string>),
- templatedFamily.FindPlugin("Third").PluggedType);
- }
-
-
[Test]
public void DirectImplementationOfInterfaceCanBeCast()
{
Modified: trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -55,23 +55,6 @@
}
[Test]
- public void Import_from_family_picks_up_new_InstanceBuilders()
- {
- InstanceFactory factory = new InstanceFactory(typeof (IWidget));
-
- PluginFamily family = new PluginFamily(typeof (IWidget));
- family.AddPlugin(typeof (AWidget));
- family.AddPlugin(typeof (ColorWidget));
- factory.ImportFrom(family);
-
- InstanceBuilder builder = factory.FindBuilderByType(typeof (AWidget));
- Assert.IsNotNull(builder);
-
- builder = factory.FindBuilderByType(typeof (ColorWidget));
- Assert.IsNotNull(builder);
- }
-
- [Test]
public void Import_from_family_picks_up_new_instances()
{
InstanceFactory factory = new InstanceFactory(typeof (IWidget));
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -153,11 +153,8 @@
public void If_PluginType_is_concrete_automatically_add_a_plugin_called_default()
{
PluginFamily family = new PluginFamily(GetType());
- Assert.AreEqual(1, family.PluginCount);
-
- Plugin plugin = family.FindPlugin(GetType());
- Assert.AreEqual(Plugin.DEFAULT, plugin.ConcreteKey);
- Assert.AreEqual(GetType(), plugin.PluggedType);
+ family.PluginCount.ShouldEqual(1);
+ family.FindPlugin(Plugin.DEFAULT).PluggedType.ShouldEqual(GetType());
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Graph/PluginGraphBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginGraphBuilderTester.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap.Testing/Graph/PluginGraphBuilderTester.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -164,9 +164,7 @@
public void GotPluginThatIsAddedInConfigXml()
{
PluginFamily family = graph.FindFamily(typeof (IWidget));
- Plugin plugin = family.FindPlugin(typeof (NotPluggableWidget));
- Assert.IsNotNull(plugin);
- Assert.AreEqual("NotPluggable", plugin.ConcreteKey);
+ family.FindPlugin("NotPluggable").PluggedType.ShouldEqual(typeof (NotPluggableWidget));
}
Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -3,6 +3,7 @@
using NUnit.Framework;
using Rhino.Mocks;
using StructureMap.Attributes;
+using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Pipeline;
using StructureMap.Testing.Widget;
@@ -275,18 +276,15 @@
{
try
{
- Constructor ctor = new Constructor(typeof (ClassWithNoConstructor));
- Assert.Fail("Should have thrown a StructureMapException");
+ new Registry().ForRequestedType<ClassWithNoConstructor>().TheDefaultIsConcreteType<ClassWithNoConstructor>();
}
catch (StructureMapException ex)
{
Assert.AreEqual(180, ex.ErrorCode);
- Assert.AreEqual(
- "StructureMap Exception Code: 180\nCannot construct a Plugin for Class ClassWithNoConstructor, No public constructor found.",
- ex.Message);
}
}
+
[Test]
public void Visit_arguments()
{
@@ -313,6 +311,18 @@
plugin.VisitArguments(visitor);
}
}
+
+ [Test]
+ public void CanBeCreated_positive_with_a_public_constructor()
+ {
+ new Plugin(typeof(LotsOfStuff)).CanBeCreated().ShouldBeTrue();
+ }
+
+ [Test]
+ public void CanBeCreated_is_negative_with_no_public_constructors()
+ {
+ new Plugin(typeof(ClassWithNoConstructor)).CanBeCreated().ShouldBeFalse();
+ }
}
public class LotsOfStuff
Modified: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-08-10 17:05:08 UTC (rev 135)
+++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2008-08-10 21:38:45 UTC (rev 136)
@@ -183,7 +183,7 @@
using (mocks.Record())
{
- Expect.Call(session.FindBuilderByType(thePluginType, thePluggedType)).Return(builder);
+ PluginCache.Store(thePluggedType, builder);
Expect.Call(builder.BuildInstance(instance, session)).Return(new object());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|