|
From: <jer...@us...> - 2008-04-26 01:57:27
|
Revision: 83
http://structuremap.svn.sourceforge.net/structuremap/?rev=83&view=rev
Author: jeremydmiller
Date: 2008-04-25 18:57:25 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
Eliminated the InterceptionChain business
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/InstanceManager.cs
trunk/Source/StructureMap/Pipeline/BuildStrategies.cs
trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Removed Paths:
-------------
trunk/Source/StructureMap/Graph/InterceptionChain.cs
trunk/Source/StructureMap/Interceptors/CacheInterceptor.cs
trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs
trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs
trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs
trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs
trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs
trunk/Source/StructureMap/Interceptors/SingletonInterceptor.cs
trunk/Source/StructureMap/Interceptors/ThreadLocalStorageInterceptor.cs
trunk/Source/StructureMap/XmlMapping/
trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs
trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs
trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs
trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs
trunk/Source/StructureMap.Testing/NewFolder1/
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -147,8 +147,6 @@
family.AddMementoSource(source);
family.SetScopeTo(Scope);
- //InterceptorChainBuilder builder = new InterceptorChainBuilder();
- //family.InterceptionChain = builder.Build(Scope);
return family;
}
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -29,8 +29,7 @@
void IExpression.Configure(PluginGraph graph)
{
PluginFamily family = graph.LocateOrCreateFamilyForType(_pluginType);
- InterceptorChainBuilder builder = new InterceptorChainBuilder();
- family.InterceptionChain = builder.Build(_scope);
+ family.SetScopeTo(_scope);
foreach (IExpression child in _children)
{
@@ -108,8 +107,7 @@
{
_alterations.Add(delegate(PluginFamily family)
{
- InterceptorChainBuilder builder = new InterceptorChainBuilder();
- family.InterceptionChain = builder.Build(scope);
+ family.SetScopeTo(scope);
});
return this;
@@ -122,7 +120,7 @@
public CreatePluginFamilyExpression<PLUGINTYPE> AsSingletons()
{
_alterations.Add(
- delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(new SingletonInterceptor()); });
+ delegate(PluginFamily family) { family.SetScopeTo(InstanceScope.Singleton); });
return this;
}
@@ -165,9 +163,12 @@
return this;
}
- public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(InstanceFactoryInterceptor interceptor)
+ public CreatePluginFamilyExpression<PLUGINTYPE> InterceptConstructionWith(IInstanceInterceptor interceptor)
{
- _alterations.Add(delegate(PluginFamily family) { family.InterceptionChain.AddInterceptor(interceptor); });
+ _alterations.Add(delegate(PluginFamily family)
+ {
+ family.AddInterceptor(interceptor);
+ });
return this;
}
}
Modified: trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Configuration/NormalGraphBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -11,22 +11,14 @@
{
public class NormalGraphBuilder : IGraphBuilder
{
- private readonly IInterceptorChainBuilder _builder;
private MachineOverride _machine;
private PluginGraph _pluginGraph;
private Profile _profile;
private PluginGraph _systemGraph;
private InstanceManager _systemInstanceManager;
-
- public NormalGraphBuilder(Registry[] registries) : this(new InterceptorChainBuilder(), registries)
+ public NormalGraphBuilder(Registry[] registries)
{
- }
-
- public NormalGraphBuilder(IInterceptorChainBuilder builder, Registry[] registries)
- {
- _builder = builder;
-
_pluginGraph = new PluginGraph();
foreach (Registry registry in registries)
{
@@ -137,8 +129,7 @@
// Xml configuration wins
family.DefaultInstanceKey = defaultKey;
- InterceptionChain interceptionChain = _builder.Build(scope);
- family.AddInterceptionChain(interceptionChain);
+ family.SetScopeTo(scope);
}
public virtual void AttachSource(TypePath pluginTypePath, InstanceMemento sourceMemento)
@@ -188,11 +179,11 @@
PluginFamily family = _pluginGraph.PluginFamilies[pluginTypePath.FindType()];
try
{
- InstanceFactoryInterceptor interceptor =
- (InstanceFactoryInterceptor)
- buildSystemObject(typeof (InstanceFactoryInterceptor), interceptorMemento);
+ IInstanceInterceptor interceptor =
+ (IInstanceInterceptor)
+ buildSystemObject(typeof(IInstanceInterceptor), interceptorMemento);
- family.InterceptionChain.AddInterceptor(interceptor);
+ family.AddInterceptor(interceptor);
}
catch (Exception ex)
{
Deleted: trunk/Source/StructureMap/Graph/InterceptionChain.cs
===================================================================
--- trunk/Source/StructureMap/Graph/InterceptionChain.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Graph/InterceptionChain.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,104 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using StructureMap.Interceptors;
-
-namespace StructureMap.Graph
-{
- /// <summary>
- /// Manages a list of InstanceFactoryInterceptor's. Design-time model of an array
- /// of decorators to alter the InstanceFactory behavior for a PluginType.
- /// </summary>
- [Obsolete] public class InterceptionChain : IEnumerable<InstanceFactoryInterceptor>, IEquatable<InterceptionChain>
- {
- private List<InstanceFactoryInterceptor> _interceptorList;
-
- public InterceptionChain()
- {
- _interceptorList = new List<InstanceFactoryInterceptor>();
- }
-
- public int Count
- {
- get { return _interceptorList.Count; }
- }
-
- public InstanceFactoryInterceptor this[int index]
- {
- get { return _interceptorList[index]; }
- }
-
- #region IEnumerable<InstanceFactoryInterceptor> Members
-
- IEnumerator<InstanceFactoryInterceptor> IEnumerable<InstanceFactoryInterceptor>.GetEnumerator()
- {
- return _interceptorList.GetEnumerator();
- }
-
- public IEnumerator GetEnumerator()
- {
- return _interceptorList.GetEnumerator();
- }
-
- #endregion
-
- public IInstanceFactory WrapInstanceFactory(IInstanceFactory factory)
- {
- IInstanceFactory outerFactory = factory;
-
- for (int i = _interceptorList.Count - 1; i >= 0; i--)
- {
- InstanceFactoryInterceptor interceptor = _interceptorList[i];
- interceptor.InnerInstanceFactory = outerFactory;
- outerFactory = interceptor;
- }
-
- return outerFactory;
- }
-
- public void AddInterceptor(InstanceFactoryInterceptor interceptor)
- {
- _interceptorList.Add(interceptor);
- }
-
- public bool Contains(Type interceptorType)
- {
- foreach (InstanceFactoryInterceptor interceptor in _interceptorList)
- {
- if (interceptor.GetType() == interceptorType)
- {
- return true;
- }
- }
-
- return false;
- }
-
- public bool Equals(InterceptionChain interceptionChain)
- {
- if (interceptionChain == null) return false;
-
-
- if (!Equals(_interceptorList.Count, interceptionChain._interceptorList.Count)) return false;
-
- for (int i = 0; i < _interceptorList.Count; i++)
- {
- if (!Equals(_interceptorList[i], interceptionChain._interceptorList[i])) return false;
-
- }
-
- return true;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(this, obj)) return true;
- return Equals(obj as InterceptionChain);
- }
-
- public override int GetHashCode()
- {
- return _interceptorList != null ? _interceptorList.GetHashCode() : 0;
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -38,7 +38,6 @@
private bool _canUseUnMarkedPlugins = false;
private string _defaultKey = string.Empty;
private InstanceInterceptor _instanceInterceptor = new NulloInterceptor();
- private InterceptionChain _interceptionChain;
private PluginGraph _parent;
private Type _pluginType;
private string _pluginTypeName;
@@ -53,11 +52,9 @@
_pluginTypeName = TypePath.GetAssemblyQualifiedName(_pluginType);
_defaultKey = defaultInstanceKey;
_plugins = new PluginCollection(this);
-
- _interceptionChain = new InterceptionChain();
}
-
+ // TODO: Need to unit test the scope from the attribute
/// <summary>
/// Testing constructor
/// </summary>
@@ -65,10 +62,12 @@
public PluginFamily(Type pluginType) :
this(pluginType, PluginFamilyAttribute.GetDefaultKey(pluginType))
{
- if (PluginFamilyAttribute.IsMarkedAsSingleton(pluginType))
+ PluginFamilyAttribute attribute = PluginFamilyAttribute.GetAttribute(pluginType);
+ if (attribute != null)
{
- InterceptionChain.AddInterceptor(new SingletonInterceptor());
+ SetScopeTo(attribute.Scope);
}
+
}
@@ -82,7 +81,6 @@
{
_plugins = new PluginCollection(this);
_pluginTypeName = path.AssemblyQualifiedName;
- _interceptionChain = new InterceptionChain();
initializeExplicit(path, defaultKey);
}
@@ -125,12 +123,6 @@
templatedFamily.Parent = Parent;
templatedFamily._buildPolicy = _buildPolicy.Clone();
- foreach (InstanceFactoryInterceptor interceptor in _interceptionChain)
- {
- InstanceFactoryInterceptor clonedInterceptor = (InstanceFactoryInterceptor) interceptor.Clone();
- templatedFamily.InterceptionChain.AddInterceptor(clonedInterceptor);
- }
-
// Add Plugins
foreach (Plugin plugin in _plugins)
{
@@ -207,21 +199,6 @@
return _mementoList.Find(delegate(InstanceMemento m) { return m.InstanceKey == instanceKey; });
}
- public void AddInterceptionChain(InterceptionChain chain)
- {
- if (_interceptionChain == null)
- {
- _interceptionChain = chain;
- }
- else
- {
- foreach (InstanceFactoryInterceptor interceptor in chain)
- {
- _interceptionChain.AddInterceptor(interceptor);
- }
- }
- }
-
public void DiscoverImplicitInstances()
{
List<Plugin> list = _plugins.FindAutoFillablePlugins();
@@ -256,13 +233,6 @@
set { _defaultKey = value ?? string.Empty; }
}
- [Obsolete("Make this go away")]
- public InterceptionChain InterceptionChain
- {
- get { return _interceptionChain; }
- set { _interceptionChain = value; }
- }
-
public PluginCollection Plugins
{
get { return _plugins; }
Modified: trunk/Source/StructureMap/InstanceManager.cs
===================================================================
--- trunk/Source/StructureMap/InstanceManager.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/InstanceManager.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -351,11 +351,9 @@
private IInstanceFactory registerPluginFamily(PluginFamily family)
{
InstanceFactory factory = new InstanceFactory(family, _failOnException);
- IInstanceFactory wrappedFactory = family.InterceptionChain.WrapInstanceFactory(factory);
+ RegisterType(factory);
- RegisterType(wrappedFactory);
-
- return wrappedFactory;
+ return factory;
}
/// <summary>
@@ -511,15 +509,7 @@
#endregion
- //public InstanceInterceptor FindInterceptor(Type pluginType, Type actualType)
- //{
- // InstanceInterceptor interceptor = getOrCreateFactory(pluginType).GetInterceptor();
- // CompoundInterceptor compoundInterceptor = _interceptorLibrary.FindInterceptor(actualType);
-
- // return compoundInterceptor.Merge(interceptor);
- //}
-
object IInstanceCreator.ApplyInterception(Type pluginType, object actualValue)
{
IInstanceFactory factory = getOrCreateFactory(pluginType);
Deleted: trunk/Source/StructureMap/Interceptors/CacheInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/CacheInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/CacheInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,41 +0,0 @@
-namespace StructureMap.Interceptors
-{
- public abstract class CacheInterceptor : InstanceFactoryInterceptor
- {
- public CacheInterceptor() : base()
- {
- }
-
- public override object GetInstance()
- {
- return GetInstance(DefaultInstanceKey);
- }
-
- public override object GetInstance(string instanceKey)
- {
- ensureInstanceIsCached(instanceKey);
- return getInstance(instanceKey);
- }
-
- private void ensureInstanceIsCached(string instanceKey)
- {
- if (!isCached(instanceKey))
- {
- lock (this)
- {
- if (!isCached(instanceKey))
- {
- object instance = InnerInstanceFactory.GetInstance(instanceKey);
- cache(instanceKey, instance);
- }
- }
- }
- }
-
- protected abstract void cache(string instanceKey, object instance);
-
- protected abstract bool isCached(string instanceKey);
-
- protected abstract object getInstance(string instanceKey);
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/HttpContextItemInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,45 +0,0 @@
-using System.Web;
-
-namespace StructureMap.Interceptors
-{
- [Pluggable("HttpContext")]
- public class HttpContextItemInterceptor : CacheInterceptor
- {
- public HttpContextItemInterceptor() : base()
- {
- }
-
- public static bool HasContext()
- {
- return HttpContext.Current != null;
- }
-
- private string getKey(string instanceKey)
- {
- return string.Format("{0}:{1}", InnerInstanceFactory.PluginType.AssemblyQualifiedName, instanceKey);
- }
-
- protected override void cache(string instanceKey, object instance)
- {
- string key = getKey(instanceKey);
- HttpContext.Current.Items.Add(key, instance);
- }
-
- protected override bool isCached(string instanceKey)
- {
- string key = getKey(instanceKey);
- return HttpContext.Current.Items.Contains(key);
- }
-
- protected override object getInstance(string instanceKey)
- {
- string key = getKey(instanceKey);
- return HttpContext.Current.Items[key];
- }
-
- public override object Clone()
- {
- return MemberwiseClone();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/HybridCacheInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,48 +0,0 @@
-using StructureMap.Pipeline;
-
-namespace StructureMap.Interceptors
-{
- [Pluggable("Hybrid")]
- public class HybridCacheInterceptor : InstanceFactoryInterceptor
- {
- private InstanceFactoryInterceptor _innerInterceptor;
-
- public HybridCacheInterceptor() : base()
- {
- if (HttpContextItemInterceptor.HasContext())
- {
- _innerInterceptor = new HttpContextItemInterceptor();
- }
- else
- {
- _innerInterceptor = new ThreadLocalStorageInterceptor();
- }
- }
-
- public override IInstanceFactory InnerInstanceFactory
- {
- get { return _innerInterceptor.InnerInstanceFactory; }
- set { _innerInterceptor.InnerInstanceFactory = value; }
- }
-
- public override object GetInstance(string instanceKey)
- {
- return _innerInterceptor.GetInstance(instanceKey);
- }
-
- public override object GetInstance(IConfiguredInstance instance, IInstanceCreator instanceCreator)
- {
- return _innerInterceptor.GetInstance(instance, instanceCreator);
- }
-
- public override object GetInstance()
- {
- return _innerInterceptor.GetInstance();
- }
-
- public override object Clone()
- {
- return new HybridCacheInterceptor();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/IInterceptorChainBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,13 +0,0 @@
-using System;
-using StructureMap.Attributes;
-using StructureMap.Graph;
-
-namespace StructureMap.Interceptors
-{
- [Obsolete]
- public interface IInterceptorChainBuilder
- {
- [Obsolete]
- InterceptionChain Build(InstanceScope scope);
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/InstanceFactoryInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,141 +0,0 @@
-using System;
-using System.Collections;
-using StructureMap.Pipeline;
-
-namespace StructureMap.Interceptors
-{
- /// <summary>
- /// Base "Decorator" class around IInstanceFactory to alter the object creation process
- /// for a PluginType. The SingletonInterceptor is an example subclass that ensures that
- /// only one instance is created for a given InstanceKey as a more testable alternative to
- /// the GoF Singleton pattern.
- /// </summary>
- [PluginFamily]
- public abstract class InstanceFactoryInterceptor : IInstanceFactory, ICloneable
- {
- private IInstanceFactory _innerInstanceFactory;
-
-
- public virtual IInstanceFactory InnerInstanceFactory
- {
- get { return _innerInstanceFactory; }
- set { _innerInstanceFactory = value; }
- }
-
- /// <summary>
- /// Declares whether or not the interceptor creates a stubbed or mocked version of the PluginType
- /// </summary>
- public virtual bool IsMockedOrStubbed
- {
- get { return false; }
- }
-
- #region ICloneable Members
-
- public abstract object Clone();
-
- #endregion
-
- #region IInstanceFactory Members
-
- /// <summary>
- /// Establishes a reference to the parent InstanceManager
- /// </summary>
- /// <param name="instanceManager"></param>
- public void SetInstanceManager(InstanceManager instanceManager)
- {
- InnerInstanceFactory.SetInstanceManager(instanceManager);
- }
-
- /// <summary>
- /// The CLR System.Type that the IInstanceManager builds instances
- /// </summary>
- public Type PluginType
- {
- get { return InnerInstanceFactory.PluginType; }
- }
-
- /// <summary>
- /// Creates an object instance for the InstanceKey
- /// </summary>
- /// <param name="instanceKey">The named instance</param>
- /// <returns></returns>
- public virtual object GetInstance(string instanceKey)
- {
- return InnerInstanceFactory.GetInstance(instanceKey);
- }
-
- /// <summary>
- /// Creates an object instance directly from the Memento
- /// </summary>
- /// <param name="instance">A representation of an object instance</param>
- /// <returns></returns>
- public virtual object GetInstance(IConfiguredInstance instance, IInstanceCreator instanceCreator)
- {
- return InnerInstanceFactory.GetInstance(instance, instanceCreator);
- }
-
- /// <summary>
- /// Creates a new object instance of the default instance memento
- /// </summary>
- /// <returns></returns>
- public virtual object GetInstance()
- {
- return InnerInstanceFactory.GetInstance();
- }
-
- /// <summary>
- /// Sets the default instance
- /// </summary>
- /// <param name="instanceKey"></param>
- public void SetDefault(string instanceKey)
- {
- InnerInstanceFactory.SetDefault(instanceKey);
- }
-
- /// <summary>
- /// Makes the InstanceMemento the basis of the default instance
- /// </summary>
- /// <param name="instance"></param>
- public void SetDefault(Instance instance)
- {
- InnerInstanceFactory.SetDefault(instance);
- }
-
- /// <summary>
- /// The InstanceKey of the default instance built by this IInstanceFactory
- /// </summary>
- public string DefaultInstanceKey
- {
- get { return InnerInstanceFactory.DefaultInstanceKey; }
- }
-
- public IList GetAllInstances()
- {
- return InnerInstanceFactory.GetAllInstances();
- }
-
- public void AddInstance(Instance instance)
- {
- InnerInstanceFactory.AddInstance(instance);
- }
-
- public Instance AddType<T>()
- {
- return InnerInstanceFactory.AddType<T>();
- }
-
- public Instance GetDefault()
- {
- return InnerInstanceFactory.GetDefault();
- }
-
-
- public virtual object ApplyInterception(object rawValue)
- {
- return InnerInstanceFactory.ApplyInterception(rawValue);
- }
-
- #endregion
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/InterceptorChainBuilder.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,46 +0,0 @@
-using System;
-using StructureMap.Attributes;
-using StructureMap.Graph;
-
-namespace StructureMap.Interceptors
-{
- [Obsolete]
- public class InterceptorChainBuilder : IInterceptorChainBuilder
- {
- public InterceptorChainBuilder()
- {
- }
-
- #region IInterceptorChainBuilder Members
-
- [Obsolete]
- public InterceptionChain Build(InstanceScope scope)
- {
- InterceptionChain returnValue = new InterceptionChain();
-
- switch (scope)
- {
- case (InstanceScope.HttpContext):
- returnValue.AddInterceptor(new HttpContextItemInterceptor());
- break;
-
- case (InstanceScope.Hybrid):
- returnValue.AddInterceptor(new HybridCacheInterceptor());
- break;
-
- case (InstanceScope.Singleton):
- returnValue.AddInterceptor(new SingletonInterceptor());
- break;
-
- case (InstanceScope.ThreadLocal):
- returnValue.AddInterceptor(new ThreadLocalStorageInterceptor());
- break;
- }
-
-
- return returnValue;
- }
-
- #endregion
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/SingletonInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/SingletonInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/SingletonInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,46 +0,0 @@
-using System.Collections;
-
-namespace StructureMap.Interceptors
-{
- /// <summary>
- /// The SingletonInterceptor is a GoF Decorator around an IInstanceFactory that ensures that
- /// only one instance is created for a given InstanceKey as a more testable alternative to
- /// the GoF Singleton pattern.
- /// </summary>
- [Pluggable("Singleton")]
- public class SingletonInterceptor : CacheInterceptor
- {
- private IDictionary _instances;
-
- [DefaultConstructor]
- public SingletonInterceptor() : this(new Hashtable())
- {
- }
-
- public SingletonInterceptor(IDictionary instances) : base()
- {
- _instances = instances;
- }
-
-
- protected override void cache(string instanceKey, object instance)
- {
- _instances.Add(instanceKey, instance);
- }
-
- protected override bool isCached(string instanceKey)
- {
- return _instances.Contains(instanceKey);
- }
-
- protected override object getInstance(string instanceKey)
- {
- return _instances[instanceKey];
- }
-
- public override object Clone()
- {
- return new SingletonInterceptor();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/Interceptors/ThreadLocalStorageInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/ThreadLocalStorageInterceptor.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Interceptors/ThreadLocalStorageInterceptor.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,58 +0,0 @@
-using System;
-using System.Collections;
-
-namespace StructureMap.Interceptors
-{
- [Pluggable("ThreadLocal")]
- public class ThreadLocalStorageInterceptor : CacheInterceptor
- {
- [ThreadStatic] private static Hashtable _instances = new Hashtable();
-
- private static object _lock = new object();
-
- public ThreadLocalStorageInterceptor() : base()
- {
- }
-
- private void guaranteeHashExists()
- {
- if (_instances == null)
- {
- lock (_lock)
- {
- if (_instances == null)
- {
- _instances = new Hashtable();
- }
- }
- }
- }
-
-
- private string getKey(string instanceKey)
- {
- return string.Format("{0}:{1}", InnerInstanceFactory.PluginType.AssemblyQualifiedName, instanceKey);
- }
-
- protected override void cache(string instanceKey, object instance)
- {
- _instances.Add(getKey(instanceKey), instance);
- }
-
- protected override bool isCached(string instanceKey)
- {
- guaranteeHashExists();
- return _instances.ContainsKey(getKey(instanceKey));
- }
-
- protected override object getInstance(string instanceKey)
- {
- return _instances[getKey(instanceKey)];
- }
-
- public override object Clone()
- {
- return MemberwiseClone();
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/BuildStrategies.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Pipeline/BuildStrategies.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -25,6 +25,7 @@
#endregion
}
+ [PluginFamily]
public interface IInstanceInterceptor : IBuildPolicy
{
IBuildPolicy InnerPolicy { get; set; }
Modified: trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -3,6 +3,7 @@
namespace StructureMap.Pipeline
{
+ [Pluggable("Singleton")]
public class SingletonPolicy : CacheInterceptor
{
private readonly Dictionary<string, object> _instances = new Dictionary<string, object>();
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap/StructureMap.csproj 2008-04-26 01:57:25 UTC (rev 83)
@@ -308,9 +308,6 @@
<Compile Include="Graph\InstanceDefaultManager.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Graph\InterceptionChain.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Graph\MachineOverride.cs">
<SubType>Code</SubType>
</Compile>
@@ -357,37 +354,13 @@
<Compile Include="InstanceMemento.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Interceptors\CacheInterceptor.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Interceptors\CompoundInterceptor.cs" />
<Compile Include="Interceptors\EnrichmentInterceptor.cs" />
- <Compile Include="Interceptors\HttpContextItemInterceptor.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Interceptors\HybridCacheInterceptor.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Interceptors\IInterceptorChainBuilder.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Interceptors\InstanceFactoryInterceptor.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Interceptors\InstanceInterceptor.cs" />
- <Compile Include="Interceptors\InterceptorChainBuilder.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Interceptors\InterceptorLibrary.cs" />
<Compile Include="Interceptors\Interceptors.cs" />
<Compile Include="Interceptors\NulloInterceptor.cs" />
- <Compile Include="Interceptors\SingletonInterceptor.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Interceptors\StartupInterceptor.cs" />
- <Compile Include="Interceptors\ThreadLocalStorageInterceptor.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Interceptors\FilteredInstanceInterceptor.cs" />
<Compile Include="IPluginGraphSource.cs" />
<Compile Include="MementoSource.cs">
Modified: trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -78,7 +78,7 @@
att.Scope = InstanceScope.PerRequest;
PluginFamily family = att.BuildPluginFamily(typeof (Target1));
- Assert.AreEqual(0, family.InterceptionChain.Count);
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -6,6 +6,7 @@
using StructureMap.Configuration.DSL.Expressions;
using StructureMap.Graph;
using StructureMap.Interceptors;
+using StructureMap.Pipeline;
using StructureMap.Testing.Widget;
using StructureMap.Testing.Widget3;
@@ -73,7 +74,7 @@
}
PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)];
- Assert.IsTrue(family.InterceptionChain.Contains(typeof (ThreadLocalStorageInterceptor)));
+ Assert.IsInstanceOfType(typeof(ThreadLocalStoragePolicy), family.Policy);
}
[Test]
@@ -101,7 +102,7 @@
}
PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)];
- Assert.AreEqual(0, family.InterceptionChain.Count);
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
}
[Test]
@@ -116,7 +117,7 @@
}
PluginFamily family = pluginGraph.PluginFamilies[typeof (IGateway)];
- Assert.IsTrue(family.InterceptionChain.Contains(typeof (SingletonInterceptor)));
+ Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy);
}
[Test]
@@ -179,9 +180,7 @@
registry.BuildInstancesOf<IGateway>().InterceptConstructionWith(factoryInterceptor);
}
- InterceptionChain chain = pluginGraph.PluginFamilies[typeof (IGateway)].InterceptionChain;
- Assert.AreEqual(1, chain.Count);
- Assert.AreSame(factoryInterceptor, chain[0]);
+ Assert.AreSame(pluginGraph.PluginFamilies[typeof(IGateway)].Policy, factoryInterceptor);
}
[Test]
@@ -215,11 +214,22 @@
}
}
- public class StubbedInstanceFactoryInterceptor : InstanceFactoryInterceptor
+ public class StubbedInstanceFactoryInterceptor : IInstanceInterceptor
{
- public override object Clone()
+ public IBuildPolicy InnerPolicy
{
+ get { throw new NotImplementedException(); }
+ set { }
+ }
+
+ public object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance)
+ {
throw new NotImplementedException();
}
+
+ public IBuildPolicy Clone()
+ {
+ throw new NotImplementedException();
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -96,27 +96,6 @@
Assert.AreEqual(profileName, defaultManager.Profiles[0].ProfileName);
}
- [Test]
- public void ScopeIsUsedToCreateTheInterceptionChain()
- {
- InstanceScope theScope = InstanceScope.PerRequest;
- InterceptionChain chain = new InterceptionChain();
- DynamicMock builderMock = new DynamicMock(typeof (IInterceptorChainBuilder));
- builderMock.ExpectAndReturn("Build", chain, theScope);
- NormalGraphBuilder graphBuilder =
- new NormalGraphBuilder((IInterceptorChainBuilder) builderMock.MockInstance, new Registry[0]);
-
- TypePath typePath = new TypePath(GetType());
-
-
- graphBuilder.AddPluginFamily(typePath, "something", theScope);
-
- PluginFamily family = graphBuilder.PluginGraph.PluginFamilies[GetType()];
-
- Assert.AreEqual(chain, family.InterceptionChain);
-
- builderMock.Verify();
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Container/DynamicInjectionTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -67,21 +67,7 @@
Assert.AreSame(_blue, manager.CreateInstance(typeof (IService), "Blue"));
}
- [Test]
- public void AddInstanceWithInstanceFactoryInterceptor()
- {
- InstanceFactoryInterceptor interceptor = new FakeInstanceFactoryInterceptor();
- InstanceFactory factory = ObjectMother.Factory<IService>();
- interceptor.InnerInstanceFactory = factory;
-
- interceptor.AddInstance(new LiteralInstance(_red).WithName("Red"));
- interceptor.AddInstance(new LiteralInstance(_blue).WithName("Blue"));
-
- Assert.AreSame(_red, interceptor.GetInstance("Red"));
- Assert.AreSame(_blue, interceptor.GetInstance("Blue"));
- }
-
[Test]
public void AddNamedInstanceByType()
{
@@ -219,12 +205,23 @@
}
}
- public class FakeInstanceFactoryInterceptor : InstanceFactoryInterceptor
+ public class FakeInstanceFactoryInterceptor : IInstanceInterceptor
{
- public override object Clone()
+ public IBuildPolicy InnerPolicy
{
+ get { throw new NotImplementedException(); }
+ set { throw new NotImplementedException(); }
+ }
+
+ public object Build(IInstanceCreator instanceCreator, Type pluginType, Instance instance)
+ {
throw new NotImplementedException();
}
+
+ IBuildPolicy IBuildPolicy.Clone()
+ {
+ throw new NotImplementedException();
+ }
}
public interface ISomething
Modified: trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Container/InstanceManagerTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -112,31 +112,9 @@
Assert.AreSame(differentProvider, classThatUsesProvider.Provider);
}
- [Test]
- public void CreatesInterceptionChainOnInstanceFactory()
- {
- // Create a PluginFamily with one Interceptor in the InterceptionChain of the Family
- PluginFamily family = new PluginFamily(typeof (Rule));
- SingletonInterceptor interceptor = new SingletonInterceptor();
- family.InterceptionChain.AddInterceptor(interceptor);
- // Create a PluginGraph with the PluginFamily
- PluginGraph pluginGraph = new PluginGraph();
- pluginGraph.Assemblies.Add("StructureMap.Testing.Widget");
- pluginGraph.PluginFamilies.Add(family);
- pluginGraph.Seal();
- // Create an InstanceManager and examine the InstanceFactory for the PluginFamily
- InstanceManager instanceManager = new InstanceManager(pluginGraph);
- IInstanceFactory wrappedFactory = instanceManager[typeof (Rule)];
- Assert.AreSame(interceptor, wrappedFactory);
-
- InstanceFactory factory = (InstanceFactory) interceptor.InnerInstanceFactory;
- Assert.AreEqual(typeof (Rule), factory.PluginType);
- }
-
-
[Test]
public void FindAPluginFamilyForAGenericTypeFromPluginTypeName()
{
Deleted: trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Container/Interceptors/InteceptorChainBuilderTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,39 +0,0 @@
-using System;
-using NUnit.Framework;
-using StructureMap.Attributes;
-using StructureMap.Graph;
-using StructureMap.Interceptors;
-
-namespace StructureMap.Testing.Container.Interceptors
-{
- [TestFixture]
- public class InteceptorChainBuilderTester
- {
- private InterceptorChainBuilder builder = new InterceptorChainBuilder();
-
- private void assertScopeLeadsToInterceptor(InstanceScope scope, Type interceptorType)
- {
- InterceptionChain chain = builder.Build(scope);
- Assert.AreEqual(1, chain.Count);
- Type actualType = chain[0].GetType();
- Assert.IsTrue(actualType.Equals(interceptorType));
- }
-
- [Test]
- public void PerInstanceMeansNoInterceptors()
- {
- InterceptionChain chain = builder.Build(InstanceScope.PerRequest);
- Assert.AreEqual(0, chain.Count);
- }
-
-
- [Test]
- public void ScopeToInterceptorTypes()
- {
- assertScopeLeadsToInterceptor(InstanceScope.HttpContext, typeof (HttpContextItemInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.Hybrid, typeof (HybridCacheInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.Singleton, typeof (SingletonInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.ThreadLocal, typeof (ThreadLocalStorageInterceptor));
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Container/Interceptors/SingletonInterceptorTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,60 +0,0 @@
-using NUnit.Framework;
-using StructureMap.Graph;
-using StructureMap.Interceptors;
-using StructureMap.Testing.Widget;
-
-namespace StructureMap.Testing.Container.Interceptors
-{
- [TestFixture]
- public class SingletonInterceptorTester
- {
- // "Red", "Blue", "Bigger" are the possible rule choices
-
- #region Setup/Teardown
-
- [SetUp]
- public void SetUp()
- {
- PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule));
- InstanceFactory factory = new InstanceFactory(family, true);
- factory.SetInstanceManager(new InstanceManager());
-
- _interceptor = new SingletonInterceptor();
- _interceptor.InnerInstanceFactory = factory;
- }
-
- #endregion
-
- private SingletonInterceptor _interceptor;
-
- [Test]
- public void CanSetDefaultAndGetTheDefaultInstance()
- {
- _interceptor.SetDefault("Red");
- Assert.AreEqual("Red", _interceptor.DefaultInstanceKey);
-
- ColorRule rule1 = (ColorRule) _interceptor.GetInstance();
- Assert.AreEqual("Red", rule1.Color);
-
- // Fetch the rule 2 more times. Verify that it is the same object
- ColorRule rule2 = (ColorRule) _interceptor.GetInstance();
- ColorRule rule3 = (ColorRule) _interceptor.GetInstance();
-
- Assert.AreSame(rule1, rule2);
- Assert.AreSame(rule1, rule3);
- }
-
- [Test]
- public void GetsTheSameNamedInstance()
- {
- ColorRule rule1 = (ColorRule) _interceptor.GetInstance("Blue");
-
- // Fetch the rule 2 more times. Verify that it is the same object
- ColorRule rule2 = (ColorRule) _interceptor.GetInstance("Blue");
- ColorRule rule3 = (ColorRule) _interceptor.GetInstance("Blue");
-
- Assert.AreSame(rule1, rule2);
- Assert.AreSame(rule1, rule3);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Container/Interceptors/ThreadLocalStorageInterceptorTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,86 +0,0 @@
-using System.Threading;
-using NUnit.Framework;
-using StructureMap.Graph;
-using StructureMap.Interceptors;
-using StructureMap.Testing.Widget;
-
-namespace StructureMap.Testing.Container.Interceptors
-{
- [TestFixture]
- public class ThreadLocalStorageInterceptorTester
- {
- #region Setup/Teardown
-
- [SetUp]
- public void SetUp()
- {
- PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule));
- InstanceFactory factory = new InstanceFactory(family, true);
- factory.SetInstanceManager(new InstanceManager());
-
- _interceptor = new ThreadLocalStorageInterceptor();
- _interceptor.InnerInstanceFactory = factory;
- }
-
- #endregion
-
- private ThreadLocalStorageInterceptor _interceptor;
- private ColorRule _rule1;
- private ColorRule _rule2;
- private ColorRule _rule3;
-
-
- private void findRule1()
- {
- _rule1 = (ColorRule) _interceptor.GetInstance();
-
- ColorRule rule = (ColorRule) _interceptor.GetInstance();
- Assert.AreSame(_rule1, rule);
- }
-
- private void findRule2()
- {
- _rule2 = (ColorRule) _interceptor.GetInstance();
-
- ColorRule rule = (ColorRule) _interceptor.GetInstance();
- Assert.AreSame(_rule2, rule);
- }
-
- private void findRule3()
- {
- _rule3 = (ColorRule) _interceptor.GetInstance();
-
- ColorRule rule = (ColorRule) _interceptor.GetInstance();
- Assert.AreSame(_rule3, rule);
-
- rule = (ColorRule) _interceptor.GetInstance();
- Assert.AreSame(_rule3, rule);
-
- rule = (ColorRule) _interceptor.GetInstance();
- Assert.AreSame(_rule3, rule);
-
- rule = (ColorRule) _interceptor.GetInstance();
- Assert.AreSame(_rule3, rule);
- }
-
- [Test]
- public void FindUniqueInstancePerThread()
- {
- Thread t1 = new Thread(new ThreadStart(findRule1));
- Thread t2 = new Thread(new ThreadStart(findRule2));
- Thread t3 = new Thread(new ThreadStart(findRule3));
-
- t1.Start();
- t2.Start();
- t3.Start();
-
- t1.Join();
- t2.Join();
- t3.Join();
-
- Assert.IsTrue(_rule1.ID != _rule2.ID);
- Assert.IsTrue(_rule1.ID != _rule3.ID);
- Assert.IsTrue(_rule2.ID != _rule3.ID);
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Container/PluginGraphBuilderTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -45,14 +45,12 @@
PluginGraph pluginGraph = DataMother.GetDiagnosticPluginGraph("SingletonIntercepterTest.xml");
PluginFamily family = pluginGraph.PluginFamilies[typeof (Rule)];
+ Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy);
- Assert.AreEqual(1, family.InterceptionChain.Count);
- Assert.IsTrue(family.InterceptionChain[0] is SingletonInterceptor);
-
// The PluginFamily for IWidget has no intercepters configured
PluginFamily widgetFamily = pluginGraph.PluginFamilies[typeof (IWidget)];
- Assert.AreEqual(0, widgetFamily.InterceptionChain.Count);
- }
+ Assert.IsInstanceOfType(typeof(BuildPolicy), widgetFamily.Policy);
+ }
[Test]
public void CanDefinedSourceBuildMemento()
@@ -197,21 +195,7 @@
Assert.AreEqual("Green", defaultManager.DefaultProfileName);
}
- [Test]
- public void ReadScopeFromXmlConfiguration()
- {
- PluginGraph pluginGraph = DataMother.GetDiagnosticPluginGraph("ScopeInFamily.xml");
- PluginFamily family = pluginGraph.PluginFamilies[typeof (Column)];
- Assert.AreEqual(1, family.InterceptionChain.Count);
- Assert.IsTrue(family.InterceptionChain[0] is ThreadLocalStorageInterceptor);
-
- // The PluginFamily for IWidget has no intercepters configured
- PluginFamily widgetFamily = pluginGraph.PluginFamilies[typeof (IWidget)];
- Assert.AreEqual(1, widgetFamily.InterceptionChain.Count);
- Assert.IsTrue(widgetFamily.InterceptionChain[0] is HttpContextItemInterceptor);
- }
-
[Test]
public void SetsTheDefaultInstanceKey()
{
Deleted: trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Graph/InterceptionChainTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -1,80 +0,0 @@
-using NUnit.Framework;
-using StructureMap.Graph;
-using StructureMap.Interceptors;
-using StructureMap.Testing.Widget;
-
-namespace StructureMap.Testing.Graph
-{
- [TestFixture]
- public class InterceptionChainTester
- {
- #region Setup/Teardown
-
- [SetUp]
- public void SetUp()
- {
- _singleton1 = new SingletonInterceptor();
- _singleton2 = new SingletonInterceptor();
-
- _chain = new InterceptionChain();
- _chain.AddInterceptor(_singleton1);
- _chain.AddInterceptor(_singleton2);
- }
-
- #endregion
-
- private InterceptionChain _chain;
- private SingletonInterceptor _singleton1;
- private SingletonInterceptor _singleton2;
-
- [Test]
- public void CreateInterceptionChainWithNoIntercepters()
- {
- InterceptionChain chain = new InterceptionChain();
- PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule));
- InstanceFactory factory = new InstanceFactory(family, true);
-
- IInstanceFactory wrappedFactory = chain.WrapInstanceFactory(factory);
-
- Assert.AreSame(factory, wrappedFactory);
- }
-
- [Test]
- public void CreateInterceptionChainWithOneIntercepter()
- {
- InterceptionChain chain = new InterceptionChain();
- chain.AddInterceptor(_singleton1);
-
- PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule));
- InstanceFactory factory = new InstanceFactory(family, true);
-
- IInstanceFactory wrappedFactory = chain.WrapInstanceFactory(factory);
- Assert.AreSame(_singleton1, wrappedFactory);
- Assert.AreSame(factory, _singleton1.InnerInstanceFactory);
- }
-
- [Test]
- public void CreateInterceptionChainWithTwoInterceptors()
- {
- PluginFamily family = ObjectMother.GetPluginFamily(typeof (Rule));
- InstanceFactory factory = new InstanceFactory(family, true);
-
- IInstanceFactory wrappedFactory = _chain.WrapInstanceFactory(factory);
-
- Assert.IsNotNull(wrappedFactory);
-
- // Cast exception if wrappedFactory is not a Singleton
- SingletonInterceptor singletonWrapper = (SingletonInterceptor) wrappedFactory;
-
- Assert.AreSame(_singleton1, singletonWrapper);
- Assert.AreSame(_singleton2, _singleton1.InnerInstanceFactory);
- Assert.AreSame(factory, _singleton2.InnerInstanceFactory);
- }
-
- [Test]
- public void tryIt()
- {
- ObjectMother.Reset();
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-04-26 01:57:25 UTC (rev 83)
@@ -72,13 +72,10 @@
public void ImplicitPluginFamilyCreatesASingletonInterceptorWhenIsSingletonIsTrue()
{
PluginFamily family = new PluginFamily(typeof (ISingletonRepository));
- Assert.AreEqual(1, family.InterceptionChain.Count);
+ Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy);
- InstanceFactoryInterceptor interceptor = family.InterceptionChain[0];
- Assert.IsTrue(interceptor is SingletonInterceptor);
-
PluginFamily family2 = new PluginFamily(typeof (IDevice));
- Assert.AreEqual(0, family2.InterceptionChain.Count);
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family2.Policy);
}
[Test]
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-25 18:02:44 UTC (rev 82)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-04-26 01:57:25 UTC (rev 83)
@@ -235,17 +235,8 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Container\Interceptors\CompoundInterceptorTester.cs" />
- <Compile Include="Container\Interceptors\InteceptorChainBuilderTester.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Container\Interceptors\InterceptorLibraryTester.cs" />
<Compile Include="Container\Interceptors\MockTypeInterceptor.cs" />
- <Compile Include="Container\Interceptors\SingletonInterceptorTester.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Container\Interceptors\ThreadLocalStorageInterceptorTester.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Container\Interceptors\TypeInterceptionTester.cs" />
<Compile Include="Container\MockingTester.cs">
<SubType>Code</SubType>
@@ -325,9 +316,6 @@
<Compile Include="Graph\InstanceTarget.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Graph\InterceptionChainTester.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Graph\OverrideGraphTester.cs">
<SubType>Code</SubType>
</Compile>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|