|
From: <jer...@us...> - 2008-04-25 18:03:00
|
Revision: 82
http://structuremap.svn.sourceforge.net/structuremap/?rev=82&view=rev
Author: jeremydmiller
Date: 2008-04-25 11:02:44 -0700 (Fri, 25 Apr 2008)
Log Message:
-----------
little refactoring for the build policies. Making sure that the attribute builds the PluginFamily correctly
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-25 17:26:13 UTC (rev 81)
+++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2008-04-25 18:02:44 UTC (rev 82)
@@ -146,8 +146,9 @@
PluginFamily family = new PluginFamily(exportedType, DefaultKey);
family.AddMementoSource(source);
- InterceptorChainBuilder builder = new InterceptorChainBuilder();
- family.InterceptionChain = builder.Build(Scope);
+ family.SetScopeTo(Scope);
+ //InterceptorChainBuilder builder = new InterceptorChainBuilder();
+ //family.InterceptionChain = builder.Build(Scope);
return family;
}
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-25 17:26:13 UTC (rev 81)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-04-25 18:02:44 UTC (rev 82)
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
+using StructureMap.Attributes;
using StructureMap.Interceptors;
using StructureMap.Pipeline;
@@ -255,6 +256,7 @@
set { _defaultKey = value ?? string.Empty; }
}
+ [Obsolete("Make this go away")]
public InterceptionChain InterceptionChain
{
get { return _interceptionChain; }
@@ -314,5 +316,32 @@
return _instances.Find(delegate(Instance i) { return i.Name == name; });
}
+ public void SetScopeTo(InstanceScope scope)
+ {
+ switch(scope)
+ {
+ case InstanceScope.Singleton:
+ AddInterceptor(new SingletonPolicy());
+ break;
+
+ case InstanceScope.HttpContext:
+ AddInterceptor(new HttpContextBuildPolicy());
+ break;
+
+ case InstanceScope.ThreadLocal:
+ AddInterceptor(new ThreadLocalStoragePolicy());
+ break;
+
+ case InstanceScope.Hybrid:
+ AddInterceptor(new HybridBuildPolicy());
+ break;
+ }
+ }
+
+ public void AddInterceptor(IInstanceInterceptor interceptor)
+ {
+ interceptor.InnerPolicy = _buildPolicy;
+ _buildPolicy = interceptor;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-04-25 17:26:13 UTC (rev 81)
+++ trunk/Source/StructureMap.Testing/Attributes/PluginFamilyAttributeTester.cs 2008-04-25 18:02:44 UTC (rev 82)
@@ -3,6 +3,7 @@
using StructureMap.Attributes;
using StructureMap.Graph;
using StructureMap.Interceptors;
+using StructureMap.Pipeline;
using StructureMap.Source;
namespace StructureMap.Testing.Attributes
@@ -16,9 +17,7 @@
att.Scope = scope;
PluginFamily family = att.BuildPluginFamily(typeof (Target1));
- Assert.AreEqual(1, family.InterceptionChain.Count);
- Type actualType = family.InterceptionChain[0].GetType();
- Assert.IsTrue(actualType.Equals(interceptorType));
+ Assert.IsInstanceOfType(interceptorType, family.Policy);
}
[PluginFamily]
@@ -92,10 +91,10 @@
[Test]
public void ScopeToInterceptorTypes()
{
- assertScopeLeadsToInterceptor(InstanceScope.HttpContext, typeof (HttpContextItemInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.Hybrid, typeof (HybridCacheInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.Singleton, typeof (SingletonInterceptor));
- assertScopeLeadsToInterceptor(InstanceScope.ThreadLocal, typeof (ThreadLocalStorageInterceptor));
+ assertScopeLeadsToInterceptor(InstanceScope.HttpContext, typeof (HttpContextBuildPolicy));
+ assertScopeLeadsToInterceptor(InstanceScope.Hybrid, typeof (HybridBuildPolicy));
+ assertScopeLeadsToInterceptor(InstanceScope.Singleton, typeof (SingletonPolicy));
+ assertScopeLeadsToInterceptor(InstanceScope.ThreadLocal, typeof (ThreadLocalStoragePolicy));
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-04-25 17:26:13 UTC (rev 81)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2008-04-25 18:02:44 UTC (rev 82)
@@ -1,8 +1,10 @@
using System;
using System.Reflection;
using NUnit.Framework;
+using StructureMap.Attributes;
using StructureMap.Graph;
using StructureMap.Interceptors;
+using StructureMap.Pipeline;
using StructureMap.Source;
using StructureMap.Testing.Widget;
@@ -86,10 +88,6 @@
pluginGraph.Assemblies.Add(Assembly.GetExecutingAssembly());
pluginGraph.Seal();
- PluginFamily family = pluginGraph.PluginFamilies[typeof (ISingletonRepository)];
- Assert.AreEqual(1, family.InterceptionChain.Count);
- Assert.IsTrue(family.InterceptionChain[0] is SingletonInterceptor);
-
InstanceManager manager = new InstanceManager(pluginGraph);
ISingletonRepository repository1 =
@@ -108,8 +106,54 @@
Assert.AreSame(repository1, repository4);
Assert.AreSame(repository1, repository5);
}
+
+
+ [Test]
+ public void SetScopeToSingleton()
+ {
+ PluginFamily family = new PluginFamily(typeof(IServiceProvider));
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
+
+ family.SetScopeTo(InstanceScope.Singleton);
+ Assert.IsInstanceOfType(typeof(SingletonPolicy), family.Policy);
+ }
+
+ [Test]
+ public void SetScopeToThreadLocal()
+ {
+ PluginFamily family = new PluginFamily(typeof(IServiceProvider));
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
+
+ family.SetScopeTo(InstanceScope.ThreadLocal);
+ Assert.IsInstanceOfType(typeof(ThreadLocalStoragePolicy), family.Policy);
+ }
+
+
+ [Test]
+ public void SetScopeToHttpContext()
+ {
+ PluginFamily family = new PluginFamily(typeof(IServiceProvider));
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
+
+ family.SetScopeTo(InstanceScope.HttpContext);
+ Assert.IsInstanceOfType(typeof(HttpContextBuildPolicy), family.Policy);
+ }
+
+
+ [Test]
+ public void SetScopeToHybrid()
+ {
+ PluginFamily family = new PluginFamily(typeof(IServiceProvider));
+ Assert.IsInstanceOfType(typeof(BuildPolicy), family.Policy);
+
+ family.SetScopeTo(InstanceScope.Hybrid);
+ Assert.IsInstanceOfType(typeof(HybridBuildPolicy), family.Policy);
+ }
+
}
+
+
/// <summary>
/// Specifying the default instance is "Default" and marking the PluginFamily
/// as an injected Singleton
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|