From: <jer...@us...> - 2008-08-07 21:52:23
|
Revision: 130 http://structuremap.svn.sourceforge.net/structuremap/?rev=130&view=rev Author: jeremydmiller Date: 2008-08-07 21:52:19 +0000 (Thu, 07 Aug 2008) Log Message: ----------- enhancing the explicit argument passing Modified Paths: -------------- trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/Pipeline/IBuildSession.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs trunk/Source/StructureMap.Testing/Pipeline/StubBuildSession.cs trunk/Source/StructureMap.Testing/SpecificationExtensions.cs Added Paths: ----------- trunk/Source/Backup/ trunk/Source/Backup/ExplicitArguments.htm trunk/Source/Backup/HTML.csproj Added: trunk/Source/Backup/ExplicitArguments.htm =================================================================== --- trunk/Source/Backup/ExplicitArguments.htm (rev 0) +++ trunk/Source/Backup/ExplicitArguments.htm 2008-08-07 21:52:19 UTC (rev 130) @@ -0,0 +1,19 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> + <head> + <title></title> + </head> + <body> + <h1> + Explicit Arguments</h1> + <p> + A new feature in StructureMap 2.5 is the ability to pass in arguments to ObjectFactory.</p> + <p> + </p> + <h4> + Primitive Value</h4> + <p> + </p> + + </body> +</html> \ No newline at end of file Added: trunk/Source/Backup/HTML.csproj =================================================================== --- trunk/Source/Backup/HTML.csproj (rev 0) +++ trunk/Source/Backup/HTML.csproj 2008-08-07 21:52:19 UTC (rev 130) @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>HTML</RootNamespace> + <AssemblyName>HTML</AssemblyName> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> + <ItemGroup> + <Content Include="ExplicitArguments.htm" /> + </ItemGroup> +</Project> \ No newline at end of file Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap/BuildSession.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -4,6 +4,7 @@ using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; +using StructureMap.Util; namespace StructureMap { @@ -12,11 +13,24 @@ private readonly InterceptorLibrary _interceptorLibrary; private readonly PipelineGraph _pipelineGraph; private readonly InstanceCache _cache = new InstanceCache(); + private readonly Cache<Type, object> _defaults; public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) { _pipelineGraph = pipelineGraph; _interceptorLibrary = interceptorLibrary; + + _defaults = new Cache<Type, object>(t => + { + Instance instance = _pipelineGraph.GetDefault(t); + + if (instance == null) + { + throw new StructureMapException(202, t); + } + + return CreateInstance(t, instance); + }); } public BuildSession(PluginGraph graph) @@ -87,14 +101,7 @@ public object CreateInstance(Type pluginType) { - Instance instance = _pipelineGraph.GetDefault(pluginType); - - if (instance == null) - { - throw new StructureMapException(202, pluginType.FullName); - } - - return CreateInstance(pluginType, instance); + return _defaults.Retrieve(pluginType); } public object ApplyInterception(Type pluginType, object actualValue) @@ -112,6 +119,11 @@ return forType(pluginType).FindBuilderByConcreteKey(concreteKey); } + public void RegisterDefault(Type pluginType, object defaultObject) + { + _defaults.Store(pluginType, defaultObject); + } + #endregion private IInstanceFactory forType(Type pluginType) Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap/Container.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -80,10 +80,7 @@ public PLUGINTYPE GetInstance<PLUGINTYPE>(ExplicitArguments args) { - Instance defaultInstance = _pipelineGraph.GetDefault(typeof (PLUGINTYPE)); - - ExplicitInstance instance = new ExplicitInstance(typeof(PLUGINTYPE), args, defaultInstance); - return GetInstance<PLUGINTYPE>(instance); + return (PLUGINTYPE) GetInstance(typeof(PLUGINTYPE), args); } public object GetInstance(Type type, ExplicitArguments args) @@ -91,8 +88,11 @@ Instance defaultInstance = _pipelineGraph.GetDefault(type); Instance instance = new ExplicitInstance(type, args, defaultInstance); + IBuildSession session = withNewSession(); - return GetInstance(type, instance); + args.RegisterDefaults(session); + + return session.CreateInstance(type, instance); } public void Inject<PLUGINTYPE>(PLUGINTYPE instance) Modified: trunk/Source/StructureMap/ExplicitArgsExpression.cs =================================================================== --- trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap/ExplicitArgsExpression.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -11,12 +11,12 @@ public class ExplicitArgsExpression : IExplicitProperty { private readonly ExplicitArguments _args = new ExplicitArguments(); - private readonly IContainer _manager; + private readonly IContainer _container; private string _lastArgName; internal ExplicitArgsExpression(IContainer manager) { - _manager = manager; + _container = manager; } #region IExplicitProperty Members @@ -59,7 +59,7 @@ /// <returns></returns> public T GetInstance<T>() { - return _manager.GetInstance<T>(_args); + return _container.GetInstance<T>(_args); } /// <summary> @@ -69,7 +69,7 @@ /// <returns></returns> public object GetInstance(Type type) { - return _manager.GetInstance(type, _args); + return _container.GetInstance(type, _args); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -62,6 +62,14 @@ { return _args.ContainsKey(propertyName); } + + public void RegisterDefaults(IBuildSession session) + { + foreach (var pair in _children) + { + session.RegisterDefault(pair.Key, pair.Value); + } + } } public class ExplicitInstance : ConfiguredInstance Modified: trunk/Source/StructureMap/Pipeline/IBuildSession.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IBuildSession.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap/Pipeline/IBuildSession.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -11,5 +11,6 @@ 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/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -155,7 +155,7 @@ return InstanceFactory.CreateFactoryForType(pluggedType, _profileManager); } - public Instance GetDefault(Type pluginType) + public virtual Instance GetDefault(Type pluginType) { // Need to ensure that the factory exists first createFactoryIfMissing(pluginType); Modified: trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -74,13 +74,31 @@ } [Test] + public void Explicit_services_are_used_throughout_the_object_graph() + { + var theTrade = new Trade(); + + IContainer container = new Container(r => + { + r.ForRequestedType<IView>().TheDefaultIsConcreteType<TradeView>(); + r.ForRequestedType<Node>().TheDefaultIsConcreteType<TradeNode>(); + }); + + Command command = container.With<Trade>(theTrade).GetInstance<Command>(); + + command.Trade.ShouldBeTheSameAs(theTrade); + command.Node.IsType<TradeNode>().Trade.ShouldBeTheSameAs(theTrade); + command.View.IsType<TradeView>().Trade.ShouldBeTheSameAs(theTrade); + } + + [Test] public void ExplicitArguments_can_return_child_by_name() { - ExplicitArguments args = new ExplicitArguments(); - Node theNode = new Node(); + var args = new ExplicitArguments(); + var theNode = new Node(); args.SetArg("node", theNode); - IConfiguredInstance instance = new ExplicitInstance(typeof(Command), args, null); + IConfiguredInstance instance = new ExplicitInstance(typeof (Command), args, null); Assert.AreSame(theNode, instance.GetChild("node", typeof (Node), new StubBuildSession())); } @@ -88,13 +106,13 @@ [Test] public void Fill_in_argument_by_name() { - Container container = new Container(); + var container = new Container(); container.SetDefault<IView, View>(); - Node theNode = new Node(); - Trade theTrade = new Trade(); + var theNode = new Node(); + var theTrade = new Trade(); - Command command = container + var command = container .With("node").EqualTo(theNode) .With(theTrade) .GetInstance<Command>(); @@ -117,12 +135,12 @@ ObjectFactory.Reset(); // Get the ExplicitTarget without setting an explicit arg for IProvider - ExplicitTarget firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); + var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); // Now, set the explicit arg for IProvider - BlueProvider theBlueProvider = new BlueProvider(); - ExplicitTarget secondTarget = ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>(); + var theBlueProvider = new BlueProvider(); + var secondTarget = ObjectFactory.With<IProvider>(theBlueProvider).GetInstance<ExplicitTarget>(); Assert.AreSame(theBlueProvider, secondTarget.Provider); } @@ -139,28 +157,28 @@ ObjectFactory.Reset(); // Get the ExplicitTarget without setting an explicit arg for IProvider - ExplicitTarget firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); + var firstTarget = ObjectFactory.GetInstance<ExplicitTarget>(); Assert.AreEqual("Jeremy", firstTarget.Name); // Now, set the explicit arg for IProvider - ExplicitTarget secondTarget = ObjectFactory.With("name").EqualTo("Julia").GetInstance<ExplicitTarget>(); + var secondTarget = ObjectFactory.With("name").EqualTo("Julia").GetInstance<ExplicitTarget>(); Assert.AreEqual("Julia", secondTarget.Name); } [Test] public void Pass_in_arguments_as_dictionary() { - Container manager = new Container(); + var manager = new Container(); manager.SetDefault<IView, View>(); - Node theNode = new Node(); - Trade theTrade = new Trade(); + var theNode = new Node(); + var theTrade = new Trade(); - ExplicitArguments args = new ExplicitArguments(); + var args = new ExplicitArguments(); args.Set(theNode); args.SetArg("trade", theTrade); - Command command = manager.GetInstance<Command>(args); + var command = manager.GetInstance<Command>(args); Assert.IsInstanceOfType(typeof (View), command.View); Assert.AreSame(theNode, command.Node); @@ -175,11 +193,11 @@ new Container( registry => registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<LumpProvider>()); - ExplicitArguments args = new ExplicitArguments(); - Lump theLump = new Lump(); + var args = new ExplicitArguments(); + var theLump = new Lump(); args.Set(theLump); - LumpProvider instance = (LumpProvider) manager.GetInstance<IProvider>(args); + var instance = (LumpProvider) manager.GetInstance<IProvider>(args); Assert.AreSame(theLump, instance.Lump); } @@ -188,17 +206,17 @@ { StructureMapConfiguration.ForRequestedType<IProvider>().TheDefaultIsConcreteType<LumpProvider>(); ObjectFactory.Reset(); - Lump theLump = new Lump(); + var theLump = new Lump(); - LumpProvider provider = (LumpProvider) ObjectFactory.With(theLump).GetInstance<IProvider>(); + var provider = (LumpProvider) ObjectFactory.With(theLump).GetInstance<IProvider>(); Assert.AreSame(theLump, provider.Lump); } [Test] public void PassAnArgumentIntoExplicitArgumentsThatMightNotAlreadyBeRegistered() { - Lump theLump = new Lump(); - LumpProvider provider = ObjectFactory.With(theLump).GetInstance<LumpProvider>(); + var theLump = new Lump(); + var provider = ObjectFactory.With(theLump).GetInstance<LumpProvider>(); Assert.AreSame(theLump, provider.Lump); } @@ -212,25 +230,25 @@ .WithProperty("name").EqualTo("Jeremy") )); - ExplicitArguments args = new ExplicitArguments(); + var args = new ExplicitArguments(); // Get the ExplicitTarget without setting an explicit arg for IProvider - ExplicitTarget firstTarget = manager.GetInstance<ExplicitTarget>(args); + var firstTarget = manager.GetInstance<ExplicitTarget>(args); Assert.IsInstanceOfType(typeof (RedProvider), firstTarget.Provider); // Now, set the explicit arg for IProvider args.Set<IProvider>(new BlueProvider()); - ExplicitTarget secondTarget = manager.GetInstance<ExplicitTarget>(args); + var secondTarget = manager.GetInstance<ExplicitTarget>(args); Assert.IsInstanceOfType(typeof (BlueProvider), secondTarget.Provider); } [Test] public void RegisterAndFindServicesOnTheExplicitArgument() { - ExplicitArguments args = new ExplicitArguments(); + var args = new ExplicitArguments(); Assert.IsNull(args.Get<IProvider>()); - RedProvider red = new RedProvider(); + var red = new RedProvider(); args.Set<IProvider>(red); Assert.AreSame(red, args.Get<IProvider>()); @@ -242,7 +260,7 @@ [Test] public void RegisterAndRetrieveArgs() { - ExplicitArguments args = new ExplicitArguments(); + var args = new ExplicitArguments(); Assert.IsNull(args.GetArg("name")); args.SetArg("name", "Jeremy"); @@ -278,6 +296,21 @@ { } + public class TradeView : IView + { + private readonly Trade _trade; + + public TradeView(Trade trade) + { + _trade = trade; + } + + public Trade Trade + { + get { return _trade; } + } + } + public class Node { } @@ -318,4 +351,19 @@ get { return _view; } } } + + public class TradeNode : Node + { + private readonly Trade _trade; + + public TradeNode(Trade trade) + { + _trade = trade; + } + + public Trade Trade + { + get { return _trade; } + } + } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Pipeline/StubBuildSession.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/StubBuildSession.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap.Testing/Pipeline/StubBuildSession.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -49,6 +49,11 @@ throw new NotImplementedException(); } + public void RegisterDefault(Type pluginType, object defaultObject) + { + + } + #endregion public object CreateInstance(string typeName, IConfiguredInstance instance) Modified: trunk/Source/StructureMap.Testing/SpecificationExtensions.cs =================================================================== --- trunk/Source/StructureMap.Testing/SpecificationExtensions.cs 2008-08-07 20:23:07 UTC (rev 129) +++ trunk/Source/StructureMap.Testing/SpecificationExtensions.cs 2008-08-07 21:52:19 UTC (rev 130) @@ -46,6 +46,12 @@ return expected; } + public static T IsType<T>(this object actual) + { + actual.ShouldBeOfType(typeof(T)); + return (T) actual; + } + public static object ShouldNotBeTheSameAs(this object actual, object expected) { Assert.AreNotSame(expected, actual); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-08-25 20:12:48
|
Revision: 146 http://structuremap.svn.sourceforge.net/structuremap/?rev=146&view=rev Author: jeremydmiller Date: 2008-08-25 20:12:32 +0000 (Mon, 25 Aug 2008) Log Message: ----------- making exceptions serializable Modified Paths: -------------- trunk/Source/StructureMap/Graph/Constructor.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs trunk/Source/StructureMap.sln trunk/Source/StructureMap.sln.cache Removed Paths: ------------- trunk/Source/StructureMap/Interceptors/TypeInterceptor.cs Property Changed: ---------------- trunk/Source/HTML/ Property changes on: trunk/Source/HTML ___________________________________________________________________ Modified: svn:ignore - bin obj + bin obj [Bb]in [Dd]ebug [Rr]elease *.user *.aps *.eto Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2008-08-25 19:47:23 UTC (rev 145) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2008-08-25 20:12:32 UTC (rev 146) @@ -110,6 +110,7 @@ public bool HasArguments() { + if (_ctor == null) return false; return _ctor.GetParameters().Length > 0; } Deleted: trunk/Source/StructureMap/Interceptors/TypeInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/TypeInterceptor.cs 2008-08-25 19:47:23 UTC (rev 145) +++ trunk/Source/StructureMap/Interceptors/TypeInterceptor.cs 2008-08-25 20:12:32 UTC (rev 146) @@ -1,9 +0,0 @@ -using System; - -namespace StructureMap.Interceptors -{ - public interface TypeInterceptor : InstanceInterceptor - { - bool MatchesType(Type type); - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2008-08-25 19:47:23 UTC (rev 145) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2008-08-25 20:12:32 UTC (rev 146) @@ -18,13 +18,15 @@ protected ConfiguredInstanceBase(Type pluggedType, string name) { + // TODO -- need defensive check HERE! + //throw new NotImplementedException("Need to check for public constructor HERE!"); + _pluggedType = pluggedType; Name = name; } - protected ConfiguredInstanceBase(Type pluggedType) + protected ConfiguredInstanceBase(Type pluggedType) : this(pluggedType, Guid.NewGuid().ToString()) { - _pluggedType = pluggedType; } Modified: trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2008-08-25 19:47:23 UTC (rev 145) +++ trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2008-08-25 20:12:32 UTC (rev 146) @@ -33,7 +33,7 @@ public void specify_a_constructor_dependency() { var widget = new ColorWidget("Red"); - build<ClassWithWidget>(i => i.CtorDependency<IWidget>("widget").Is(x => x.Object(widget))).Widget. + build<ClassWithWidget>(instance => instance.CtorDependency<IWidget>("widget").Is(x => x.Object(widget))).Widget. ShouldBeTheSameAs(widget); } @@ -56,7 +56,7 @@ [Test] public void specify_a_simple_property() { - build<SimplePropertyTarget>(i => i.SetProperty(x => x.Name = "Jeremy")).Name.ShouldEqual("Jeremy"); + build<SimplePropertyTarget>(instance => instance.SetProperty(x => x.Name = "Jeremy")).Name.ShouldEqual("Jeremy"); build<SimplePropertyTarget>(i => i.SetProperty(x => x.Age = 16)).Age.ShouldEqual(16); } Modified: trunk/Source/StructureMap.sln =================================================================== --- trunk/Source/StructureMap.sln 2008-08-25 19:47:23 UTC (rev 145) +++ trunk/Source/StructureMap.sln 2008-08-25 20:12:32 UTC (rev 146) @@ -52,6 +52,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMapDoctor", "StructureMapDoctor\StructureMapDoctor.csproj", "{9048635D-A2CE-4387-A4F5-9BB1CFF04703}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTML", "HTML\HTML.csproj", "{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Build|.NET = Build|.NET @@ -245,6 +247,20 @@ {9048635D-A2CE-4387-A4F5-9BB1CFF04703}.Release|Any CPU.Build.0 = Release|Any CPU {9048635D-A2CE-4387-A4F5-9BB1CFF04703}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {9048635D-A2CE-4387-A4F5-9BB1CFF04703}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|.NET.ActiveCfg = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Any CPU.ActiveCfg = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Any CPU.Build.0 = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Mixed Platforms.ActiveCfg = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Mixed Platforms.Build.0 = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|.NET.ActiveCfg = Debug|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|.NET.ActiveCfg = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Any CPU.Build.0 = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE Modified: trunk/Source/StructureMap.sln.cache =================================================================== --- trunk/Source/StructureMap.sln.cache 2008-08-25 19:47:23 UTC (rev 145) +++ trunk/Source/StructureMap.sln.cache 2008-08-25 20:12:32 UTC (rev 146) @@ -5,6 +5,7 @@ <_SolutionProjectCacheVersion>3.5</_SolutionProjectCacheVersion> </PropertyGroup> <ItemGroup> + <_SolutionProjectProjects Include="HTML\HTML.csproj" /> <_SolutionProjectProjects Include="StructureMap.AutoMocking\StructureMap.AutoMocking.csproj" /> <_SolutionProjectProjects Include="StructureMap.DataAccess\StructureMap.DataAccess.csproj" /> <_SolutionProjectProjects Include="StructureMap.DeploymentTasks\StructureMap.DeploymentTasks.csproj" /> @@ -19,6 +20,7 @@ <_SolutionProjectProjects Include="StructureMap\StructureMap.csproj" /> </ItemGroup> <ItemGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') "> + <SkipLevel0 Include="HTML" /> <SkipLevel0 Include="StructureMap" /> <SkipLevel0 Include="StructureMap.Testing.Widget4" /> <SkipLevel4 Include="StructureMap.Testing" /> @@ -33,6 +35,10 @@ <SkipLevel3 Include="StructureMap.Testing.Widget5" /> </ItemGroup> <ItemGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') "> + <BuildLevel0 Include="HTML\HTML.csproj"> + <Configuration>Release</Configuration> + <Platform>AnyCPU</Platform> + </BuildLevel0> <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> <Configuration>Release</Configuration> <Platform>AnyCPU</Platform> @@ -83,6 +89,10 @@ </BuildLevel3> </ItemGroup> <ItemGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') "> + <BuildLevel0 Include="HTML\HTML.csproj"> + <Configuration>Release</Configuration> + <Platform>AnyCPU</Platform> + </BuildLevel0> <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> <Configuration>Release</Configuration> <Platform>AnyCPU</Platform> @@ -133,6 +143,7 @@ </BuildLevel3> </ItemGroup> <ItemGroup Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') "> + <SkipLevel0 Include="HTML" /> <SkipLevel0 Include="StructureMap" /> <SkipLevel0 Include="StructureMap.Testing.Widget4" /> <SkipLevel4 Include="StructureMap.Testing" /> @@ -147,6 +158,10 @@ <SkipLevel3 Include="StructureMap.Testing.Widget5" /> </ItemGroup> <ItemGroup Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') "> + <BuildLevel0 Include="HTML\HTML.csproj"> + <Configuration>Debug</Configuration> + <Platform>AnyCPU</Platform> + </BuildLevel0> <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> <Configuration>Debug</Configuration> <Platform>AnyCPU</Platform> @@ -245,8 +260,10 @@ <Configuration>Debug</Configuration> <Platform>AnyCPU</Platform> </BuildLevel3> + <SkipLevel0 Include="HTML" /> </ItemGroup> <ItemGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') "> + <SkipLevel0 Include="HTML" /> <SkipLevel0 Include="StructureMap" /> <SkipLevel0 Include="StructureMap.Testing.Widget4" /> <SkipLevel4 Include="StructureMap.Testing" /> @@ -261,6 +278,10 @@ <SkipLevel3 Include="StructureMap.Testing.Widget5" /> </ItemGroup> <ItemGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') "> + <BuildLevel0 Include="HTML\HTML.csproj"> + <Configuration>Release</Configuration> + <Platform>AnyCPU</Platform> + </BuildLevel0> <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> <Configuration>Release</Configuration> <Platform>AnyCPU</Platform> @@ -311,6 +332,10 @@ </BuildLevel3> </ItemGroup> <ItemGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') "> + <BuildLevel0 Include="HTML\HTML.csproj"> + <Configuration>Release</Configuration> + <Platform>AnyCPU</Platform> + </BuildLevel0> <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> <Configuration>Release</Configuration> <Platform>AnyCPU</Platform> @@ -397,6 +422,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -415,6 +441,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -433,6 +460,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -451,6 +479,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Debug|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Debug|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Debug|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Debug|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -469,6 +498,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Debug|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Debug|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Debug|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Debug|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -487,6 +517,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Debug|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Debug|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Debug|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Debug|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -505,6 +536,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -523,6 +555,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -541,6 +574,7 @@ <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> + <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> </SolutionConfiguration> </CurrentSolutionConfigurationContents> </PropertyGroup> @@ -1368,6 +1402,70 @@ <MSBuild Projects="StructureMapDoctor\StructureMapDoctor.csproj" Targets="Publish" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') " /> <MSBuild Projects="StructureMapDoctor\StructureMapDoctor.csproj" Targets="Publish" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') " /> </Target> + <Target Name="HTML" Condition="'$(CurrentSolutionConfigurationContents)' != ''" Outputs="@(HTMLBuildOutput)"> + <Message Text="The project "HTML" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + <MSBuild Projects="HTML\HTML.csproj" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + <Message Text="The project "HTML" is not selected for building in solution configuration "Debug|.NET"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + <Message Text="The project "HTML" is not selected for building in solution configuration "Debug|Mixed Platforms"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') " /> + <Message Text="The project "HTML" is not selected for building in solution configuration "Release|.NET"." Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + <MSBuild Projects="HTML\HTML.csproj" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + </Target> + <Target Name="HTML:Clean" Condition="'$(CurrentSolutionConfigurationContents)' != ''"> + <Message Text="The project "HTML" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Clean" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Clean" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') " /> + <Message Text="The project "HTML" is not selected for building in solution configuration "Debug|.NET"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Clean" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') " /> + <Message Text="The project "HTML" is not selected for building in solution configuration "Debug|Mixed Platforms"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') " /> + <Message Text="The project "HTML" is not selected for building in solution configuration "Release|.NET"." Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Clean" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Clean" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') " /> + </Target> + <Target Name="HTML:Rebuild" Condition="'$(CurrentSolutionConfigurationContents)' != ''" Outputs="@(HTMLBuildOutput)"> + <Message Text="The project "HTML" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Rebuild" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + <MSBuild Projects="HTML\HTML.csproj" Targets="Rebuild" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + <Message Text="The project "HTML" is not selected for building in solution configuration "Debug|.NET"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Rebuild" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + <Message Text="The project "HTML" is not selected for building in solution configuration "Debug|Mixed Platforms"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') " /> + <Message Text="The project "HTML" is not selected for building in solution configuration "Release|.NET"." Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Rebuild" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + <MSBuild Projects="HTML\HTML.csproj" Targets="Rebuild" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') "> + <Output TaskParameter="TargetOutputs" ItemName="HTMLBuildOutput" /> + </MSBuild> + </Target> + <Target Name="HTML:Publish" Condition="'$(CurrentSolutionConfigurationContents)' != ''"> + <Message Text="The project "HTML" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Publish" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Publish" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') " /> + <Message Text="The project "HTML" is not selected for building in solution configuration "Debug|.NET"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Publish" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') " /> + <Message Text="The project "HTML" is not selected for building in solution configuration "Debug|Mixed Platforms"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') " /> + <Message Text="The project "HTML" is not selected for building in solution configuration "Release|.NET"." Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Publish" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') " /> + <MSBuild Projects="HTML\HTML.csproj" Targets="Publish" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') " /> + </Target> <Target Name="Build" Condition="'$(CurrentSolutionConfigurationContents)' != ''" Outputs="@(CollectedBuildOutput)"> <MSBuild Condition="@(BuildLevel0) != ''" Projects="@(BuildLevel0)" Properties="Configuration=%(Configuration); Platform=%(Platform); BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="true" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)"> <Output TaskParameter="TargetOutputs" ItemName="CollectedBuildOutput" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2008-09-02 21:40:43
|
Revision: 148 http://structuremap.svn.sourceforge.net/structuremap/?rev=148&view=rev Author: flimflan Date: 2008-09-02 21:40:36 +0000 (Tue, 02 Sep 2008) Log Message: ----------- Removed HTML project from Release configuration to fix build. Modified Paths: -------------- trunk/Source/StructureMap.sln Removed Paths: ------------- trunk/Source/StructureMap.sln.cache Property Changed: ---------------- trunk/Source/ Property changes on: trunk/Source ___________________________________________________________________ Modified: svn:ignore - *.suo _ReSharper.StructureMap PrecompiledWeb *.resharper *.user Ankh.Load _UpgradeReport_Files UpgradeLog.XML UpgradeLog2.XML UpgradeLog3.XML UpgradeLog4.XML + *.suo _ReSharper.StructureMap PrecompiledWeb *.resharper *.user Ankh.Load _UpgradeReport_Files UpgradeLog.XML UpgradeLog2.XML UpgradeLog3.XML UpgradeLog4.XML *.cache Modified: trunk/Source/StructureMap.sln =================================================================== --- trunk/Source/StructureMap.sln 2008-08-25 20:39:23 UTC (rev 147) +++ trunk/Source/StructureMap.sln 2008-09-02 21:40:36 UTC (rev 148) @@ -251,7 +251,6 @@ {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Any CPU.ActiveCfg = Release|Any CPU {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Any CPU.Build.0 = Release|Any CPU {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Mixed Platforms.ActiveCfg = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Build|Mixed Platforms.Build.0 = Release|Any CPU {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|.NET.ActiveCfg = Debug|Any CPU {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Debug|Any CPU.Build.0 = Debug|Any CPU @@ -260,7 +259,6 @@ {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Any CPU.ActiveCfg = Release|Any CPU {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Any CPU.Build.0 = Release|Any CPU {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE Deleted: trunk/Source/StructureMap.sln.cache =================================================================== --- trunk/Source/StructureMap.sln.cache 2008-08-25 20:39:23 UTC (rev 147) +++ trunk/Source/StructureMap.sln.cache 2008-09-02 21:40:36 UTC (rev 148) @@ -1,1558 +0,0 @@ -<Project DefaultTargets="Build" ToolsVersion="3.5" InitialTargets="ValidateSolutionConfiguration;ValidateToolsVersions" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <_SolutionProjectConfiguration>Release|Mixed Platforms</_SolutionProjectConfiguration> - <_SolutionProjectToolsVersion>3.5</_SolutionProjectToolsVersion> - <_SolutionProjectCacheVersion>3.5</_SolutionProjectCacheVersion> - </PropertyGroup> - <ItemGroup> - <_SolutionProjectProjects Include="HTML\HTML.csproj" /> - <_SolutionProjectProjects Include="StructureMap.AutoMocking\StructureMap.AutoMocking.csproj" /> - <_SolutionProjectProjects Include="StructureMap.DataAccess\StructureMap.DataAccess.csproj" /> - <_SolutionProjectProjects Include="StructureMap.DeploymentTasks\StructureMap.DeploymentTasks.csproj" /> - <_SolutionProjectProjects Include="StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj" /> - <_SolutionProjectProjects Include="StructureMap.Testing.Widget2\StructureMap.Testing.Widget2.csproj" /> - <_SolutionProjectProjects Include="StructureMap.Testing.Widget3\StructureMap.Testing.Widget3.csproj" /> - <_SolutionProjectProjects Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj" /> - <_SolutionProjectProjects Include="StructureMap.Testing.Widget5\StructureMap.Testing.Widget5.csproj" /> - <_SolutionProjectProjects Include="StructureMap.Testing.Widget\StructureMap.Testing.Widget.csproj" /> - <_SolutionProjectProjects Include="StructureMap.Testing\StructureMap.Testing.csproj" /> - <_SolutionProjectProjects Include="StructureMapDoctor\StructureMapDoctor.csproj" /> - <_SolutionProjectProjects Include="StructureMap\StructureMap.csproj" /> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') "> - <SkipLevel0 Include="HTML" /> - <SkipLevel0 Include="StructureMap" /> - <SkipLevel0 Include="StructureMap.Testing.Widget4" /> - <SkipLevel4 Include="StructureMap.Testing" /> - <SkipLevel1 Include="StructureMap.AutoMocking" /> - <SkipLevel1 Include="StructureMap.DataAccess" /> - <SkipLevel1 Include="StructureMap.DeploymentTasks" /> - <SkipLevel1 Include="StructureMap.Testing.GenericWidgets" /> - <SkipLevel1 Include="StructureMap.Testing.Widget" /> - <SkipLevel1 Include="StructureMap.Testing.Widget3" /> - <SkipLevel1 Include="StructureMapDoctor" /> - <SkipLevel2 Include="StructureMap.Testing.Widget2" /> - <SkipLevel3 Include="StructureMap.Testing.Widget5" /> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') "> - <BuildLevel0 Include="HTML\HTML.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap\StructureMap.csproj"> - <Configuration>Build</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel4 Include="StructureMap.Testing\StructureMap.Testing.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel4> - <BuildLevel1 Include="StructureMap.AutoMocking\StructureMap.AutoMocking.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DataAccess\StructureMap.DataAccess.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DeploymentTasks\StructureMap.DeploymentTasks.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget3\StructureMap.Testing.Widget3.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget\StructureMap.Testing.Widget.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMapDoctor\StructureMapDoctor.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel2 Include="StructureMap.Testing.Widget2\StructureMap.Testing.Widget2.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel2> - <BuildLevel3 Include="StructureMap.Testing.Widget5\StructureMap.Testing.Widget5.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel3> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') "> - <BuildLevel0 Include="HTML\HTML.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap\StructureMap.csproj"> - <Configuration>Build</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel4 Include="StructureMap.Testing\StructureMap.Testing.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel4> - <BuildLevel1 Include="StructureMap.AutoMocking\StructureMap.AutoMocking.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DataAccess\StructureMap.DataAccess.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DeploymentTasks\StructureMap.DeploymentTasks.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget3\StructureMap.Testing.Widget3.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget\StructureMap.Testing.Widget.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMapDoctor\StructureMapDoctor.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel2 Include="StructureMap.Testing.Widget2\StructureMap.Testing.Widget2.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel2> - <BuildLevel3 Include="StructureMap.Testing.Widget5\StructureMap.Testing.Widget5.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel3> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') "> - <SkipLevel0 Include="HTML" /> - <SkipLevel0 Include="StructureMap" /> - <SkipLevel0 Include="StructureMap.Testing.Widget4" /> - <SkipLevel4 Include="StructureMap.Testing" /> - <SkipLevel1 Include="StructureMap.AutoMocking" /> - <SkipLevel1 Include="StructureMap.DataAccess" /> - <SkipLevel1 Include="StructureMap.DeploymentTasks" /> - <SkipLevel1 Include="StructureMap.Testing.GenericWidgets" /> - <SkipLevel1 Include="StructureMap.Testing.Widget" /> - <SkipLevel1 Include="StructureMap.Testing.Widget3" /> - <SkipLevel1 Include="StructureMapDoctor" /> - <SkipLevel2 Include="StructureMap.Testing.Widget2" /> - <SkipLevel3 Include="StructureMap.Testing.Widget5" /> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') "> - <BuildLevel0 Include="HTML\HTML.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap\StructureMap.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel4 Include="StructureMap.Testing\StructureMap.Testing.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel4> - <BuildLevel1 Include="StructureMap.AutoMocking\StructureMap.AutoMocking.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DataAccess\StructureMap.DataAccess.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DeploymentTasks\StructureMap.DeploymentTasks.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget3\StructureMap.Testing.Widget3.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget\StructureMap.Testing.Widget.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMapDoctor\StructureMapDoctor.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel2 Include="StructureMap.Testing.Widget2\StructureMap.Testing.Widget2.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel2> - <BuildLevel3 Include="StructureMap.Testing.Widget5\StructureMap.Testing.Widget5.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel3> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') "> - <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap\StructureMap.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel4 Include="StructureMap.Testing\StructureMap.Testing.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel4> - <BuildLevel1 Include="StructureMap.AutoMocking\StructureMap.AutoMocking.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DataAccess\StructureMap.DataAccess.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DeploymentTasks\StructureMap.DeploymentTasks.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget3\StructureMap.Testing.Widget3.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget\StructureMap.Testing.Widget.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMapDoctor\StructureMapDoctor.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel2 Include="StructureMap.Testing.Widget2\StructureMap.Testing.Widget2.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel2> - <BuildLevel3 Include="StructureMap.Testing.Widget5\StructureMap.Testing.Widget5.csproj"> - <Configuration>Debug</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel3> - <SkipLevel0 Include="HTML" /> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') "> - <SkipLevel0 Include="HTML" /> - <SkipLevel0 Include="StructureMap" /> - <SkipLevel0 Include="StructureMap.Testing.Widget4" /> - <SkipLevel4 Include="StructureMap.Testing" /> - <SkipLevel1 Include="StructureMap.AutoMocking" /> - <SkipLevel1 Include="StructureMap.DataAccess" /> - <SkipLevel1 Include="StructureMap.DeploymentTasks" /> - <SkipLevel1 Include="StructureMap.Testing.GenericWidgets" /> - <SkipLevel1 Include="StructureMap.Testing.Widget" /> - <SkipLevel1 Include="StructureMap.Testing.Widget3" /> - <SkipLevel1 Include="StructureMapDoctor" /> - <SkipLevel2 Include="StructureMap.Testing.Widget2" /> - <SkipLevel3 Include="StructureMap.Testing.Widget5" /> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') "> - <BuildLevel0 Include="HTML\HTML.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap\StructureMap.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel4 Include="StructureMap.Testing\StructureMap.Testing.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel4> - <BuildLevel1 Include="StructureMap.AutoMocking\StructureMap.AutoMocking.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DataAccess\StructureMap.DataAccess.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DeploymentTasks\StructureMap.DeploymentTasks.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget3\StructureMap.Testing.Widget3.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget\StructureMap.Testing.Widget.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMapDoctor\StructureMapDoctor.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel2 Include="StructureMap.Testing.Widget2\StructureMap.Testing.Widget2.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel2> - <BuildLevel3 Include="StructureMap.Testing.Widget5\StructureMap.Testing.Widget5.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel3> - </ItemGroup> - <ItemGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') "> - <BuildLevel0 Include="HTML\HTML.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap.Testing.Widget4\StructureMap.Testing.Widget4.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel0 Include="StructureMap\StructureMap.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel0> - <BuildLevel4 Include="StructureMap.Testing\StructureMap.Testing.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel4> - <BuildLevel1 Include="StructureMap.AutoMocking\StructureMap.AutoMocking.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DataAccess\StructureMap.DataAccess.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.DeploymentTasks\StructureMap.DeploymentTasks.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget3\StructureMap.Testing.Widget3.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMap.Testing.Widget\StructureMap.Testing.Widget.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel1 Include="StructureMapDoctor\StructureMapDoctor.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel1> - <BuildLevel2 Include="StructureMap.Testing.Widget2\StructureMap.Testing.Widget2.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel2> - <BuildLevel3 Include="StructureMap.Testing.Widget5\StructureMap.Testing.Widget5.csproj"> - <Configuration>Release</Configuration> - <Platform>AnyCPU</Platform> - </BuildLevel3> - </ItemGroup> - <UsingTask TaskName="Microsoft.Build.Tasks.CreateTemporaryVCProject" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> - <UsingTask TaskName="Microsoft.Build.Tasks.ResolveVCProjectOutput" AssemblyName="Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> - <PropertyGroup Condition=" '$(Configuration)' == '' "> - <Configuration>Debug</Configuration> - </PropertyGroup> - <PropertyGroup Condition=" '$(Platform)' == '' "> - <Platform>Mixed Platforms</Platform> - </PropertyGroup> - <PropertyGroup Condition=" ('$(AspNetConfiguration)' == '') "> - <AspNetConfiguration>$(Configuration)</AspNetConfiguration> - </PropertyGroup> - <PropertyGroup> - <SolutionDir>C:\code\StructureMap\source\</SolutionDir> - <SolutionExt>.sln</SolutionExt> - <SolutionFileName>StructureMap.sln</SolutionFileName> - <SolutionName>StructureMap</SolutionName> - <SolutionPath>C:\code\StructureMap\source\StructureMap.sln</SolutionPath> - </PropertyGroup> - <PropertyGroup> - <TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == '' and '$(MSBuildToolsVersion)' == '2.0'">v2.0</TargetFrameworkVersion> - <TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == '' and '$(MSBuildToolsVersion)' != '2.0'">v3.5</TargetFrameworkVersion> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Build|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Build|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Build|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Debug|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Debug|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Debug|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Debug|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <PropertyGroup Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') "> - <CurrentSolutionConfigurationContents> - <SolutionConfiguration xmlns=""> - <ProjectConfiguration Project="{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{63C2742D-B6E2-484F-AFDB-346873075C5E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{E21E1651-3E32-47B7-A290-F461E63FEAD2}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{027E996C-75E8-40F8-9073-0E3B77A6BE1F}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C8878328-281F-4F4F-8D6E-88C60F304B89}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{901D15CB-EF37-4F84-864B-E70F4B5F1DFF}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{CAB97F7F-FB75-410C-898A-88DCAAC036BE}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB6A0B91-873E-4E04-866A-7483E136A8D4}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{DB798C07-0C82-4298-8BAA-D702CF96C28E}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{9048635D-A2CE-4387-A4F5-9BB1CFF04703}">Release|AnyCPU</ProjectConfiguration> - <ProjectConfiguration Project="{A6358895-641F-4CC2-BE8E-C61EBE1DBEB9}">Release|AnyCPU</ProjectConfiguration> - </SolutionConfiguration> - </CurrentSolutionConfigurationContents> - </PropertyGroup> - <Target Name="ValidateSolutionConfiguration"> - <Error Text="The specified solution configuration "$(Configuration)|$(Platform)" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration." Code="MSB4126" HelpKeyword="MSBuild.SolutionInvalidSolutionConfiguration" Condition="('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidConfigurations)' != 'true')" /> - <Warning Text="The specified solution configuration "$(Configuration)|$(Platform)" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration." Code="MSB4126" HelpKeyword="MSBuild.SolutionInvalidSolutionConfiguration" Condition="('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidConfigurations)' == 'true')" /> - <Message Text="Building solution configuration "$(Configuration)|$(Platform)"." Condition="'$(CurrentSolutionConfigurationContents)' != ''" /> - </Target> - <Target Name="ValidateToolsVersions"> - <Error Text="The tools version "$(MSBuildToolsVersion)" of the solution does not support building projects with a different tools version." Code="MSB4149" HelpKeyword="MSBuild.SolutionToolsVersionDoesNotSupportProjectToolsVersion" Condition="'$(MSBuildToolsVersion)' == '2.0' and ('$(ProjectToolsVersion)' != '2.0' and '$(ProjectToolsVersion)' != '')" /> - </Target> - <Target Name="StructureMap" Condition="'$(CurrentSolutionConfigurationContents)' != ''" Outputs="@(StructureMapBuildOutput)"> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Properties="Configuration=Build; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <MSBuild Projects="StructureMap\StructureMap.csproj" Properties="Configuration=Build; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Debug|.NET"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <MSBuild Projects="StructureMap\StructureMap.csproj" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Release|.NET"." Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <MSBuild Projects="StructureMap\StructureMap.csproj" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - </Target> - <Target Name="StructureMap:Clean" Condition="'$(CurrentSolutionConfigurationContents)' != ''"> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Clean" Properties="Configuration=Build; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Clean" Properties="Configuration=Build; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') " /> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Debug|.NET"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Clean" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Clean" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') " /> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Release|.NET"." Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Clean" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Clean" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') " /> - </Target> - <Target Name="StructureMap:Rebuild" Condition="'$(CurrentSolutionConfigurationContents)' != ''" Outputs="@(StructureMapBuildOutput)"> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Rebuild" Properties="Configuration=Build; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Rebuild" Properties="Configuration=Build; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Debug|.NET"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Rebuild" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Rebuild" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Release|.NET"." Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Rebuild" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Rebuild" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') "> - <Output TaskParameter="TargetOutputs" ItemName="StructureMapBuildOutput" /> - </MSBuild> - </Target> - <Target Name="StructureMap:Publish" Condition="'$(CurrentSolutionConfigurationContents)' != ''"> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Publish" Properties="Configuration=Build; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Any CPU') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Publish" Properties="Configuration=Build; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == 'Mixed Platforms') " /> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Debug|.NET"." Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Publish" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Any CPU') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Publish" Properties="Configuration=Debug; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Debug') and ('$(Platform)' == 'Mixed Platforms') " /> - <Message Text="The project "StructureMap" is not selected for building in solution configuration "Release|.NET"." Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Publish" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Any CPU') " /> - <MSBuild Projects="StructureMap\StructureMap.csproj" Targets="Publish" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" Condition=" ('$(Configuration)' == 'Release') and ('$(Platform)' == 'Mixed Platforms') " /> - </Target> - <Target Name="StructureMap_Testing" DependsOnTargets="StructureMap_AutoMocking;StructureMap_DataAccess;Widgets\StructureMap_Testing_GenericWidgets;Widgets\StructureMap_Testing_Widget2;Widgets\StructureMap_Testing_Widget3;Widgets\StructureMap_Testing_Widget4;Widgets\StructureMap_Testing_Widget5;Widgets\StructureMap_Testing_Widget;StructureMap" Condition="'$(CurrentSolutionConfigurationContents)' != ''" Outputs="@(StructureMap_TestingBuildOutput)"> - <Message Text="The project "StructureMap.Testing" is not selected for building in solution configuration "Build|.NET"." Condition=" ('$(Configuration)' == 'Build') and ('$(Platform)' == '.NET') " /> - <MSBuild Projects="StructureMap.Testing\StructureMap.Testing.csproj" Properties="Configuration=Release; Platform=AnyCPU; BuildingSolutionFile=true; CurrentSolutionConfigurationCon... [truncated message content] |
From: <jer...@us...> - 2008-10-02 01:05:56
|
Revision: 161 http://structuremap.svn.sourceforge.net/structuremap/?rev=161&view=rev Author: jeremydmiller Date: 2008-10-02 01:05:46 +0000 (Thu, 02 Oct 2008) Log Message: ----------- did some cleanup Modified Paths: -------------- trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs trunk/Source/StructureMap.AutoMocking/Properties/AssemblyInfo.cs trunk/Source/StructureMap.DataAccess/AssemblyInfo.cs trunk/Source/StructureMap.DataAccess/CommandCollection.cs trunk/Source/StructureMap.DataAccess/CommandFactory.cs trunk/Source/StructureMap.DataAccess/CommandFailureException.cs trunk/Source/StructureMap.DataAccess/Commands/CommandBase.cs trunk/Source/StructureMap.DataAccess/Commands/QueryFilter.cs trunk/Source/StructureMap.DataAccess/Commands/StoredProcedureCommand.cs trunk/Source/StructureMap.DataAccess/Commands/TemplatedCommand.cs trunk/Source/StructureMap.DataAccess/Commands/TemplatedQuery.cs trunk/Source/StructureMap.DataAccess/ExecutionStates/AutoCommitExecutionState.cs trunk/Source/StructureMap.DataAccess/ExecutionStates/TransactionalExecutionState.cs trunk/Source/StructureMap.DataAccess/IDatabaseEngine.cs trunk/Source/StructureMap.DataAccess/JSON/Field.cs trunk/Source/StructureMap.DataAccess/JSON/JSONArray.cs trunk/Source/StructureMap.DataAccess/JSON/JSONObject.cs trunk/Source/StructureMap.DataAccess/JSON/JSONSerializer.cs trunk/Source/StructureMap.DataAccess/JSON/Part.cs trunk/Source/StructureMap.DataAccess/MSSQL/MSSQLDatabaseEngine.cs trunk/Source/StructureMap.DataAccess/Oracle/OracleDatabaseEngine.cs trunk/Source/StructureMap.DataAccess/ParameterCollection.cs trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommand.cs trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommandBuilder.cs trunk/Source/StructureMap.DataAccess/Parameters/Parameter.cs trunk/Source/StructureMap.DataAccess/ReaderSourceCollection.cs trunk/Source/StructureMap.DataAccess/TemplateParser.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/CommandExpectation.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockCommand.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockDataSession.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockReaderSource.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/NotExecutedCommandException.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterList.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterValidationFailureException.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedCommandCollection.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSource.cs trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSourceCollection.cs trunk/Source/StructureMap.DataAccess/Tools/TableDataReader.cs trunk/Source/StructureMap.DeploymentTasks/AddAssembly.cs trunk/Source/StructureMap.DeploymentTasks/AssemblyInfo.cs trunk/Source/StructureMap.DeploymentTasks/SetOverrideTask.cs trunk/Source/StructureMap.DeploymentTasks/SubstitutionTask.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/CheckVersionTask.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedDirectory.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedFile.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DotNetAssembly.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/GenerateVersionReport.cs trunk/Source/StructureMap.Testing.GenericWidgets/Properties/AssemblyInfo.cs trunk/Source/StructureMap.Testing.GenericWidgets/Widgets.cs trunk/Source/StructureMap.Testing.Widget/BuilderSamples.cs trunk/Source/StructureMap.Testing.Widget/IWidget.cs trunk/Source/StructureMap.Testing.Widget/Rule.cs trunk/Source/StructureMap.Testing.Widget2/Rule1.cs trunk/Source/StructureMap.Testing.Widget3/Gateways.cs trunk/Source/StructureMap.Testing.Widget5/AutoFilledGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/BasicGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/CannotBeAutoFilledGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/GridColumns.cs trunk/Source/StructureMap.Testing.Widget5/OtherGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/WidgetRegistry.cs trunk/Source/StructureMapDoctor/Properties/AssemblyInfo.cs Modified: trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -23,13 +23,13 @@ return null; } - InstanceFactory factory = new InstanceFactory(new PluginFamily(pluginType)); + var factory = new InstanceFactory(new PluginFamily(pluginType)); try { object service = _locator.Service(pluginType); - LiteralInstance instance = new LiteralInstance(service); + var instance = new LiteralInstance(service); profileManager.SetDefault(pluginType, instance); } Modified: trunk/Source/StructureMap.AutoMocking/Properties/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/Properties/AssemblyInfo.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.AutoMocking/Properties/AssemblyInfo.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -1,8 +1,8 @@ -using System.Reflection; +using System.Reflection; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly : AssemblyTitle("StructureMap.AutoMocking")] -[assembly : AssemblyDescription("")] \ No newline at end of file +[assembly: AssemblyTitle("StructureMap.AutoMocking")] +[assembly: AssemblyDescription("")] \ No newline at end of file Modified: trunk/Source/StructureMap.DataAccess/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/AssemblyInfo.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/AssemblyInfo.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -6,5 +6,5 @@ // associated with an assembly. // -[assembly : AssemblyTitle("StructureMap DataAccess")] -[assembly : AssemblyDescription("An interface to databases done the StructureMap way")] \ No newline at end of file +[assembly: AssemblyTitle("StructureMap DataAccess")] +[assembly: AssemblyDescription("An interface to databases done the StructureMap way")] \ No newline at end of file Modified: trunk/Source/StructureMap.DataAccess/CommandCollection.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/CommandCollection.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/CommandCollection.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -6,8 +6,8 @@ public class CommandCollection : ICommandCollection { private readonly ICommandFactory _commandFactory; + private readonly Hashtable _commands; private readonly DataSession _parent; - private Hashtable _commands; public CommandCollection(DataSession parent, ICommandFactory commandFactory) { Modified: trunk/Source/StructureMap.DataAccess/CommandFactory.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/CommandFactory.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/CommandFactory.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -14,7 +14,7 @@ public ICommand BuildCommand(string commandName) { - ICommand command = (ICommand) ObjectFactory.GetNamedInstance(typeof (ICommand), commandName); + var command = (ICommand) ObjectFactory.GetNamedInstance(typeof (ICommand), commandName); initialize(command); command.Name = commandName; @@ -23,7 +23,7 @@ public IReaderSource BuildReaderSource(string name) { - IReaderSource source = (IReaderSource) ObjectFactory.GetNamedInstance(typeof (IReaderSource), name); + var source = (IReaderSource) ObjectFactory.GetNamedInstance(typeof (IReaderSource), name); initialize(source); source.Name = name; @@ -34,7 +34,7 @@ private void initialize(object target) { - IInitializable initializable = target as IInitializable; + var initializable = target as IInitializable; if (initializable != null) { initializable.Initialize(_engine); Modified: trunk/Source/StructureMap.DataAccess/CommandFailureException.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/CommandFailureException.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/CommandFailureException.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -38,7 +38,7 @@ private void buildMessage(IDbCommand command) { - StringBuilder SB = new StringBuilder(); + var SB = new StringBuilder(); SB.Append("Command Failure!\r\n"); SB.Append(InnerException.Message); Modified: trunk/Source/StructureMap.DataAccess/Commands/CommandBase.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Commands/CommandBase.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Commands/CommandBase.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -8,7 +8,6 @@ public abstract class CommandBase : IInitializable, IReaderSource, ICommand { private IDbCommand _innerCommand; - private string _name; private ParameterCollection _parameters; private IDataSession _session; @@ -57,11 +56,7 @@ #region IReaderSource Members - public string Name - { - get { return _name; } - set { _name = value; } - } + public string Name { get; set; } [IndexerName("Parameter")] public object this[string parameterName] @@ -83,7 +78,7 @@ public string ExecuteJSON() { DataSet dataSet = ExecuteDataSet(); - JSONSerializer serializer = new JSONSerializer(dataSet.Tables[0]); + var serializer = new JSONSerializer(dataSet.Tables[0]); return serializer.CreateJSON(); } Modified: trunk/Source/StructureMap.DataAccess/Commands/QueryFilter.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Commands/QueryFilter.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Commands/QueryFilter.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -6,7 +6,7 @@ { protected const string REPLACEMENT_VALUE = "{Value}"; private readonly string _parameterName; - protected object _innerValue = null; + protected object _innerValue; protected string _sqlSnippet; Modified: trunk/Source/StructureMap.DataAccess/Commands/StoredProcedureCommand.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Commands/StoredProcedureCommand.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Commands/StoredProcedureCommand.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -34,7 +34,7 @@ public override void Initialize(IDatabaseEngine engine) { IDbCommand innerCommand = engine.CreateStoredProcedureCommand(_commandText); - ParameterCollection parameters = new ParameterCollection(innerCommand.Parameters); + var parameters = new ParameterCollection(innerCommand.Parameters); initializeMembers(parameters, innerCommand); } Modified: trunk/Source/StructureMap.DataAccess/Commands/TemplatedCommand.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Commands/TemplatedCommand.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Commands/TemplatedCommand.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -7,14 +7,14 @@ [Pluggable("Templated")] public class TemplatedCommand : CommandBase { - private string[] _substitutions; - private string _template; + private readonly string[] _substitutions; + private readonly string _template; [DefaultConstructor] - public TemplatedCommand(string template) : base() + public TemplatedCommand(string template) { _template = template; - TemplateParser parser = new TemplateParser(template); + var parser = new TemplateParser(template); _substitutions = parser.Parse(); } @@ -31,10 +31,10 @@ public override void Initialize(IDatabaseEngine engine) { - ParameterCollection parameters = new ParameterCollection(); + var parameters = new ParameterCollection(); foreach (string substitution in _substitutions) { - TemplateParameter parameter = new TemplateParameter(substitution); + var parameter = new TemplateParameter(substitution); parameters.AddParameter(parameter); } @@ -44,7 +44,7 @@ public string GetSql() { - StringBuilder sb = new StringBuilder(_template); + var sb = new StringBuilder(_template); foreach (TemplateParameter parameter in Parameters) { parameter.Substitute(sb); Modified: trunk/Source/StructureMap.DataAccess/Commands/TemplatedQuery.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Commands/TemplatedQuery.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Commands/TemplatedQuery.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -10,9 +10,9 @@ { private readonly IQueryFilter[] _filters; private readonly string _selectAndFromClause; - private ArrayList _templatedParameters = new ArrayList(); + private readonly ArrayList _templatedParameters = new ArrayList(); - public TemplatedQuery(string selectAndFromClause, IQueryFilter[] filters) : base() + public TemplatedQuery(string selectAndFromClause, IQueryFilter[] filters) { _selectAndFromClause = selectAndFromClause; _filters = filters; @@ -20,14 +20,14 @@ public override void Initialize(IDatabaseEngine engine) { - ParameterCollection parameters = new ParameterCollection(_filters); + var parameters = new ParameterCollection(_filters); IDbCommand command = engine.GetCommand(); - TemplateParser parser = new TemplateParser(_selectAndFromClause); + var parser = new TemplateParser(_selectAndFromClause); string[] substitutions = parser.Parse(); foreach (string substitution in substitutions) { - TemplateParameter parameter = new TemplateParameter(substitution); + var parameter = new TemplateParameter(substitution); _templatedParameters.Add(parameter); parameters.AddParameter(parameter); } @@ -44,13 +44,13 @@ { command.Parameters.Clear(); - StringBuilder sb = new StringBuilder(_selectAndFromClause); + var sb = new StringBuilder(_selectAndFromClause); foreach (TemplateParameter parameter in _templatedParameters) { parameter.Substitute(sb); } - ArrayList whereList = new ArrayList(); + var whereList = new ArrayList(); foreach (IQueryFilter filter in _filters) { if (filter.IsActive()) @@ -63,7 +63,7 @@ if (whereList.Count > 0) { sb.Append(" where "); - string[] filterStrings = (string[]) whereList.ToArray(typeof (string)); + var filterStrings = (string[]) whereList.ToArray(typeof (string)); string whereClause = string.Join(" and ", filterStrings); sb.Append(whereClause); } Modified: trunk/Source/StructureMap.DataAccess/ExecutionStates/AutoCommitExecutionState.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/ExecutionStates/AutoCommitExecutionState.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/ExecutionStates/AutoCommitExecutionState.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -49,7 +49,7 @@ { setupConnection(command); _adapter.SelectCommand = command; - DataSet dataSet = new DataSet(); + var dataSet = new DataSet(); _adapter.Fill(dataSet); return dataSet; Modified: trunk/Source/StructureMap.DataAccess/ExecutionStates/TransactionalExecutionState.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/ExecutionStates/TransactionalExecutionState.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/ExecutionStates/TransactionalExecutionState.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -47,7 +47,7 @@ { prepareCommand(command); _adapter.SelectCommand = command; - DataSet dataSet = new DataSet(); + var dataSet = new DataSet(); _adapter.Fill(dataSet); Modified: trunk/Source/StructureMap.DataAccess/IDatabaseEngine.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/IDatabaseEngine.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/IDatabaseEngine.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -15,6 +15,4 @@ IDataParameter CreateParameter(string parameterName, DbType dbType, bool isNullable); string GetParameterName(string logicalName); } - - } \ No newline at end of file Modified: trunk/Source/StructureMap.DataAccess/JSON/Field.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/JSON/Field.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/JSON/Field.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -32,7 +32,7 @@ public static Field[] GetFields(DataTable table) { - Field[] returnValue = new Field[table.Columns.Count]; + var returnValue = new Field[table.Columns.Count]; for (int i = 0; i < table.Columns.Count; i++) Modified: trunk/Source/StructureMap.DataAccess/JSON/JSONArray.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/JSON/JSONArray.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/JSON/JSONArray.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -6,8 +6,8 @@ { public class JSONArray : Part { - private ArrayList _parts = new ArrayList(); - private bool _pretty; + private readonly ArrayList _parts = new ArrayList(); + private readonly bool _pretty; public JSONArray(bool pretty) { Modified: trunk/Source/StructureMap.DataAccess/JSON/JSONObject.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/JSON/JSONObject.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/JSON/JSONObject.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -6,12 +6,8 @@ { public class JSONObject : Part { - private ArrayList _parts = new ArrayList(); + private readonly ArrayList _parts = new ArrayList(); - public JSONObject() - { - } - public JSONObject AddString(string propertyName, string propertyValue) { _parts.Add(JSONProperty.String(propertyName, propertyValue)); Modified: trunk/Source/StructureMap.DataAccess/JSON/JSONSerializer.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/JSON/JSONSerializer.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/JSON/JSONSerializer.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -16,7 +16,7 @@ { _fields = Field.GetFields(_table); - JSONArray array = new JSONArray(true); + var array = new JSONArray(true); foreach (DataRow row in _table.Rows) @@ -29,7 +29,7 @@ private void writeObject(JSONArray array, DataRow row) { - JSONObject obj = new JSONObject(); + var obj = new JSONObject(); foreach (Field field in _fields) { Modified: trunk/Source/StructureMap.DataAccess/JSON/Part.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/JSON/Part.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/JSON/Part.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -8,7 +8,7 @@ public string ToJSON() { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); Write(sb); return sb.ToString().Trim(); } Modified: trunk/Source/StructureMap.DataAccess/MSSQL/MSSQLDatabaseEngine.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/MSSQL/MSSQLDatabaseEngine.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/MSSQL/MSSQLDatabaseEngine.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -67,7 +67,7 @@ public IDbCommand CreateStoredProcedureCommand(string commandText) { SqlCommand command = null; - SqlConnection connection = new SqlConnection(_connectionString); + var connection = new SqlConnection(_connectionString); try { @@ -90,8 +90,8 @@ } catch (SqlException e) { - Exception ex = new Exception("Error connecting or executing database command " + e.Message); - throw(ex); + var ex = new Exception("Error connecting or executing database command " + e.Message); + throw (ex); } finally { @@ -112,7 +112,7 @@ private SqlParameter createParameter(string logicalName) { - SqlParameter parameter = new SqlParameter(); + var parameter = new SqlParameter(); parameter.ParameterName = "@" + logicalName; return parameter; } @@ -124,9 +124,9 @@ private void pruneDuplicates(SqlCommand command) { - ArrayList list = new ArrayList(); + var list = new ArrayList(); - SqlParameter[] parameters = new SqlParameter[command.Parameters.Count]; + var parameters = new SqlParameter[command.Parameters.Count]; command.Parameters.CopyTo(parameters, 0); foreach (SqlParameter parameter in parameters) Modified: trunk/Source/StructureMap.DataAccess/Oracle/OracleDatabaseEngine.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Oracle/OracleDatabaseEngine.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Oracle/OracleDatabaseEngine.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -1,20 +1,20 @@ -using System; -using System.Collections.Generic; +using System; using System.Data; using System.Data.OracleClient; -using System.Text; namespace StructureMap.DataAccess.Oracle { public class OracleDatabaseEngine : IDatabaseEngine { - private IConnectionStringProvider _provider; + private readonly IConnectionStringProvider _provider; public OracleDatabaseEngine(IConnectionStringProvider provider) { _provider = provider; } + #region IDatabaseEngine Members + public IDbConnection GetConnection() { return new OracleConnection(_provider.GetConnectionString()); @@ -27,7 +27,7 @@ public IDbCommand CreateStoredProcedureCommand(string commandText) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public IDbDataAdapter GetDataAdapter() @@ -37,17 +37,19 @@ public IDataParameter CreateStringParameter(string parameterName, int size, bool isNullable) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public IDataParameter CreateParameter(string parameterName, DbType dbType, bool isNullable) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public string GetParameterName(string logicalName) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } + + #endregion } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap.DataAccess/ParameterCollection.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/ParameterCollection.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/ParameterCollection.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -7,7 +7,7 @@ { public class ParameterCollection : IEnumerable { - private Hashtable _parameters = new Hashtable(); + private readonly Hashtable _parameters = new Hashtable(); public ParameterCollection() { @@ -17,7 +17,7 @@ { foreach (IDataParameter innerParameter in parameters) { - Parameter parameter = new Parameter(innerParameter); + var parameter = new Parameter(innerParameter); AddParameter(parameter); } } Modified: trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommand.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommand.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommand.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -14,7 +14,7 @@ public override void Initialize(IDatabaseEngine engine) { - ParameterizedCommandBuilder builder = new ParameterizedCommandBuilder(engine, _commandText); + var builder = new ParameterizedCommandBuilder(engine, _commandText); builder.Build(); initializeMembers(builder.Parameters, builder.Command); Modified: trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommandBuilder.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommandBuilder.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Parameterization/ParameterizedCommandBuilder.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -7,13 +7,13 @@ { public class ParameterizedCommandBuilder { + private readonly IDbCommand _command; private readonly string _commandTemplate; + private readonly StringBuilder _commandTextBuilder; private readonly IDatabaseEngine _engine; - private IDbCommand _command; - private StringBuilder _commandTextBuilder; - private bool _hasBuilt = false; - private string[] _parameterNames; - private ParameterCollection _parameters; + private readonly string[] _parameterNames; + private readonly ParameterCollection _parameters; + private bool _hasBuilt; public ParameterizedCommandBuilder(IDatabaseEngine engine, string commandTemplate) { @@ -21,7 +21,7 @@ _commandTemplate = commandTemplate; _parameters = new ParameterCollection(); - TemplateParser parser = new TemplateParser(_commandTemplate); + var parser = new TemplateParser(_commandTemplate); _parameterNames = parser.Parse(); _commandTextBuilder = new StringBuilder(_commandTemplate); Modified: trunk/Source/StructureMap.DataAccess/Parameters/Parameter.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Parameters/Parameter.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Parameters/Parameter.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -5,7 +5,7 @@ public class Parameter : IParameter { private readonly IDataParameter _innerParameter; - private string _parameterName; + private readonly string _parameterName; public Parameter(IDataParameter innerParameter) : this(innerParameter, innerParameter.ParameterName) { Modified: trunk/Source/StructureMap.DataAccess/ReaderSourceCollection.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/ReaderSourceCollection.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/ReaderSourceCollection.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -7,7 +7,7 @@ { private readonly ICommandFactory _commandFactory; private readonly DataSession _parent; - private Hashtable _sources; + private readonly Hashtable _sources; public ReaderSourceCollection(DataSession session, ICommandFactory commandFactory) { Modified: trunk/Source/StructureMap.DataAccess/TemplateParser.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/TemplateParser.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/TemplateParser.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -24,13 +24,13 @@ throw new ApplicationException(_template); } - string[] tempValues = new string[_leftCurlyIndexes.Length]; + var tempValues = new string[_leftCurlyIndexes.Length]; for (int i = 0; i < _leftCurlyIndexes.Length; i++) { tempValues[i] = getSubstitution(i); } - ArrayList list = new ArrayList(); + var list = new ArrayList(); foreach (string tempValue in tempValues) { if (!list.Contains(tempValue)) @@ -58,7 +58,7 @@ private int[] findAllOccurrences(string bracket) { - ArrayList list = new ArrayList(); + var list = new ArrayList(); int curlyIndex = _template.IndexOf(bracket, 0); while (curlyIndex > -1) Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/CommandExpectation.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/CommandExpectation.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/CommandExpectation.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -4,10 +4,10 @@ { public class CommandExpectation : ICloneable { + private readonly ParameterList _inputs; + private readonly ParameterList _outputs; private readonly int _rowsAffected; - private ParameterList _inputs; - private ParameterList _outputs; - private bool _wasExecuted = false; + private bool _wasExecuted; public CommandExpectation() : this(1) { Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockCommand.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockCommand.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockCommand.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -5,25 +5,20 @@ { public class MockCommand : ICommand { + private readonly Queue _expectations; + private readonly ParameterList _inputs; private CommandExpectation _currentExpectation; - private Queue _expectations; - private ParameterList _inputs; - private string _name; public MockCommand(string name) { - _name = name; + Name = name; _expectations = new Queue(); _inputs = new ParameterList(); } #region ICommand Members - public string Name - { - get { return _name; } - set { _name = value; } - } + public string Name { get; set; } public int Execute() @@ -57,7 +52,7 @@ if (_expectations.Count > 0) { - CommandExpectation nextExpectation = (CommandExpectation) _expectations.Peek(); + var nextExpectation = (CommandExpectation) _expectations.Peek(); if (nextExpectation.IsOutput(parameterName)) { throw new NotExecutedCommandException(parameterName, Name); Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockDataSession.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockDataSession.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockDataSession.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -5,8 +5,8 @@ { public class MockDataSession : IDataSession { - private StubbedCommandCollection _commands; - private StubbedReaderSourceCollection _sources; + private readonly StubbedCommandCollection _commands; + private readonly StubbedReaderSourceCollection _sources; public MockDataSession() { @@ -105,14 +105,14 @@ public void AddReaderExpectation(string name, ReaderExpectation expectation) { - MockReaderSource source = (MockReaderSource) _sources[name]; + var source = (MockReaderSource) _sources[name]; source.AddExpectation(expectation); } public void AddCommandExpectation(string name, CommandExpectation expectation) { - MockCommand command = (MockCommand) _commands[name]; + var command = (MockCommand) _commands[name]; command.AddExpectation(expectation); } } Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockReaderSource.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockReaderSource.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/MockReaderSource.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -7,25 +7,20 @@ { public class MockReaderSource : IReaderSource { - private Queue _expectations; - private string _name; - private ParameterList _parameters; + private readonly Queue _expectations; + private readonly ParameterList _parameters; public MockReaderSource(string name) { - _name = name; + Name = name; _parameters = new ParameterList(); _expectations = new Queue(); } #region IReaderSource Members - public string Name - { - get { return _name; } - set { _name = value; } - } + public string Name { get; set; } public IDataReader ExecuteReader() { @@ -34,7 +29,7 @@ throw new UnExpectedCallException(Name); } - ReaderExpectation expectation = (ReaderExpectation) _expectations.Dequeue(); + var expectation = (ReaderExpectation) _expectations.Dequeue(); return expectation.VerifyAndGetReader(_parameters); } Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/NotExecutedCommandException.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/NotExecutedCommandException.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/NotExecutedCommandException.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -7,7 +7,7 @@ private readonly string _parameterName; private string _commandName = string.Empty; - public NotExecutedCommandException(string parameterName) : base() + public NotExecutedCommandException(string parameterName) { _parameterName = parameterName; } Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterList.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterList.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterList.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -24,7 +24,7 @@ { get { - string[] returnValue = new string[_values.Count]; + var returnValue = new string[_values.Count]; _values.Keys.CopyTo(returnValue, 0); Array.Sort(returnValue); @@ -37,7 +37,7 @@ public object Clone() { - ParameterList clone = new ParameterList(); + var clone = new ParameterList(); clone._values = (Hashtable) _values.Clone(); return clone; @@ -47,11 +47,11 @@ public void Verify(ParameterList actualList) { - ArrayList expectedKeys = new ArrayList(AllKeys); - ArrayList actualKeys = new ArrayList(actualList.AllKeys); - ArrayList unionKeys = new ArrayList(); + var expectedKeys = new ArrayList(AllKeys); + var actualKeys = new ArrayList(actualList.AllKeys); + var unionKeys = new ArrayList(); - string[] keys = (string[]) actualKeys.ToArray(typeof (string)); + var keys = (string[]) actualKeys.ToArray(typeof (string)); foreach (string key in keys) { @@ -63,7 +63,7 @@ } } - ParameterValidationFailureException failureCondition = new ParameterValidationFailureException(); + var failureCondition = new ParameterValidationFailureException(); checkForWrongParameterValues(unionKeys, actualList, failureCondition); checkForMissingParameters(expectedKeys, failureCondition); Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterValidationFailureException.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterValidationFailureException.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/ParameterValidationFailureException.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -6,10 +6,6 @@ { private string _message = string.Empty; - public ParameterValidationFailureException() : base() - { - } - public override string Message { get { return _message; } Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedCommandCollection.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedCommandCollection.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedCommandCollection.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -5,7 +5,7 @@ { public class StubbedCommandCollection : ICommandCollection { - private Hashtable _commands; + private readonly Hashtable _commands; public StubbedCommandCollection() { @@ -21,7 +21,7 @@ { if (!_commands.ContainsKey(commandName)) { - MockCommand command = new MockCommand(commandName); + var command = new MockCommand(commandName); _commands.Add(commandName, command); } Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSource.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSource.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSource.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -2,8 +2,5 @@ { public class StubbedReaderSource { - public StubbedReaderSource() - { - } } } \ No newline at end of file Modified: trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSourceCollection.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSourceCollection.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/Mocks/StubbedReaderSourceCollection.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -5,7 +5,7 @@ { public class StubbedReaderSourceCollection : IReaderSourceCollection { - private Hashtable _sources; + private readonly Hashtable _sources; public StubbedReaderSourceCollection() { @@ -31,7 +31,7 @@ { if (!_sources.ContainsKey(name)) { - MockReaderSource source = new MockReaderSource(name); + var source = new MockReaderSource(name); _sources.Add(name, source); } Modified: trunk/Source/StructureMap.DataAccess/Tools/TableDataReader.cs =================================================================== --- trunk/Source/StructureMap.DataAccess/Tools/TableDataReader.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DataAccess/Tools/TableDataReader.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -5,12 +5,12 @@ { public class TableDataReader : IDataReader { + private readonly DataTable[] _tables; private int _currentPosition; private DataRow _currentRow; private DataTable _currentTable; private bool _isClosed; private int _tableIndex = -1; - private DataTable[] _tables; public TableDataReader() : this(new DataTable()) @@ -18,7 +18,7 @@ } public TableDataReader(DataTable table) - : this(new DataTable[] {table}) + : this(new[] {table}) { } Modified: trunk/Source/StructureMap.DeploymentTasks/AddAssembly.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/AddAssembly.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/AddAssembly.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -11,18 +11,14 @@ private string _assemblyName; private string _configPath; - public AddAssembly() - { - } - - [TaskAttribute("configPath", Required=true)] + [TaskAttribute("configPath", Required = true)] public string ConfigPath { get { return _configPath; } set { _configPath = value; } } - [TaskAttribute("assemblyName", Required=true)] + [TaskAttribute("assemblyName", Required = true)] public string AssemblyName { get { return _assemblyName; } @@ -41,7 +37,7 @@ public XmlDocument AddAssemblyNode() { - XmlDocument document = new XmlDocument(); + var document = new XmlDocument(); document.Load(_configPath); AddAssemblyToDocument(document); Modified: trunk/Source/StructureMap.DeploymentTasks/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/AssemblyInfo.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/AssemblyInfo.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -7,6 +7,6 @@ // associated with an assembly. // -[assembly : AssemblyTitle("StructureMap v0.91")] -[assembly : AssemblyDescription("Deployment Tasks for NAnt")] -[assembly : ReflectionPermission(SecurityAction.RequestMinimum, ReflectionEmit=true)] \ No newline at end of file +[assembly: AssemblyTitle("StructureMap v0.91")] +[assembly: AssemblyDescription("Deployment Tasks for NAnt")] +[assembly: ReflectionPermission(SecurityAction.RequestMinimum, ReflectionEmit = true)] \ No newline at end of file Modified: trunk/Source/StructureMap.DeploymentTasks/SetOverrideTask.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/SetOverrideTask.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/SetOverrideTask.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -13,32 +13,28 @@ private string _profileName = string.Empty; private string _typeName = string.Empty; - public SetOverrideTask() : base() - { - } - - [TaskAttribute("configPath", Required=true)] + [TaskAttribute("configPath", Required = true)] public string ConfigPath { get { return _configPath; } set { _configPath = value; } } - [TaskAttribute("profileName", Required=false)] + [TaskAttribute("profileName", Required = false)] public string ProfileName { get { return _profileName; } set { _profileName = value; } } - [TaskAttribute("typeName", Required=true)] + [TaskAttribute("typeName", Required = true)] public string TypeName { get { return _typeName; } set { _typeName = value; } } - [TaskAttribute("key", Required=true)] + [TaskAttribute("key", Required = true)] public string DefaultKey { get { return _defaultKey; } @@ -48,7 +44,7 @@ protected override void ExecuteTask() { - XmlDocument document = new XmlDocument(); + var document = new XmlDocument(); document.Load(_configPath); ApplyToDocument(document); @@ -85,7 +81,7 @@ private XmlElement findOverrideElement(XmlElement profileElement, XmlDocument document) { string overrideXPath = string.Format("Override[@Type='{0}']", _typeName); - XmlElement overrideElement = (XmlElement) profileElement.SelectSingleNode(overrideXPath); + var overrideElement = (XmlElement) profileElement.SelectSingleNode(overrideXPath); if (overrideElement == null) { overrideElement = document.CreateElement("Override"); @@ -98,7 +94,7 @@ private XmlElement findProfileElement(string profileName, XmlDocument document) { string profileXPath = string.Format("Profile[@Name='{0}']", profileName); - XmlElement profileElement = (XmlElement) document.DocumentElement.SelectSingleNode(profileXPath); + var profileElement = (XmlElement) document.DocumentElement.SelectSingleNode(profileXPath); if (profileElement == null) { profileElement = document.CreateElement("Profile"); Modified: trunk/Source/StructureMap.DeploymentTasks/SubstitutionTask.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/SubstitutionTask.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/SubstitutionTask.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -12,25 +12,21 @@ private string _flag; private string _value; - public SubstitutionTask() : base() - { - } - - [TaskAttribute("flag", Required=true)] + [TaskAttribute("flag", Required = true)] public string Flag { get { return _flag; } set { _flag = value; } } - [TaskAttribute("value", Required=true)] + [TaskAttribute("value", Required = true)] public string Value { get { return _value; } set { _value = value; } } - [TaskAttribute("file", Required=true)] + [TaskAttribute("file", Required = true)] public string FilePath { get { return _filePath; } @@ -47,16 +43,16 @@ { string xml = string.Empty; - using (FileStream stream = new FileStream(_filePath, FileMode.Open, FileAccess.Read)) + using (var stream = new FileStream(_filePath, FileMode.Open, FileAccess.Read)) { - StreamReader reader = new StreamReader(stream); + var reader = new StreamReader(stream); xml = reader.ReadToEnd(); } string searchString = string.Format("{{{0}}}", _flag); xml = xml.Replace(searchString, _value); - XmlDocument document = new XmlDocument(); + var document = new XmlDocument(); document.LoadXml(xml); document.Save(_filePath); } Modified: trunk/Source/StructureMap.DeploymentTasks/Versioning/CheckVersionTask.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/Versioning/CheckVersionTask.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/Versioning/CheckVersionTask.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -8,15 +8,11 @@ [TaskName("structuremap.checkversion")] public class CheckVersionTask : Task, IVersionReport { - private ArrayList _exclusionList = new ArrayList(); + private readonly ArrayList _exclusionList = new ArrayList(); private string _manifestFile; private bool _succeeded = true; private string _targetFolder; - public CheckVersionTask() : base() - { - } - [TaskAttribute("manifest", Required = true)] public string ManifestFile { @@ -97,8 +93,8 @@ string.Format("Starting version checking of folder {0} against manifest file {1}", _targetFolder, _manifestFile)); - DirectoryInfo targetDirectoryInfo = new DirectoryInfo(TargetFolder); - DeployedDirectory actualDirectory = new DeployedDirectory(targetDirectoryInfo); + var targetDirectoryInfo = new DirectoryInfo(TargetFolder); + var actualDirectory = new DeployedDirectory(targetDirectoryInfo); DeployedDirectory expectedDirectory = DeployedDirectory.ReadFromXml(_manifestFile); Modified: trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedDirectory.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedDirectory.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedDirectory.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -9,7 +9,6 @@ private Hashtable _assemblies; private Hashtable _childDirectories; private Hashtable _files; - private string _name; public DeployedDirectory() { @@ -20,7 +19,7 @@ public DeployedDirectory(DirectoryInfo directory) : this() { - _name = directory.Name; + Name = directory.Name; // foreach (DirectoryInfo childDirectory in directory.GetDirectories()) // { @@ -43,11 +42,7 @@ } } - public string Name - { - get { return _name; } - set { _name = value; } - } + public string Name { get; set; } // public DeployedDirectory[] ChildDeployedDirectories // { @@ -83,7 +78,7 @@ { get { - DeployedFile[] children = new DeployedFile[_files.Count]; + var children = new DeployedFile[_files.Count]; _files.Values.CopyTo(children, 0); return children; @@ -102,7 +97,7 @@ { get { - DotNetAssembly[] assemblies = new DotNetAssembly[_assemblies.Count]; + var assemblies = new DotNetAssembly[_assemblies.Count]; _assemblies.Values.CopyTo(assemblies, 0); return assemblies; @@ -155,8 +150,8 @@ public void WriteToXml(string fileName) { - XmlSerializer serializer = new XmlSerializer(GetType()); - using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) + var serializer = new XmlSerializer(GetType()); + using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { serializer.Serialize(stream, this); } @@ -165,8 +160,8 @@ public static DeployedDirectory ReadFromXml(string fileName) { - XmlSerializer serializer = new XmlSerializer(typeof (DeployedDirectory)); - using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) + var serializer = new XmlSerializer(typeof (DeployedDirectory)); + using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { return (DeployedDirectory) serializer.Deserialize(stream); } Modified: trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedFile.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedFile.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedFile.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -31,8 +31,8 @@ public static DeployedFile CreateFile(FileInfo fileInfo) { - DeployedFile deployedFile = new DeployedFile(fileInfo.Name); - SHA1CryptoServiceProvider crypto = new SHA1CryptoServiceProvider(); + var deployedFile = new DeployedFile(fileInfo.Name); + var crypto = new SHA1CryptoServiceProvider(); using (FileStream stream = fileInfo.OpenRead()) { Modified: trunk/Source/StructureMap.DeploymentTasks/Versioning/DotNetAssembly.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/Versioning/DotNetAssembly.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/Versioning/DotNetAssembly.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -6,9 +6,7 @@ { public class DotNetAssembly { - private string _assemblyName; private byte[] _publicKey = new byte[0]; - private string _version; public DotNetAssembly() { @@ -17,20 +15,20 @@ public DotNetAssembly(byte[] publicKey, string assemblyName, string version) { _publicKey = publicKey; - _assemblyName = assemblyName; - _version = version; + AssemblyName = assemblyName; + Version = version; } public DotNetAssembly(string assemblyName, string version) { - _assemblyName = assemblyName; - _version = version; + AssemblyName = assemblyName; + Version = version; } public DotNetAssembly(Assembly assembly) { - _assemblyName = assembly.GetName().Name; - _version = assembly.GetName().Version.ToString(); + AssemblyName = assembly.GetName().Name; + Version = assembly.GetName().Version.ToString(); _publicKey = assembly.GetName().GetPublicKey(); } @@ -40,17 +38,9 @@ set { _publicKey = value; } } - public string AssemblyName - { - get { return _assemblyName; } - set { _assemblyName = value; } - } + public string AssemblyName { get; set; } - public string Version - { - get { return _version; } - set { _version = value; } - } + public string Version { get; set; } public static DotNetAssembly TryCreateAssembly(FileInfo fileInfo) { Modified: trunk/Source/StructureMap.DeploymentTasks/Versioning/GenerateVersionReport.cs =================================================================== --- trunk/Source/StructureMap.DeploymentTasks/Versioning/GenerateVersionReport.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.DeploymentTasks/Versioning/GenerateVersionReport.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -10,18 +10,14 @@ private string _directory; private string _outputPath; - public GenerateVersionReport() : base() - { - } - - [TaskAttribute("directory", Required=true)] + [TaskAttribute("directory", Required = true)] public string Directory { get { return _directory; } set { _directory = value; } } - [TaskAttribute("manifest", Required=true)] + [TaskAttribute("manifest", Required = true)] public string OutputPath { get { return _outputPath; } @@ -33,8 +29,8 @@ Log(Level.Info, string.Format("Generating a versioning manifest file for {0} to {1}", _directory, _outputPath)); - DirectoryInfo directoryInfo = new DirectoryInfo(_directory); - DeployedDirectory deployedDirectory = new DeployedDirectory(directoryInfo); + var directoryInfo = new DirectoryInfo(_directory); + var deployedDirectory = new DeployedDirectory(directoryInfo); deployedDirectory.WriteToXml(_outputPath); } Modified: trunk/Source/StructureMap.Testing.GenericWidgets/Properties/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap.Testing.GenericWidgets/Properties/AssemblyInfo.cs 2008-10-01 18:29:38 UTC (rev 160) +++ trunk/Source/StructureMap.Testing.GenericWidgets/Properties/AssemblyInfo.cs 2008-10-02 01:05:46 UTC (rev 161) @@ -5,24 +5,24 @@ // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly : AssemblyTitle("StructureMap.Testing.GenericWidgets")] -[assembly : AssemblyDescription("")] -[assembly : AssemblyConfiguration("")] -[assembly : AssemblyCompany("")] -[assembly : AssemblyProduct("StructureMap.Testing.GenericWidgets")] -[assembly : AssemblyCopyright("Copyright \xA9 2006")] -[assembly : AssemblyTrademark("")] -[assembly : AssemblyCulture("")] +[assembly: AssemblyTitle("StructureMap.Testing.GenericWidgets")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StructureMap.Testing.GenericWidgets")] +[assembly: AssemblyCopyright("Copyright \xA9 2006")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. -[assembly : ComVisible(false)] +[assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly : Guid("1af9fe... [truncated message content] |
From: <fli...@us...> - 2008-09-25 23:18:22
|
Revision: 156 http://structuremap.svn.sourceforge.net/structuremap/?rev=156&view=rev Author: flimflan Date: 2008-09-25 23:18:11 +0000 (Thu, 25 Sep 2008) Log Message: ----------- Added support for automatically creating mocks that are compatible with the Rhino.Mocks AAA style of tests. Modified Paths: -------------- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs Property Changed: ---------------- trunk/Source/StructureMap.AutoMocking/ Property changes on: trunk/Source/StructureMap.AutoMocking ___________________________________________________________________ Modified: svn:ignore - bin obj + bin obj [Bb]in [Dd]ebug [Rr]elease *.user *.aps *.eto Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-09-25 17:38:24 UTC (rev 155) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-09-25 23:18:11 UTC (rev 156) @@ -11,6 +11,9 @@ public delegate void VoidMethod(); + public enum MockStyle { Dynamic, DynamicWithAAASupport } + + // Note that it subclasses the RhinoMocks.MockRepository class /// <summary> /// Provides an "Auto Mocking Container" for the concrete class TARGETCLASS /// </summary> @@ -20,10 +23,23 @@ private readonly AutoMockedContainer _container; private TARGETCLASS _classUnderTest; - public RhinoAutoMocker() + public RhinoAutoMocker() : this(MockStyle.Dynamic) {} + + public RhinoAutoMocker(MockStyle mockStyle) { - var locator = new RhinoMocksServiceLocator(this); - _container = new AutoMockedContainer(locator); + ServiceLocator serviceLocator; + switch (mockStyle) + { + case MockStyle.DynamicWithAAASupport: + serviceLocator = new RhinoMocksAAAServiceLocator(this); + break; + case MockStyle.Dynamic: + serviceLocator = new RhinoMocksServiceLocator(this); + break; + default: + throw new InvalidOperationException("Unsupported MockStyle " + mockStyle); + } + _container = new AutoMockedContainer(serviceLocator); } Modified: trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs 2008-09-25 17:38:24 UTC (rev 155) +++ trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs 2008-09-25 23:18:11 UTC (rev 156) @@ -31,4 +31,36 @@ #endregion } + + public class RhinoMocksAAAServiceLocator : ServiceLocator + { + private readonly MockRepository _mocks; + + public RhinoMocksAAAServiceLocator(MockRepository mocks) + { + _mocks = mocks; + } + + + public RhinoMocksAAAServiceLocator() + : this(new MockRepository()) + { + } + + #region ServiceLocator Members + + public T Service<T>() + { + return MockRepository.GenerateMock<T>(); + } + + public object Service(Type serviceType) + { + var mock = _mocks.DynamicMock(serviceType); + _mocks.Replay(mock); + return mock; + } + + #endregion + } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-09-25 17:38:24 UTC (rev 155) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-09-25 23:18:11 UTC (rev 156) @@ -85,6 +85,11 @@ { get { return _service3; } } + + public void CallService() + { + _service.Go(); + } } public interface IMockedService @@ -326,5 +331,16 @@ Assert.AreEqual("Max", concreteClass.Name); } + + [Test] + public void TheAutoMockerOptionallyPushesInMocksInReplayModeToAllowForAAAsyntax() + { + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockStyle.DynamicWithAAASupport); + + autoMocker.ClassUnderTest.CallService(); + + autoMocker.Get<IMockedService>().AssertWasCalled(s => s.Go()); + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2008-09-26 01:03:25
|
Revision: 157 http://structuremap.svn.sourceforge.net/structuremap/?rev=157&view=rev Author: flimflan Date: 2008-09-26 01:03:19 +0000 (Fri, 26 Sep 2008) Log Message: ----------- Cleaning up AAA support in RhinoAutoMocker Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-09-25 23:18:11 UTC (rev 156) +++ trunk/Source/CommonAssemblyInfo.cs 2008-09-26 01:03:19 UTC (rev 157) @@ -5,7 +5,7 @@ //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. -// Runtime Version:2.0.50727.1434 +// Runtime Version:2.0.50727.1433 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-09-25 23:18:11 UTC (rev 156) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-09-26 01:03:19 UTC (rev 157) @@ -11,7 +11,7 @@ public delegate void VoidMethod(); - public enum MockStyle { Dynamic, DynamicWithAAASupport } + public enum MockMode { Record, Replay } // Note that it subclasses the RhinoMocks.MockRepository class /// <summary> @@ -23,23 +23,27 @@ private readonly AutoMockedContainer _container; private TARGETCLASS _classUnderTest; - public RhinoAutoMocker() : this(MockStyle.Dynamic) {} + public RhinoAutoMocker() : this(MockMode.Record) {} - public RhinoAutoMocker(MockStyle mockStyle) + public RhinoAutoMocker(MockMode mockMode) { - ServiceLocator serviceLocator; - switch (mockStyle) + var mockCreationStrategy = getMockCreationStrategy(mockMode); + var serviceLocator = new RhinoMocksServiceLocator(this, mockCreationStrategy); + _container = new AutoMockedContainer(serviceLocator); + } + + + private static Func<MockRepository, Type, object> getMockCreationStrategy(MockMode mockMode) + { + switch (mockMode) { - case MockStyle.DynamicWithAAASupport: - serviceLocator = new RhinoMocksAAAServiceLocator(this); - break; - case MockStyle.Dynamic: - serviceLocator = new RhinoMocksServiceLocator(this); - break; + case MockMode.Record: + return MockCreationStrategy.RecordMode; + case MockMode.Replay: + return MockCreationStrategy.ReplayMode; default: - throw new InvalidOperationException("Unsupported MockStyle " + mockStyle); + throw new InvalidOperationException("Unsupported MockMode " + mockMode); } - _container = new AutoMockedContainer(serviceLocator); } Modified: trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs 2008-09-25 23:18:11 UTC (rev 156) +++ trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs 2008-09-26 01:03:19 UTC (rev 157) @@ -6,12 +6,17 @@ public class RhinoMocksServiceLocator : ServiceLocator { private readonly MockRepository _mocks; + private readonly Func<MockRepository, Type, object> mockCreationStrategy; - public RhinoMocksServiceLocator(MockRepository mocks) + public RhinoMocksServiceLocator(MockRepository mocks, Func<MockRepository, Type, object> mockCreationStrategy) { _mocks = mocks; + this.mockCreationStrategy = mockCreationStrategy; } + public RhinoMocksServiceLocator(MockRepository mocks) : this(mocks, MockCreationStrategy.RecordMode) + { + } public RhinoMocksServiceLocator() : this(new MockRepository()) { @@ -21,46 +26,30 @@ public T Service<T>() { - return _mocks.DynamicMock<T>(); + return (T)mockCreationStrategy(_mocks, typeof (T)); } public object Service(Type serviceType) { - return _mocks.DynamicMock(serviceType); + return mockCreationStrategy(_mocks, serviceType); } #endregion } - public class RhinoMocksAAAServiceLocator : ServiceLocator + public static class MockCreationStrategy { - private readonly MockRepository _mocks; - - public RhinoMocksAAAServiceLocator(MockRepository mocks) + public static object RecordMode(MockRepository repository, Type type) { - _mocks = mocks; + return repository.DynamicMock(type); } - - public RhinoMocksAAAServiceLocator() - : this(new MockRepository()) + public static object ReplayMode(MockRepository repository, Type type) { - } - - #region ServiceLocator Members - - public T Service<T>() - { - return MockRepository.GenerateMock<T>(); - } - - public object Service(Type serviceType) - { - var mock = _mocks.DynamicMock(serviceType); - _mocks.Replay(mock); + var mock = repository.DynamicMock(type); + repository.Replay(mock); return mock; } - - #endregion } + } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-09-25 23:18:11 UTC (rev 156) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-09-26 01:03:19 UTC (rev 157) @@ -335,7 +335,7 @@ [Test] public void TheAutoMockerOptionallyPushesInMocksInReplayModeToAllowForAAAsyntax() { - var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockStyle.DynamicWithAAASupport); + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.Replay); autoMocker.ClassUnderTest.CallService(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-05 04:07:08
|
Revision: 175 http://structuremap.svn.sourceforge.net/structuremap/?rev=175&view=rev Author: jeremydmiller Date: 2008-10-05 04:04:34 +0000 (Sun, 05 Oct 2008) Log Message: ----------- Incorporating patches for Mono support. That's right, I said Mono support Modified Paths: -------------- trunk/Source/HTML/ConstructorAndSetterInjection.htm trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs trunk/Source/StructureMap/Source/XmlFileMementoSource.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/SetterInjectionTesting.xml trunk/Source/StructureMap.sln Modified: trunk/Source/HTML/ConstructorAndSetterInjection.htm =================================================================== --- trunk/Source/HTML/ConstructorAndSetterInjection.htm 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/HTML/ConstructorAndSetterInjection.htm 2008-10-05 04:04:34 UTC (rev 175) @@ -328,7 +328,7 @@ <p>I can direct StructureMap to use these properties in a <Plugin> node for OtherGridColumn.</p> <!-- -{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 \tab <\cf3 PluginFamily\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5.IGridColumn\cf0 "\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5\cf0 "\cf1 \cf4 DefaultKey\cf1 =\cf0 ""\cf1 >\par ??\tab \tab <\cf3 Source\cf1 \cf4 Type\cf1 =\cf0 "\cf1 XmlFile\cf0 "\cf1 \cf4 FilePath\cf1 =\cf0 "\cf1 GridColumnInstances.XML\cf0 "\cf1 \cf4 XPath\cf1 =\cf0 "\cf1 //GridColumns\cf0 "\cf1 \cf4 NodeName\cf1 =\cf0 "\cf1 GridColumn\cf0 "\cf1 />\par ??\tab \tab <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5.OtherGridColumn\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Other\cf0 "\cf1 >\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 ColumnName\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 FontStyle\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 Rules\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 Widget\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 WrapLines\cf0 "\cf1 />\par ??\tab \tab </\cf3 Plugin\cf1 >\par ??\tab </\cf3 PluginFamily\cf1 >} +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 \tab <\cf3 PluginFamily\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5.IGridColumn\cf0 "\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5\cf0 "\cf1 \cf4 DefaultKey\cf1 =\cf0 ""\cf1 >\par ??\tab \tab <\cf3 Source\cf1 \cf4 Type\cf1 =\cf0 "\cf1 XmlFile\cf0 "\cf1 \cf4 FilePath\cf1 =\cf0 "\cf1 GridColumnInstances.xml\cf0 "\cf1 \cf4 XPath\cf1 =\cf0 "\cf1 //GridColumns\cf0 "\cf1 \cf4 NodeName\cf1 =\cf0 "\cf1 GridColumn\cf0 "\cf1 />\par ??\tab \tab <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5.OtherGridColumn\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Other\cf0 "\cf1 >\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 ColumnName\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 FontStyle\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 Rules\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 Widget\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 WrapLines\cf0 "\cf1 />\par ??\tab \tab </\cf3 Plugin\cf1 >\par ??\tab </\cf3 PluginFamily\cf1 >} --> <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> <p style="margin: 0px;"> Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-10-05 04:04:34 UTC (rev 175) @@ -149,7 +149,7 @@ private static Assembly findTheCallingAssembly() { - var trace = new StackTrace(Thread.CurrentThread, false); + var trace = new StackTrace(false); Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); Assembly callingAssembly = null; Modified: trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs 2008-10-05 04:04:34 UTC (rev 175) @@ -65,20 +65,12 @@ private string resolvePath(string directory) { - string returnValue = string.Empty; - if (!Path.IsPathRooted(directory)) { - returnValue = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; - returnValue += "\\" + directory; - returnValue = returnValue.Replace("\\\\", "\\"); + return Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, directory); } - else - { - returnValue = Path.GetFullPath(directory); - } - return returnValue; + return Path.GetFullPath(directory); } @@ -104,7 +96,7 @@ private string getFilePath(string instanceKey) { - return string.Format("{0}\\{1}.{2}", _directory, instanceKey, _extension); + return Path.Combine(_directory, string.Format("{0}.{1}", instanceKey, _extension)); } protected override InstanceMemento retrieveMemento(string instanceKey) Modified: trunk/Source/StructureMap/Source/XmlFileMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlFileMementoSource.cs 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap/Source/XmlFileMementoSource.cs 2008-10-05 04:04:34 UTC (rev 175) @@ -81,16 +81,10 @@ // crude work-around for web application problems if (!Path.IsPathRooted(_filePath)) { - string relativePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; - relativePath += "\\" + _filePath; - relativePath = relativePath.Replace("\\\\", "\\"); - - return relativePath; + return Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase, _filePath); } - else - { - return _filePath; - } + + return _filePath; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-10-05 04:04:34 UTC (rev 175) @@ -105,7 +105,8 @@ if (!File.Exists(configPath)) { - configPath = Path.Combine(basePath, @"..\" + CONFIG_FILE_NAME); + configPath = Path.Combine(basePath, ".."); + configPath = Path.Combine(configPath, CONFIG_FILE_NAME); } } Modified: trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs 2008-10-05 04:04:34 UTC (rev 175) @@ -49,7 +49,7 @@ </PluginFamily> <PluginFamily Type='StructureMap.Testing.Widget5.IGridColumn' Assembly='StructureMap.Testing.Widget5' DefaultKey=''> - <Source Type='XmlFile' FilePath='GridColumnInstances.XML' XPath='//GridColumns' NodeName='GridColumn'/> + <Source Type='XmlFile' FilePath='GridColumnInstances.xml' XPath='//GridColumns' NodeName='GridColumn'/> <Plugin Assembly='StructureMap.Testing.Widget5' Type='StructureMap.Testing.Widget5.OtherGridColumn' ConcreteKey='Other'> <Setter Name='ColumnName' /> <Setter Name='FontStyle' /> Modified: trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap.Testing/Graph/SetterInjectionTester.cs 2008-10-05 04:04:34 UTC (rev 175) @@ -47,7 +47,7 @@ </PluginFamily> <PluginFamily Type='StructureMap.Testing.Widget5.IGridColumn' Assembly='StructureMap.Testing.Widget5' DefaultKey=''> - <Source Type='XmlFile' FilePath='GridColumnInstances.XML' XPath='//GridColumns' NodeName='GridColumn'/> + <Source Type='XmlFile' FilePath='GridColumnInstances.xml' XPath='//GridColumns' NodeName='GridColumn'/> <Plugin Assembly='StructureMap.Testing.Widget5' Type='StructureMap.Testing.Widget5.OtherGridColumn' ConcreteKey='Other'> <Setter Name='ColumnName' /> <Setter Name='FontStyle' /> Modified: trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap.Testing/Graph/Source/DirectoryXmlMementoSourceTester.cs 2008-10-05 04:04:34 UTC (rev 175) @@ -23,9 +23,9 @@ string instance3 = "<Instance Key=\"Bigger\" Type=\"GreaterThan\"><Property Name=\"Attribute\" Value=\"MyDad\" /><Property Name=\"Value\" Value=\"10\" /></Instance>"; - writeFile(instance1, @"MementoDirectory\Red.xml"); - writeFile(instance2, @"MementoDirectory\Blue.xml"); - writeFile(instance3, @"MementoDirectory\Bigger.xml"); + writeFile(instance1, Path.Combine("MementoDirectory", "Red.xml")); + writeFile(instance2, Path.Combine("MementoDirectory", "Blue.xml")); + writeFile(instance3, Path.Combine("MementoDirectory", "Bigger.xml")); _source = new DirectoryXmlMementoSource("MementoDirectory", "xml", XmlMementoStyle.NodeNormalized); } Modified: trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs 2008-10-05 04:04:34 UTC (rev 175) @@ -12,8 +12,9 @@ [SetUp] public void SetUp() { - DataMother.WriteDocument("RuleSource.xml"); - source = new XmlFileMementoSource("RuleSource.XML", "", "Rule"); + var theFileName = "RuleSource.xml"; + DataMother.WriteDocument(theFileName); + source = new XmlFileMementoSource(theFileName, "", "Rule"); } #endregion Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-05 04:04:34 UTC (rev 175) @@ -121,10 +121,6 @@ <Project>{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}</Project> <Name>StructureMap.AutoMocking</Name> </ProjectReference> - <ProjectReference Include="..\StructureMap.DataAccess\StructureMap.DataAccess.csproj"> - <Project>{DB798C07-0C82-4298-8BAA-D702CF96C28E}</Project> - <Name>StructureMap.DataAccess</Name> - </ProjectReference> <ProjectReference Include="..\StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj"> <Project>{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}</Project> <Name>StructureMap.Testing.GenericWidgets</Name> @@ -284,38 +280,6 @@ <SubType>Code</SubType> </Compile> <Compile Include="Graph\TypeFindingTester.cs" /> - <Compile Include="DataAccess\CommandCollectionTester.cs" /> - <Compile Include="DataAccess\CommandFactoryTester.cs" /> - <Compile Include="DataAccess\Commands\ParameterizedQueryFilterTester.cs" /> - <Compile Include="DataAccess\Commands\StoredProcedureCommandTester.cs" /> - <Compile Include="DataAccess\Commands\TemplatedQueryFilterTester.cs" /> - <Compile Include="DataAccess\Commands\TemplatedQueryTester.cs" /> - <Compile Include="DataAccess\DataSessionTester.cs" /> - <Compile Include="DataAccess\DataSetMapping\ReaderToColumnMapTester.cs" /> - <Compile Include="DataAccess\DataSetMapping\ReaderToTableMapperTester.cs" /> - <Compile Include="DataAccess\DataSetMapping\YesNoReaderToColumnMapTester.cs" /> - <Compile Include="DataAccess\Debugging.cs" /> - <Compile Include="DataAccess\ExecutionStates\AutoCommitExecutionStateTester.cs" /> - <Compile Include="DataAccess\ExecutionStates\TransactionalExecutionStateTester.cs" /> - <Compile Include="DataAccess\JSON\ArrayTester.cs" /> - <Compile Include="DataAccess\JSON\FieldTester.cs" /> - <Compile Include="DataAccess\JSON\ObjectTester.cs" /> - <Compile Include="DataAccess\JSON\PropertyTester.cs" /> - <Compile Include="DataAccess\MSSQL\MSSQLDatabaseEngineTester.cs" /> - <Compile Include="DataAccess\ObjectMother.cs" /> - <Compile Include="DataAccess\Parameterization\ParameterizedCommandBuilderTester.cs" /> - <Compile Include="DataAccess\Parameterization\ParameterTemplateTester.cs" /> - <Compile Include="DataAccess\Parameters\TemplateParameterTester.cs" /> - <Compile Include="DataAccess\ReaderSourceCollectionTester.cs" /> - <Compile Include="DataAccess\StubbedCommand.cs" /> - <Compile Include="DataAccess\StubbedReaderSource.cs" /> - <Compile Include="DataAccess\TemplatedCommandTester.cs" /> - <Compile Include="DataAccess\Tools\Mocks\CommandExpectationTester.cs" /> - <Compile Include="DataAccess\Tools\Mocks\MockCommandTester.cs" /> - <Compile Include="DataAccess\Tools\Mocks\MockDataSessionTester.cs" /> - <Compile Include="DataAccess\Tools\Mocks\MockReaderSourceTester.cs" /> - <Compile Include="DataAccess\Tools\Mocks\ParameterListTester.cs" /> - <Compile Include="DataAccess\Tools\TableDataReaderTester.cs" /> <Compile Include="Diagnostics\IntegrationTester.cs" /> <Compile Include="Diagnostics\TextReportWriterSmokeTester.cs" /> <Compile Include="GenericsAcceptanceTester.cs" /> Modified: trunk/Source/StructureMap.Testing/TestData/SetterInjectionTesting.xml =================================================================== --- trunk/Source/StructureMap.Testing/TestData/SetterInjectionTesting.xml 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap.Testing/TestData/SetterInjectionTesting.xml 2008-10-05 04:04:34 UTC (rev 175) @@ -22,7 +22,7 @@ </PluginFamily> <PluginFamily Type="StructureMap.Testing.Widget5.IGridColumn" Assembly="StructureMap.Testing.Widget5" DefaultKey=""> - <Source Type="XmlFile" FilePath="GridColumnInstances.XML" XPath="//GridColumns" NodeName="GridColumn"/> + <Source Type="XmlFile" FilePath="GridColumnInstances.xml" XPath="//GridColumns" NodeName="GridColumn"/> <Plugin Assembly="StructureMap.Testing.Widget5" Type="StructureMap.Testing.Widget5.OtherGridColumn" ConcreteKey="Other"> <Setter Name="ColumnName" /> <Setter Name="FontStyle" /> Modified: trunk/Source/StructureMap.sln =================================================================== --- trunk/Source/StructureMap.sln 2008-10-05 03:29:12 UTC (rev 174) +++ trunk/Source/StructureMap.sln 2008-10-05 04:04:34 UTC (rev 175) @@ -46,8 +46,6 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.Testing.GenericWidgets", "StructureMap.Testing.GenericWidgets\StructureMap.Testing.GenericWidgets.csproj", "{C205EA4C-4CD0-4221-A3CB-AFD835F0B263}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.DataAccess", "StructureMap.DataAccess\StructureMap.DataAccess.csproj", "{DB798C07-0C82-4298-8BAA-D702CF96C28E}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.AutoMocking", "StructureMap.AutoMocking\StructureMap.AutoMocking.csproj", "{0ED1B206-A1C9-4A52-BA87-3BA416C8725C}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMapDoctor", "StructureMapDoctor\StructureMapDoctor.csproj", "{9048635D-A2CE-4387-A4F5-9BB1CFF04703}" @@ -202,21 +200,6 @@ {C205EA4C-4CD0-4221-A3CB-AFD835F0B263}.Release|Any CPU.Build.0 = Release|Any CPU {C205EA4C-4CD0-4221-A3CB-AFD835F0B263}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {C205EA4C-4CD0-4221-A3CB-AFD835F0B263}.Release|Mixed Platforms.Build.0 = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Build|.NET.ActiveCfg = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Build|Any CPU.ActiveCfg = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Build|Any CPU.Build.0 = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Build|Mixed Platforms.ActiveCfg = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Build|Mixed Platforms.Build.0 = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Debug|.NET.ActiveCfg = Debug|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Release|.NET.ActiveCfg = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Release|Any CPU.Build.0 = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU - {DB798C07-0C82-4298-8BAA-D702CF96C28E}.Release|Mixed Platforms.Build.0 = Release|Any CPU {0ED1B206-A1C9-4A52-BA87-3BA416C8725C}.Build|.NET.ActiveCfg = Release|Any CPU {0ED1B206-A1C9-4A52-BA87-3BA416C8725C}.Build|Any CPU.ActiveCfg = Release|Any CPU {0ED1B206-A1C9-4A52-BA87-3BA416C8725C}.Build|Any CPU.Build.0 = Release|Any CPU This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-06 16:22:15
|
Revision: 176 http://structuremap.svn.sourceforge.net/structuremap/?rev=176&view=rev Author: jeremydmiller Date: 2008-10-06 14:52:15 +0000 (Mon, 06 Oct 2008) Log Message: ----------- fixing a bug with using arrays as a constraint in a generic type Modified Paths: -------------- trunk/Source/HTML/FluentInterfaceAPI.htm trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Examples/ trunk/Source/StructureMap.Testing/Examples/RegisteringWithTheAPI.cs Modified: trunk/Source/HTML/FluentInterfaceAPI.htm =================================================================== --- trunk/Source/HTML/FluentInterfaceAPI.htm 2008-10-05 04:04:34 UTC (rev 175) +++ trunk/Source/HTML/FluentInterfaceAPI.htm 2008-10-06 14:52:15 UTC (rev 176) @@ -1,10 +1,13 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> - <title></title> + <title>Configuring StructureMap with the Programmatic API</title> </head> <body> - <h4>Adding an Instance by Type</h4> + <h4>Configuring StructureMap with the Programmatic API</h4> + <p> + </p> + </body> </html> \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-10-05 04:04:34 UTC (rev 175) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2008-10-06 14:52:15 UTC (rev 176) @@ -5,8 +5,22 @@ { public interface IsExpression<T> { + /// <summary> + /// Gives you full access to all the different ways to specify an "Instance" + /// </summary> InstanceExpression<T> Is { get; } + + /// <summary> + /// Shortcut to specify a prebuilt Instance + /// </summary> + /// <param name="instance"></param> void IsThis(Instance instance); + + /// <summary> + /// Shortcut to directly inject an object + /// </summary> + /// <param name="obj"></param> + /// <returns></returns> LiteralInstance IsThis(T obj); } Modified: trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs =================================================================== --- trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-10-05 04:04:34 UTC (rev 175) +++ trunk/Source/StructureMap/Emitting/InstanceBuilderAssembly.cs 2008-10-06 14:52:15 UTC (rev 176) @@ -58,7 +58,7 @@ private static string escapeClassName(Type type) { string typeName = type.Namespace + type.Name; - string returnValue = typeName.Replace(".", string.Empty); + string returnValue = typeName.Replace(".", string.Empty).Replace("[]", "Array"); return returnValue.Replace("`", string.Empty); } Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-10-05 04:04:34 UTC (rev 175) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-10-06 14:52:15 UTC (rev 176) @@ -23,7 +23,7 @@ { get { - foreach (PluginFamily family in _families) + foreach (PluginFamily family in _families.GetAll()) { yield return family.GetConfiguration(); } Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2008-10-05 04:04:34 UTC (rev 175) +++ trunk/Source/StructureMap/PipelineGraph.cs 2008-10-06 14:52:15 UTC (rev 176) @@ -74,10 +74,11 @@ yield return configuration; } - foreach (var pair in _factories) + IInstanceFactory[] factories = new IInstanceFactory[_factories.Count]; + _factories.Values.CopyTo(factories, 0); + + foreach (var factory in factories) { - IInstanceFactory factory = pair.Value; - yield return new PluginTypeConfiguration { Default = _profileManager.GetDefault(factory.PluginType), Added: trunk/Source/StructureMap.Testing/Examples/RegisteringWithTheAPI.cs =================================================================== --- trunk/Source/StructureMap.Testing/Examples/RegisteringWithTheAPI.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Examples/RegisteringWithTheAPI.cs 2008-10-06 14:52:15 UTC (rev 176) @@ -0,0 +1,58 @@ +using StructureMap.Configuration.DSL; + +namespace StructureMap.Testing.Examples +{ + public interface IRepository + { + } + + public class InMemoryRepository : IRepository + { + } + + public class DatabaseRepository : IRepository + { + public DatabaseRepository(string connectionString) + { + } + } + + // WeirdLegacyRepository is some sort of Singleton that we + // can't create directly with a constructor function + public class WeirdLegacyRepository : IRepository + { + private WeirdLegacyRepository() + { + } + + public static WeirdLegacyRepository Current { get; set; } + } + + + public class RepositoryRegistry : Registry + { + public RepositoryRegistry() + { + // First I'll specify the "default" Instance of IRepository + ForRequestedType<IRepository>().TheDefaultIsConcreteType<InMemoryRepository>(); + + // Now, I'll add three more Instances of IRepository + ForRequestedType<IRepository>().AddInstances(x => + { + // "NorthAmerica" is the concrete type DatabaseRepository with + // the connectionString pointed to the NorthAmerica database + x.OfConcreteType<DatabaseRepository>().WithName("NorthAmerica") + .WithCtorArg("connectionString").EqualTo("database=NorthAmerica"); + + // "Asia/Pacific" is the concrete type DatabaseRepository with + // the connectionString pointed to the AsiaPacific database + x.OfConcreteType<DatabaseRepository>().WithName("Asia/Pacific") + .WithCtorArg("connectionString").EqualTo("database=AsiaPacific"); + + // Lastly, the "Weird" instance is built by calling a specified + // Lambda (an anonymous delegate will work as well). + x.ConstructedBy(() => WeirdLegacyRepository.Current).WithName("Weird"); + }); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-05 04:04:34 UTC (rev 175) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-10-06 14:52:15 UTC (rev 176) @@ -205,6 +205,7 @@ <Compile Include="Examples.cs"> <SubType>Form</SubType> </Compile> + <Compile Include="Examples\RegisteringWithTheAPI.cs" /> <Compile Include="Graph\ArrayConstructorTester.cs"> <SubType>Code</SubType> </Compile> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2008-10-08 20:12:29
|
Revision: 179 http://structuremap.svn.sourceforge.net/structuremap/?rev=179&view=rev Author: flimflan Date: 2008-10-08 20:12:24 +0000 (Wed, 08 Oct 2008) Log Message: ----------- Fixed AAA support for PartialMockTheClassUnderTest, AddAdditionalMockFor, and CreateMockArrayFor Modified Paths: -------------- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-10-08 19:29:40 UTC (rev 178) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-10-08 20:12:24 UTC (rev 179) @@ -22,14 +22,15 @@ { private readonly AutoMockedContainer _container; private TARGETCLASS _classUnderTest; + private readonly RhinoMocksServiceLocator _serviceLocator; public RhinoAutoMocker() : this(MockMode.RecordAndReplay) {} public RhinoAutoMocker(MockMode mockMode) { var mockCreationStrategy = getMockCreationStrategy(mockMode); - var serviceLocator = new RhinoMocksServiceLocator(this, mockCreationStrategy); - _container = new AutoMockedContainer(serviceLocator); + _serviceLocator = new RhinoMocksServiceLocator(this, mockCreationStrategy); + _container = new AutoMockedContainer(_serviceLocator); } @@ -159,7 +160,7 @@ /// <returns></returns> public T AddAdditionalMockFor<T>() where T : class { - var mock = DynamicMock<T>(); + var mock = _serviceLocator.Service<T>(); _container.Configure(r => r.InstanceOf<T>().Is.Object(mock)); return mock; @@ -190,7 +191,7 @@ for (int i = 0; i < returnValue.Length; i++) { - returnValue[i] = DynamicMock<T>(); + returnValue[i] = _serviceLocator.Service<T>(); } InjectArray(returnValue); Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-10-08 19:29:40 UTC (rev 178) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-10-08 20:12:24 UTC (rev 179) @@ -338,9 +338,72 @@ var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.AAA); autoMocker.ClassUnderTest.CallService(); + autoMocker.IsInReplayMode(autoMocker.Get<IMockedService>()).ShouldBeTrue(); autoMocker.Get<IMockedService>().AssertWasCalled(s => s.Go()); } + public interface IAnotherService + { + + } + + [Test] + public void AddAdditionalMockForCreatesMocksInRecordModeWhenUsingRecordReplay() + { + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.RecordAndReplay); + autoMocker.AddAdditionalMockFor<IAnotherService>(); + + autoMocker.IsInReplayMode(autoMocker.Get<IAnotherService>()).ShouldBeFalse(); + } + + [Test] + public void AddAdditionalMockForCreatesMocksInReplayModeWhenUsingAAA() + { + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.AAA); + autoMocker.AddAdditionalMockFor<IAnotherService>(); + + autoMocker.IsInReplayMode(autoMocker.Get<IAnotherService>()).ShouldBeTrue(); + } + + [Test] + public void CreateMockArrayForCreatesMocksInRecordModeWhenUsingReplayRecord() + { + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.RecordAndReplay); + var mockArray = autoMocker.CreateMockArrayFor<IAnotherService>(3); + foreach (var service in mockArray) + { + autoMocker.IsInReplayMode(service).ShouldBeFalse(); + } + } + + [Test] + public void CreateMockArrayForCreatesMocksInReplayModeWhenUsingAAA() + { + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.AAA); + var mockArray = autoMocker.CreateMockArrayFor<IAnotherService>(3); + foreach (var service in mockArray) + { + autoMocker.IsInReplayMode(service).ShouldBeTrue(); + } + } + + [Test] + public void PartialMockClassUnderTestCreatesMocksInRecordModeWhenUsingRecordReplay() + { + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.RecordAndReplay); + autoMocker.PartialMockTheClassUnderTest(); + + autoMocker.IsInReplayMode(autoMocker.Get<IMockedService>()).ShouldBeFalse(); + } + + [Test] + public void PartialMockClassUnderTestCreatesMocksInReplayModeWhenUsingAAA() + { + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.AAA); + autoMocker.PartialMockTheClassUnderTest(); + + autoMocker.IsInReplayMode(autoMocker.Get<IMockedService>()).ShouldBeTrue(); + } } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2008-10-08 20:38:59
|
Revision: 180 http://structuremap.svn.sourceforge.net/structuremap/?rev=180&view=rev Author: flimflan Date: 2008-10-08 20:38:53 +0000 (Wed, 08 Oct 2008) Log Message: ----------- PartialMockTheClassUnderTest now puts the class under test in replay mode when using MockMode.AAA Modified Paths: -------------- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-10-08 20:12:24 UTC (rev 179) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-10-08 20:38:53 UTC (rev 180) @@ -23,25 +23,26 @@ private readonly AutoMockedContainer _container; private TARGETCLASS _classUnderTest; private readonly RhinoMocksServiceLocator _serviceLocator; + private readonly Func<object, object> _mockDecorator; public RhinoAutoMocker() : this(MockMode.RecordAndReplay) {} public RhinoAutoMocker(MockMode mockMode) { - var mockCreationStrategy = getMockCreationStrategy(mockMode); - _serviceLocator = new RhinoMocksServiceLocator(this, mockCreationStrategy); + _mockDecorator = getMockDecorator(mockMode); + _serviceLocator = new RhinoMocksServiceLocator(this, _mockDecorator); _container = new AutoMockedContainer(_serviceLocator); } - private static Func<MockRepository, Type, object> getMockCreationStrategy(MockMode mockMode) + private static Func<object, object> getMockDecorator(MockMode mockMode) { switch (mockMode) { case MockMode.RecordAndReplay: - return MockCreationStrategy.RecordMode; + return MockDecorator.Nullo; case MockMode.AAA: - return MockCreationStrategy.ReplayMode; + return MockDecorator.PutInReplayMode; default: throw new InvalidOperationException("Unsupported MockMode " + mockMode); } @@ -88,7 +89,7 @@ /// </summary> public void PartialMockTheClassUnderTest() { - _classUnderTest = PartialMock<TARGETCLASS>(getConstructorArgs()); + _classUnderTest = (TARGETCLASS)_mockDecorator(PartialMock<TARGETCLASS>(getConstructorArgs())); } private object[] getConstructorArgs() Modified: trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs 2008-10-08 20:12:24 UTC (rev 179) +++ trunk/Source/StructureMap.AutoMocking/RhinoMocksServiceLocator.cs 2008-10-08 20:38:53 UTC (rev 180) @@ -6,15 +6,15 @@ public class RhinoMocksServiceLocator : ServiceLocator { private readonly MockRepository _mocks; - private readonly Func<MockRepository, Type, object> mockCreationStrategy; + private readonly Func<object, object> _mockDecorator; - public RhinoMocksServiceLocator(MockRepository mocks, Func<MockRepository, Type, object> mockCreationStrategy) + public RhinoMocksServiceLocator(MockRepository mocks, Func<object, object> mockDecorator) { _mocks = mocks; - this.mockCreationStrategy = mockCreationStrategy; + _mockDecorator = mockDecorator; } - public RhinoMocksServiceLocator(MockRepository mocks) : this(mocks, MockCreationStrategy.RecordMode) + public RhinoMocksServiceLocator(MockRepository mocks) : this(mocks, MockDecorator.Nullo) { } @@ -26,28 +26,27 @@ public T Service<T>() { - return (T)mockCreationStrategy(_mocks, typeof (T)); + return (T) Service(typeof (T)); } public object Service(Type serviceType) { - return mockCreationStrategy(_mocks, serviceType); + return _mockDecorator(_mocks.DynamicMock(serviceType)); } #endregion } - public static class MockCreationStrategy + public static class MockDecorator { - public static object RecordMode(MockRepository repository, Type type) + public static object Nullo(object mock) { - return repository.DynamicMock(type); + return mock; } - public static object ReplayMode(MockRepository repository, Type type) + public static object PutInReplayMode(object mock) { - var mock = repository.DynamicMock(type); - repository.Replay(mock); + mock.Replay(); return mock; } } Modified: trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-10-08 20:12:24 UTC (rev 179) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs 2008-10-08 20:38:53 UTC (rev 180) @@ -405,5 +405,15 @@ autoMocker.IsInReplayMode(autoMocker.Get<IMockedService>()).ShouldBeTrue(); } + + [Test] + public void PartialMockClassUnderTestPutsTheClassUnderTestInReplayModeWhenUsingAAA() + { + var autoMocker = new RhinoAutoMocker<ConcreteClass>(MockMode.AAA); + autoMocker.PartialMockTheClassUnderTest(); + + autoMocker.IsInReplayMode(autoMocker.ClassUnderTest).ShouldBeTrue(); + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-10-18 03:05:58
|
Revision: 184 http://structuremap.svn.sourceforge.net/structuremap/?rev=184&view=rev Author: jeremydmiller Date: 2008-10-18 03:05:42 +0000 (Sat, 18 Oct 2008) Log Message: ----------- html updates, ndoc type documentation, merged rhino mocker Modified Paths: -------------- trunk/Source/HTML/ConstructorAndSetterInjection.htm trunk/Source/HTML/HTML.csproj trunk/Source/HTML/ScanningAssemblies.htm trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/Model.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/BuildStack.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/ServiceLocator.cs trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj trunk/Source/StructureMap.Testing/AutoMocking/RhinoAutoMockerTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/DeepInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Graph/IntegratedTester.cs trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs trunk/Source/StructureMap.Testing/Pipeline/OptionalSetterInjectionTester.cs trunk/Source/StructureMap.sln Added Paths: ----------- trunk/Source/HTML/Example.xml trunk/Source/StructureMap.AutoMocking/AutoMocker.cs Modified: trunk/Source/HTML/ConstructorAndSetterInjection.htm =================================================================== --- trunk/Source/HTML/ConstructorAndSetterInjection.htm 2008-10-17 19:00:37 UTC (rev 183) +++ trunk/Source/HTML/ConstructorAndSetterInjection.htm 2008-10-18 03:05:42 UTC (rev 184) @@ -11,7 +11,7 @@ <ol> <li>Constructor Injection -- "Pushing" dependencies into a concrete class through constructor arguments.</li> - <li>Setter Injection -- "Pushing" depencencies into a concrete class through public + <li>Setter Injection -- "Pushing" dependencies into a concrete class through public properties. The "Setter" nomenclature is taken from Java where properties are getSomething() and setSomething(value).</li> </ol> @@ -24,7 +24,7 @@ Martin Fowler's discussion on Constructor versus Setter Injection</a> for more information. My feeling has always been that Constructor Injection is preferrable from a design perspective. When you exclusively use - Constructor Injection, the code is somewhat self-documenting because the + Constructor Injection, the code is somewhat more self-documenting because the constructor arguments will clearly delineate the dependencies of a concrete class. It's also important to think about the constructor method of a class being a contract. If you satisfy all of the arguments of the @@ -33,10 +33,14 @@ which setters need to be created externally to use the class. Of course, not using any form of Dependency Injection can be the worst answer because then you have no idea what it really takes to bootstrap the service. </p> + <p>Despite my personal distaste for Setter Injection, I gave into user demand and + greatly increased StructureMap's support for Setter Injection -- and promptly + found that support to be more useful than I thought it would be.</p> <h2>Using Constructor Injection</h2> <p>Now, the first question you might ask is how does StructureMap know which constructor function to use in a class that has multiple constructors? The - answer is that StructureMap will automatically select the "greediest" public + answer is that StructureMap will automatically select the "greediest" + <b>public</b> constructor of a class to use for injection. In this case, the "greediest" constructor is the constructor with the most arguments. In the case of a tie, StructureMap will use the first constructor that it encountered. For @@ -111,96 +115,357 @@ [InternalsVisibleTo] attribute to give StructureMap access to your own internal members. StructureMap 2.5 is now strongly signed (thanks to <a href="http://stevenharman.net/">Steve Harman</a>) partially for this - scenario. There is an architectural limitation </p> + scenario. </p> <h2>Using Setter Injection</h2> <p>Setter injection is a pattern of "injecting" dependencies via public properties. - Setter Injection with StructureMap is admittedly a second class citizen, but + Setter Injection with StructureMap is somewhat a second class citizen, but this is partially by design. My strong recommendation is to use constructor injection for all code that you control, and save setter injection - strictly for classes from external libraries where you do not have any control. </p> + strictly for classes from external libraries where you do not have any control. + As a summary, these are the Setter Injection features that are described in + detail below:</p> + <ul> + <li>By default, all public "Setters" are optional, meaning that these setters will + only be set if they are explicitly configured for a specific Instance</li> + <li>StructureMap can be directed to "auto wire" a property for a given Instance</li> + <li>Setters can be made mandatory by decorating the property with the + [SetterProperty] attribute</li> + <li>Any type that StructureMap can use in constructor arguments can be used for + setter properties</li> + <li>StructureMap can be directed to automatically inject the default value for any + property of a given type. This was added primarily for "optional" + dependencies like logging.</li> + <li>The StructureMap diagnostic tools will check for missing Setter values</li> + </ul> - <p>Ok, now that you've read that I don't believe that setter injection is a good - idea, but you're bound and determined to use it anyway, let's talk about how to - do it with StructureMap. First off, StructureMap needs to be explicitly - told to build a concrete class with each setter. These setter properties - are then considered to be mandatory anytime an Instance of that concrete type is - requested. StructureMap does not support optional setter properties (but - it could easily be done with the new post processing support). That - restriction may be relaxed in later versions.</p> - <p>Once StructureMap does know to use a setter in constructing a class, configuring - the actual property values is done no differently than constructor arguments.</p> - <p>Let's say you have a class called Repository with these properties:</p> - + <h4>Configuring Primitive Setter Properties</h4> + <p>Ok, now that you've read that I don't believe that setter injection is a good + idea, but you're bound and determined to use it anyway, let's talk about how to + do it with StructureMap. Let's say we have this class with a string + property called "Name":</p> <!-- -{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IDataProvider\cf0 \{\}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 Repository\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 IDataProvider\cf0 _provider;\par ??\par ?? \cf3 public\cf0 \cf4 IDataProvider\cf0 Provider\par ?? \{\par ?? \cf3 set\par ??\cf0 \{\par ?? _provider = \cf3 value\cf0 ;\par ?? \}\par ?? \}\par ?? \}} +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 OptionalSetterTarget\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf3 string\cf0 Name \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 string\cf0 Name2 \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}} --> - <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> <p style="margin: 0px;"> - </p> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">OptionalSetterTarget</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">string</span> Name { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>;; }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>I can specify the value of the "Name" property in the configuration API like + this:</p> <!-- -{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IDataProvider\cf0 \{\}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 Repository\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 IDataProvider\cf0 _provider;\par ??\par ?? \cf3 public\cf0 \cf4 IDataProvider\cf0 Provider\par ?? \{\par ?? \cf3 set\par ??\cf0 \{\par ?? _provider = \cf3 value\cf0 ;\par ?? \}\par ?? \}\par ?? \}} +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 [\cf3 Test\cf0 ]\par ?? \cf4 public\cf0 \cf4 void\cf0 optional_setter_injection_with_string()\par ?? \{\par ?? \cf4 var\cf0 container = \cf4 new\cf0 \cf3 Container\cf0 (r =>\par ?? \{\par ?? \cf5 // The "Name" property is not configured for this instance\par ??\cf0 r.InstanceOf<\cf3 OptionalSetterTarget\cf0 >().Is.OfConcreteType<\cf3 OptionalSetterTarget\cf0 >().WithName(\cf6 "NoName"\cf0 );\par ??\par ?? \cf5 // The "Name" property is configured for this instance\par ??\cf0 r.ForConcreteType<\cf3 OptionalSetterTarget\cf0 >().Configure\par ?? .WithProperty(\cf6 "Name"\cf0 ).EqualTo(\cf6 "Jeremy"\cf0 );\par ?? \});\par ??\par ?? container.GetInstance<\cf3 OptionalSetterTarget\cf0 >().Name.ShouldEqual(\cf6 "Jeremy"\cf0 );\par ?? container.GetInstance<\cf3 OptionalSetterTarget\cf0 >(\cf6 "NoName"\cf0 ).Name.ShouldBeNull();\par ?? \}} --> - <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Test</span>]/p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> optional_setter_injection_with_string()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(r =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// The "Name" property is not configured for this + instance</span></p> + <p style="margin: 0px;"> + + r.InstanceOf<<span style="color: #2b91af;">OptionalSetterTarget</span>>().Is.OfConcreteType<<span + style="color: #2b91af;">OptionalSetterTarget</span>>().WithName(<span + style="color: #a31515;">"NoName"</span>);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// The "Name" property is configured for this + instance</span></p> + <p style="margin: 0px;"> + + r.ForConcreteType<<span style="color: #2b91af;">OptionalSetterTarget</span>>().Configure</p> + <p style="margin: 0px;"> + + .WithProperty(<span style="color: #a31515;">"Name"</span>).EqualTo(<span + style="color: #a31515;">"Jeremy"</span>);</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + container.GetInstance<<span style="color: #2b91af;">OptionalSetterTarget</span>>().Name.ShouldEqual(<span + style="color: #a31515;">"Jeremy"</span>);</p> + <p style="margin: 0px;"> + + container.GetInstance<<span style="color: #2b91af;">OptionalSetterTarget</span>>(<span + style="color: #a31515;">"NoName"</span>).Name.ShouldBeNull();</p> + <p style="margin: 0px;"> +& }</p> +</div> +<!--EndFragment--> +<p>In the case above I specified the value for the "Name" setter directly by + embedding the property value directly with the + WithProperty("Name").EqualTo("Jeremy"). You could also retrieve the value + for the property from the AppSettings portion of a .Net application config file + like this with the WithProperty("Name").EqualToAppSetting("name") syntax.</p> <!-- -{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IDataProvider\cf0 \{\}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 Repository\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 IDataProvider\cf0 _provider;\par ??\par ?? \cf3 public\cf0 \cf4 IDataProvider\cf0 Provider\par ?? \{\par ?? \cf3 set\par ??\cf0 \{\par ?? _provider = \cf3 value\cf0 ;\par ?? \}\par ?? \}\par ??\par ??\par ?? \cf3 public\cf0 \cf3 bool\cf0 ShouldCache \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}} +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (r =>\par ?? \{\par ?? \cf5 // The "Name" property is configured for this instance\par ??\cf0 r.ForConcreteType<\cf4 OptionalSetterTarget\cf0 >().Configure\par ?? .WithProperty(\cf6 "Name"\cf0 ).EqualToAppSetting(\cf6 "name"\cf0 );\par ?? \});} --> - <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> - <p style="margin: 0px;"> - <span style="color: blue;">public</span> <span style="color: blue;">interface</span> - <span style="color: #2b91af;">IDataProvider</span>{}</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(r =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + r.ForConcreteType<<span style="color: #2b91af;">OptionalSetterTarget</span>>().Configure</p> + <p style="margin: 0px;"> + + .WithProperty(<span style="color: #a31515;">"Name"</span>).EqualToAppSetting(<span + style="color: #a31515;">"name"</span>);</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p>In both of the cases above the property name is designated by a string. + Using strings to designate property names is always going to be somewhat + problematic, so there's a new option in 2.5 to specify property values with a + Lambda expression (inspired by + <a href="http://www.udidahan.com/2008/06/13/external-value-configuration-with-ioc/"> + this post from Udi Dahan</a>) using an Action<T>.</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 r.ForConcreteType<\cf3 OptionalSetterTarget\cf0 >().Configure\par ?? .SetProperty(x => x.Name = \cf4 "Jeremy"\cf0 );} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + r.ForConcreteType<<span style="color: #2b91af;">OptionalSetterTarget</span>>().Configure</p> + <p style="margin: 0px;"> + + .SetProperty(x => x.Name = <span style="color: #a31515;">"Jeremy"</span>);</p> +</div> +<!--EndFragment--> +<p>The value of the Lamdba expression mechanism is that it makes the configuration + static-typed with all of the advantages that static typing brings. This + action is executed on the object after creation. Technically, this + mechanism can be used to do anything to the new object before StructureMap + returns the new object to the code that requested it. There is no + limitation to the number of Action<T> handlers you can use. </p> +<p> </p> +<h4>Configuring Setter Dependencies</h4> + <p>Let's say you have a class that has a public property for a singular dependency + and another public property for an array of dependencies.</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 ClassWithDependency\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf4 Rule\cf0 Rule \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf4 Rule\cf0 [] Rules \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> - <span style="color: #2b91af;">Repository</span></p> - <p style="margin: 0px;"> + <span style="color: #2b91af;">ClassWithDependency</span></p> + <p style="margin: 0px;"> {</p> - <p style="margin: 0px;"> - <span style="color: blue;">private</span> - <span style="color: #2b91af;">IDataProvider</span> _provider;</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: #2b91af;">IDataProvider</span> Provider</p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - <span style="color: blue;">set</span></p> - <p style="margin: 0px;"> + <span style="color: #2b91af;">Rule</span> Rule { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: #2b91af;">Rule</span>[] Rules { <span style="color: blue;"> + get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> +& }</p> + </div> +<!--EndFragment--> +<p>I can explicitly configure what gets injected into the "Rule" property for a + specific Instance of ClassWithDependency like this with the + .SetterDependency<T>() method that will look for the first public setter of type + T:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20 r.ForConcreteType<\cf3 ClassWithDependency\cf0 >().Configure\par ?? .SetterDependency<\cf3 Rule\cf0 >().Is(\cf4 new\cf0 \cf3 ColorRule\cf0 (\cf5 "Red"\cf0 ));} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + r.ForConcreteType<<span style="color: #2b91af;">ClassWithDependency</span>>().Configure</p> + <p style="margin: 0px;"> + + .SetterDependency<<span style="color: #2b91af;">Rule</span>>().Is(<span + style="color: blue;">new</span> <span style="color: #2b91af;">ColorRule</span>(<span + style="color: #a31515;">"Red"</span>));</p> +</div> +<!--EndFragment--> +<p>or for cases where a class may have multiple public setters of the same type, you + can specify the exact property with an Expression (.SetterDependency<T>( + expression ) ):</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (r =>\par ?? \{\par ?? r.ForConcreteType<\cf4 ClassWithDependency\cf0 >().Configure\par ?? .SetterDependency<\cf4 Rule\cf0 >().Is(\cf3 new\cf0 \cf4 ColorRule\cf0 (\cf5 "Red"\cf0 ));\par ?? \});} +--> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (r =>\par ?? \{\par ?? r.ForConcreteType<\cf4 ClassWithDependency\cf0 >().Configure\par ?? .SetterDependency<\cf4 Rule\cf0 >(x => x.Rule).Is(\cf3 new\cf0 \cf4 ColorRule\cf0 (\cf5 "Red"\cf0 ));\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(r =></p> + <p style="margin: 0px;"> {</p> - <p style="margin: 0px;"> - _provider - = <span style="color: blue;">value</span>;</p> - <p style="margin: 0px;"> - }</p> - <p style="margin: 0px;"> - }</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> + <p style="margin: 0px;"> + + r.ForConcreteType<<span style="color: #2b91af;">ClassWithDependency</span>>().Configure</p> + <p style="margin: 0px;"> + + .SetterDependency<<span style="color: #2b91af;">Rule</span>>(x => x.Rule).Is(<span + style="color: blue;">new</span> <span style="color: #2b91af;">ColorRule</span>(<span + style="color: #a31515;">"Red"</span>));</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p> </p> +<h4>"Auto Filling" a Setter Dependency</h4> +<p>Sometimes all you want to do is to simply say "fill in this property for me." + That's what the code below does for the "Rule" property with the + .SetterDependency<Rule>().IsTheDefault() syntax:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (r =>\par ?? \{\par ?? r.ForConcreteType<\cf4 ClassWithDependency\cf0 >().Configure\par ?? .SetterDependency<\cf4 Rule\cf0 >().IsTheDefault();\par ??\par ?? r.ForRequestedType<\cf4 Rule\cf0 >().TheDefault.Is.Object(\cf3 new\cf0 \cf4 ColorRule\cf0 (\cf5 "Green"\cf0 ));\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(r =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + r.ForConcreteType<<span style="color: #2b91af;">ClassWithDependency</span>>().Configure</p> + <p style="margin: 0px;"> + + .SetterDependency<<span style="color: #2b91af;">Rule</span>>().IsTheDefault();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + r.ForRequestedType<<span style="color: #2b91af;">Rule</span>>().TheDefault.Is.Object(<span + style="color: blue;">new</span> <span style="color: #2b91af;">ColorRule</span>(<span + style="color: #a31515;">"Green"</span>));</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p>For certain dependency types you might want StructureMap to automatically fill + any public property of that type. The first usage that comes to mind is + logging. Let's say that we have an interface for our logging support + called ILogger. We can specify that any concrete class that has a public + property for the ILogger type will be filled in construction with code like this + (FillAllPropertiesOfType<ILogger>()):</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (r =>\par ?? \{\par ?? r.FillAllPropertiesOfType<\cf4 ILogger\cf0 >().TheDefault.Is\par ?? .ConstructedBy(context => \cf3 new\cf0 \cf4 Logger\cf0 (context.ParentType));\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(r =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + r.FillAllPropertiesOfType<<span style="color: #2b91af;">ILogger</span>>().TheDefault.Is</p> + <p style="margin: 0px;"> + + .ConstructedBy(context => <span style="color: blue;">new</span> + <span style="color: #2b91af;">Logger</span>(context.ParentType));</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p>Now, if I have some classes like:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 ClassWithLogger\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf4 ILogger\cf0 Logger \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 ClassWithLogger2\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf4 ILogger\cf0 Logger \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">ClassWithLogger</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: blue;">bool</span> ShouldCache { <span style="color: blue;"> - get</span>; <span style="color: blue;">set</span>; }</p> - <p style="margin: 0px;"> + <span style="color: #2b91af;">ILogger</span> Logger { <span style="color: blue;"> + get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> }</p> - </div> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">ClassWithLogger2</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: #2b91af;">ILogger</span> Logger { <span style="color: blue;"> + get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> + }</p> +</div> <!--EndFragment--> -<p style="margin: 0px;"> - </p> - </div> -<!--EndFragment--> +<p>Now, when StructureMap builds new instances of these classes above the Logger + properties will be filled automatically without any explicit configuration for + either type. Here's a sample from the unit tests that constructs objects + of both ClassWithLogger and ClassWithLogger2 and verifies that the "Logger" + property was filled for both types without any further configuration.</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 \par ?? container.GetInstance<\cf3 ClassWithLogger\cf0 >().Logger.ShouldBeOfType<\cf3 Logger\cf0 >().Type.ShouldEqual(\cf4 typeof\cf0 (\cf3 ClassWithLogger\cf0 ));\par ?? container.GetInstance<\cf3 ClassWithLogger2\cf0 >().Logger.ShouldBeOfType<\cf3 Logger\cf0 >().Type.ShouldEqual(\cf4 typeof\cf0 (\cf3 ClassWithLogger2\cf0 ));\par ??} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + container.GetInstance<<span style="color: #2b91af;">ClassWithLogger</span>>().Logger.ShouldBeOfType<<span + style="color: #2b91af;">Logger</span>>();</p> + <p style="margin: 0px;"> + + container.GetInstance<<span style="color: #2b91af;">ClassWithLogger2</span>>().Logger.ShouldBeOfType<<span + style="color: #2b91af;">Logger</span>>();</p> + <p style="margin: 0px;"> + </p> </div> <!--EndFragment--> -<h4>Defining Setter Properties with Attributes</h4> -<p>Just use the [StructureMap.Attributes.SetterProperty] to denote properties that - need to be filled by StructureMap. If you despise scattering attributes in - your code, and the tight coupling </p> +<p> </p> + <!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IDataProvider\cf0 \{\}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 Repository\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 IDataProvider\cf0 _provider;\par ??\par ?? \cf3 public\cf0 \cf4 IDataProvider\cf0 Provider\par ?? \{\par ?? \cf3 set\par ??\cf0 \{\par ?? _provider = \cf3 value\cf0 ;\par ?? \}\par ?? \}\par ?? \}} +--> +<!--EndFragment--> +<h4>Defining Setter Properties with Attributes<p>Just use the [StructureMap.Attributes.SetterProperty] to denote properties that + need to be filled by StructureMap. Marking a property with the + [SetterProperty] makes the setter mandatory. StructureMap will throw an + exception if the "ShouldCache" property isn't specified for the concrete type + shown below. If the "Provider" property isn't explicitly configured, + StructureMap will use the default instance of IDataProvider for the "Provider" + property (or throw an exception if StructureMap doesn't know how to build the + type IDataProvider). </p> +<!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 Repository\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 IDataProvider\cf0 _provider;\par ??\par ?? \cf5 // Adding the SetterProperty to a setter directs\par ??\cf0 \cf5 // StructureMap to use this property when\par ??\cf0 \cf5 // constructing a Repository instance\par ??\cf0 [\cf4 SetterProperty\cf0 ]\par ?? \cf3 public\cf0 \cf4 IDataProvider\cf0 Provider\par ?? \{\par ?? \cf3 set\par ??\cf0 \{\par ?? _provider = \cf3 value\cf0 ;\par ?? \}\par ?? \}\par ??\par ?? [\cf4 SetterProperty\cf0 ]\par ?? \cf3 public\cf0 \cf3 bool\cf0 ShouldCache \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}} --> <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> @@ -224,7 +489,7 @@ <span style="color: green;">// constructing a Repository instance</span></p> <p style="margin: 0px;"> - [<span style="color: #2b91af;">SetterProperty</span>]</p> + [<span style="color: #2b91af;">SetterProperty</span>]/p> <p style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: #2b91af;">IDataProvider</span> Provider</p> @@ -258,81 +523,124 @@ <h4>Defining Setter Properties in Xml</h4> <p>Setter properties can be defined in the Xml configuration by explicitly directing - StructureMap to use setter properties while building a concrete type. From + StructureMap to use setter properties while building a concrete type. In + the Xml, Setter configuration is done with the exact syntax as constructor + arguments. For example, the "Name" property of the OptionalSetterTarget + class shown in previous sections can be set just like a constructor argument in + an Xml node:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 <\cf3 StructureMap\cf1 \cf4 MementoStyle\cf1 =\cf0 "\cf1 Attribute\cf0 "\cf1 >\par ?? <\cf3 DefaultInstance\par ??\cf1 \cf4 PluginType\cf1 =\cf0 "\cf1 StructureMap.Testing.Pipeline.OptionalSetterTarget, StructureMap.Testing\cf0 "\par ??\cf1 \cf4 PluggedType\cf1 =\cf0 "\cf1 StructureMap.Testing.Pipeline.OptionalSetterTarget, StructureMap.Testing\cf0 "\par ??\cf1 \cf4 Name\cf1 =\cf0 "\cf1 Jeremy\cf0 "\cf1 />\par ??</\cf3 StructureMap\cf1 >} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">StructureMap</span><span + style="color: blue;"> </span><span style="color: red;">MementoStyle</span><span + style="color: blue;">=</span>"<span style="color: blue;">Attribute</span>"<span + style="color: blue;">> </span> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span + style="color: #a31515;">DefaultInstance</span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span> + <span style="color: red;">PluginType</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap.Testing.Pipeline.OptionalSetterTarget, + StructureMap.Testing</span>"</p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span> + <span style="color: red;"> PluggedType</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap.Testing.Pipeline.OptionalSetterTarget, + StructureMap.Testing</span>"</p> + <p style="margin: 0px;"> + <span style="color: blue;"> </span> + <span style="color: red;"> Name</span><span style="color: blue;">=</span>"<span + style="color: blue;">Jeremy</span>"<span style="color: blue;"> /></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span style="color: #a31515;">StructureMap</span><span + style="color: blue;">></span></p> + </div> +<!--EndFragment--> +<p> </p> +<p>Setter properties can also be designated as mandatory setters with the <Setter> + node in the Xml configuration. From the unit tests, I have a class called OtherGridColumn that exposes several properties:</p> <!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 OtherGridColumn\cf0 : \cf4 IGridColumn\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf4 IWidget\cf0 Widget \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ??\par ?? \cf3 public\cf0 \cf3 string\cf0 ReadOnly\par ?? \{\par ?? \cf3 get\par ??\cf0 \{\par ?? \cf3 return\cf0 \cf5 "whatever"\cf0 ;\par ?? \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf4 FontStyleEnum\cf0 FontStyle \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 string\cf0 ColumnName \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf4 Rule\cf0 [] Rules \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 bool\cf0 WrapLines \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 bool\cf0 Displayed \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 int\cf0 Size \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}} --> <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> - <p style="margin: 0px;"> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 OtherGridColumn\cf0 : \cf4 IGridColumn\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf4 IWidget\cf0 Widget \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ??\par ?? \cf3 public\cf0 \cf3 string\cf0 ReadOnly\par ?? \{\par ?? \cf3 get\cf0 \{ \cf3 return\cf0 \cf5 "whatever"\cf0 ; \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf4 FontStyleEnum\cf0 FontStyle \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 string\cf0 ColumnName \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf4 Rule\cf0 [] Rules \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 bool\cf0 WrapLines \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 bool\cf0 Displayed \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf3 int\cf0 Size \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> - <span style="color: #2b91af;">OtherGridColumn</span> : - <span style="color: #2b91af;">IGridColumn</span></p> - <p style="margin: 0px;"> + <span style="color: #2b91af;">OtherGridColumn</span> : + <span style="color: #2b91af;">IGridColumn</span></p> + <p style="margin: 0px;"> {</p> - <p style="margin: 0px;"> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: #2b91af;">IWidget</span> Widget { <span style="color: blue;"> - get</span>; <span style="color: blue;">set</span>; }</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> + <span style="color: #2b91af;">IWidget</span> Widget { <span style="color: blue;"> + get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: blue;">string</span> ReadOnly</p> - <p style="margin: 0px;"> + <span style="color: blue;">string</span> ReadOnly</p> + <p style="margin: 0px;"> {</p> - <p style="margin: 0px;"> - - <span style="color: blue;">get</span></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - <span style="color: blue;">return</span> <span style="color: #a31515;"> - "whatever"</span>;</p> - <p style="margin: 0px;"> - }</p> - <p style="margin: 0px;"> + <p style="margin: 0px;"> + <span style="color: blue;"> + get</span> { <span style="color: blue;">return</span> + <span style="color: #a31515;">"whatever"</span>; }</p> + <p style="margin: 0px;"> }</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: #2b91af;">FontStyleEnum</span> FontStyle { - <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p> - <p style="margin: 0px;"> + <span style="color: #2b91af;">FontStyleEnum</span> FontStyle { + <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: blue;">string</span> ColumnName { <span style="color: blue;"> - get</span>; <span style="color: blue;">set</span>; }</p> - <p style="margin: 0px;"> + <span style="color: blue;">string</span> ColumnName { <span style="color: blue;"> + get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: #2b91af;">Rule</span>[] Rules { <span style="color: blue;"> - get</span>; <span style="color: blue;">set</span>; }</p> - <p style="margin: 0px;"> + <span style="color: #2b91af;">Rule</span>[] Rules { <span style="color: blue;"> + get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: blue;">bool</span> WrapLines { <span style="color: blue;"> - get</span>; <span style="color: blue;">set</span>; }</p> - <p style="margin: 0px;"> + <span style="color: blue;">bool</span> WrapLines { <span style="color: blue;"> + get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: blue;">bool</span> Displayed { <span style="color: blue;"> - get</span>; <span style="color: blue;">set</span>; }</p> - <p style="margin: 0px;"> + <span style="color: blue;">bool</span> Displayed { <span style="color: blue;"> + get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> <span style="color: blue;">public</span> - <span style="color: blue;">int</span> Size { <span style="color: blue;">get</span>; - <span style="color: blue;">set</span>; }</p> - <p style="margin: 0px;"> + <span style="color: blue;">int</span> Size { <span style="color: blue;">get</span>; + <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> }</p> + </div> +<!--EndFragment--> +<p style="margin: 0px;"> + </p> </div> <!--EndFragment--> -<p>I can direct StructureMap to use these properties in a <Plugin> node for - OtherGridColumn.</p> +<p>I can direct StructureMap to make the properties on the OtherGridColumn class + mandatory in a <Plugin> node for + OtherGridColumn. This probably isn't necessary with the new optional + setter injection capabilities, but it is still valid and the equivalent of using + the [SetterProperty] attribute.</p> <!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;}??\fs20 \cf1 \tab <\cf3 PluginFamily\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5.IGridColumn\cf0 "\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5\cf0 "\cf1 \cf4 DefaultKey\cf1 =\cf0 ""\cf1 >\par ??\tab \tab <\cf3 Source\cf1 \cf4 Type\cf1 =\cf0 "\cf1 XmlFile\cf0 "\cf1 \cf4 FilePath\cf1 =\cf0 "\cf1 GridColumnInstances.xml\cf0 "\cf1 \cf4 XPath\cf1 =\cf0 "\cf1 //GridColumns\cf0 "\cf1 \cf4 NodeName\cf1 =\cf0 "\cf1 GridColumn\cf0 "\cf1 />\par ??\tab \tab <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.Widget5.OtherGridColumn\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Other\cf0 "\cf1 >\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 ColumnName\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 FontStyle\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 Rules\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 Widget\cf0 "\cf1 />\par ??\tab \tab \tab <\cf3 Setter\cf1 \cf4 Name\cf1 =\cf0 "\cf1 WrapLines\cf0 "\cf1 />\par ??\tab \tab </\cf3 Plugin\cf1 >\par ??\tab </\cf3 PluginFamily\cf1 >} --> <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> <p style="margin: 0px;"> - <span style="color: blue;"> <</span><span style="color: #a31515;">PluginFamily</span><span + <span style="color: blue;"> <</span><span style="color: #a31515;">PluginFamily/span><span style="color: blue;"> </span><span style="color: red;">Type</span><span style="color: blue;">=</span>"<span style="color: blue;">StructureMap.Testing.Widget5.IGridColumn</span>"<span style="color: blue;"> </span><span style="color: red;">Assembly</span><span @@ -379,13 +687,10 @@ style="color: #a31515;">Plugin</span><span style="color: blue;">></span></p> <p style="margin: 0px;"> <span style="color: blue;"> </</span><span style="color: #a31515;">PluginFamily</span><span - style="color: blue;">></span></p> + style="color: blue;">&></span></p> </div> <!--EndFragment--> <p> </p> - <h4>Defining Setter Properties with the Fluent Interface</h4> - <p>This isn't possible today, except with a post processing method. This - feature will be added in the next minor release.</p> - </body> + </body> </html> \ No newline at end of file Added: trunk/Source/HTML/Example.xml =================================================================== --- trunk/Source/HTML/Example.xml (rev 0) +++ trunk/Source/HTML/Example.xml 2008-10-18 03:05:42 UTC (rev 184) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8" ?> +<StructureMap MementoStyle="Attribute"> + <DefaultInstance + PluginType="StructureMap.Testing.Pipeline.OptionalSetterTarget, StructureMap.Testing" + PluggedType="StructureMap.Testing.Pipeline.OptionalSetterTarget, StructureMap.Testing" + Name="Jeremy" /> +</StructureMap> \ No newline at end of file Modified: trunk/Source/HTML/HTML.csproj =================================================================== --- trunk/Source/HTML/HTML.csproj 2008-10-17 19:00:37 UTC (rev 183) +++ trunk/Source/HTML/HTML.csproj 2008-10-18 03:05:42 UTC (rev 184) @@ -62,6 +62,7 @@ <Content Include="BestPractices.htm" /> <Content Include="ChangingDefaultsAtRuntime.htm" /> <Content Include="CompositeConfiguration.htm" /> + <Content Include="Example.xml" /> <Content Include="Glossary.htm" /> <Content Include="ConcreteTypes.htm" /> <Content Include="ConfigurationArchitecture.htm" /> Modified: trunk/Source/HTML/ScanningAssemblies.htm =================================================================== --- trunk/Source/HTML/ScanningAssemblies.htm 2008-10-17 19:00:37 UTC (rev 183) +++ trunk/Source/HTML/ScanningAssemblies.htm 2008-10-18 03:05:42 UTC (rev 184) @@ -1,9 +1,406 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> - <title></title> + <title>Auto Registration with Type Scanning</title> </head> <body> - + <h1>Auto Registration with Type Scanning</h1> + + <p> + StructureMap has always had some ability to register types by by scanning + assemblies (auto registration). The original version of StructureMap circa + 2004 looked for types decorated with specific attributes. Version 2.0 + added the ability to look for Registry classes within those assemblies. + The auto registration mechanism has been completely revamped in StructureMap 2.5 + with greatly extended capabilities. The downside is that the "scanning" + syntax in v2.5 is completely incompatible with previous versions, including the + 2.4.9 preview release. However, the Xml configuration has remained + consistent in both form and function.</p> + <h4> + Table of Contents</h4> + <ul> + <li>The Scan() Expression</li> + </ul> + <h4> + Using the Scan() Expression</h4> + <p> + Auto registration begins with the Scan() expression inside a Registry class or + the now deprecated StructureMapConfiguration class. Here's an example from + my current project:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;}??\fs20 Scan(x =>\par ?? \{\par ?? x.TheCallingAssembly();\par ??\par ?? x.ExcludeNamespaceContainingType<\cf3 IEvent\cf0 >();\par ?? x.ExcludeNamespaceContainingType<\cf3 SearchModel\cf0 >();\par ?? x.ExcludeNamespaceContainingType<\cf3 AuthenticationService\cf0 >();\par ?? x.ExcludeNamespaceContainingType<\cf3 DovetailController\cf0 >();\par ??\par ?? x.AddAllTypesOf<\cf3 IDomainMap\cf0 >();\par ?? \par ?? x.WithDefaultConventions();\par ?? x.With<\cf3 DomainEntityAliaser\cf0 >();\par ?? \});} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + ... [truncated message content] |
From: <jer...@us...> - 2008-10-18 20:49:28
|
Revision: 187 http://structuremap.svn.sourceforge.net/structuremap/?rev=187&view=rev Author: jeremydmiller Date: 2008-10-18 20:49:21 +0000 (Sat, 18 Oct 2008) Log Message: ----------- documentation Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/HTML/Glossary.htm trunk/Source/HTML/ScanningAssemblies.htm trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap.Testing/Examples.cs Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-10-18 13:26:11 UTC (rev 186) +++ trunk/Source/CommonAssemblyInfo.cs 2008-10-18 20:49:21 UTC (rev 187) @@ -5,7 +5,7 @@ //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. -// Runtime Version:2.0.50727.1433 +// Runtime Version:2.0.50727.1434 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. Modified: trunk/Source/HTML/Glossary.htm =================================================================== --- trunk/Source/HTML/Glossary.htm 2008-10-18 13:26:11 UTC (rev 186) +++ trunk/Source/HTML/Glossary.htm 2008-10-18 20:49:21 UTC (rev 187) @@ -184,8 +184,122 @@ <!--EndFragment--> <p> </p> <h4>Instance</h4> - <p>In StructureMap terms, an "Instance" is a named way to build or locate an object - instance for a requested PluginType. There is an actual class in + <p>In StructureMap terms, an "Instance" is a named way to build or locate a + named object + instance for a requested PluginType. An "Instance" does not automatically + equate to a concrete type. For example, let's say that we're building a + system to automate a warehouse. Our system might consume an interface + called IShippingService that acts as a Gateway[LINK] to various ways of shipping + boxes out of our warehouse.</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IShippingService\par ??\cf0 \{\par ?? \cf3 void\cf0 ShipIt();\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + interface</span> <span style="color: #2b91af;">IShippingService</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> ShipIt();</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>Our warehouse system might have to interact with three types of shipping: + domestic, international, and intra-company or internal shipments. The + internal shipping service runs in process with the warehouse application, but + domestic and international shipping is done by invoking external web services. + The registration of the IShippingService Instances might look like this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 ShippingRegistry\cf0 : \cf4 Registry\par ??\cf0 \{\par ?? \cf3 public\cf0 ShippingRegistry()\par ?? \{\par ?? ForRequestedType<\cf4 IShippingService\cf0 >().AddInstances(x =>\par ?? \{\par ?? x.OfConcreteType<\cf4 ShippingWebService\cf0 >()\par ?? .WithCtorArg(\cf5 "url"\cf0 ).EqualTo(\cf5 "a url"\cf0 )\par ?? .WithName(\cf5 "Domestic"\cf0 );\par ??\par ?? x.OfConcreteType<\cf4 ShippingWebService\cf0 >()\par ?? .WithCtorArg(\cf5 "url"\cf0 ).EqualTo(\cf5 "a different url"\cf0 )\par ?? .WithName(\cf5 "International"\cf0 );\par ??\par ?? x.OfConcreteType<\cf4 InternalShippingService\cf0 >().WithName(\cf5 "Internal"\cf0 );\par ?? \});\par ?? \}\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">ShippingRegistry</span> : + <span style="color: #2b91af;">Registry</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + ShippingRegistry()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">IShippingService</span>>().AddInstances(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.OfConcreteType<<span style="color: #2b91af;">ShippingWebService</span>>()</p> + <p style="margin: 0px;"> + + .WithCtorArg(<span style="color: #a31515;">"url"</span>).EqualTo(<span + style="color: #a31515;">"a url"</span>)</p> + <p style="margin: 0px;"> + + .WithName(<span style="color: #a31515;">"Domestic"</span>);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.OfConcreteType<<span style="color: #2b91af;">ShippingWebService</span>>()</p> + <p style="margin: 0px;"> + + .WithCtorArg(<span style="color: #a31515;">"url"</span>).EqualTo(<span + style="color: #a31515;">"a different url"</span>)</p> + <p style="margin: 0px;"> + + .WithName(<span style="color: #a31515;">"International"</span>);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.OfConcreteType<<span style="color: #2b91af;">InternalShippingService</span>>().WithName(<span + style="color: #a31515;">"Internal"</span>);</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> +</div> +<!--EndFragment--> +<p>In the registration code above, there are three "Instance's." You can + access the various IShippingService Instance's by name:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 // Accessing the IShippingService Instance's by name\par ??\cf0 \cf4 var\cf0 internationalService = \cf5 ObjectFactory\cf0 .GetNamedInstance<\cf5 IShippingService\cf0 >(\cf6 "International"\cf0 );\par ?? \cf4 var\cf0 domesticService = \cf5 ObjectFactory\cf0 .GetNamedInstance<\cf5 IShippingService\cf0 >(\cf6 "Domestic"\cf0 );\par ?? \cf4 var\cf0 internalService = \cf5 ObjectFactory\cf0 .GetNamedInstance<\cf5 IShippingService\cf0 >(\cf6 "Internal"\cf0 );\par ??} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: green;">// Accessing the IShippingService Instance's by name</span></p> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> internationalService = + <span style="color: #2b91af;">ObjectFactory</span>.GetNamedInstance<<span + style="color: #2b91af;">IShippingService</span>>(<span + style="color: #a31515;">"International"</span>);</p> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> domesticService = + <span style="color: #2b91af;">ObjectFactory</span>.GetNamedInstance<<span + style="color: #2b91af;">IShippingService</span>>(<span + style="color: #a31515;">"Domestic"</span>);</p> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> internalService = + <span style="color: #2b91af;">ObjectFactory</span>.GetNamedInstance<<span + style="color: #2b91af;">IShippingService</span>>(<span + style="color: #a31515;">"Internal"</span>);</p> +</div> +<!--EndFragment--> +<p>Asking for the "International" or the "Domestic" instance of IShippingService + will both return an object of type ShippingWebService, but the two objects will + be differently configured with unique Url's.</p> +<p>There is an actual class in StructureMap 2.5 that represents an "Instance." An abreviated version of the abstract Instance class is shown below:</p> <!-- @@ -296,16 +410,212 @@ method to create a new object or get an existing object. Note the abstract build(Type, IBuildSession) method. This is a Template Method that can be overriden to write your own customized Instance type.</p> -<p>When you call ObjectFactory.Get</p> - <h4>Scoping</h4> - <p>a;lskdfje</p> - <h4>PluginFamily</h4> - <p>a;lskdfj</p> - <h4>Profile</h4> - <p>a;lskdfj</p> +<p>When you call ObjectFactory.GetNamedInstance<T>("the instance that I want") or + ObjectFactory.GetInstance<T>(), the internal Container object is locating the + correct Instance object and calling its Build() method.</p> + <h4>Scoping (or Lifecycle)</h4> + <p>When you register a PluginType in the system you can "scope" the Instance's of + that PluginType like this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;}??\fs20 \cf3 // This is used as a sort of lightweight ScriptManager in\par ??\cf0 \cf3 // our website application\par ??\cf0 ForRequestedType<\cf4 ICachedSet\cf0 >().TheDefaultIsConcreteType<\cf4 CachedSet\cf0 >()\par ?? .CacheBy(\cf4 InstanceScope\cf0 .Hybrid);\par ??} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: green;">// This is used as a sort of lightweight + ScriptManager in</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// our website application</span></p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">ICachedSet</span>>().TheDefaultIsConcreteType<<span + style="color: #2b91af;">CachedSet</span>>()</p> + <p style="margin: 0px;"> + + .CacheBy(<span style="color: #2b91af;">InstanceScope</span>.HttpContext);</p> + </div> +<!--EndFragment--> +<p>Note the CacheBy() method hanging off the end of the expression. This is + directing the StructureMap container to use the same object instance for + ICachedSet for all requests in the same HttpContext. In this case, if a + request is made for any Instance of ICachedSet, StructureMap will first check + the HttpContext.Items collection to see if that exact Instance has already been + created within the same HttpContext. </p> + <ol> + <li>PerRequest - The default option unless otherwise overridden. A new object + will be created for each time you request an Instance from the container. + Some other IoC containers call this "Transient." Please note that this is + the default behavior in StructureMap. Many other IoC container tools will + use "Singleton" instead. </li> + <li>Singleton - A single object will be shared across + all requests for a specific Instance. StructureMap will only create the + singleton object upon demand</li> + <li>ThreadLocal - A single object will be created for + each requesting thread. Caches the instances with + ThreadLocalStorage.</li> + <li>HttpContext - A single object will be created for + each HttpContext. Caches the instances in the + HttpContext.Items collection.</li> + <li>Hybrid - Uses HttpContext storage if it exists, + otherwise uses ThreadLocal storage.</li> + </ol> + <p> + It is possible to create your own type of scoping. See "Extending + StructureMap" [LINK -- doesn't exist yet] for more information. Also note + that StructureMap provides no functionality for cleaning up resources of the + objects held by the container. To date, I have not found a need for this + behavior or functionality. I generally assume that a combination of basic + garbage collection and proper class design is sufficient.</p> + <h4> </h4> + <h4>Profile</h4> + <p>From the very beginning, StructureMap has supported the ability to define a named + set of default instances called a "Profile." The Profile feature was + originally meant to be a quick way of switching the connection mode of a smart + client application from connected to disconnected modes. In practice, it's + more commonly used as a way to migrate configuration between environments or for + creating alternative deployment configurations. My team uses the Profile + feature in our system as a quick way to collapse our entire distributed + application into a single AppDomain for easier testing and debugging. Our + "InMemory" profile is defined like this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 // Using this Profile configures our application to \par ??\cf0 \cf3 // run completely inside a single AppDomain\par ??\cf0 \cf3 // In production the application will consist\par ??\cf0 \cf3 // of the website and 2-3 external windows\par ??\cf0 \cf3 // services\par ??\cf0 \cf4 var\cf0 repository = \cf4 new\cf0 \cf5 InMemoryRepository\cf0 ();\par ?? CreateProfile(IN_MEMORY_PROFILE, x =>\par ?? \{\par ?? x.For<\cf5 IRepository\cf0 >().Use(repository);\par ?? x.For<\cf5 IEventPublishingService\cf0 >().Use(\cf4 new\cf0 \cf5 InMemoryEventPublishingService\cf0 (repository));\par ?? x.For<\cf5 IUserMessagePublisher\cf0 >().UseConcreteType<\cf5 InMemoryUserMessageQueue\cf0 >();\par ?? x.For<\cf5 IUnitOfWork\cf0 >().UseConcreteType<\cf5 InMemoryUnitOfWork\cf0 >();\par ?? \});} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: green;">// Using this Profile configures our application to + </span> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// run completely inside a single AppDomain</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// In production the application will consist</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// of the website and 2-3 external windows</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// services</span></p> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> repository = <span style="color: blue;"> + new</span> <span style="color: #2b91af;">InMemoryRepository</span>();</p> + <p style="margin: 0px;"> + + CreateProfile(IN_MEMORY_PROFILE, x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.For<<span style="color: #2b91af;">IRepository</span>>().Use(repository);</p> + <p style="margin: 0px;"> + + x.For<<span style="color: #2b91af;">IEventPublishingService</span>>().Use(<span + style="color: blue;">new</span> <span style="color: #2b91af;"> + InMemoryEventPublishingService</span>(repository));</p> + <p style="margin: 0px;"> + + x.For<<span style="color: #2b91af;">IUserMessagePublisher</span>>().UseConcreteType<<span + style="color: #2b91af;">InMemoryUserMessageQueue</span>>();</p> + <p style="margin: 0px;"> + + x.For<<span style="color: #2b91af;">IUnitOfWork</span>>().UseConcreteType<<span + style="color: #2b91af;">InMemoryUnitOfWork</span>>();</p> + <p style="margin: 0px;"> + });</p> + </div> +<!--EndFragment--> +<p>In the code, we can switch the application to the in memory mode by calling the + SetDefaultsToProfile() method on the Container (or ObjectFactory.Profile = + CoreRegistry.IN_MEMORY_PROFILE):</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 \cf3 // This is actual code from a test harness class we use\par ??\cf0 \cf3 // for integration testing\par ??\cf0 \cf4 IContainer\cf0 container = createContainer(\cf5 new\cf0 \cf4 RuleSet\cf0 []\{ruleSet\});\par ?? container.SetDefaultsToProfile(\cf4 CoreRegistry\cf0 .IN_MEMORY_PROFILE);\par ??} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: green;">// This is actual code from a test harness class we + use</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// for integration testing</span></p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">IContainer</span> container = createContainer(<span + style="color: blue;">new</span> <span style="color: #2b91af;">RuleSet</span>[]{ruleSet});</p> + <p style="margin: 0px;"> + + container.SetDefaultsToProfile(<span style="color: #2b91af;">CoreRegistry</span>.IN_MEMORY_PROFILE);</p> +</div> +<!--EndFragment--> +<p> </p> <h4>Interceptor</h4> - <p>a;lskdfj</p> - <h4>PostProcessor</h4> - <p>a;lskdfj</p> + <p>A new feature for StructureMap 2.5 is the ability to "intercept" an object + getting created in StructureMap before the new object is handed back to the + requesting code. The intention behind this feature is to support runtime + Aspect Oriented Programming techniques or any type of object initialization + beyond the constructor function. </p> + <p> + To explain the sequence of events, here's an ellided version of the Build() + method of the Instance abstract class:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 virtual\cf0 \cf3 object\cf0 Build(\cf4 Type\cf0 pluginType, \cf4 BuildSession\cf0 session)\par ?? \{\par ?? markBuildStackStart(session, pluginType);\par ??\par ?? \cf5 // "Build" the desired object\par ??\cf0 \cf3 object\cf0 rawValue = createRawObject(pluginType, session);\par ?? \par ?? \cf5 // Allow the Interceptor a chance to enhance, configure, \par ??\cf0 \cf5 // wrap with a decorator, or even replace the rawValue\par ??\cf0 \cf3 object\cf0 finalValue = applyInterception(rawValue, pluginType);\par ??\par ?? markBuildStackFinish(session);\par ??\par ?? \cf3 return\cf0 finalValue;\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">virtual</span> <span style="color: blue;">object</span> + Build(<span style="color: #2b91af;">Type</span> pluginType, + <span style="color: #2b91af;">BuildSession</span> session)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + markBuildStackStart(session, pluginType);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// "Build" the desired object</span></p> + <p style="margin: 0px;"> + + <span style="color: blue;">object</span> rawValue = createRawObject(pluginType, + session);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Allow the Interceptor a chance to enhance, + configure, </span> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// wrap with a decorator, or even replace the + rawValue</span></p> + <p style="margin: 0px;"> + + <span style="color: blue;">object</span> finalValue = + applyInterception(rawValue, pluginType);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + markBuildStackFinish(session);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: blue;">return</span> finalValue;</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p> + The Instance class first builds the raw object, then applies any registered + interception on the raw object to get the final value. +</p> </body> </html> \ No newline at end of file Modified: trunk/Source/HTML/ScanningAssemblies.htm =================================================================== --- trunk/Source/HTML/ScanningAssemblies.htm 2008-10-18 13:26:11 UTC (rev 186) +++ trunk/Source/HTML/ScanningAssemblies.htm 2008-10-18 20:49:21 UTC (rev 187) @@ -92,8 +92,16 @@ <p> The actual work is performed by an IAssemblyScanner object. The Scan() method uses the <a href="http://martinfowler.com/dslwip/NestedClosure.html"> - Nested Closure</a> pattern as a way of configuring the IAssemblyScanner and then - executing the scanner at the correct time in the configuration process. + Nested Closure</a> pattern as a way of configuring and registering the IAssemblyScanner + in a single atomic action. Each Scan() expression is a completely + self-contained, atomic action. This is a significant change from the + earlier functionality in versions 2.0 and 2.4.9. This breaking change was + made to reduce confusion by making the actual functionality more closely match + the DSL expression. </p> +<p> + The scanner itself will not be executed until near the end of the configuration process. + Be aware of this issue if you are trying to debug custom ITypeScanner classes.</p> +<p> The IAssemblyScanner interface exposes these directives to control the assembly scanning:</p> <!-- @@ -188,55 +196,624 @@ </div> <!--EndFragment--> <p> - </p> + Roughly put, these are the features and options of each individual Scan() + expression:</p> +<ol> + <li>Analyzing all the exported types in the specified Assembly's</li> + <li>By default, looking for all types decorated with either the [PluginFamily] or + [Pluggable] attributes. This feature can be disabled by calling the + IAssemblyScanner.IgnoreStructureMapAttributes() method. See NEED A LINK + HERE for more information</li> + <li><b>If explicitly specified</b> with the use of the LookForRegistries() method, + the scanning will apply the configuration contained within any concrete Registry + class found in the assemblies being scanned.</li> + <li>Optionally, the scanning can automatically add any concrete types found that can + be "plugged" into a given PluginType</li> + <li>The scanning of types within an Assembly can be further filtered by specifying + rules to either include or exclude types based on Predicate<Type> rules[LINK].</li> + <li>Lastly, custom scanning conventions and policies can be added and used from the + Scan() expression. </li> +</ol> <h4> Rules for Auto Registering a Type</h4> +<p> + If you are interested in using the Scan() expression for auto registration, the + first thing to know is how StructureMap determines whether or not a given + concrete type should be registered. </p> +<p> + </p> +<ul> + <li>The PluginType is assignable from the concrete type</li> + <li>The concrete type has a public constructor</li> + <li>Cannot have a primitive constructor argument</li> + <li>Auto scanning only works if there is only one concrete type registered for a + PluginType</li> + <li>The scanning can be overridden explicitly</li> +</ul> <h4> - Designating Assemblies <h4> + Designating Assemblies +<p> + The first thing you need to do to utilize the type scanning is to designate + which assemblies to scan. The type scanning will throw an exception if you + attempt to call the Scan() expression without designating at least one assembly. + Use one of the following methods on IAssemblyScanner to designate assemblies:\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IAssemblyScanner\par ??\cf0 \{\par ?? \cf5 // Determining which assemblies to scan\par ??\cf0 \cf3 void\cf0 Assembly(\cf4 Assembly\cf0 assembly);\par ?? \cf3 void\cf0 Assembly(\cf3 string\cf0 assemblyName);\par ?? \cf3 void\cf0 TheCallingAssembly();\par ?? \cf3 void\cf0 AssemblyContainingType<T>();\par ?? \cf3 void\cf0 AssemblyContainingType(\cf4 Type\cf0 type);\par ?? \cf3 void\cf0 AssembliesFromPath(\cf3 string\cf0 path);\par ?? \cf3 void\cf0 AssembliesFromPath(\cf3 string\cf0 path, \cf4 Predicate\cf0 <\cf4 Assembly\cf0 > assemblyFilter);\par ?? \par ?? \cf5 // Adding conventions\par ??\cf0 \cf3 void\cf0 With(\cf4 ITypeScanner\cf0 scanner);\par ?? \cf3 void\cf0 WithDefaultConventions();\par ?? \cf3 void\cf0 With<T>() \cf3 where\cf0 T : \cf4 ITypeScanner\cf0 , \cf3 new\cf0 ();\par ?? \par ?? \cf5 // Other options\par ??\cf0 \cf3 void\cf0 LookForRegistries();\par ?? \cf3 void\cf0 AddAllTypesOf<PLUGINTYPE>();\par ?? \cf3 void\cf0 AddAllTypesOf(\cf4 Type\cf0 pluginType);\par ?? \cf3 void\cf0 IgnoreStructureMapAttributes();\par ?? \par ?? \cf5 // Filtering the types that will be scanned\par ??\cf0 \cf3 void\cf0 Exclude(\cf4 Predicate\cf0 <\cf4 Type\cf0 > exclude);\par ?? \cf3 void\cf0 ExcludeNamespace(\cf3 string\cf0 nameSpace);\par ?? \cf3 void\cf0 ExcludeNamespaceContainingType<T>();\par ?? \cf3 void\cf0 Include(\cf4 Predicate\cf0 <\cf4 Type\cf0 > predicate);\par ?? \cf3 void\cf0 IncludeNamespace(\cf3 string\cf0 nameSpace);\par ?? \cf3 void\cf0 IncludeNamespaceContainingType<T>();\par ?? \cf3 void\cf0 ExcludeType<T>();\par ?? \}} +--> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IAssemblyScanner\par ??\cf0 \{\par ??\cf3 #region\cf0 Designating Assemblies\par ??\par ?? \cf3 void\cf0 Assembly(\cf4 Assembly\cf0 assembly);\par ?? \cf3 void\cf0 Assembly(\cf3 string\cf0 assemblyName);\par ?? \cf3 void\cf0 TheCallingAssembly();\par ?? \cf3 void\cf0 AssemblyContainingType<T>();\par ?? \cf3 void\cf0 AssemblyContainingType(\cf4 Type\cf0 type);\par ?? \cf3 void\cf0 AssembliesFromPath(\cf3 string\cf0 path);\par ?? \cf3 void\cf0 AssembliesFromPath(\cf3 string\cf0 path, \cf4 Predicate\cf0 <\cf4 Assembly\cf0 > assemblyFilter);\par ??\par ??\cf3 #endregion\par ??\par ??\cf0 \cf5 // ... Other methods\par ??\par ??\cf3 #region\cf0 Adding TypeScanners\par ??\par ?? \cf3 void\cf0 With(\cf4 ITypeScanner\cf0 scanner);\par ?? \cf3 void\cf0 WithDefaultConventions();\par ?? \cf3 void\cf0 With<T>() \cf3 where\cf0 T : \cf4 ITypeScanner\cf0 , \cf3 new\cf0 ();\par ??\par ??\cf3 #endregion\par ??\par ?? #region\cf0 Other options\par ??\par ?? \cf3 void\cf0 LookForRegistries();\par ?? \cf3 void\cf0 AddAllTypesOf<PLUGINTYPE>();\par ?? \cf3 void\cf0 AddAllTypesOf(\cf4 Type\cf0 pluginType);\par ?? \cf3 void\cf0 IgnoreStructureMapAttributes();\par ??\par ??\cf3 #endregion\par ??\par ?? #region\cf0 Filtering types\par ??\par ?? \cf3 void\cf0 Exclude(\cf4 Predicate\cf0 <\cf4 Type\cf0 > exclude);\par ?? \cf3 void\cf0 ExcludeNamespace(\cf3 string\cf0 nameSpace);\par ?? \cf3 void\cf0 ExcludeNamespaceContainingType<T>();\par ?? \cf3 void\cf0 Include(\cf4 Predicate\cf0 <\cf4 Type\cf0 > predicate);\par ?? \cf3 void\cf0 IncludeNamespace(\cf3 string\cf0 nameSpace);\par ?? \cf3 void\cf0 IncludeNamespaceContainingType<T>();\par ?? \cf3 void\cf0 ExcludeType<T>();\par ??\par ??\cf3 #endregion\par ??\par ??\cf0 \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + interface</span> <span style="color: #2b91af;">IAssemblyScanner</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + Assembly(<span style="color: #2b91af;">Assembly</span> assembly);</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + Assembly(<span style="color: blue;">string</span> assemblyName);</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + TheCallingAssembly();</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + AssemblyContainingType<T>();</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + AssemblyContainingType(<span style="color: #2b91af;">Type</span> type);</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + AssembliesFromPath(<span style="color: blue;">string</span> path);</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + AssembliesFromPath(<span style="color: blue;">string</span> path, + <span style="color: #2b91af;">Predicate</span><<span style="color: #2b91af;">Assembly</span>> + assemblyFilter);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// ... Other methods</span></p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p> + Adding an assembly directly:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 ScanningRegistry\cf0 : \cf4 Registry\par ??\cf0 \{\par ?? \cf3 public\cf0 ScanningRegistry()\par ?? \{\par ?? Scan(x =>\par ?? \{\par ?? \cf5 // Add assembly by name.\par ??\cf0 x.Assembly(\cf6 "StructureMap.Testing.Widget"\cf0 );\par ??\par ?? \cf5 // Add an assembly directly\par ??\cf0 x.Assembly(\cf4 Assembly\cf0 .GetExecutingAssembly());\par ??\par ?? \cf5 // Add the assembly that contains a certain type\par ??\cf0 x.AssemblyContainingType<\cf4 IService\cf0 >();\par ?? \cf5 // or\par ??\cf0 x.AssemblyContainingType(\cf3 typeof\cf0 (\cf4 IService\cf0 ));\par ?? \});\par ?? \}\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">ScanningRegistry</span> : + <span style="color: #2b91af;">Registry</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + ScanningRegistry()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + Scan(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// Add assembly by name.</span></p> + <p style="margin: 0px;"> + + x.Assembly(<span style="color: #a31515;">"StructureMap.Testing.Widget"</span>);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Add an assembly directly</span></p> + <p style="margin: 0px;"> + + x.Assembly(<span style="color: #2b91af;">Assembly</span>.GetExecutingAssembly());</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Add the assembly that contains a certain type</span></p> + <p style="margin: 0px;"> + + x.AssemblyContainingType<<span style="color: #2b91af;">IService</span>>();</p> + <p style="margin: 0px;"> + + <span style="color: green;">// or</span></p> + <p style="margin: 0px;"> + + x.AssemblyContainingType(<span style="color: blue;">typeof</span>(<span + style="color: #2b91af;">IService</span>));</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> +</div> +<!--EndFragment--> +<p> + The most common usage is probably just specifying "this" assembly with + IAssemblyScanner.TheCallingAssembly():</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 WebCoreRegistry\cf0 : \cf4 Registry\par ??\cf0 \{\par ?? \cf3 protected\cf0 \cf3 override\cf0 \cf3 void\cf0 configure()\par ?? \{\par ?? ForRequestedType<\cf4 ICachedSet\cf0 >().TheDefaultIsConcreteType<\cf4 CachedSet\cf0 >().CacheBy(\cf4 InstanceScope\cf0 .Hybrid);\par ?? ForRequestedType<\cf4 IControlBuilder\cf0 >().TheDefault.Is.OfConcreteType<\cf4 AspNetControlBuilder\cf0 >();\par ?? ForRequestedType<\cf4 IPartialRenderer\cf0 >().TheDefault.Is.OfConcreteType<\cf4 PartialRenderer\cf0 >();\par ??\par ?? Scan(x =>\par ?? \{\par ?? \cf5 // Scan "this" assembly. In other words, the assembly that \par ??\cf0 \cf5 // contains the WebCoreRegistry class\par ??\cf0 x.TheCallingAssembly();\par ??\par ?? x.IncludeNamespaceContainingType<\cf4 AuthenticationContext\cf0 >();\par ?? x.IncludeNamespaceContainingType<\cf4 ISecurityDataService\cf0 >();\par ??\par ?? x.WithDefaultConventions();\par ?? \});\par ?? \}\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">WebCoreRegistry</span> : + <span style="color: #2b91af;">Registry</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">protected</span> + <span style="color: blue;">override</span> <span style="color: blue;">void</span> + configure()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">ICachedSet</span>>().TheDefaultIsConcreteType<<span + style="color: #2b91af;">CachedSet</span>>().CacheBy(<span + style="color: #2b91af;">InstanceScope</span>.Hybrid);</p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">IControlBuilder</span>>().TheDefault.Is.OfConcreteType<<span + style="color: #2b91af;">AspNetControlBuilder</span>>();</p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">IPartialRenderer</span>>().TheDefault.Is.OfConcreteType<<span + style="color: #2b91af;">PartialRenderer</span>>();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + Scan(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// Scan "this" assembly. In other words, the + assembly that </span> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// contains the WebCoreRegistry class</span></p> + <p style="margin: 0px;"> + + x.TheCallingAssembly();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.IncludeNamespaceContainingType<<span style="color: #2b91af;">AuthenticationContext</span>>();</p> + <p style="margin: 0px;"> + + x.IncludeNamespaceContainingType<<span style="color: #2b91af;">ISecurityDataService</span>>();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.WithDefaultConventions();</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> +</div> +<p> + StructureMap 2.5 has a brand new capability to auto register types in all + assemblies in a given folder path. My current project is using this + feature for our extensibility mechanism. For customer-specific + deployments, we need to add business rules and even all new screens and features + to our application that can be discovered at runtime -- without changing our + core code. Our design calls for all extensions to be created in separate + assemblies. On application startup, our system will look for all + assemblies in a well known folder and use StructureMap to scan these assemblies + for the extensions that will be specified in Registry classes. Our + bootstrapping looks like:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 Scan(x =>\par ?? \{\par ?? \cf3 // I'm telling StructureMap to sweep a folder called "Extensions" directly\par ??\cf0 \cf3 // underneath the application root folder for any assemblies\par ??\cf0 x.AssembliesFromPath(\cf4 "Extensions"\cf0 );\par ??\par ?? \cf3 // I also direct StructureMap to add any Registries that it finds in these\par ??\cf0 \cf3 // assemblies. I'm assuming that all the StructureMap directives are\par ??\cf0 \cf3 // contained in Registry classes -- and this is the recommended approach\par ??\cf0 x.LookForRegistries();\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + Scan(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// I'm telling StructureMap to sweep a folder called + "Extensions" directly</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// underneath the application root folder for any + assemblies found in that folder</span></p> + <p style="margin: 0px;"> + + x.AssembliesFromPath(<span style="color: #a31515;">"Extensions"</span>);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// I also direct StructureMap to add any Registries + that it finds in these</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// assemblies. I'm assuming that all the + StructureMap directives are</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// contained in Registry classes -- and this is the + recommended approach</span></p> + <p style="margin: 0px;"> + + x.LookForRegistries();</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p> + Note in the code above that I made an explicit call to "LookForRegistries." + Scanning for Registry's is no longer active by default. This is a breaking + change from the 2.4.9 preview release. +</p> +<p> + You can also filter the assemblies based on a Predicate like this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 Scan(x =>\par ?? \{\par ?? \cf3 // This time I'm going to specify a filter on the assembly such that \par ??\cf0 \cf3 // only assemblies that have "Extension" in their name will be scanned\par ??\cf0 x.AssembliesFromPath(\cf4 "Extensions"\cf0 , assembly => assembly.GetName().Name.Contains(\cf4 "Extension"\cf0 ));\par ??\par ?? x.LookForRegistries();\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + Scan(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// This time I'm going to specify a filter on the + assembly such that </span> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// only assemblies that have "Extension" in their + name will be scanned</span></p> + <p style="margin: 0px;"> + + x.AssembliesFromPath(<span style="color: #a31515;">"Extensions"</span>, assembly + => assembly.GetName().Name.Contains(<span style="color: #a31515;">"Extension"</span>));</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.LookForRegistries();</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p> + </p> +<p> + </p> +<h4> Add All Concrete Types for a PluginType</h4> +<p> + Sometimes you may simply want to automatically add all the concrete classes that + implement or inherit from a given PluginType. In my current project we are + using StructureMap to bootstrap and configure NHibernate. We're also using + Fluent NHibernate for our mapping configuration. The mapping configuration + is specified in classes that implement an interface named IDomainMap. To + configure NHibernate, we need to sweep our core assembly to find all concrete + implementations of IDomainMap and execute the mappings on each type. We + have a Registry called "CoreRegistry" that configures NHibernate (among other + things). We specify the auto registration of all the IDomainMap types like + this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;}??\fs20 Scan(x =>\par ?? \{\par ?? \cf3 // Scan the types in the assembly that contains this Registry class\par ??\cf0 x.TheCallingAssembly();\par ??\par ?? x.ExcludeNamespaceContainingType<\cf4 IEvent\cf0 >();\par ?? x.ExcludeNamespaceContainingType<\cf4 SearchModel\cf0 >();\par ?? x.ExcludeNamespaceContainingType<\cf4 AuthenticationService\cf0 >();\par ?? x.ExcludeNamespaceContainingType<\cf4 DovetailController\cf0 >();\par ??\par ?? \cf3 // Finds and adds all concrete implementations of the IDomainMap\par ??\cf0 \cf3 // interface in the targetted assemblies\par ??\cf0 x.AddAllTypesOf<\cf4 IDomainMap\cf0 >();\par ?? x.WithDefaultConventions();\par ?? x.With<\cf4 DomainEntityAliaser\cf0 >();\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + Scan(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// Scan the types in the assembly that contains this + Registry class</span></p> + <p style="margin: 0px;"> + + x.TheCallingAssembly();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Finds and adds all concrete implementations of + the IDomainMap</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// interface in the targetted assemblies</span></p> + <p style="margin: 0px;"> + + x.AddAllTypesOf<<span style="color: #2b91af;">IDomainMap</span>>();</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p> + After running the Scan() statement above, we can retrieve an instance of all the + IDomainMap types by calling:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;}??\fs20 \par ?? \cf3 // Retrieve all registered IDomainMap objects\par ??\cf0 \cf4 IList\cf0 <\cf4 IDomainMap\cf0 > allMaps = \cf4 ObjectFactory\cf0 .GetAllInstances<\cf4 IDomainMap\cf0 >();\par ??} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Retrieve all registered IDomainMap objects</span></p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">IList</span><<span style="color: #2b91af;">IDomainMap</span>> + allMaps = <span style="color: #2b91af;">ObjectFactory</span>.GetAllInstances<<span + style="color: #2b91af;">IDomainMap</span>>();</p> + <p style="margin: 0px;"> + </p> +</div> +<!--EndFragment--> +<p> + More appropriately in our code, we have a "Query" subsystem that also uses the + IDomainMap objects for its metadata. We have a class called + EntityQueryRepository that "knows" how each Domain Model class is queried. + When the EntityQueryRepository object is created, it takes in an array of + IDomainMap objects.</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 // Unless explicitly configured otherwise, when StructureMap\par ??\cf0 \cf3 // sees a constructor or setter argument that is an array,\par ??\cf0 \cf3 // it will fill this argument with all of the instances\par ??\cf0 \cf3 // of the argument type -- in this case, all the registered\par ??\cf0 \cf3 // IDomainMap objects\par ??\cf0 \cf4 public\cf0 EntityQueryRegistry(\cf5 IDomainMap\cf0 [] maps)\par ?? \{\par ?? maps.Each(m => m.RegisterQueryModel(\cf4 this\cf0 ));\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: green;">// Unless + explicitly configured otherwise, when StructureMap</span></p> + <p style="margin: 0px;"> + <span style="color: green;">// sees a + constructor or setter argument that is an array,</span></p> + <p style="margin: 0px;"> + <span style="color: green;">// it will fill + this argument with all of the instances</span></p> + <p style="margin: 0px;"> + <span style="color: green;">// of the + argument type -- in this case, all the registered</span></p> + <p style="margin: 0px;"> + <span style="color: green;">// IDomainMap + objects</span></p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + EntityQueryRegistry(<span style="color: #2b91af;">IDomainMap</span>[] maps)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + maps.Each(m => + m.RegisterQueryModel(<span style="color: blue;">this</span>));</p> + <p style="margin... [truncated message content] |
From: <jer...@us...> - 2008-10-21 22:10:30
|
Revision: 189 http://structuremap.svn.sourceforge.net/structuremap/?rev=189&view=rev Author: jeremydmiller Date: 2008-10-21 22:10:22 +0000 (Tue, 21 Oct 2008) Log Message: ----------- documentation Modified Paths: -------------- trunk/Source/HTML/HTML.csproj trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/InitializationExpression.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/SmartInstance.cs trunk/Source/StructureMap.Testing/AlternativeConfigurationTester.cs trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs trunk/Source/StructureMap.Testing/Examples.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs Added Paths: ----------- trunk/Source/HTML/ConfiguringStructureMap.htm trunk/Source/HTML/InstanceExpression.htm trunk/Source/HTML/RegistryDSL.htm trunk/Source/StructureMap.Testing/Graph/ExplicitArgumentTester.cs Removed Paths: ------------- trunk/Source/HTML/AutoMocking.htm trunk/Source/HTML/BestPractices.htm trunk/Source/HTML/ChangingDefaultsAtRuntime.htm trunk/Source/HTML/CompositeConfiguration.htm trunk/Source/HTML/ConcreteTypes.htm trunk/Source/HTML/ConfigurationArchitecture.htm trunk/Source/HTML/ConfiguringStructureMap.htm trunk/Source/HTML/CreatingContainer.htm trunk/Source/HTML/EnvironmentTests.htm trunk/Source/HTML/FAQ.htm trunk/Source/HTML/FluentInterfaceAPI.htm trunk/Source/HTML/GentleGuide.htm trunk/Source/HTML/ImplicitInstances.htm trunk/Source/HTML/Profiles.htm trunk/Source/HTML/Scoping.htm trunk/Source/HTML/StructureMapAndMocks.htm trunk/Source/HTML/StructureMapDoctor.htm trunk/Source/HTML/TroubleShooting.htm trunk/Source/HTML/WhatWillStructureMapDoWhenI.htm Deleted: trunk/Source/HTML/AutoMocking.htm =================================================================== --- trunk/Source/HTML/AutoMocking.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/AutoMocking.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/BestPractices.htm =================================================================== --- trunk/Source/HTML/BestPractices.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/BestPractices.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/ChangingDefaultsAtRuntime.htm =================================================================== --- trunk/Source/HTML/ChangingDefaultsAtRuntime.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/ChangingDefaultsAtRuntime.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/CompositeConfiguration.htm =================================================================== --- trunk/Source/HTML/CompositeConfiguration.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/CompositeConfiguration.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/ConcreteTypes.htm =================================================================== --- trunk/Source/HTML/ConcreteTypes.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/ConcreteTypes.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/ConfigurationArchitecture.htm =================================================================== --- trunk/Source/HTML/ConfigurationArchitecture.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/ConfigurationArchitecture.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/ConfiguringStructureMap.htm =================================================================== --- trunk/Source/HTML/ConfiguringStructureMap.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/ConfiguringStructureMap.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Added: trunk/Source/HTML/ConfiguringStructureMap.htm =================================================================== --- trunk/Source/HTML/ConfiguringStructureMap.htm (rev 0) +++ trunk/Source/HTML/ConfiguringStructureMap.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -0,0 +1,558 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> + <head> + <title>Configuring StructureMap</title> + </head> + <body> + <h1>Configuring StructureMap</h1> + + + <p> + </p> + <p> + The first step in using StructureMap is configuring a Container or + ObjectFactory. The configuration options have changed more than anything + else from the initial releases to StructureMap 2.5. You have three forms + of configuration to choose from:</p> + <ol> + <li>The Registry DSL</li> + <li>Xml configuration (StructureMap.config, the App.config file, or named files)</li> + <li>StructureMap Attributes</li> + </ol> + <p> + The configuration is highly modular and you can mix and match configuration + choices within the same Container instance. The strong recommendation is + to use the Registry DSL as much as possible, and use the Xml configuration + strictly for configuration that absolutely must be external to the code + (connection strings, file paths, Url's, etc.). The attributes are + deprecated and largely unnecessary now, but still supported for backwards + compatibility.</p> + <ul> + <li>Registry - </li> + <li>StructureMap.config - </li> + <li>Xml files - </li> + <li>StructureMapConfiguration - StructureMapConfiguration is a static class that + provides an alternative for bootstrapping that was introduced in 2.0. This + class has been problematic and confusing in real world usage. At this + point, StructureMapConfiguration is deprecated and you are strongly urged to use + the ObjectFactory.Initialize() method instead.</li> + </ul> + <p> + </p> + <h4> + Initializing the Container</h4> + <p> + The recommended mechanism for initializing the Container is the Initialize() + method. The Initialize() method is a Nested Closure that acts against an + InitializationExpression object. The InitializationExpression has methods + for all all the possible configuration directives.</p> + <p> + </p> + <p> + </p> + <p> + </p> + <p> + </p> + <h4> + Using a Bootstrapper</h4> + <p> + </p> + <p> + </p> + <h4> + The StructureMap.config File</h4> + <p> + Historically, StructureMap looked for all of its configuration in a file named + "StructureMap.config" file in the ApplicationBase folder. By default, if + the StructureMap.config file is found in the ApplicationBase folder, the Xml + configuration from StructureMap.config will be applied to the internal container + of ObjectFactory. Technically, you could still do all configuration in the + StructureMap.config file. In this case, the StructureMap.config file would + be read and applied in the first call to any of the ObjectFactory methods that + request services. Likewise, StructureMap will not throw any exceptions if + the StructureMap.config file cannot be found.</p> + <p> + The default behavior can be overriden. First, if you are using the + StructureMap.config file, you might want to make the existence of this file + mandatory to prevent odd problems from missing configuration:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 \cf3 // This code enforces the existence of the StructureMap.config file\par ??\cf0 \cf3 // Initialize() will throw an exception if the StructureMap.config file\par ??\cf0 \cf3 // cannot be found\par ??\cf0 \cf4 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.UseDefaultStructureMapConfigFile = \cf5 true\cf0 ;\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: green;">// This code enforces the existence of the + StructureMap.config file</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// Initialize() will throw an exception if the + StructureMap.config file</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// cannot be found</span></p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.UseDefaultStructureMapConfigFile = <span style="color: blue;">true</span>;</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p> + You can also specifically ignore the StructureMap.config file at initialization + time so that the StructureMap.config file will never be used:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.IgnoreStructureMapConfig = \cf4 true\cf0 ;\par ?? \par ?? x.ForRequestedType<\cf3 IWidget\cf0 >().TheDefault.Is\par ?? .OfConcreteType<\cf3 DoctorTester\cf0 .\cf3 NumberWidget\cf0 >()\par ?? .WithCtorArg(\cf5 "age"\cf0 ).EqualToAppSetting(\cf5 "age"\cf0 );\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.IgnoreStructureMapConfig = <span style="color: blue;">true</span>;</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p> + </p> +<p> + </p> +<p> + </p> +<p> + </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 Bootstrapper\cf0 : \cf4 IBootstrapper\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 static\cf0 \cf3 bool\cf0 _hasStarted;\par ??\par ??\cf3 #region\cf0 IBootstrapper Members\par ??\par ?? \cf3 public\cf0 \cf3 void\cf0 BootstrapStructureMap()\par ?? \{\par ?? \cf4 ValidationMessages\cf0 .Register();\par ??\par ?? \cf4 FilterTypeRegistry\cf0 .ResetAll();\par ??\par ?? \cf4 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.AddRegistry(\cf3 new\cf0 \cf4 CoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf3 new\cf0 \cf4 SearchRegistry\cf0 ());\par ?? x.AddRegistry(\cf3 new\cf0 \cf4 WebCoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf3 new\cf0 \cf4 WebRegistry\cf0 ());\par ?? x.AddRegistry(\cf3 new\cf0 \cf4 RuleRegistry\cf0 ());\par ?? \});\par ??\par ?? \cf4 ConventionRegistry\cf0 .RegisterFor<\cf4 CultureValue\cf0 , \cf4 CultureValueObjectListConvention\cf0 >();\par ?? \}\par ??\par ??\cf3 #endregion\par ??\par ??\cf0 \cf3 public\cf0 \cf3 static\cf0 \cf3 void\cf0 Restart()\par ?? \{\par ?? \cf3 if\cf0 (_hasStarted)\par ?? \{\par ?? \cf4 ObjectFactory\cf0 .ResetDefaults();\par ?? \}\par ?? \cf3 else\par ??\cf0 \{\par ?? Bootstrap();\par ?? _hasStarted = \cf3 true\cf0 ;\par ?? \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 static\cf0 \cf3 void\cf0 Bootstrap()\par ?? \{\par ?? \cf3 new\cf0 \cf4 Bootstrapper\cf0 ().BootstrapStructureMap();\par ?? \}\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">Bootstrapper</span> : + <span style="color: #2b91af;">IBootstrapper</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> BootstrapStructureMap()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.AddRegistry(<span style="color: blue;">new</span> + <span style="color: #2b91af;">CoreRegistry</span>());</p> + <p style="margin: 0px;"> + + x.AddRegistry(<span style="color: blue;">new</span> + <span style="color: #2b91af;">SearchRegistry</span>());</p> + <p style="margin: 0px;"> + + x.AddRegistry(<span style="color: blue;">new</span> + <span style="color: #2b91af;">WebCoreRegistry</span>());</p> + <p style="margin: 0px;"> + + x.AddRegistry(<span style="color: blue;">new</span> + <span style="color: #2b91af;">WebRegistry</span>());</p> + <p style="margin: 0px;"> + + x.AddRegistry(<span style="color: blue;">new</span> + <span style="color: #2b91af;">RuleRegistry</span>());</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p style="margin: 0px"> + </p> + <p style="margin: 0px"> + </p> + <p style="margin: 0px"> + * need an example of calling this from Global.asax</p> + <p style="margin: 0px"> + * one of doing from main executable</p> + <p style="margin: 0px"> + *adding Xml file</p> + <p style="margin: 0px"> + * the StructureMap.config file</p> + <p style="margin: 0px"> + * sample Xml file</p> + <p style="margin: 0px"> + </p> + <p style="margin: 0px"> + </p> + <p style="margin: 0px"> + </p> + <h4 style="margin: 0px"> + Adding Configuration to a Container after Initialization</h4> + <p style="margin: 0px"> + </p> + <p style="margin: 0px"> + Sometimes you may want to add additional types and Instances to an existing + container. The Configure() method on both ObjectFactory and IContainer is + used for this purpose. + </p> + <p style="margin: 0px"> + </p> + <p style="margin: 0px"> + Here's a scenario. You're building a composite desktop application, and + for performance reasons you want to delay loading the screens and features for a + module of the application until the user explicitly activates that module. + When the user decides to start using that module, your code needs to immediately + add more types and Instances to the already running ObjectFactory. The + following code would search an assembly named + "MyCompany.MyApp.ExtensionAssembly" for Registry classes. The + configuration embedded in these new Registry classes would be added to the + Container internal to ObjectFactory.</p> + <p style="margin: 0px"> + </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 // Adding configuration from an extension Assembly\par ??\cf0 \cf3 // after ObjectFactory is already configured\par ??\cf0 \cf4 ObjectFactory\cf0 .Configure(x =>\par ?? \{\par ?? x.Scan(scan =>\par ?? \{\par ?? scan.Assembly(\cf5 "MyCompany.MyApp.ExtensionAssembly"\cf0 );\par ?? scan.LookForRegistries();\par ?? \});\par ?? \});} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: green;">// Adding configuration from an extension Assembly</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// after ObjectFactory is already configured</span></p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ObjectFactory</span>.Configure(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.Scan(scan =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + scan.Assembly(<span style="color: #a31515;">"MyCompany.MyApp.ExtensionAssembly"</span>);</p> + <p style="margin: 0px;"> + + scan.LookForRegistries();</p> + <p style="margin: 0px;"> + + });</p> + <p style="margin: 0px;"> + });</p> + </div> +<!--EndFragment--> +<p style="margin: 0px"> + </p> + <p style="margin: 0px"> + </p> + <h4 style="margin: 0px"> + Using Container independent of ObjectFactory</h4> + <p style="margin: 0px"> + </p> + <p style="margin: 0px"> + New to 2.5 is the ability to create an instance of the underlying Container + class independent of the static ObjectFactory class (actually, you always could + do this, but it's much easier in 2.5). The IContainer interface has + roughly the same methods as ObjectFactory (the only major difference is that + ObjectFactory.GetNamedInstance<T>(name) is IContainer.GetInstance<T>(name) ) + You can build a Container with a single Registry object:</p> + <p style="margin: 0px"> + </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (\cf3 new\cf0 \cf4 BasicActionRegistry\cf0 ());} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(<span style="color: blue;">new</span> + <span style="color: #2b91af;">BasicActionRegistry</span>());</p> + </div> +<!--EndFragment--> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + Or more commonly, you can build the Container in a manner very similar to the + ObjectFactory.Initialize() method. One of the constructors for Container + takes in an Action<ConfigurationExpression><ConfigurationExpression> expression + that can be used to configure the Container in one atomic action like this code + below:</p> +<p style="margin: 0px"> + </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.Scan(scanner =>\par ?? \{\par ?? scanner.Assembly(\cf5 "StructureMap.Testing.Widget"\cf0 )\par ?? \});\par ??\par ?? x.ForRequestedType<\cf4 Rule\cf0 >().TheDefault.Is.OfConcreteType<\cf4 ColorRule\cf0 >()\par ?? .WithCtorArg(\cf5 "Color"\cf0 ).EqualTo(\cf5 "Blue"\cf0 );\par ??\par ??\par ?? x.IncludeConfigurationFromConfigFile = \cf3 true\cf0 ;\par ??\par ?? x.AddConfigurationFromXmlFile(\cf5 "ExternalFile.xml"\cf0 );\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.Scan(scanner =></p> + <p style="margin: 0px;"> + + {</p> + <p style="margin: 0px;"> + + scanner.Assembly(<span style="color: #a31515;">"StructureMap.Testing.Widget"</span>)</p> + <p style="margin: 0px;"> + + });</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.ForRequestedType<<span style="color: #2b91af;">Rule</span>>().TheDefault.Is.OfConcreteType<<span + style="color: #2b91af;">ColorRule</span>>()</p> + <p style="margin: 0px;"> + + .WithCtorArg(<span style="color: #a31515;">"Color"</span>).EqualTo(<span + style="color: #a31515;">"Blue"</span>);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.IncludeConfigurationFromConfigFile = <span style="color: blue;">true</span>;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.AddConfigurationFromXmlFile(<span style="color: #a31515;">"ExternalFile.xml"</span>);</p> + <p style="margin: 0px;"> + });</p> +</div> +<!--EndFragment--> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + The ConfigurationExpression class is a Registry, so you can use all of the + Registry DSL in the Lambda expression passed into the Container constructor. + In addition to the Registry DSL, you also have these options:</p> +<p style="margin: 0px"> + </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 bool\cf0 IncludeConfigurationFromConfigFile \{ \cf3 set\cf0 ; \}\par ?? \cf3 void\cf0 AddRegistry<T>() \cf3 where\cf0 T : \cf4 Registry\cf0 , \cf3 new\cf0 ();\par ?? \cf3 void\cf0 AddRegistry(\cf4 Registry\cf0 registry);\par ?? \cf3 void\cf0 AddConfigurationFromXmlFile(\cf3 string\cf0 fileName);\par ?? \cf3 void\cf0 AddConfigurationFromNode(\cf4 XmlNode\cf0 node);} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">bool</span> + IncludeConfigurationFromConfigFile { <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + AddRegistry<T>() <span style="color: blue;">where</span> T : + <span style="color: #2b91af;">Registry</span>, <span style="color: blue;">new</span>();</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + AddRegistry(<span style="color: #2b91af;">Registry</span> registry);</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + AddConfigurationFromXmlFile(<span style="color: blue;">string</span> fileName);</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> + AddConfigurationFromNode(<span style="color: #2b91af;">XmlNode</span> node);</p> + <p style="margin: 0px;"> + </p> +</div> +<!--EndFragment--> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + These other options will allow you to add configuration from additional Registry + classes, the StructureMap section in the App.config file, or other Xml files.</p> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + Lastly, you can create a Container directly with a no argument constructor, then + use the Inject() methods or later use the Configure() method.</p> +<p style="margin: 0px"> + </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 [\cf3 Test\cf0 ]\par ?? \cf4 public\cf0 \cf4 void\cf0 Add_an_assembly_on_the_fly_and_pick_up_plugins2()\par ?? \{\par ?? \cf4 var\cf0 container = \cf4 new\cf0 \cf3 Container\cf0 ();\par ?? container.Configure(\par ?? registry =>\par ?? \{\par ?? registry.Scan(x =>\par ?? \{\par ?? x.AssemblyContainingType(\cf4 typeof\cf0 (\cf3 IService\cf0 <>));\par ?? x.AddAllTypesOf(\cf4 typeof\cf0 (\cf3 IService\cf0 <>));\par ?? \});\par ?? \}\par ?? );\par ??\par ?? \cf3 IList\cf0 <\cf3 IService\cf0 <\cf4 string\cf0 >> instances = container.GetAllInstances<\cf3 IService\cf0 <\cf4 string\cf0 >>();\par ?? instances.Count.ShouldBeGreaterThan(0);\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Test</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> + Add_an_assembly_on_the_fly_and_pick_up_plugins2()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>();</p> + <p style="margin: 0px;"> + container.Configure(</p> + <p style="margin: 0px;"> + + registry =></p> + <p style="margin: 0px;"> + + {</p> + <p style="margin: 0px;"> + + registry.Scan(x =></p> + <p style="margin: 0px;"> + + {</p> + <p style="margin: 0px;"> + + x.AssemblyContainingType(<span style="color: blue;">typeof</span> (<span + style="color: #2b91af;">IService</span><>));</p> + <p style="margin: 0px;"> + + x.AddAllTypesOf(<span style="color: blue;">typeof</span> (<span + style="color: #2b91af;">IService</span><>));</p> + <p style="margin: 0px;"> + + });</p> + <p style="margin: 0px;"> + + }</p> + <p style="margin: 0px;"> + + );</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">IList</span><<span style="color: #2b91af;">IService</span><<span + style="color: blue;">string</span>>> instances = container.GetAllInstances<<span + style="color: #2b91af;">IService</span><<span style="color: blue;">string</span>>>();</p> + <p style="margin: 0px;"> + + instances.Count.ShouldBeGreaterThan(0);</p> + <p style="margin: 0px;"> + }</p> +</div> +<!--EndFragment--> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + </p> +<p> + </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 WebCoreRegistry\cf0 : \cf4 Registry\par ??\cf0 \{\par ?? \cf3 public\cf0 WebCoreRegistry()\par ?? \{\par ?? \cf5 // This is used as a sort of lightweight ScriptManager in\par ??\cf0 \cf5 // our website application\par ??\cf0 ForRequestedType<\cf4 ICachedSet\cf0 >().TheDefaultIsConcreteType<\cf4 CachedSet\cf0 >()\par ?? .CacheBy(\cf4 InstanceScope\cf0 .Hybrid);\par ??\par ?? ForRequestedType<\cf4 IControlBuilder\cf0 >().TheDefault.Is.OfConcreteType<\cf4 AspNetControlBuilder\cf0 >();\par ?? ForRequestedType<\cf4 IPartialRenderer\cf0 >().TheDefault.Is.OfConcreteType<\cf4 PartialRenderer\cf0 >();\par ??\par ?? Scan(x =>\par ?? \{\par ?? \cf5 // Scan "this" assembly. In other words, the assembly that \par ??\cf0 \cf5 // contains the WebCoreRegistry class\par ??\cf0 x.TheCallingAssembly();\par ??\par ?? x.IncludeNamespaceContainingType<\cf4 AuthenticationContext\cf0 >();\par ?? x.IncludeNamespaceContainingType<\cf4 ISecurityDataService\cf0 >();\par ??\par ?? x.WithDefaultConventions();\par ?? \});\par ?? \}\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + class</span> <span style="color: #2b91af;">WebCoreRegistry</span> : + <span style="color: #2b91af;">Registry</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + WebCoreRegistry()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// This is used as a sort of lightweight + ScriptManager in</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// our website application</span></p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">ICachedSet</span>>().TheDefaultIsConcreteType<<span + style="color: #2b91af;">CachedSet</span>>()</p> + <p style="margin: 0px;"> + + .CacheBy(<span style="color: #2b91af;">InstanceScope</span>.Hybrid);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">IControlBuilder</span>>().TheDefault.Is.OfConcreteType<<span + style="color: #2b91af;">AspNetControlBuilder</span>>();</p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">IPartialRenderer</span>>().TheDefault.Is.OfConcreteType<<span + style="color: #2b91af;">PartialRenderer</span>>();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + Scan(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// Scan "this" assembly. In other words, the + assembly that </span> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// contains the WebCoreRegistry class</span></p> + <p style="margin: 0px;"> + + x.TheCallingAssembly();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.IncludeNamespaceContainingType<<span style="color: #2b91af;">AuthenticationContext</span>>();</p> + <p style="margin: 0px;"> + + x.IncludeNamespaceContainingType<<span style="color: #2b91af;">ISecurityDataService</span>>();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.WithDefaultConventions();</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> +</div> +<!--EndFragment--> +<p> + </p> +<h4> + </h4> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + </p> +<p style="margin: 0px"> + </p> +<h4 style="margin: 0px"> + </h4> +<h4 style="margin: 0px"> + StructureMapConfiguration/h4> + <p style="margin: 0px"> + </p> + <p style="margin: 0px"> + </p> + + + </body> +</html> \ No newline at end of file Deleted: trunk/Source/HTML/CreatingContainer.htm =================================================================== --- trunk/Source/HTML/CreatingContainer.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/CreatingContainer.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/EnvironmentTests.htm =================================================================== --- trunk/Source/HTML/EnvironmentTests.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/EnvironmentTests.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/FAQ.htm =================================================================== --- trunk/Source/HTML/FAQ.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/FAQ.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/FluentInterfaceAPI.htm =================================================================== --- trunk/Source/HTML/FluentInterfaceAPI.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/FluentInterfaceAPI.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,13 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title>Configuring StructureMap with the Programmatic API</title> - </head> - <body> - <h4>Configuring StructureMap with the Programmatic API</h4> - - <p> - </p> - - </body> -</html> \ No newline at end of file Deleted: trunk/Source/HTML/GentleGuide.htm =================================================================== --- trunk/Source/HTML/GentleGuide.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/GentleGuide.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Modified: trunk/Source/HTML/HTML.csproj =================================================================== --- trunk/Source/HTML/HTML.csproj 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/HTML.csproj 2008-10-21 22:10:22 UTC (rev 189) @@ -58,42 +58,26 @@ --> <ItemGroup> <Content Include="AttributeNormalized.htm" /> - <Content Include="AutoMocking.htm" /> - <Content Include="BestPractices.htm" /> - <Content Include="ChangingDefaultsAtRuntime.htm" /> - <Content Include="CompositeConfiguration.htm" /> + <Content Include="ConfiguringStructureMap.htm" /> <Content Include="Example.xml" /> <Content Include="Glossary.htm" /> - <Content Include="ConcreteTypes.htm" /> - <Content Include="ConfigurationArchitecture.htm" /> - <Content Include="ConfiguringStructureMap.htm" /> - <Content Include="CreatingContainer.htm" /> <Content Include="Default.htm" /> <Content Include="Diagnostics.htm" /> - <Content Include="EnvironmentTests.htm" /> <Content Include="ExplicitArguments.htm" /> <Content Include="ExtendingStructureMap.htm" /> - <Content Include="FAQ.htm" /> - <Content Include="FluentInterfaceAPI.htm" /> + <Content Include="InstanceExpression.htm" /> + <Content Include="RegistryDSL.htm" /> <Content Include="Generics.htm" /> - <Content Include="GentleGuide.htm" /> - <Content Include="ImplicitInstances.htm" /> <Content Include="InjectingServicesAtRuntime.htm" /> <Content Include="Interception.htm" /> <Content Include="NodeNormalized.htm" /> - <Content Include="Profiles.htm" /> <Content Include="QuickStart.htm" /> <Content Include="RuntimeArchitecture.htm" /> <Content Include="Sample.xml" /> <Content Include="ScanningAssemblies.htm" /> - <Content Include="Scoping.htm" /> <Content Include="ConstructorAndSetterInjection.htm" /> - <Content Include="StructureMapAndMocks.htm" /> - <Content Include="StructureMapDoctor.htm" /> - <Content Include="TroubleShooting.htm" /> <Content Include="RetrievingServices.htm" /> <Content Include="UsingStructureMapWithinUnitTests.htm" /> - <Content Include="WhatWillStructureMapDoWhenI.htm" /> <Content Include="XmlConfiguration.htm" /> </ItemGroup> <ItemGroup> Deleted: trunk/Source/HTML/ImplicitInstances.htm =================================================================== --- trunk/Source/HTML/ImplicitInstances.htm 2008-10-21 22:02:21 UTC (rev 188) +++ trunk/Source/HTML/ImplicitInstances.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -1,9 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html> - <head> - <title></title> - </head> - <body> - - </body> -</html> \ No newline at end of file Added: trunk/Source/HTML/InstanceExpression.htm =================================================================== --- trunk/Source/HTML/InstanceExpression.htm (rev 0) +++ trunk/Source/HTML/InstanceExpression.htm 2008-10-21 22:10:22 UTC (rev 189) @@ -0,0 +1,551 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> + <head> + <title>The Instance Expression</title> + </head> + <body> + <h1>The Instance Expression</h1> + <p> + One of the most common tasks in the Registry DSL [LINK] is defining how an + Instance will be created. In an effort to standardize the Registry DSL and + make the API more predictable and consistent, we have introduced the + "InstanceExpression" as a shared + <a href="http://martinfowler.com/dslwip/ExpressionBuilder.html">Expression + Builder</a>. As of 2.5, all operations in the Registry DSL that require + the definition of an Instance expose an option to use an InstanceExpression with + these options:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IInstanceExpression\cf0 <T> : \cf4 IsExpression\cf0 <T>\par ?? \{\par ?? \cf5 // Attach an Instance object that is configured\par ??\cf0 \cf5 // independently of the DSL\par ??\cf0 \cf3 void\cf0 Instance(\cf4 Instance\cf0 instance);\par ?? \cf3 void\cf0 IsThis(\cf4 Instance\cf0 instance);\par ?? \par ?? \cf5 // Use a pre-built object\par ??\cf0 \cf4 LiteralInstance\cf0 IsThis(T obj);\par ?? \cf4 LiteralInstance\cf0 Object(T theObject);\par ??\par ?? \cf5 // Use a type\par ??\cf0 \cf4 SmartInstance\cf0 <PLUGGEDTYPE> OfConcreteType<PLUGGEDTYPE>() \cf3 where\cf0 PLUGGEDTYPE : T;\par ?? \cf4 ConfiguredInstance\cf0 OfConcreteType(\cf4 Type\cf0 type);\par ??\par ?? \cf5 // Build by a Lambda or an Anonymous Delegate\par ??\cf0 \cf4 ConstructorInstance\cf0 <T> ConstructedBy(\cf4 Func\cf0 <T> func);\par ?? \cf4 ConstructorInstance\cf0 <T> ConstructedBy(\cf4 Func\cf0 <\cf4 IContext\cf0 , T> func);\par ??\par ?? \cf5 // Refer to a named Instance\par ??\cf0 \cf4 ReferencedInstance\cf0 TheInstanceNamed(\cf3 string\cf0 key);\par ?? \cf4 DefaultInstance\cf0 TheDefault();\par ??\par ?? \cf5 // Use a cloned copy of the template\par ??\cf0 \cf4 PrototypeInstance\cf0 PrototypeOf(T template);\par ??\par ?? \cf5 // Cache the template as a binary serialized blob\par ??\cf0 \cf4 SerializedInstance\cf0 SerializedCopyOf(T template);\par ?? \par ?? \cf5 // Load an ASCX control\par ??\cf0 \cf4 UserControlInstance\cf0 LoadControlFrom(\cf3 string\cf0 url);\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;"> + interface</span> <span style="color: #2b91af;">IInstanceExpression</span><T> : <span style="color: #2b91af;">IsExpression</span><T></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: green;">// Attach an Instance + object that is configured</span></p> + <p style="margin: 0px;"> + <span style="color: green;">/// independently of + the DSL. This is an extensibility point</span></p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> Instance(<span + style="color: #2b91af;">Instance</span> instance);</p> + <p style="margin: 0px;"> + <span style="color: blue;">void</span> IsThis(<span + style="color: #2b91af;">Instance</span> instance);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// Use a pre-built + object</span></p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">LiteralInstance</span> + IsThis(T obj);</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">LiteralInstance</span> + Object(T theObject);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// Use a type and + build with its constructor function</span></p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">SmartInstance</span><PLUGGEDTYPE> + OfConcreteType<PLUGGEDTYPE>() <span style="color: blue;">where</span> + PLUGGEDTYPE : T;</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">ConfiguredInstance</span> + OfConcreteType(<span style="color: #2b91af;">Type</span> type);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// Build by a Lambda + or an Anonymous Delegate</span></p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">ConstructorInstance</span><T> + ConstructedBy(<span style="color: #2b91af;">Func</span><T> func);</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">ConstructorInstance</span><T> + ConstructedBy(<span style="color: #2b91af;">Func</span><<span + style="color: #2b91af;">IContext</span>, T> func);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// Refer to a named + Instance</span></p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">ReferencedInstance</span> + TheInstanceNamed(<span style="color: blue;">string</span> key);</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">DefaultInstance</span> + TheDefault();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// Use a cloned copy + of the template</span></p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">PrototypeInstance</span> + PrototypeOf(T template);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// Cache the template + as a binary serialized blob</span></p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">SerializedInstance</span> + SerializedCopyOf(T template);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// Load an ASCX + control</span></p> + <p style="margin: 0px;"> + <span style="color: #2b91af;">UserControlInstance</span> + LoadControlFrom(<span style="color: blue;">string</span> url);</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p> + Here's several examples of how the InstanceExpression is invoked. In the + code sample below, the text "**********;" represents a call to an + InstanceExpression.</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 InstanceExampleRegistry\cf0 : \cf4 Registry\par ??\cf0 \{\par ?? \cf3 public\cf0 InstanceExampleRegistry()\par ?? \{\par ?? \cf5 // Shortcut for just specifying "use this type -- with auto wiring"\par ??\cf0 ForRequestedType<\cf4 IService\cf0 >().TheDefaultIsConcreteType<\cf4 RemoteService\cf0 >();\par ?? \par ?? \cf5 // Set the default Instance of a PluginType\par ??\cf0 ForRequestedType<\cf4 IService\cf0 >().TheDefault.Is.OfConcreteType<\cf4 RemoteService\cf0 >();\par ?? \par ?? \cf5 // Add an additional Instance of a PluginType\par ??\cf0 InstanceOf<\cf4 IService\cf0 >().Is.OfConcreteType<\cf4 RemoteService\cf0 >();\par ??\par ?? \cf5 // Add multiple additional Instances of a PluginType\par ??\cf0 ForRequestedType<\cf4 IService\cf0 >().AddInstances(x =>\par ?? \{\par ?? x.ConstructedBy(() => \cf3 new\cf0 \cf4 ColorService\cf0 (\cf6 "Red"\cf0 ));\par ??\par ?? x.OfConcreteType<\cf4 RemoteService\cf0 >();\par ??\par ?? x.Object(\cf3 new\cf0 \cf4 ColorService\cf0 (\cf6 "Red"\cf0 ));\par ?? \});\par ??\par ?? \cf5 // Use the InstanceExpression to define the default Instance\par ??\cf0 \cf5 // of a PluginType within a Profile\par ??\cf0 CreateProfile(\cf6 "Connected"\cf0 , x =>\par ?? \{\par ?? x.Type<\cf4 IService\cf0 >().Is.OfConcreteType<\cf4 RemoteService\cf0 >();\par ?? \});\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">InstanceExampleRegistry</span> : + <span style="color: #2b91af;">Registry</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + InstanceExampleRegistry()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// Set the default Instance of a PluginType</span></p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">IService</span>>().TheDefault.Is.**********;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Add an additional Instance of a PluginType</span></p> + <p style="margin: 0px;"> + InstanceOf<<span + style="color: #2b91af;">IService</span>>().Is.**********;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Add multiple additional Instances of a PluginType</span></p> + <p style="margin: 0px;"> + ForRequestedType<<span + style="color: #2b91af;">IService</span>>().AddInstances(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.**********;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.**********;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + x.**********;</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Use the InstanceExpression to define the default + Instance</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// of a PluginType within a Profile</span></p> + <p style="margin: 0px;"> + CreateProfile(<span + style="color: #a31515;">"Connected"</span>, x =></p> + <p style="margin: 0px;"> + &nb... [truncated message content] |
From: <jer...@us...> - 2008-10-27 01:07:32
|
Revision: 193 http://structuremap.svn.sourceforge.net/structuremap/?rev=193&view=rev Author: jeremydmiller Date: 2008-10-27 01:07:28 +0000 (Mon, 27 Oct 2008) Log Message: ----------- Making the final check in (knock on wood) for the 2.5 binary release Modified Paths: -------------- trunk/Source/HTML/ConfiguringStructureMap.htm trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/ConfigurationExpression.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/InitializationExpression.cs trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs trunk/Source/StructureMap/Pipeline/BuildFrame.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/IBuildInterceptor.cs trunk/Source/StructureMap/Pipeline/IBuildPolicy.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/SmartInstance.cs trunk/Source/StructureMap.AutoMocking/AutoMocker.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ProfileExpressionTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/ModelQueryTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.dll.config Modified: trunk/Source/HTML/ConfiguringStructureMap.htm =================================================================== --- trunk/Source/HTML/ConfiguringStructureMap.htm 2008-10-23 23:02:07 UTC (rev 192) +++ trunk/Source/HTML/ConfiguringStructureMap.htm 2008-10-27 01:07:28 UTC (rev 193) @@ -15,14 +15,14 @@ else from the initial releases to StructureMap 2.5. You have three forms of configuration to choose from:</p> <ol> - <li>The Registry DSL</li> + <li>The Registry DSL -- The programmatic API for configuring the Container in code.</li> <li>Xml configuration (StructureMap.config, the App.config file, or named files)</li> - <li>StructureMap Attributes</li> + <li>StructureMap Attributes -- Not deprecated, but not really recommended either. </li> </ol> <p> The configuration is highly modular and you can mix and match configuration choices within the same Container instance. The strong recommendation is - to use the Registry DSL as much as possible, and use the Xml configuration + to use the Registry DSL as much as possible, then use the Xml configuration strictly for configuration that absolutely must be external to the code (connection strings, file paths, Url's, etc.). The attributes are deprecated and largely unnecessary now, but still supported for backwards @@ -42,89 +42,433 @@ <h4> Initializing the Container</h4> <p> - The recommended mechanism for initializing the Container is the Initialize() - method. The Initialize() method is a Nested Closure that acts against an - InitializationExpression object. The InitializationExpression has methods + The recommended mechanism for initializing the Container or ObjectFactory is the Initialize() + method. The Initialize() method is new for StructureMap 2.5, and largely + driven by (my current love affair with Lambda's) the confusion and misuse of + StructureMapConfiguration. StructureMapConfiguration is still supported, + but it is deprecated in the code and will be eliminated in a future release. Initialize() is a Nested Closure that + gives you a chance to express directives telling the Container how to construct + itself and add one or more sources of configuration. </p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 Container(\cf4 Action\cf0 <\cf4 ConfigurationExpression\cf0 > action)\par ?? \{\par ?? \cf3 var\cf0 expression = \cf3 new\cf0 \cf4 ConfigurationExpression\cf0 ();\par ?? action(expression);\par ??\par ?? construct(expression.BuildGraph());\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">public Container(</span><span + style="color: #2b91af; overflow: scroll;">Action</span><span + style="overflow: scroll;"><</span><span + style="color: #2b91af; overflow: scroll;">ConfigurationExpression</span><span + style="overflow: scroll;">> action)</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> {</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">var</span><span + style="overflow: scroll;"> expression = </span> + <span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">ConfigurationExpression</span><span + style="overflow: scroll;">();</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + action(expression);</span></p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + construct(expression.BuildGraph());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> }</span></p> +</div> +<!--EndFragment--> +</div> +<!--EndFragment--> +<p> + Typically, you would make a single call to the Initialize() method at + application start up (Global.asax for web application, or the main routine for a + desktop application). The Container (ObjectFactory is simply a static + wrapper around a single Container) is completely initialized and configured by + the Initialize() method in one atomic action. <b>Any successive calls to + Initialize() will effectively wipe out any existing configuration and + effectively restart the Container.</b> Here's a sample usage of + Initialize():</p> + +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.UseDefaultStructureMapConfigFile = \cf4 true\cf0 ;\par ??\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 CoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 SearchRegistry\cf0 ());\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 WebCoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 WebRegistry\cf0 ());\par ?? x.AddRegistry(\cf4 new\cf0 \cf3 RuleRegistry\cf0 ());\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: #2b91af; overflow: scroll;">ObjectFactory</span><span + style="overflow: scroll;">.Initialize(x =></span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + {</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.UseDefaultStructureMapConfigFile = </span> + <span style="color: blue; overflow: scroll;">true</span><span + style="overflow: scroll;">;</span></p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">CoreRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">SearchRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">WebCoreRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">WebRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + x.AddRegistry(</span><span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">RuleRegistry</span><span + style="overflow: scroll;">());</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + });</span></p> +</div> +<!--EndFragment--> +<p> + Inside the Initialization() method you can declare directives against an + InitializationExpression object. The InitializationExpression object has + these methods for all all the possible configuration directives.</p> - <p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IInitializationExpression\par ??\cf0 \{\par ?? \cf5 // Directives on how to treat the StructureMap.config file\par ??\cf0 \cf3 bool\cf0 UseDefaultStructureMapConfigFile \{ \cf3 set\cf0 ; \}\par ?? \cf3 bool\cf0 IgnoreStructureMapConfig \{ \cf3 set\cf0 ; \}\par ??\par ?? \cf5 // Xml configuration from the App.Config file\par ??\cf0 \cf3 bool\cf0 PullConfigurationFromAppConfig \{ \cf3 set\cf0 ; \}\par ??\par ?? \cf5 // Ancillary sources of Xml configuration\par ??\cf0 \cf3 void\cf0 AddConfigurationFromXmlFile(\cf3 string\cf0 fileName);\par ?? \cf3 void\cf0 AddConfigurationFromNode(\cf4 XmlNode\cf0 node);\par ??\par ?? \cf5 // Specifying Registry's\par ??\cf0 \cf3 void\cf0 AddRegistry<T>() \cf3 where\cf0 T : \cf4 Registry\cf0 , \cf3 new\cf0 ();\par ?? \cf3 void\cf0 AddRegistry(\cf4 Registry\cf0 registry);\par ??\par ?? \cf5 // Designate the Default Profile. This will be applied as soon as the \par ??\cf0 \cf5 // Container is initialized.\par ??\cf0 \cf3 string\cf0 DefaultProfileName \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ??\par ?? \cf5 // ... and the Registry DSL as well\par ??\par ??\cf0 \cf5 // The Registry DSL\par ??\cf0 \cf4 CreatePluginFamilyExpression\cf0 <PLUGINTYPE> BuildInstancesOf<PLUGINTYPE>();\par ?? \cf4 CreatePluginFamilyExpression\cf0 <PLUGINTYPE> ForRequestedType<PLUGINTYPE>();\par ?? \cf4 GenericFamilyExpression\cf0 ForRequestedType(\cf4 Type\cf0 pluginType);\par ?? \cf4 Registry\cf0 .\cf4 BuildWithExpression\cf0 <T> ForConcreteType<T>();\par ??\par ?? \cf4 IsExpression\cf0 <T> InstanceOf<T>();\par ?? \cf4 GenericIsExpression\cf0 InstanceOf(\cf4 Type\cf0 pluginType);\par ??\par ?? \cf4 ProfileExpression\cf0 CreateProfile(\cf3 string\cf0 profileName);\par ?? \cf3 void\cf0 CreateProfile(\cf3 string\cf0 profileName, \cf4 Action\cf0 <\cf4 ProfileExpression\cf0 > action);\par ??\par ?? \cf3 void\cf0 RegisterInterceptor(\cf4 TypeInterceptor\cf0 interceptor);\par ?? \cf4 MatchedTypeInterceptor\cf0 IfTypeMatches(\cf4 Predicate\cf0 <\cf4 Type\cf0 > match);\par ??\par ?? \cf3 void\cf0 Scan(\cf4 Action\cf0 <\cf4 IAssemblyScanner\cf0 > action);\par ??\par ?? \cf4 CreatePluginFamilyExpression\cf0 <PLUGINTYPE> FillAllPropertiesOfType<PLUGINTYPE>();\par ?? \}} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> </p> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> </span> + <span style="color: blue; overflow: scroll;">public</span><span + style="overflow: scroll;"> </span> + <span style="color: blue; overflow: scroll;">interface</span><span + style="overflow: scroll;"> </span> + <span style="color: #2b91af; overflow: scroll;">IInitializationExpression</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> {</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Directives on how to + treat the StructureMap.config file</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">bool</span><span + style="overflow: scroll;"> UseDefaultStructureMapConfigFile { </span> + <span style="color: blue; overflow: scroll;">set</span><span + style="overflow: scroll;">; }</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">bool</span><span + style="overflow: scroll;"> IgnoreStructureMapConfig { </span> + <span style="color: blue; overflow: scroll;">set</span><span + style="overflow: scroll;">; }</span></p> + <p style="margin: 0px;"> </p> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Xml configuration from + the App.Config file</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">bool</span><span + style="overflow: scroll;"> PullConfigurationFromAppConfig { </span> + <span style="color: blue; overflow: scroll;">set</span><span + style="overflow: scroll;">; }</span></p> + <p style="margin: 0px;"> </p> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Ancillary sources of Xml + configuration</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">void</span><span + style="overflow: scroll;"> AddConfigurationFromXmlFile(</span><span + style="color: blue; overflow: scroll;">string</span><span + style="overflow: scroll;"> fileName);</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">void</span><span + style="overflow: scroll;"> AddConfigurationFromNode(</span><span + style="color: #2b91af; overflow: scroll;">XmlNode</span><span + style="overflow: scroll;"> node);</span></p> + <p style="margin: 0px;"> </p> - <h4> - Using a Bootstrapper</h4> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Specifying Registry's</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">void</span><span + style="overflow: scroll;"> AddRegistry<T>() </span> + <span style="color: blue; overflow: scroll;">where</span><span + style="overflow: scroll;"> T : </span> + <span style="color: #2b91af; overflow: scroll;">Registry</span><span + style="overflow: scroll;">, </span> + <span style="color: blue; overflow: scroll;">new</span><span + style="overflow: scroll;">();</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">void</span><span + style="overflow: scroll;"> AddRegistry(</span><span + style="color: #2b91af; overflow: scroll;">Registry</span><span + style="overflow: scroll;"> registry);</span></p> + <p style="margin: 0px;"> </p> - <p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Designate the Default + Profile. This will be applied as soon as the </span> + </p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// Container is + initialized.</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: blue; overflow: scroll;">string</span><span + style="overflow: scroll;"> DefaultProfileName { </span> + <span style="color: blue; overflow: scroll;">get</span><span + style="overflow: scroll;">; </span> + <span style="color: blue; overflow: scroll;">set</span><span + style="overflow: scroll;">; }</span></p> + <p style="margin: 0px;"> </p> - <h4> - The StructureMap.config File</h4> - <p> - Historically, StructureMap looked for all of its configuration in a file named - "StructureMap.config" file in the ApplicationBase folder. By default, if - the StructureMap.config file is found in the ApplicationBase folder, the Xml - configuration from StructureMap.config will be applied to the internal container - of ObjectFactory. Technically, you could still do all configuration in the - StructureMap.config file. In this case, the StructureMap.config file would - be read and applied in the first call to any of the ObjectFactory methods that - request services. Likewise, StructureMap will not throw any exceptions if - the StructureMap.config file cannot be found.</p> - <p> - The default behavior can be overriden. First, if you are using the - StructureMap.config file, you might want to make the existence of this file - mandatory to prevent odd problems from missing configuration:</p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> + </span><span style="color: green; overflow: scroll;">// ... and the Registry DSL + as well</span></p> + <p style="margin: 0px;"> + <span style="overflow: scroll;"> }</span></p> + <p style="margin: 0px;"> + </p> +</div> +<!--EndFragment--> +<p> + </p> +<h4> + Adding Configuration to an Existing Container</h4> +<p> + In contrast to Initialize(), the Configure() method allows you to add additional + configuration to an existing Container or ObjectFactory. Think of this + scenario. You're building a composite application that contains multiple + modules spread over several assemblies, but you might not want to load any of + the configuration or types for a particular module until it's requested by the + user. In that case, you can use the Configure() method like this:</p> <!-- -{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 \cf3 // This code enforces the existence of the StructureMap.config file\par ??\cf0 \cf3 // Initialize() will throw an exception if the StructureMap.config file\par ??\cf0 \cf3 // cannot be found\par ??\cf0 \cf4 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.UseDefaultStructureMapConfigFile = \cf5 true\cf0 ;\par ?? \});} +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 // This code would add any configuration from\par ??\cf0 \cf3 // Registry classes found in the \par ??\cf0 \cf3 // assembly named 'MyApplication.Module1'\par ??\cf0 \cf4 ObjectFactory\cf0 .Configure(x =>\par ?? \{\par ?? x.Scan(scan =>\par ?? \{\par ?? scan.LookForRegistries();\par ?? scan.Assembly(\cf5 "MyApplication.Module1"\cf0 );\par ?? \});\par ?? \});} --> -<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid; overflow: scroll;"> <p style="margin: 0px;"> - <span style="color: green;">// This code enforces the existence of the - StructureMap.config file</span></p> + <span style="color: green;">// This code would add any configuration from</span></p> <p style="margin: 0px;"> - <span style="color: green;">// Initialize() will throw an exception if the - StructureMap.config file</span></p> + <span style="color: green;">// Registry classes found in the </span> + </p> <p style="margin: 0px;"> - <span style="color: green;">// cannot be found</span></p> + <span style="color: green;">// assembly named 'MyApplication.Module1'</span></p> <p style="margin: 0px;"> - <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <span style="color: #2b91af;">ObjectFactory</span>.Configure(x =></p> <p style="margin: 0px;"> {</p> <p style="margin: 0px;"> - x.UseDefaultStructureMapConfigFile = <span style="color: blue;">true</span>;</p> + x.Scan(scan =></p> <p style="margin: 0px;"> + + {</p> + <p style="margin: 0px;"> + + scan.LookForRegistries();</p> + <p style="margin: 0px;"> + + scan.Assembly(<span style="color: #a31515;">"MyApplication.Module1"</span>);</p> + <p style="margin: 0px;"> + + });</p> + <p style="margin: 0px;"> });</p> </div> <!--EndFragment--> <p> - You can also specifically ignore the StructureMap.config file at initialization - time so that the StructureMap.config file will never be used:</p> + To summarize, Initialize() completely resets the configuration of a Container, + and Configure() is purely additive. If Configure() should happen to be + called before Initialize(), it will set up the Container with the configuration + in the Configure() call. Configure() offers a subset of the Initialize() + method (it leaves out the directives for the StructureMap.config file), and it + also includes the entire Registry DSL. You can take advantage of that fact + to add a few types or instances at a time:</p> <!-- -{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.IgnoreStructureMapConfig = \cf4 true\cf0 ;\par ?? \par ?? x.ForRequestedType<\cf3 IWidget\cf0 >().TheDefault.Is\par ?? .OfConcreteType<\cf3 DoctorTester\cf0 .\cf3 NumberWidget\cf0 >()\par ?? .WithCtorArg(\cf5 "age"\cf0 ).EqualToAppSetting(\cf5 "age"\cf0 );\par ?? \});} +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;}??\fs20 \par ?? \cf3 ObjectFactory\cf0 .Configure(x =>\par ?? \{\par ?? x.ForRequestedType<\cf3 ISomething\cf0 >().TheDefaultIsConcreteType<\cf3 SomethingOne\cf0 >();\par ?? \});\par ??} --> -<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid; overflow: scroll;"> <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> - <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <span style="color: #2b91af;">ObjectFactory</span>.Configure(x =></p> <p style="margin: 0px;"> {</p> <p style="margin: 0px;"> - x.IgnoreStructureMapConfig = <span style="color: blue;">true</span>;</p> + x.ForRequestedType<<span style="color: #2b91af;">ISomething</span>>().TheDefaultIsConcreteType<<span + style="color: #2b91af;">SomethingOne</span>>();</p> <p style="margin: 0px;"> });</p> </div> <!--EndFragment--> <p> - </p> + </p> <p> + </p> +<p> + </p> +<h4> + Using the App.Config File</h4> +<p> + The <a href="http://msdn.microsoft.com/en-us/library/system.configuration.aspx"> + System.Configuration</a> namespace in the .Net framework provides a lot of + functionality for caching and encrypting configuration. To take advantage + of this functionality StructureMap offers an option to embed configuration + directly into the App.config file (web.config for web development). Just + add a section for StructureMap like this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;\red0\green128\blue0;}??\fs20 \cf1 <?\cf3 xml\cf1 \cf4 version\cf1 =\cf0 "\cf1 1.0\cf0 "\cf1 \cf4 encoding\cf1 =\cf0 "\cf1 utf-8\cf0 "\cf1 ?>\par ??<\cf3 configuration\cf1 >\par ?? <\cf3 configSections\cf1 >\par ?? <\cf3 section\cf1 \cf4 name\cf1 =\cf0 "\cf1 StructureMap\cf0 "\cf1 \cf4 type\cf1 =\cf0 "\cf1 StructureMap.Configuration.StructureMapConfigurationSection,StructureMap\cf0 "\cf1 />\par ?? </\cf3 configSections\cf1 >\par ??\par ?? <\cf3 StructureMap\cf1 >\par ?? <!--\cf6 Put StructureMap configuration here \cf1 -->\par ?? \par ?? <\cf3 Assembly\cf1 \cf4 Name\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 />\par ??\par ?? <\cf3 PluginFamily\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.IThing`2\cf0 "\cf1 \cf4 DefaultKey\cf1 =\cf0 "\cf1 Cornflower\cf0 "\cf1 >\par ?? <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.ColorThing`2\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Color\cf0 "\cf1 />\par ?? <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.ComplexThing`2\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Complex\cf0 "\cf1 />\par ??\par ?? <\cf3 Instance\cf1 \cf4 Key\cf1 =\cf0 "\cf1 Cornflower\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 Color\cf0 "\cf1 >\par ?? <\cf3 Property\cf1 \cf4 Name\cf1 =\cf0 "\cf1 color\cf0 "\cf1 \cf4 Value\cf1 =\cf0 "\cf1 Cornflower\cf0 "\cf1 />\par ?? </\cf3 Instance\cf1 >\par ??\par ?? <\cf3 Instance\cf1 \cf4 Key\cf1 =\cf0 "\cf1 Complicated\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 Complex\cf0 "\cf1 >\par ?? <\cf3 Property\cf1 \cf4 Name\cf1 =\cf0 "\cf1 name\cf0 "\cf1 \cf4 Value\cf1 =\cf0 "\cf1 Jeremy\cf0 "\cf1 />\par ?? <\cf3 Property\cf1 \cf4 Name\cf1 =\cf0 "\cf1 age\cf0 "\cf1 \cf4 Value\cf1 =\cf0 "\cf1 32\cf0 "\cf1 />\par ?? <\cf3 Property\cf1 \cf4 Name\cf1 =\cf0 "\cf1 ready\cf0 "\cf1 \cf4 Value\cf1 =\cf0 "\cf1 true\cf0 "\cf1 />\par ?? </\cf3 Instance\cf1 >\par ?? </\cf3 PluginFamily\cf1 >\par ??\par ?? <\cf3 PluginFamily\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.ISimpleThing`1\cf0 "\cf1 \cf4 DefaultKey\cf1 =\cf0 "\cf1 Simple\cf0 "\cf1 >\par ?? <\cf3 Plugin\cf1 \cf4 Assembly\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets\cf0 "\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.GenericWidgets.SimpleThing`1\cf0 "\cf1 \cf4 ConcreteKey\cf1 =\cf0 "\cf1 Simple\cf0 "\cf1 />\par ?? </\cf3 PluginFamily\cf1 >\par ?? </\cf3 StructureMap\cf1 >\par ?? \par ?? \par ?? <\cf3 appSettings\cf1 >\par ?? <\cf3 add\cf1 \cf4 key\cf1 =\cf0 "\cf1 Color\cf0 "\cf1 \cf4 value\cf1 =\cf0 "\cf1 Blue\cf0 "\cf1 />\par ?? <\cf3 add\cf1 \cf4 key\cf1 =\cf0 "\cf1 Day\cf0 "\cf1 \cf4 value\cf1 =\cf0 "\cf1 Monday\cf0 "\cf1 />\par ?? </\cf3 appSettings\cf1 >\par ??\par ??\par ??</\cf3 configuration\cf1 >} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid; overflow: scroll;"> + <p style="margin: 0px;"> + <span style="color: blue;"><?</span><span style="color: #a31515;">xml</span><span + style="color: blue;"> </span><span style="color: red;">version</span><span + style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span + style="color: blue;"> </span><span style="color: red;">encoding</span><span + style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span + style="color: blue;"> ?></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"><</span><span style="color: #a31515;">configuration</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">configSections</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span + style="color: #a31515;">section</span><span style="color: blue;"> </span> + <span style="color: red;">name</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap</span>"<span style="color: blue;"> </span> + <span style="color: red;">type</span><span style="color: blue;">=</span>"<span + style="color: blue;">StructureMap.Configuration.StructureMapConfigurationSection,StructureMap</span>"<span + style="color: blue;">/></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span style="color: #a31515;">configSections</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">StructureMap</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <!--</span><span + style="color: green;"> Put StructureMap configuration here </span> + <span style="color: blue;">--></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> </</span><span style="color: #a31515;">StructureMap</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"></</span><span style="color: #a31515;">configuration</span><span + style="color: blue;">></span></p> +</div> +<!--EndFragment--> +<p> + Then you need to explicitly tell ObjectFactory to use this configuration:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red0\green128\blue0;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.UseDefaultStructureMapConfigFile = \cf4 false\cf0 ;\par ??\par ?? \cf5 // Tell StructureMap to look for configuration \par ??\cf0 \cf5 // from the App.config file\par ??\cf0 \cf5 // The default is false\par ??\cf0 x.PullConfigurationFromAppConfig = \cf4 true\cf0 ;\par ?? \});} +--> +<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid; overflow: scroll;"> + <p style="margin: 0px;"> + + <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// Tell StructureMap to look for configuration </span> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// from the App.config file</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// The default is false</span></p> + <p style="margin: 0px;"> + + x.PullConfigurationFromAppConfig = <span style="color: blue;">true</span>;</p> + <p style="margin: 0px;"> +& });</p> +</div> +<!--EndFragment--> +<p> + </p> +<h4> + The StructureMap.config File</h4> +<p>In the beginning, StructureMap configuration began and ended with a single file named "StructureMap.config" in the application base folder that contained StructureMap Xml configuration (in short, wherever your App.config file would go). Today, the default behavior is that StructureMap will automatically read in configuration data from the StructureMap.config if it is found when either ObjectFactory.Initialize() is called, or the first time that a service is requested from ObjectFactory. You can technically use only the StructureMap.config file and completely forgo the the usage of any programmatic bootstrapping./p> + +<p>You can override the default behavior for the StructureMap.config file. If you want to make the StructureMap.config file mandatory, you can do this:</p> + <!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green128\blue0;\red0\green0\blue255;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? \cf4 // We put the properties for an NHibernate ISession\par ??\cf0 \cf4 // in the StructureMap.config file, so this file\par ??\cf0 \cf4 // must be there for our application to \par ??\cf0 \cf4 // function correctly\par ??\cf0 x.UseDefaultStructureMapConfigFile = \cf5 true\cf0 ;\par ??\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 CoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 SearchRegistry\cf0 ());\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 WebCoreRegistry\cf0 ());\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 WebRegistry\cf0 ());\par ?? x.AddRegistry(\cf5 new\cf0 \cf3 RuleRegistry\cf0 ());\par ?? \});} +--> <div style="border: thin solid black; background: white none repeat scroll 0% 0%; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new;"> +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: rgb(43, 145, 175);">ObjectFactory</span><span style="overflow: scroll;">.Initialize(x =></span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> {</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: green;">// We put the properties for an NHibernate ISession</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: green;">// in the StructureMap.config file, so this file</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: green;">// must be there for our application to </span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: green;">// function correctly</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> x.UseDefaultStructureMapConfigFile = </span><span style="overflow: scroll; color: blue;">true</span><span style="overflow: scroll;">;</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> });</span></p> + </div> <!--EndFragment--> +<p>At other times you might want to force ObjectFactory to ignore the StructureMap.config file even if it does exist.</p> + <!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20 \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.IgnoreStructureMapConfig = \cf4 true\cf0 ;\par ?? \par ?? x.ForRequestedType<\cf3 IWidget\cf0 >().TheDefault.Is\par ?? .OfConcreteType<\cf3 DoctorTester\cf0 .\cf3 NumberWidget\cf0 >()\par ?? .WithCtorArg(\cf5 "age"\cf0 ).EqualToAppSetting(\cf5 "age"\cf0 );\par ?? \});} +--> <div style="border: thin solid black; background: white none repeat scroll 0% 0%; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: black; font-family: courier new;"> +<p style="margin: 0px;"><span style="overflow: scroll;"> </span><span style="overflow: scroll; color: rgb(43, 145, 175);">ObjectFactory</span><span style="overflow: scroll;">.Initialize(x =></span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> {</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;"> x.IgnoreStructureMapConfig = </span><span style="overflow: scroll; color: blue;">true</span><span style="overflow: scroll;">;</span></p> + +<p style="margin: 0px;"><span style="overflow: scroll;">& });</span></p> + </div> <!--EndFragment--><p> + </p> +<p> </p> <p> </p> @@ -147,7 +491,7 @@ {</p> <p style="margin: 0px;"> - <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =></p> + <span style="color: #2b91af;">ObjectFactory</span>.Initialize(x =>/p> <p style="margin: 0px;"> {</p> <p style="margin: 0px;"> @@ -195,74 +539,14 @@ <p style="margin: 0px"> </p> <p style="margin: 0px"> - </p> + & </p> <p style="margin: 0px"> </p> <h4 style="margin: 0px"> - Adding Configuration to a Container after Initialization</h4> + Using Container independent of ObjectFactory/h4> <p style="margin: 0px"> </p> <p style="margin: 0px"> - Sometimes you may want to add additional types and Instances to an existing - container. The Configure() method on both ObjectFactory and IContainer is - used for this purpose. - </p> - <p style="margin: 0px"> - </p> - <p style="margin: 0px"> - Here's a scenario. You're building a composite desktop application, and - for performance reasons you want to delay loading the screens and features for a - module of the application until the user explicitly activates that module. - When the user decides to start using that module, your code needs to immediately - add more types and Instances to the already running ObjectFactory. The - following code would search an assembly named - "MyCompany.MyApp.ExtensionAssembly" for Registry classes. The - configuration embedded in these new Registry classes would be added to the - Container internal to ObjectFactory.</p> - <p style="margin: 0px"> - </p> -<!-- -{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green128\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 // Adding configuration from an extension Assembly\par ??\cf0 \cf3 // after ObjectFactory is already configured\par ??\cf0 \cf4 ObjectFactory\cf0 .Configure(x =>\par ?? \{\par ?? x.Scan(scan =>\par ?? \{\par ?? scan.Assembly(\cf5 "MyCompany.MyApp.ExtensionAssembly"\cf0 );\par ?? scan.LookForRegistries();\par ?? \});\par ?? \});} ---> - <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> - <p style="margin: 0px;"> - - <span style="color: green;">// Adding configuration from an extension Assembly</span></p> - <p style="margin: 0px;"> - - <span style="color: green;">// after ObjectFactory is already configured</span></p> - <p style="margin: 0px;"> - - <span style="color: #2b91af;">ObjectFactory</span>.Configure(x =></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - x.Scan(scan =></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - scan.Assembly(<span style="color: #a31515;">"MyCompany.MyApp.ExtensionAssembly"</span>);</p> - <p style="margin: 0px;"> - - scan.LookForRegistries();</p> - <p style="margin: 0px;"> - - });</p> - <p style="margin: 0px;"> - });</p> - </div> -<!--EndFragment--> -<p style="margin: 0px"> - </p> - <p style="margin: 0px"> - </p> - <h4 style="margin: 0px"> - Using Container independent of ObjectFactory</h4> - <p style="margin: 0px"> - </p> - <p style="margin: 0px"> New to 2.5 is the ability to create an instance of the underlying Container class independent of the static ObjectFactory class (actually, you always could do this, but it's much easier in 2.5). The IContainer interface has @@ -454,101 +738,13 @@ <p style="margin: 0px"> </p> <p style="margin: 0px"> - </p> -<p> - </p> -<!-- -{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 WebCoreRegistry\cf0 : \cf4 Registry\par ??\cf0 \{\par ?? \cf3 public\cf0 WebCoreRegistry()\par ?? \{\par ?? \cf5 // This is used as a sort of lightweight ScriptManager in\par ??\cf0 \cf5 // our website application\par ??\cf0 ForRequestedType<\cf4 ICachedSet\cf0 >().TheDefaultIsConcreteType<\cf4 CachedSet\cf0 >()\par ?? .CacheBy(\cf4 InstanceScope\cf0 .Hybrid);\par ??\par ?? ForRequestedType<\cf4 IControlBuilder\cf0 >().TheDefault.Is.OfConcreteType<\cf4 AspNetControlBuilder\cf0 >();\par ?? ForRequestedType<\cf4 IPartialRenderer\cf0 >().TheDefault.Is.OfConcreteType<\cf4 PartialRenderer\cf0 >();\par ??\par ?? Scan(x =>\par ?? \{\par ?? \cf5 // Scan "this" assembly. In other words, the assembly that \par ??\cf0 \cf5 // contains the WebCoreRegistry class\par ??\cf0 x.TheCallingAssembly();\par ??\par ?? x.IncludeNamespaceContainingType<\cf4 AuthenticationContext\cf0 >();\par ?? x.IncludeNamespaceContainingType<\cf4 ISecurityDataService\cf0 >();\par ??\par ?? x.WithDefaultConventions();\par ?? \});\par ?? \}\par ?? \}} ---> -<div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> - <p style="margin: 0px;"> - <span style="color: blue;">public</span> <span style="color: blue;"> - class</span> <span style="color: #2b91af;">WebCoreRegistry</span> : - <span style="color: #2b91af;">Registry</span></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - <span style="color: blue;">public</span> - WebCoreRegistry()</p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - <span style="color: green;">// This is used as a sort of lightweight - ScriptManager in</span></p> - <p style="margin: 0px;"> - - <span style="color: green;">// our website application</span></p> - <p style="margin: 0px;"> - ForRequestedType<<span - style="color: #2b91af;">ICachedSet</span>>().TheDefaultIsConcreteType<<span - style="color: #2b91af;">CachedSet</span>>()</p> - <p style="margin: 0px;"> - - .CacheBy(<span style="color: #2b91af;">InstanceScope</span>.Hybrid);</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - ForRequestedType<<span - style="color: #2b91af;">IControlBuilder</span>>().TheDefault.Is.OfConcreteType<<span - style="color: #2b91af;">AspNetControlBuilder</span>>();</p> - <p style="margin: 0px;"> - ForRequestedType<<span - style="color: #2b91af;">IPartialRenderer</span>>().TheDefault.Is.OfConcreteType<<span - style="color: #2b91af;">PartialRenderer</span>>();</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - Scan(x =></p> - <p style="margin: 0px;"> - {</p> - <p style="margin: 0px;"> - - <span style="color: green;">// Scan "this" assembly. In other words, the - assembly that </span> - </p> - <p style="margin: 0px;"> - - <span style="color: green;">// contains the WebCoreRegistry class</span></p> - <p style="margin: 0px;"> - - x.TheCallingAssembly();</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - - x.IncludeNamespaceContainingType<<span style="color: #2b91af;">AuthenticationContext</span>>();</p> - <p style="margin: 0px;"> - - x.IncludeNamespaceContainingType<<span style="color: #2b91af;">ISecurityDataService</span>>();</p> - <p style="margin: 0px;"> - </p> - <p style="margin: 0px;"> - - x.WithDefaultConventions();</p> - <p style="margin: 0px;"> - });</p> - <p style="margin: 0px;"> - }</p> - <p style="margin: 0px;"> - }</p> -</div> -<!--EndFragment--> -<p> - </p> -<h4> - </h4> + & </p> <p style="margin: 0px"> </p> -<p style="margin: 0px"> - </p> -<p style="margin: 0px"> - </p> <h4 style="margin: 0px"> </h4> <h4 style="margin: 0px"> - StructureMapConfiguration/h4> - <p style="margin: 0px"> + StructureMapConfigurationp style="margin: 0px"> </p> <p style="margin: 0px"> </p> Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-10-23 23:02:07 UTC (rev 192) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2008-10-27 01:07:28 UTC (rev 193) @@ -8,7 +8,8 @@ namespace StructureMap.Configuration.DSL.Expressions { /// <summary> - /// Represents the parameters for creating instances of a given Type + /// Expression Builder that has grammars for defining policies at the + /// PluginType level /// </summary> public class CreatePluginFamilyExpression<PLUGINTYPE> { @@ -29,11 +30,19 @@ }); } + /// <summary> + /// Define the Default Instance for this PluginType + /// </summary> public IsExpression<PLUGINTYPE> TheDefault { get { return new InstanceExpression<PLUGINTYPE>(i => registerDefault(i)); } } + /// <summary> + /// Add multiple Instance's to this PluginType + /// </summary> + /// <param name="action"></param> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> AddInstances(Action<IInstanceExpression<PLUGINTYPE>> action) { var list = new List<Instance>(); @@ -108,7 +117,12 @@ return this; } - + /// <summary> + /// Register an Action to run against any object of this PluginType immediately after + /// it is created, but before the new object is passed back to the caller + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(Action<PLUGINTYPE> handler) { _children.Add( @@ -127,6 +141,14 @@ return this; } + /// <summary> + /// Register a Func to run against any object of this PluginType immediately after it is created, + /// but before the new object is passed back to the caller. Unlike <see cref="OnCreation">OnCreation()</see>, + /// EnrichWith() gives the the ability to return a different object. Use this method for runtime AOP + /// scenarios or to return a decorator. + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(EnrichmentHandler<PLUGINTYPE> handler) { _children.Add( @@ -141,9 +163,20 @@ return this; } - + /// <summary> + /// Shortcut method to add an additional Instance to this Plugin Type + /// as just a Concrete Type. This will only work if the Concrete Type + /// has no primitive constructor or mandatory Setter arguments. + /// </summary> + /// <typeparam name="PLUGGEDTYPE"></typeparam> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> AddConcreteType<PLUGGEDTYPE>() { + if (!PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).CanBeAutoFilled) + { + throw new StructureMapException(231); + } + _alterations.Add(family => { string name = PluginCache.GetPlugin(typeof (PLUGGEDTYPE)).ConcreteKey; @@ -154,12 +187,24 @@ return this; } + /// <summary> + /// Registers an IBuildInterceptor for this Plugin Type that executes before + /// any object of this PluginType is created. IBuildInterceptor's can be + /// used to create a custom scope + /// </summary> + /// <param name="interceptor"></param> + /// <returns></returns> public CreatePlu... [truncated message content] |
From: <fli...@us...> - 2008-12-19 02:41:31
|
Revision: 199 http://structuremap.svn.sourceforge.net/structuremap/?rev=199&view=rev Author: flimflan Date: 2008-12-19 02:41:25 +0000 (Fri, 19 Dec 2008) Log Message: ----------- Removed static reference to Rhino.Mocks.dll in AutoMocker - Allows Ayende to release as often as he wants, and we dont have to stay in synch - Allows MVBA to continue to live on the bleeding edge Modified Paths: -------------- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/ServiceLocator.cs trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.AutoMocking/RhinoMockRepositoryProxy.cs trunk/Source/StructureMap.Testing/AutoMocking/RhinoMockRepositoryProxyTester.cs Modified: trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-12-17 16:41:58 UTC (rev 198) +++ trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs 2008-12-19 02:41:25 UTC (rev 199) @@ -1,9 +1,4 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using Rhino.Mocks; -using StructureMap.Graph; namespace StructureMap.AutoMocking { Added: trunk/Source/StructureMap.AutoMocking/RhinoMockRepositoryProxy.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/RhinoMockRepositoryProxy.cs (rev 0) +++ trunk/Source/StructureMap.AutoMocking/RhinoMockRepositoryProxy.cs 2008-12-19 02:41:25 UTC (rev 199) @@ -0,0 +1,53 @@ +using System; +using System.Reflection; + +namespace StructureMap.AutoMocking +{ + public class RhinoMockRepositoryProxy + { + private readonly object _instance; + private readonly Func<Type, object[], object> _PartialMock; + private readonly Action<object> _Replay; + private readonly Func<Type, object[], object> _DynamicMock; + + public RhinoMockRepositoryProxy() + { + // We may consider allowing the consumer to pass in the MockRepository Type so we can avoid any possible Assembly conflict issues. + // (The assumption being that their test project already has a reference to Rhino.Mocks.) + // ex: var myclass = RhinoAutoMocker<MyClass>(MockMode.AAA, typeof(MockRepository) + var RhinoMocks = Assembly.Load("Rhino.Mocks"); + var mockRepositoryType = RhinoMocks.GetType("Rhino.Mocks.MockRepository"); + if (mockRepositoryType == null) throw new InvalidOperationException("Unable to find Type Rhino.Mocks.MockRepository in assembly " + RhinoMocks.Location); + + _instance = Activator.CreateInstance(mockRepositoryType); + var methodInfo = mockRepositoryType.GetMethod("DynamicMock", new[] { typeof(Type), typeof(object[]) }); + if (methodInfo == null) throw new InvalidOperationException("Unable to find method DynamicMock(Type, object[]) on MockRepository."); + _DynamicMock = (Func<Type, object[], object>)Delegate.CreateDelegate(typeof(Func<Type, object[], object>), _instance, methodInfo); + + methodInfo = mockRepositoryType.GetMethod("PartialMock", new[] { typeof(Type), typeof(object[]) }); + if (methodInfo == null) throw new InvalidOperationException("Unable to find method PartialMock(Type, object[] on MockRepository."); + _PartialMock = (Func<Type, object[], object>)Delegate.CreateDelegate(typeof(Func<Type, object[], object>), _instance, methodInfo); + + + methodInfo = mockRepositoryType.GetMethod("Replay", new[] { typeof(object) }); + if (methodInfo == null) throw new InvalidOperationException("Unable to find method Replay(object) on MockRepository."); + _Replay = (Action<object>)Delegate.CreateDelegate(typeof(Action<object>), _instance, methodInfo); + } + + public object DynamicMock(Type type) + { + return _DynamicMock(type, null); + } + + public object PartialMock(Type type, object[] args) + { + return _PartialMock(type, args); + } + + public void Replay(object mock) + { + _Replay(mock); + } + + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.AutoMocking/ServiceLocator.cs =================================================================== --- trunk/Source/StructureMap.AutoMocking/ServiceLocator.cs 2008-12-17 16:41:58 UTC (rev 198) +++ trunk/Source/StructureMap.AutoMocking/ServiceLocator.cs 2008-12-19 02:41:25 UTC (rev 199) @@ -1,5 +1,4 @@ using System; -using Rhino.Mocks; namespace StructureMap.AutoMocking { @@ -12,20 +11,11 @@ public class RhinoMocksClassicServiceLocator : ServiceLocator { - private readonly MockRepository _mocks; + private readonly RhinoMockRepositoryProxy _mocks = new RhinoMockRepositoryProxy(); - public RhinoMocksClassicServiceLocator(MockRepository repository) - { - _mocks = repository; - } - - public RhinoMocksClassicServiceLocator() : this(new MockRepository()) - { - } - public T Service<T>() where T : class { - return _mocks.DynamicMock<T>(); + return (T)_mocks.DynamicMock(typeof(T)); } public object Service(Type serviceType) @@ -35,31 +25,33 @@ public T PartialMock<T>(params object[] args) where T : class { - return _mocks.PartialMock<T>(args); + return (T)_mocks.PartialMock(typeof(T), args); } } public class RhinoMocksAAAServiceLocator : ServiceLocator { + private readonly RhinoMockRepositoryProxy _mocks = new RhinoMockRepositoryProxy(); + public T Service<T>() where T : class { - return MockRepository.GenerateMock<T>(); + var instance = (T)_mocks.DynamicMock(typeof (T)); + _mocks.Replay(instance); + return instance; } public object Service(Type serviceType) { - var mock = new MockRepository().DynamicMock(serviceType); - mock.Replay(); - - return mock; + var instance = _mocks.DynamicMock(serviceType); + _mocks.Replay(instance); + return instance; } public T PartialMock<T>(params object[] args) where T : class { - T mock = new MockRepository().PartialMock<T>(args); - mock.Replay(); - - return mock; + var instance = (T)_mocks.PartialMock(typeof(T), args); + _mocks.Replay(instance); + return instance; } } } \ No newline at end of file Modified: trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj =================================================================== --- trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj 2008-12-17 16:41:58 UTC (rev 198) +++ trunk/Source/StructureMap.AutoMocking/StructureMap.AutoMocking.csproj 2008-12-19 02:41:25 UTC (rev 199) @@ -53,10 +53,6 @@ <DocumentationFile>bin\Release\StructureMap.AutoMocking.XML</DocumentationFile> </PropertyGroup> <ItemGroup> - <Reference Include="Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\bin\Rhino.Mocks.dll</HintPath> - </Reference> <Reference Include="System" /> <Reference Include="System.Core"> <RequiredTargetFramework>3.5</RequiredTargetFramework> @@ -72,6 +68,7 @@ <Compile Include="AutoMocker.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="RhinoAutoMocker.cs" /> + <Compile Include="RhinoMockRepositoryProxy.cs" /> <Compile Include="ServiceLocator.cs" /> </ItemGroup> <ItemGroup> @@ -110,4 +107,4 @@ <Target Name="AfterBuild"> </Target> --> -</Project> \ No newline at end of file +</Project> Added: trunk/Source/StructureMap.Testing/AutoMocking/RhinoMockRepositoryProxyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/AutoMocking/RhinoMockRepositoryProxyTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/AutoMocking/RhinoMockRepositoryProxyTester.cs 2008-12-19 02:41:25 UTC (rev 199) @@ -0,0 +1,66 @@ +using NUnit.Framework; +using StructureMap.AutoMocking; +using Rhino.Mocks; + +namespace StructureMap.Testing.AutoMocking +{ + [TestFixture] + public class RhinoMockRepositoryProxyTester + { + [Test] + public void can_make_dynamic_mocks() + { + var mockRepository = new RhinoMockRepositoryProxy(); + var fooMock = mockRepository.DynamicMock(typeof(ITestMocks)); + + fooMock.ShouldNotBeNull(); + } + + [Test] + public void can_put_mock_in_replay_mode() + { + var mockRepository = new RhinoMockRepositoryProxy(); + var test = (ITestMocks)mockRepository.DynamicMock(typeof(ITestMocks)); + + mockRepository.Replay(test); + + test.Stub(t => t.Answer()).Return("YES"); + test.ShouldNotBeNull(); + test.Answer().ShouldEqual("YES"); + } + + [Test] + public void can_make_partial_mocks() + { + var mockRepository = new RhinoMockRepositoryProxy(); + var testPartials = (TestPartials)mockRepository.PartialMock(typeof(TestPartials), new object[0]); + + testPartials.ShouldNotBeNull(); + mockRepository.Replay(testPartials); + testPartials.Concrete().ShouldEqual("Concrete"); + testPartials.Virtual().ShouldEqual("Virtual"); + + testPartials.Stub(t => t.Virtual()).Return("MOCKED!"); + testPartials.Virtual().ShouldEqual("MOCKED!"); + } + + } + + public interface ITestMocks + { + string Answer(); + } + + public class TestPartials + { + public string Concrete() + { + return "Concrete"; + } + + public virtual string Virtual() + { + return "Virtual"; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-12-17 16:41:58 UTC (rev 198) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-12-19 02:41:25 UTC (rev 199) @@ -170,6 +170,7 @@ <SubType>Code</SubType> </Compile> <Compile Include="AutoMocking\RhinoAutoMockerTester.cs" /> + <Compile Include="AutoMocking\RhinoMockRepositoryProxyTester.cs" /> <Compile Include="BuildSessionTester.cs" /> <Compile Include="Configuration\ConfigurationParserBuilderTester.cs" /> <Compile Include="Configuration\ConfigurationParserTester.cs" /> @@ -445,4 +446,4 @@ <PostBuildEvent> </PostBuildEvent> </PropertyGroup> -</Project> \ No newline at end of file +</Project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fli...@us...> - 2008-12-19 15:18:03
|
Revision: 201 http://structuremap.svn.sourceforge.net/structuremap/?rev=201&view=rev Author: flimflan Date: 2008-12-19 15:17:56 +0000 (Fri, 19 Dec 2008) Log Message: ----------- Added missing DebuggerVisualizers test project Added Paths: ----------- trunk/Source/StructureMap.DebuggerVisualizers.Testing/ trunk/Source/StructureMap.DebuggerVisualizers.Testing/Program.cs trunk/Source/StructureMap.DebuggerVisualizers.Testing/Properties/ trunk/Source/StructureMap.DebuggerVisualizers.Testing/Properties/AssemblyInfo.cs trunk/Source/StructureMap.DebuggerVisualizers.Testing/SampleTypes.cs trunk/Source/StructureMap.DebuggerVisualizers.Testing/StructureMap.DebuggerVisualizers.Testing.csproj trunk/Source/StructureMap.DebuggerVisualizers.Testing/VisualizerTests.cs Property changes on: trunk/Source/StructureMap.DebuggerVisualizers.Testing ___________________________________________________________________ Added: svn:ignore + bin obj Added: trunk/Source/StructureMap.DebuggerVisualizers.Testing/Program.cs =================================================================== --- trunk/Source/StructureMap.DebuggerVisualizers.Testing/Program.cs (rev 0) +++ trunk/Source/StructureMap.DebuggerVisualizers.Testing/Program.cs 2008-12-19 15:17:56 UTC (rev 201) @@ -0,0 +1,32 @@ +using System.Diagnostics; +using System.Windows.Forms; + +namespace StructureMap.DebuggerVisualizers.Testing +{ + class Program + { + static void Main(string[] args) + { + var container = new Container( x => + { + x.Scan(s => + { + s.TheCallingAssembly(); + s.WithDefaultConventions(); + }); + x.ForRequestedType<IDoMore<string>>().TheDefaultIsConcreteType<DoForStrings>(); + x.ForRequestedType<IDoThat>().AddInstances(i => + { + i.OfConcreteType<DoThat>().WithName("Red"); + i.OfConcreteType<DoThat>().WithName("Blue"); + }); + }); + + ObjectFactory.Initialize(i => i.ForRequestedType<IDoThat>().TheDefaultIsConcreteType<DoThat>()); + Debug.WriteLine(container.WhatDoIHave()); + + var details = ContainerVisualizerObjectSource.BuildContainerDetails(container); + Application.Run(new ContainerForm(details)); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.DebuggerVisualizers.Testing/Properties/AssemblyInfo.cs =================================================================== --- trunk/Source/StructureMap.DebuggerVisualizers.Testing/Properties/AssemblyInfo.cs (rev 0) +++ trunk/Source/StructureMap.DebuggerVisualizers.Testing/Properties/AssemblyInfo.cs 2008-12-19 15:17:56 UTC (rev 201) @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("StructureMap.DebuggerVisualizers.Runner")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("StructureMap.DebuggerVisualizers.Runner")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d5786571-ba46-4985-a1a7-7360d8d3190e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] Added: trunk/Source/StructureMap.DebuggerVisualizers.Testing/SampleTypes.cs =================================================================== --- trunk/Source/StructureMap.DebuggerVisualizers.Testing/SampleTypes.cs (rev 0) +++ trunk/Source/StructureMap.DebuggerVisualizers.Testing/SampleTypes.cs 2008-12-19 15:17:56 UTC (rev 201) @@ -0,0 +1,63 @@ +namespace StructureMap.DebuggerVisualizers.Testing +{ + public interface IDoThis + { + void Do(); + } + + public interface IDoThat + { + void DoIt(); + } + + public interface IDoMore<T> + { + void DoDo(T thing); + } + + public interface IHasTwoGenerics<FIRST, SECOND> + { + SECOND DoIt(FIRST input); + } + + public class DoThis : IDoThis + { + public void Do() + { + + } + } + + public class DoThat : IDoThat + { + public void DoIt() + { + + } + } + + public class DoMore<T> :IDoMore<T> + { + public void DoDo(T thing) + { + + } + } + + public class HasTwoGenerics<FIRST, SECOND> : IHasTwoGenerics<FIRST, SECOND> + { + public SECOND DoIt(FIRST input) + { + throw new System.NotImplementedException(); + } + } + + public class DoForStrings :IDoMore<string> + { + public void DoDo(string thing) + { + + + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.DebuggerVisualizers.Testing/StructureMap.DebuggerVisualizers.Testing.csproj =================================================================== --- trunk/Source/StructureMap.DebuggerVisualizers.Testing/StructureMap.DebuggerVisualizers.Testing.csproj (rev 0) +++ trunk/Source/StructureMap.DebuggerVisualizers.Testing/StructureMap.DebuggerVisualizers.Testing.csproj 2008-12-19 15:17:56 UTC (rev 201) @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>9.0.21022</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{13C368E6-A7BE-46E8-8CFB-64010C825748}</ProjectGuid> + <OutputType>WinExe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>StructureMap.DebuggerVisualizers.Testing</RootNamespace> + <AssemblyName>StructureMap.DebuggerVisualizers.Testing</AssemblyName> + <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <StartupObject> + </StartupObject> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Microsoft.VisualStudio.DebuggerVisualizers, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> + <Reference Include="nunit.framework, Version=2.4.0.2, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\bin\NUnit\nunit.framework.dll</HintPath> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core"> + <RequiredTargetFramework>3.5</RequiredTargetFramework> + </Reference> + <Reference Include="System.Windows.Forms" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="SampleTypes.cs" /> + <Compile Include="VisualizerTests.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\StructureMap.DebuggerVisualizers\StructureMap.DebuggerVisualizers.csproj"> + <Project>{F023DA4D-0B7D-4836-A56A-21F22A0A2D71}</Project> + <Name>StructureMap.DebuggerVisualizers</Name> + </ProjectReference> + <ProjectReference Include="..\StructureMap\StructureMap.csproj"> + <Project>{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}</Project> + <Name>StructureMap</Name> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file Added: trunk/Source/StructureMap.DebuggerVisualizers.Testing/VisualizerTests.cs =================================================================== --- trunk/Source/StructureMap.DebuggerVisualizers.Testing/VisualizerTests.cs (rev 0) +++ trunk/Source/StructureMap.DebuggerVisualizers.Testing/VisualizerTests.cs 2008-12-19 15:17:56 UTC (rev 201) @@ -0,0 +1,58 @@ +using System.IO; +using System.Runtime.Serialization.Formatters.Binary; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; +using StructureMap.Pipeline; + +namespace StructureMap.DebuggerVisualizers.Testing +{ + [TestFixture] + public class VisualizerTests + { + [Test] + public void can_serialize_container_details() + { + var pluginTypeDetails = new[]{ new PluginTypeDetail(typeof(string), typeof(BuildPolicy), new[]{ new InstanceDetail("First", "First Instance", typeof(string)), }) }; + var wrapper = new ContainerDetail(new[]{"config"}, pluginTypeDetails); + var binaryFormatter = new BinaryFormatter(); + Stream stream = new MemoryStream(); + binaryFormatter.Serialize(stream, wrapper); + + stream.Position = 0; + var detailOnOtherSide = (ContainerDetail) binaryFormatter.Deserialize(stream); + Assert.That(detailOnOtherSide, Is.Not.Null); + Assert.That(detailOnOtherSide, Is.TypeOf(typeof(ContainerDetail))); + } + + [Test] + public void display_nongeneric_types() + { + Assert.That( typeof(IDoThat).AsCSharp(), Is.EqualTo("IDoThat")); + } + + [Test] + public void display_open_generics_using_c_sharp_syntax() + { + Assert.That(typeof (IHasTwoGenerics<,>).AsCSharp(), Is.EqualTo("IHasTwoGenerics<FIRST,SECOND>")); + } + + [Test] + public void display_closed_generics_using_c_sharp_syntax() + { + Assert.That(typeof(IHasTwoGenerics<string, int>).AsCSharp(), Is.EqualTo("IHasTwoGenerics<String,Int32>")); + } + + [Test] + public void display_open_generics_using_c_sharp_syntax_with_fullnames() + { + Assert.That(typeof(IHasTwoGenerics<,>).AsCSharp(t => t.FullName), Is.EqualTo("StructureMap.DebuggerVisualizers.Testing.IHasTwoGenerics<FIRST,SECOND>")); + } + + [Test] + public void display_closed_generics_using_c_sharp_syntax_with_fullnames() + { + Assert.That(typeof(IHasTwoGenerics<string, int>).AsCSharp(t => t.FullName), Is.EqualTo("StructureMap.DebuggerVisualizers.Testing.IHasTwoGenerics<System.String,System.Int32>")); + } + + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-12-20 17:59:49
|
Revision: 204 http://structuremap.svn.sourceforge.net/structuremap/?rev=204&view=rev Author: jeremydmiller Date: 2008-12-20 17:59:45 +0000 (Sat, 20 Dec 2008) Log Message: ----------- Refactored the BuildPolicy caching strategies to use the Cache object and make it easier to add new types of CacheInterceptor Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Emitting/Parameters/Methods.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/Graph/PluginCache.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/SetterProperty.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/Util/Cache.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap/Pipeline/HttpContextBuildStorage.cs trunk/Source/StructureMap/Pipeline/InstanceKey.cs trunk/Source/StructureMap.Testing/Bugs/ trunk/Source/StructureMap.Testing/Bugs/ScanIndexerBugTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/CommonAssemblyInfo.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -14,9 +14,10 @@ [assembly: ComVisibleAttribute(false)] [assembly: AssemblyVersionAttribute("2.5.0.0000")] -[assembly: AssemblyCopyrightAttribute("Copyright (c) 2007, Jeremy D. Miller")] +[assembly: AssemblyCopyrightAttribute("Copyright (c) 2003-2008, Jeremy D. Miller")] [assembly: AssemblyProductAttribute("StructureMap")] [assembly: AssemblyCompanyAttribute("")] [assembly: AssemblyConfigurationAttribute("release")] [assembly: AssemblyInformationalVersionAttribute("2.5.0.0000")] +[assembly: AssemblyFileVersionAttribute("2.5.0.0000")] Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/BuildSession.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -142,7 +142,7 @@ public virtual object CreateInstance(Type pluginType) { - return _defaults.Retrieve(pluginType); + return _defaults[pluginType]; } public virtual object ApplyInterception(Type pluginType, object actualValue) @@ -153,7 +153,7 @@ public virtual void RegisterDefault(Type pluginType, object defaultObject) { - _defaults.Store(pluginType, defaultObject); + _defaults[pluginType] = defaultObject; } Modified: trunk/Source/StructureMap/Emitting/Parameters/Methods.cs =================================================================== --- trunk/Source/StructureMap/Emitting/Parameters/Methods.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Emitting/Parameters/Methods.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -39,7 +39,7 @@ public static MethodInfo ParseFor(Type type) { - return _parseMethods.Retrieve(type); + return _parseMethods[type]; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -81,7 +81,7 @@ public void AddFamily(PluginFamily family) { - _families.Store(family.PluginType, family); + _families[family.PluginType] = family; } @@ -91,7 +91,7 @@ if (_families.Has(basicType)) { - PluginFamily basicFamily = _families.Retrieve(basicType); + PluginFamily basicFamily = _families[basicType]; Type[] templatedParameterTypes = templatedType.GetGenericArguments(); @@ -158,7 +158,7 @@ public PluginFamily FindFamily(Type pluginType) { - return _families.Retrieve(pluginType); + return _families[pluginType]; } public bool HasFamily(Type pluginType) Modified: trunk/Source/StructureMap/Graph/PluginCache.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginCache.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Graph/PluginCache.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -17,7 +17,7 @@ _plugins = new Cache<Type, Plugin>(t => new Plugin(t)); _builders = new Cache<Type, InstanceBuilder>(t => { - Plugin plugin = _plugins.Retrieve(t); + Plugin plugin = _plugins[t]; plugin.SetFilledTypes(_filledTypes); return new InstanceBuilderAssembly(new[] {plugin}).Compile()[0]; }); @@ -25,12 +25,12 @@ public static Plugin GetPlugin(Type pluggedType) { - return _plugins.Retrieve(pluggedType); + return _plugins[pluggedType]; } public static InstanceBuilder FindBuilder(Type pluggedType) { - return _builders.Retrieve(pluggedType); + return _builders[pluggedType]; } public static void Compile() @@ -51,7 +51,7 @@ } var assembly = new InstanceBuilderAssembly(plugins); - assembly.Compile().ForEach(b => _builders.Store(b.PluggedType, b)); + assembly.Compile().ForEach(b => _builders[b.PluggedType] = b); } private static bool pluginHasNoBuilder(Plugin plugin) @@ -61,7 +61,7 @@ public static void Store(Type pluggedType, InstanceBuilder builder) { - _builders.Store(pluggedType, builder); + _builders[pluggedType] = builder; } internal static void ResetAll() Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -95,7 +95,7 @@ public void AddInstance(Instance instance) { - _instances.Store(instance.Name, instance); + _instances[instance.Name] = instance; } @@ -170,7 +170,7 @@ public Instance GetInstance(string name) { - return _instances.Retrieve(name); + return _instances[name]; } public bool HasPlugin(Type pluggedType) @@ -196,7 +196,7 @@ assertPluggability(pluggedType); Plugin plugin = PluginCache.GetPlugin(pluggedType); - _pluggedTypes.Store(plugin.ConcreteKey, plugin); + _pluggedTypes[plugin.ConcreteKey] = plugin; return plugin; } @@ -206,7 +206,7 @@ assertPluggability(pluggedType); Plugin plugin = PluginCache.GetPlugin(pluggedType); - _pluggedTypes.Store(key, plugin); + _pluggedTypes[key] = plugin; return plugin; } @@ -263,7 +263,7 @@ { if (_pluggedTypes.Has(concreteKey)) { - return _pluggedTypes.Retrieve(concreteKey); + return _pluggedTypes[concreteKey]; } return null; Modified: trunk/Source/StructureMap/Graph/SetterProperty.cs =================================================================== --- trunk/Source/StructureMap/Graph/SetterProperty.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Graph/SetterProperty.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -41,6 +41,9 @@ { Type propertyType = _property.PropertyType; + // Ignore indexer properties + if (_property.GetIndexParameters().Length > 0) return; + if (IsPrimitive(propertyType)) visitor.PrimitiveSetter(_property, IsMandatory); if (IsChild(propertyType)) visitor.ChildSetter(_property, IsMandatory); if (IsChildArray(propertyType)) visitor.ChildArraySetter(_property, IsMandatory); Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/InstanceFactory.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -96,7 +96,7 @@ public void AddInstance(Instance instance) { - _instances.Store(instance.Name, instance); + _instances[instance.Name] = instance; } @@ -131,7 +131,7 @@ public Instance FindInstance(string name) { - return _instances.Retrieve(name); + return _instances[name]; } public void ImportFrom(PluginFamily family) Modified: trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Pipeline/CacheInterceptor.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -1,7 +1,15 @@ using System; +using StructureMap.Util; namespace StructureMap.Pipeline { + public class InstanceCache : Cache<InstanceKey, object> + { + public InstanceCache(IBuildPolicy innerPolicy) : base(key => innerPolicy.Build(key.Session, key.PluginType, key.Instance)) + { + } + } + public abstract class CacheInterceptor : IBuildInterceptor { private readonly object _locker = new object(); @@ -15,22 +23,17 @@ set { _innerPolicy = value; } } + protected InstanceCache buildNewCache() + { + return new InstanceCache(_innerPolicy); + } + protected abstract InstanceCache findCache(); + public object Build(BuildSession buildSession, Type pluginType, Instance instance) { - if (!isCached(instance.Name, pluginType)) - { - lock (_locker) - { - if (!isCached(instance.Name, pluginType)) - { - object returnValue = _innerPolicy.Build(buildSession, pluginType, instance); - storeInCache(instance.Name, pluginType, returnValue); - } - } - } - - return retrieveFromCache(instance.Name, pluginType); + var key = new InstanceKey{Instance = instance, PluginType = pluginType, Session = buildSession}; + return findCache()[key]; } public IBuildPolicy Clone() @@ -45,10 +48,6 @@ protected abstract CacheInterceptor clone(); - protected abstract void storeInCache(string instanceKey, Type pluginType, object instance); - protected abstract bool isCached(string instanceKey, Type pluginType); - protected abstract object retrieveFromCache(string instanceKey, Type pluginType); - public override string ToString() { return GetType().FullName + " / " + _innerPolicy; Deleted: trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -1,41 +0,0 @@ -using System; -using System.Web; - -namespace StructureMap.Pipeline -{ - public class HttpContextBuildPolicy : CacheInterceptor - { - private string _prefix = Guid.NewGuid().ToString(); - - - public static bool HasContext() - { - return HttpContext.Current != null; - } - - protected override void storeInCache(string instanceKey, Type pluginType, object instance) - { - HttpContext.Current.Items.Add(getKey(instanceKey, pluginType), instance); - } - - protected override bool isCached(string instanceKey, Type pluginType) - { - return HttpContext.Current.Items.Contains(getKey(instanceKey, pluginType)); - } - - protected override object retrieveFromCache(string instanceKey, Type pluginType) - { - return HttpContext.Current.Items[getKey(instanceKey, pluginType)]; - } - - private string getKey(string instanceKey, Type pluginType) - { - return string.Format("{0}:{1}:{2}", pluginType.AssemblyQualifiedName, instanceKey, _prefix); - } - - protected override CacheInterceptor clone() - { - return this; - } - } -} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/HttpContextBuildStorage.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpContextBuildStorage.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/HttpContextBuildStorage.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -0,0 +1,41 @@ +using System.Collections; +using System.Web; + +namespace StructureMap.Pipeline +{ + public class HttpContextBuildPolicy : CacheInterceptor + { + public static readonly string ITEM_NAME = "STRUCTUREMAP-INSTANCES"; + + public static bool HasContext() + { + return HttpContext.Current != null; + } + + protected override InstanceCache findCache() + { + IDictionary items = HttpContext.Current.Items; + + if (!items.Contains(ITEM_NAME)) + { + lock (items.SyncRoot) + { + if (!items.Contains(ITEM_NAME)) + { + InstanceCache cache = buildNewCache(); + items.Add(ITEM_NAME, cache); + + return cache; + } + } + } + + return (InstanceCache) items[ITEM_NAME]; + } + + protected override CacheInterceptor clone() + { + return this; + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -2,15 +2,17 @@ namespace StructureMap.Pipeline { - public class HybridBuildPolicy : IBuildInterceptor + public abstract class HttpBuildPolicyBase<HTTP, NONHTTP> : IBuildInterceptor + where HTTP : IBuildInterceptor, new() + where NONHTTP : IBuildInterceptor, new() { private readonly IBuildInterceptor _http; - private readonly IBuildInterceptor _threadLocal; + private readonly IBuildInterceptor _nonHttp; - public HybridBuildPolicy() + public HttpBuildPolicyBase() { - _http = new HttpContextBuildPolicy(); - _threadLocal = new ThreadLocalStoragePolicy(); + _http = new HTTP(); + _nonHttp = new NONHTTP(); } private IBuildPolicy _innerPolicy; @@ -22,19 +24,17 @@ { return HttpContextBuildPolicy.HasContext() ? _http - : _threadLocal; + : _nonHttp; } } - #region IBuildInterceptor Members - public IBuildPolicy InnerPolicy { get { return _innerPolicy; } set { _http.InnerPolicy = value; - _threadLocal.InnerPolicy = value; + _nonHttp.InnerPolicy = value; _innerPolicy = value; } } @@ -44,14 +44,16 @@ return interceptor.Build(buildSession, pluginType, instance); } - public IBuildPolicy Clone() + public abstract IBuildPolicy Clone(); + } + + + public class HybridBuildPolicy : HttpBuildPolicyBase<HttpContextBuildPolicy, ThreadLocalStoragePolicy> + { + public override IBuildPolicy Clone() { - var policy = new HybridBuildPolicy(); - policy.InnerPolicy = _innerPolicy.Clone(); - - return policy; + return new HybridBuildPolicy(){InnerPolicy = InnerPolicy.Clone()}; } + } - #endregion - } } \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/InstanceKey.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/InstanceKey.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/InstanceKey.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -0,0 +1,60 @@ +using System; + +namespace StructureMap.Pipeline +{ + public class InstanceKey + { + public string Name { get; set; } + public Type PluginType { get; set; } + private WeakReference _session; + private WeakReference _instance; + + public InstanceKey() + { + } + + + + public BuildSession Session + { + get { return (BuildSession) _session.Target; } + set { _session = new WeakReference(value); } + } + + public Instance Instance + { + get + { + return (Instance) _instance.Target; + } + set + { + Name = value.Name; + _instance = new WeakReference(value); + } + } + + public bool Equals(InstanceKey obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + return Equals(obj.Name, Name) && Equals(obj.PluginType, PluginType); + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != typeof(InstanceKey)) return false; + return Equals((InstanceKey)obj); + } + + public override int GetHashCode() + { + unchecked + { + return ((Name != null ? Name.GetHashCode() : 0) * 397) ^ (PluginType != null ? PluginType.GetHashCode() : 0); + } + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -1,28 +1,27 @@ -using System; -using System.Collections.Generic; - namespace StructureMap.Pipeline { [Pluggable("Singleton")] public class SingletonPolicy : CacheInterceptor { - private readonly Dictionary<string, object> _instances = new Dictionary<string, object>(); + private readonly object _locker = new object(); + private InstanceCache _cache; - protected override void storeInCache(string instanceKey, Type pluginType, object instance) + protected override InstanceCache findCache() { - _instances.Add(instanceKey, instance); - } + if (_cache == null) + { + lock (_locker) + { + if (_cache == null) + { + _cache = buildNewCache(); + } + } + } - protected override bool isCached(string instanceKey, Type pluginType) - { - return _instances.ContainsKey(instanceKey); + return _cache; } - protected override object retrieveFromCache(string instanceKey, Type pluginType) - { - return _instances[instanceKey]; - } - protected override CacheInterceptor clone() { return new SingletonPolicy(); Modified: trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -1,48 +1,32 @@ using System; -using System.Collections.Generic; namespace StructureMap.Pipeline { public class ThreadLocalStoragePolicy : CacheInterceptor { - [ThreadStatic] private static Dictionary<string, object> _instances; + [ThreadStatic] private static InstanceCache _cache; private readonly object _locker = new object(); private void guaranteeHashExists() { - if (_instances == null) + if (_cache == null) { lock (_locker) { - if (_instances == null) + if (_cache == null) { - _instances = new Dictionary<string, object>(); + _cache = buildNewCache(); } } } } - protected override void storeInCache(string instanceKey, Type pluginType, object instance) + protected override InstanceCache findCache() { - _instances.Add(getKey(instanceKey, pluginType), instance); - } - - protected override bool isCached(string instanceKey, Type pluginType) - { guaranteeHashExists(); - return _instances.ContainsKey(getKey(instanceKey, pluginType)); + return _cache; } - protected override object retrieveFromCache(string instanceKey, Type pluginType) - { - return _instances[getKey(instanceKey, pluginType)]; - } - - private string getKey(string instanceKey, Type pluginType) - { - return string.Format("{0}:{1}", pluginType.AssemblyQualifiedName, instanceKey); - } - protected override CacheInterceptor clone() { return this; Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-12-20 17:59:45 UTC (rev 204) @@ -167,7 +167,6 @@ <Compile Include="Pipeline\ConfiguredInstance.Expressions.cs" /> <Compile Include="Pipeline\ConstructorInstance.cs" /> <Compile Include="Pipeline\DefaultInstance.cs" /> - <Compile Include="Pipeline\HttpContextBuildPolicy.cs" /> <Compile Include="Pipeline\HybridBuildPolicy.cs" /> <Compile Include="Pipeline\IBuildInterceptor.cs" /> <Compile Include="Pipeline\IBuildPolicy.cs" /> @@ -412,6 +411,8 @@ <Compile Include="Pipeline\BuildFrame.cs" /> <Compile Include="Pipeline\BuildStack.cs" /> <Compile Include="Pipeline\ConfiguredInstanceBase.cs" /> + <Compile Include="Pipeline\HttpContextBuildStorage.cs" /> + <Compile Include="Pipeline\InstanceKey.cs" /> <Compile Include="Pipeline\IStructuredInstance.cs" /> <Compile Include="Pipeline\PropertyExpression.cs" /> <Compile Include="Pipeline\SerializedInstance.cs" /> Modified: trunk/Source/StructureMap/Util/Cache.cs =================================================================== --- trunk/Source/StructureMap/Util/Cache.cs 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap/Util/Cache.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -6,26 +6,43 @@ { public class Cache<KEY, VALUE> : IEnumerable<VALUE> where VALUE : class { - private readonly Func<KEY, VALUE> _onMissing = key => + private readonly object _locker = new object(); + private readonly IDictionary<KEY, VALUE> _values; + + private Func<VALUE, KEY> _getKey = delegate { throw new NotImplementedException(); }; + + private Func<KEY, VALUE> _onMissing = delegate(KEY key) { string message = string.Format("Key '{0}' could not be found", key); throw new KeyNotFoundException(message); }; - private readonly Dictionary<KEY, VALUE> _values = new Dictionary<KEY, VALUE>(); - - private Func<VALUE, KEY> _getKey = delegate { throw new NotImplementedException(); }; - private readonly object _valuesLock = new object(); - public Cache() + : this(new Dictionary<KEY, VALUE>()) { } public Cache(Func<KEY, VALUE> onMissing) + : this(new Dictionary<KEY, VALUE>(), onMissing) { + } + + public Cache(IDictionary<KEY, VALUE> dictionary, Func<KEY, VALUE> onMissing) + : this(dictionary) + { _onMissing = onMissing; } + public Cache(IDictionary<KEY, VALUE> dictionary) + { + _values = dictionary; + } + + public Func<KEY, VALUE> OnMissing + { + set { _onMissing = value; } + } + public Func<VALUE, KEY> GetKey { get { return _getKey; } @@ -50,11 +67,43 @@ } } + + public VALUE this[KEY key] + { + get + { + if (!_values.ContainsKey(key)) + { + lock (_locker) + { + if (!_values.ContainsKey(key)) + { + VALUE value = _onMissing(key); + _values.Add(key, value); + } + } + } + + return _values[key]; + } + set + { + if (_values.ContainsKey(key)) + { + _values[key] = value; + } + else + { + _values.Add(key, value); + } + } + } + #region IEnumerable<VALUE> Members IEnumerator IEnumerable.GetEnumerator() { - return ((IEnumerable<VALUE>) this).GetEnumerator(); + return ((IEnumerable<VALUE>)this).GetEnumerator(); } public IEnumerator<VALUE> GetEnumerator() @@ -64,16 +113,6 @@ #endregion - public void Clear() - { - _values.Clear(); - } - - public void Store(KEY key, VALUE value) - { - _values[key] = value; - } - public void Fill(KEY key, VALUE value) { if (_values.ContainsKey(key)) @@ -84,22 +123,17 @@ _values.Add(key, value); } - public VALUE Retrieve(KEY key) + public bool TryRetrieve(KEY key, out VALUE value) { - if (!_values.ContainsKey(key)) + value = default(VALUE); + + if (_values.ContainsKey(key)) { - lock (_valuesLock) - { - if (!_values.ContainsKey(key)) - { - // Potential deadlock if _onMissing attempts to retrieve the same key - VALUE value = _onMissing(key); - _values.Add(key, value); - } - } + value = _values[key]; + return true; } - return _values[key]; + return false; } public void Each(Action<VALUE> action) @@ -127,7 +161,7 @@ { bool returnValue = false; - Each(value => returnValue |= predicate(value)); + Each(delegate(VALUE value) { returnValue |= predicate(value); }); return returnValue; } @@ -155,7 +189,15 @@ public void Remove(KEY key) { - _values.Remove(key); + if (_values.ContainsKey(key)) + { + _values.Remove(key); + } } + + public void Clear() + { + _values.Clear(); + } } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Bugs/ScanIndexerBugTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Bugs/ScanIndexerBugTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Bugs/ScanIndexerBugTester.cs 2008-12-20 17:59:45 UTC (rev 204) @@ -0,0 +1,31 @@ +using NUnit.Framework; + +namespace StructureMap.Testing.Bugs +{ + [TestFixture] + public class ScanIndexerBugTester + { + [Test] + public void do_not_blow_up_on_scanning_the_property_for_indexer() + { + var container = new Container(); + container.GetInstance<ClassWithIndexer>().ShouldNotBeNull(); + } + } + + public class ClassWithIndexer + { + + public string this[string key] + { + get + { + return key; + } + set + { + + } + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-12-19 19:04:47 UTC (rev 203) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2008-12-20 17:59:45 UTC (rev 204) @@ -1,7 +1,7 @@ <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> <PropertyGroup> <ProjectType>Local</ProjectType> - <ProductVersion>9.0.30729</ProductVersion> + <ProductVersion>9.0.21022</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <ProjectGuid>{63C2742D-B6E2-484F-AFDB-346873075C5E}</ProjectGuid> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> @@ -178,6 +178,7 @@ <Compile Include="AutoMocking\MoqFactoryTester.cs" /> <Compile Include="AutoMocking\RhinoAutoMockerTester.cs" /> <Compile Include="AutoMocking\RhinoMockRepositoryProxyTester.cs" /> + <Compile Include="Bugs\ScanIndexerBugTester.cs" /> <Compile Include="BuildSessionTester.cs" /> <Compile Include="Configuration\ConfigurationParserBuilderTester.cs" /> <Compile Include="Configuration\ConfigurationParserTester.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2008-12-21 16:31:52
|
Revision: 211 http://structuremap.svn.sourceforge.net/structuremap/?rev=211&view=rev Author: jeremydmiller Date: 2008-12-21 16:31:48 +0000 (Sun, 21 Dec 2008) Log Message: ----------- A performance enhancement to stop SM from needing to scan the StructureMap dll on startup Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/Configuration/IGraphBuilder.cs trunk/Source/StructureMap/MementoSource.cs trunk/Source/StructureMap/Pipeline/IBuildInterceptor.cs trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs trunk/Source/StructureMap/Source/EmbeddedFolderXmlMementoSource.cs trunk/Source/StructureMap/Source/MemoryMementoSource.cs trunk/Source/StructureMap/Source/SingleEmbeddedXmlMementoSource.cs trunk/Source/StructureMap/Source/TemplatedMementoSource.cs trunk/Source/StructureMap/Source/XmlAttributeFileMementoSource.cs trunk/Source/StructureMap/Source/XmlFileMementoSource.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs trunk/Source/StructureMap.sln Added Paths: ----------- trunk/Source/StructureMap/SystemRegistry.cs Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/CommonAssemblyInfo.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -13,11 +13,11 @@ //------------------------------------------------------------------------------ [assembly: ComVisibleAttribute(false)] -[assembly: AssemblyVersionAttribute("2.5.0.0000")] +[assembly: AssemblyVersionAttribute("2.5.1.0000")] [assembly: AssemblyCopyrightAttribute("Copyright (c) 2003-2008, Jeremy D. Miller")] [assembly: AssemblyProductAttribute("StructureMap")] [assembly: AssemblyCompanyAttribute("")] [assembly: AssemblyConfigurationAttribute("release")] -[assembly: AssemblyInformationalVersionAttribute("2.5.0.0000")] -[assembly: AssemblyFileVersionAttribute("2.5.0.0000")] +[assembly: AssemblyInformationalVersionAttribute("2.5.1.0000")] +[assembly: AssemblyFileVersionAttribute("2.5.1.0000")] Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Reflection; using StructureMap.Configuration.DSL; using StructureMap.Graph; @@ -10,10 +11,9 @@ { private readonly AssemblyScanner _assemblyScanner; private readonly PluginGraph _pluginGraph; - private readonly PluginGraph _systemGraph; - private readonly AssemblyScanner _systemScanner; private Profile _profile; private Container _systemContainer; + private readonly PluginGraph _systemGraph; public GraphBuilder(Registry[] registries) : this(registries, new PluginGraph()) @@ -31,10 +31,8 @@ registry.ConfigurePluginGraph(_pluginGraph); } - _systemScanner = new AssemblyScanner(); - _systemScanner.Assembly(Assembly.GetExecutingAssembly()); - - _systemGraph = new PluginGraph(_systemScanner); + _systemGraph = new SystemRegistry().Build(); + _systemContainer = new Container(_systemGraph); } #region IGraphBuilder Members @@ -44,11 +42,6 @@ _pluginGraph.Seal(); } - public PluginGraph SystemGraph - { - get { return _systemGraph; } - } - public PluginGraph PluginGraph { get { return _pluginGraph; } @@ -60,7 +53,6 @@ { Assembly assembly = AppDomain.CurrentDomain.Load(assemblyName); _assemblyScanner.Assembly(assembly); - _systemScanner.Assembly(assembly); } catch (Exception ex) { @@ -68,11 +60,6 @@ } } - public void PrepareSystemObjects() - { - _systemGraph.Seal(); - } - public IProfileBuilder GetProfileBuilder() { return new ProfileBuilder(_pluginGraph); @@ -116,12 +103,6 @@ private object buildSystemObject(Type type, InstanceMemento memento) { Instance instance = memento.ReadInstance(_systemGraph, type); - - if (_systemContainer == null) - { - _systemContainer = new Container(_systemGraph); - } - return _systemContainer.GetInstance(type, instance); } } Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -15,11 +15,9 @@ public interface IGraphBuilder { - PluginGraph SystemGraph { get; } PluginGraph PluginGraph { get; } void AddAssembly(string assemblyName); - void PrepareSystemObjects(); void FinishFamilies(); IProfileBuilder GetProfileBuilder(); Modified: trunk/Source/StructureMap/MementoSource.cs =================================================================== --- trunk/Source/StructureMap/MementoSource.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/MementoSource.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -10,7 +10,6 @@ /// Abstract class that is the supertype of all storage and retrieval mechanisms of /// InstanceMemento instances /// </summary> - [PluginFamily] public abstract class MementoSource { private readonly Dictionary<string, InstanceMemento> _externalMementos = Modified: trunk/Source/StructureMap/Pipeline/IBuildInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IBuildInterceptor.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Pipeline/IBuildInterceptor.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -3,7 +3,6 @@ /// <summary> /// Plugin interface to create custom build or lifecycle policies for a Plugin Type /// </summary> - [PluginFamily] public interface IBuildInterceptor : IBuildPolicy { IBuildPolicy InnerPolicy { get; set; } Modified: trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -2,7 +2,6 @@ namespace StructureMap.Pipeline { - [Pluggable("Singleton")] public class SingletonPolicy : CacheInterceptor { private readonly object _locker = new object(); Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -64,8 +64,6 @@ p.ParseAssemblies(graphBuilder); }); - graphBuilder.PrepareSystemObjects(); - forAllParsers(p => p.Parse(graphBuilder)); _graph.Seal(); Modified: trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -11,7 +11,6 @@ /// DirectoryXmlMementoSource is meant to simplify complicated object graph configurations by isolating each instance to a separate /// editable file. /// </summary> - [Pluggable("DirectoryXml")] public class DirectoryXmlMementoSource : MementoSource { private readonly string _directory; Modified: trunk/Source/StructureMap/Source/EmbeddedFolderXmlMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/EmbeddedFolderXmlMementoSource.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Source/EmbeddedFolderXmlMementoSource.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -7,7 +7,6 @@ namespace StructureMap.Source { - [Pluggable("EmbeddedXmlFolder")] public class EmbeddedFolderXmlMementoSource : MementoSource { private readonly string _assemblyName; Modified: trunk/Source/StructureMap/Source/MemoryMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/MemoryMementoSource.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Source/MemoryMementoSource.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -5,7 +5,6 @@ /// <summary> /// An in-memory MementoSource /// </summary> - [Pluggable("Default")] public class MemoryMementoSource : MementoSource { private readonly Hashtable _mementos; Modified: trunk/Source/StructureMap/Source/SingleEmbeddedXmlMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/SingleEmbeddedXmlMementoSource.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Source/SingleEmbeddedXmlMementoSource.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -4,7 +4,6 @@ namespace StructureMap.Source { - [Pluggable("EmbeddedXmlFile")] public class SingleEmbeddedXmlMementoSource : XmlMementoSource { private readonly Assembly _assembly; Modified: trunk/Source/StructureMap/Source/TemplatedMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/TemplatedMementoSource.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Source/TemplatedMementoSource.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -1,6 +1,5 @@ namespace StructureMap.Source { - [Pluggable("Templated")] public class TemplatedMementoSource : MementoSource { private readonly MementoSource _innerSource; Modified: trunk/Source/StructureMap/Source/XmlAttributeFileMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlAttributeFileMementoSource.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Source/XmlAttributeFileMementoSource.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -3,7 +3,6 @@ /// <summary> /// Stores Attribute-normalized InstanceMemento's in an external file /// </summary> - [Pluggable("XmlAttributeFile")] public class XmlAttributeFileMementoSource : XmlFileMementoSource { public XmlAttributeFileMementoSource(string filePath, string xpath, string nodeName) Modified: trunk/Source/StructureMap/Source/XmlFileMementoSource.cs =================================================================== --- trunk/Source/StructureMap/Source/XmlFileMementoSource.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/Source/XmlFileMementoSource.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -8,7 +8,6 @@ /// Implementation of XmlMementoSource that reads InstanceMemento's from an external file. /// Useful to break the StructureMap.config file into smaller pieces. /// </summary> - [Pluggable("XmlFile")] public class XmlFileMementoSource : XmlMementoSource { private readonly string _filePath; Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-12-21 16:31:48 UTC (rev 211) @@ -420,6 +420,7 @@ <Compile Include="Pipeline\SmartInstance.cs" /> <Compile Include="PluginTypeConfiguration.cs" /> <Compile Include="ReflectionHelper.cs" /> + <Compile Include="SystemRegistry.cs" /> <Compile Include="Util\Cache.cs" /> </ItemGroup> <ItemGroup> Added: trunk/Source/StructureMap/SystemRegistry.cs =================================================================== --- trunk/Source/StructureMap/SystemRegistry.cs (rev 0) +++ trunk/Source/StructureMap/SystemRegistry.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -0,0 +1,41 @@ +using StructureMap.Attributes; +using StructureMap.Configuration.DSL; +using StructureMap.Pipeline; +using StructureMap.Source; + +namespace StructureMap +{ + public class SystemRegistry : Registry + { + public SystemRegistry() + { + addExpression(graph => graph.AddType(typeof(MementoSource), typeof(XmlFileMementoSource), "XmlFile")); + + ForRequestedType<MementoSource>().TheDefaultIsConcreteType<MemoryMementoSource>(); + AddMementoSourceType<DirectoryXmlMementoSource>("DirectoryXml"); + AddMementoSourceType<EmbeddedFolderXmlMementoSource>("EmbeddedXmlFolder"); + AddMementoSourceType<SingleEmbeddedXmlMementoSource>("EmbeddedXmlFile"); + AddMementoSourceType<TemplatedMementoSource>("Templated"); + AddMementoSourceType<XmlAttributeFileMementoSource>("XmlAttributeFile"); + AddMementoSourceType<XmlFileMementoSource>("XmlFile"); + + + AddInterceptorType<SingletonPolicy>(InstanceScope.Singleton); + AddInterceptorType<ThreadLocalStoragePolicy>(InstanceScope.ThreadLocal); + AddInterceptorType<HttpContextBuildPolicy>(InstanceScope.HttpContext); + AddInterceptorType<HttpSessionBuildPolicy>(InstanceScope.HttpSession); + AddInterceptorType<HybridBuildPolicy>(InstanceScope.Hybrid); + + } + + private void AddMementoSourceType<T>(string name) + { + addExpression(graph => graph.AddType(typeof(MementoSource), typeof(T), name)); + } + + private void AddInterceptorType<T>(InstanceScope scope) + { + addExpression(graph => graph.AddType(typeof(IBuildInterceptor), typeof(T), scope.ToString())); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-12-21 16:31:48 UTC (rev 211) @@ -62,7 +62,6 @@ bool iWasCalled = false; var builder = new GraphBuilder(new Registry[0]); - builder.PrepareSystemObjects(); builder.WithSystemObject<IBuildInterceptor>(memento, "singleton", policy => { Assert.IsInstanceOfType(typeof (SingletonPolicy), policy); Modified: trunk/Source/StructureMap.sln =================================================================== --- trunk/Source/StructureMap.sln 2008-12-21 00:37:33 UTC (rev 210) +++ trunk/Source/StructureMap.sln 2008-12-21 16:31:48 UTC (rev 211) @@ -27,8 +27,6 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Widgets", "Widgets", "{E1C10209-160D-4054-ACB7-478A9FDCF84C}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GUI", "GUI", "{4F638ECF-2A69-4D6A-9B68-05CC40951217}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap", "StructureMap\StructureMap.csproj", "{3F36EA80-2F9A-4DAD-BA27-5AC6163A2EE3}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.Testing", "StructureMap.Testing\StructureMap.Testing.csproj", "{63C2742D-B6E2-484F-AFDB-346873075C5E}" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2009-01-04 02:55:46
|
Revision: 215 http://structuremap.svn.sourceforge.net/structuremap/?rev=215&view=rev Author: jeremydmiller Date: 2009-01-04 02:55:42 +0000 (Sun, 04 Jan 2009) Log Message: ----------- More documentation and examples, some new convenience methods in TypeExtensions, a convenience FI for fetching generic types, IContainer is always injected into the Container Modified Paths: -------------- trunk/Source/CommonAssemblyInfo.cs trunk/Source/HTML/AutoWiring.htm trunk/Source/HTML/Default.htm trunk/Source/HTML/FeatureList.htm trunk/Source/HTML/Generics.htm trunk/Source/HTML/HTML.csproj trunk/Source/HTML/Menu.htm trunk/Source/HTML/ScanningAssemblies.htm trunk/Source/HTML/Scoping.htm trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap/TypeExtensions.cs trunk/Source/StructureMap.Testing/AutoWiringExamples.cs trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs trunk/Source/StructureMap.Testing/ModelQueryTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/DefaultInstance.xml trunk/Source/StructureMap.Testing/TestData/ScopeInFamily.xml Added Paths: ----------- trunk/Source/StructureMap.Testing/Pipeline/ContainerIsInTheContainerTester.cs trunk/Source/StructureMap.Testing/Pipeline/GenericsHelperExpressionTester.cs trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs Removed Paths: ------------- trunk/Source/HTML/SmartInstance.htm Modified: trunk/Source/CommonAssemblyInfo.cs =================================================================== --- trunk/Source/CommonAssemblyInfo.cs 2009-01-03 00:07:32 UTC (rev 214) +++ trunk/Source/CommonAssemblyInfo.cs 2009-01-04 02:55:42 UTC (rev 215) @@ -13,11 +13,11 @@ //------------------------------------------------------------------------------ [assembly: ComVisibleAttribute(false)] -[assembly: AssemblyVersionAttribute("2.5.1.0000")] +[assembly: AssemblyVersionAttribute("2.5.2.0000")] [assembly: AssemblyCopyrightAttribute("Copyright (c) 2003-2008, Jeremy D. Miller")] [assembly: AssemblyProductAttribute("StructureMap")] [assembly: AssemblyCompanyAttribute("")] [assembly: AssemblyConfigurationAttribute("release")] -[assembly: AssemblyInformationalVersionAttribute("2.5.1.0000")] -[assembly: AssemblyFileVersionAttribute("2.5.1.0000")] +[assembly: AssemblyInformationalVersionAttribute("2.5.2.0000")] +[assembly: AssemblyFileVersionAttribute("2.5.2.0000")] Modified: trunk/Source/HTML/AutoWiring.htm =================================================================== --- trunk/Source/HTML/AutoWiring.htm 2009-01-03 00:07:32 UTC (rev 214) +++ trunk/Source/HTML/AutoWiring.htm 2009-01-04 02:55:42 UTC (rev 215) @@ -82,16 +82,15 @@ <h2> Example</h2> <p> - Typically, you’ll try to - minimize the number of service locator[LINK] usages in your system to a bare minimum - (I found 8 in my current system, but I think I’ll find a way to prune half of - those later). Most of the value of an IoC tool is in automatically doing - Dependency Injection. I’m working with the new MVC framework at the - moment, so it’s a handy sample. Let’s say that we have a Controller class - for a typical CRUD screen. That Controller class will generally need to - interact with both validation services and the data access functionality of the - Repository. Here’s a representative Controller class:-RIGHT: black thin solid; BORDER-TOP: black thin solid; FONT-SIZE: 10pt; BACKGROUND: white; OVERFLOW: scroll; BORDER-LEFT: black thin solid; COLOR: black; BORDER-BOTTOM: black thin solid; FONT-FAMILY: courier new"> - <p style="MARGIN: 0px"> + Typically, you’ll try to minimize the number of service locator[LINK] usages in + your system to a bare minimum (I found 8 in my current system, but I think I’ll + find a way to prune half of those later). Most of the value of an IoC tool + is in automatically doing Dependency Injection. I’m working with the new + MVC framework at the moment, so it’s a handy sample. Let’s say that we + have a Controller class for a typical CRUD screen. That Controller class + will generally need to interact with both validation services and the data + access functionality of the Repository. Here’s a representative Controller + class:<div class="code-sample"><p style="MARGIN: 0px" > <span style="COLOR: blue">public</span> <span style="COLOR: blue">class</span> <span style="COLOR: #2b91af">SomeScreenController</span> : <span style="COLOR: #2b91af">IController</span></p> @@ -216,10 +215,223 @@ overriden.</p> <hr /> <h4>Object Identity within a Single Request</h4> - <p>TODO</p> + <p>Within a single object request, StructureMap will only create a single object for + a single Instance configuration. What that means in effect is that if two + or more objects in a single request need the same dependency, those two objects + will get the exact same instance of that dependency. Let's immediately + jump into code to demonstrate this.</p> + <p>This auto wiring policy was intended for objects that need to be shared by lots + of other objects. A common example of this is some sort of DataContext + class:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 DataContext\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 Guid\cf0 _id = \cf4 Guid\cf0 .NewGuid();\par ??\par ?? \cf3 public\cf0 \cf3 override\cf0 \cf3 string\cf0 ToString()\par ?? \{\par ?? \cf3 return\cf0 \cf3 string\cf0 .Format(\cf5 "Id: \{0\}"\cf0 , _id);\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">class</span> <span style="color: #2b91af;"> + DataContext</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + private</span> <span style="color: #2b91af;">Guid</span> _id = + <span style="color: #2b91af;">Guid</span>.NewGuid();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> + public</span> <span style="color: blue;">override</span> + <span style="color: blue;">string</span> ToString()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">return</span> <span style="color: blue;">string</span>.Format(<span + style="color: #a31515;">"Id: {0}"</span>, _id);</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>Now, let's say that I have a hierarchy of classes that all need to work on a + DataContext:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 Class1\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 DataContext\cf0 _context;\par ??\par ?? \cf3 public\cf0 Class1(\cf4 DataContext\cf0 context)\par ?? \{\par ?? _context = context;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 override\cf0 \cf3 string\cf0 ToString()\par ?? \{\par ?? \cf3 return\cf0 \cf3 string\cf0 .Format(\cf5 "Class1 has Context: \{0\}"\cf0 , _context);\par ?? \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 Class2\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 Class1\cf0 _class1;\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 DataContext\cf0 _context;\par ??\par ?? \cf3 public\cf0 Class2(\cf4 Class1\cf0 class1, \cf4 DataContext\cf0 context)\par ?? \{\par ?? _class1 = class1;\par ?? _context = context;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 override\cf0 \cf3 string\cf0 ToString()\par ?? \{\par ?? \cf3 return\cf0 \cf3 string\cf0 .Format(\cf5 "Class2 has Context: \{0\}\\n\{1\}"\cf0 , _context, _class1);\par ?? \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 Class3\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 Class2\cf0 _class2;\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 DataContext\cf0 _context;\par ??\par ?? \cf3 public\cf0 Class3(\cf4 Class2\cf0 class2, \cf4 DataContext\cf0 context)\par ?? \{\par ?? _class2 = class2;\par ?? _context = context;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 override\cf0 \cf3 string\cf0 ToString()\par ?? \{\par ?? \cf3 return\cf0 \cf3 string\cf0 .Format(\cf5 "Class3 has Context: \{0\}\\n\{1\}"\cf0 , _context, _class2);\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">class</span> <span style="color: #2b91af;">Class1</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + public</span> Class1(<span style="color: #2b91af;">DataContext</span> context){}</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> + public</span> <span style="color: blue;">override</span> + <span style="color: blue;">string</span> ToString()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">return</span> <span style="color: blue;">string</span>.Format(<span + style="color: #a31515;">"Class1 has Context: {0}"</span>, _context);</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">class</span> <span style="color: #2b91af;">Class2</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + public</span> Class2(<span style="color: #2b91af;">Class1</span> class1, + <span style="color: #2b91af;">DataContext</span> context) {}</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> + public</span> <span style="color: blue;">override</span> + <span style="color: blue;">string</span> ToString()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">return</span> <span style="color: blue;">string</span>.Format(<span + style="color: #a31515;">"Class2 has Context: {0}\n{1}"</span>, _context, + _class1);</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">class</span> <span style="color: #2b91af;">Class3</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">public</span> Class3(<span style="color: #2b91af;">Class2</span> + class2, <span style="color: #2b91af;">DataContext</span> context) {}</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> + public</span> <span style="color: blue;">override</span> + <span style="color: blue;">string</span> ToString()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">return</span> <span style="color: blue;">string</span>.Format(<span + style="color: #a31515;">"Class3 has Context: {0}\n{1}"</span>, _context, + _class2);</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>When you request an object of Class3 with a call to + Container.GetInstance<Class3>() like this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 [\cf3 Test\cf0 ]\par ?? \cf4 public\cf0 \cf4 void\cf0 demonstrate_session_identity()\par ?? \{\par ?? \cf4 var\cf0 class3 = container.GetInstance<\cf3 Class3\cf0 >();\par ?? \cf3 Debug\cf0 .WriteLine(class3);\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Test</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> demonstrate_session_identity()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> class3 = container.GetInstance<<span style="color: #2b91af;">Class3</span>>();</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;"> + Debug</span>.WriteLine(class3);</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>The output is:</p> +<pre> +Class3 has Context: Id: 3abe0330-e94f-48a3-b8c3-56d278eea07f +Class2 has Context: Id: 3abe0330-e94f-48a3-b8c3-56d278eea07f +Class1 has Context: Id: 3abe0330-e94f-48a3-b8c3-56d278eea07f +</pre> + <p>In the sample above, when we write out the Class3, Class2, and Class1 objects to Debug.WriteLine, we find that each of these objects have a reference to the same DataContext. If we were to run this test again, the output might be:</p> + <pre> +Class3 has Context: Id: 109329ce-4058-4a35-9fd1-46d47c1e69e7 +Class2 has Context: Id: 109329ce-4058-4a35-9fd1-46d47c1e69e7 +Class1 has Context: Id: 109329ce-4058-4a35-9fd1-46d47c1e69e7 + </pre> + <p>We see the exact same behavior, but it was a different object instance of DataContext for the new object graph.</p> + <p>This behavior also applies to objects passed in to the Container as an explicit argument:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red163\green21\blue21;}??\fs20 [\cf3 Test\cf0 ]\par ?? \cf4 public\cf0 \cf4 void\cf0 demonstrate_session_identity_with_explicit_argument()\par ?? \{\par ?? \cf3 DataContext\cf0 context = \cf4 new\cf0 \cf3 DataContext\cf0 ();\par ?? \cf3 Debug\cf0 .WriteLine(\cf5 "The context being passed in is "\cf0 + context);\par ??\par ?? \cf4 var\cf0 class3 = container.With(context).GetInstance<\cf3 Class3\cf0 >();\par ?? \cf3 Debug\cf0 .WriteLine(class3);\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Test</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> + demonstrate_session_identity_with_explicit_argument()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;"> + DataContext</span> context = <span style="color: blue;">new</span> + <span style="color: #2b91af;">DataContext</span>();</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;"> + Debug</span>.WriteLine(<span style="color: #a31515;">"The context being passed + in is "</span> + context);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> class3 = container.With(context).GetInstance<<span + style="color: #2b91af;">Class3</span>>();</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;"> + Debug</span>.WriteLine(class3);</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>The output of this unit test is:</p> + <pre> +The context being passed in is Id: 87ddccfd-a441-41fd-a86d-3f32987496ba +Class3 has Context: Id: 87ddccfd-a441-41fd-a86d-3f32987496ba +Class2 has Context: Id: 87ddccfd-a441-41fd-a86d-3f32987496ba +Class1 has Context: Id: 87ddccfd-a441-41fd-a86d-3f32987496ba + </pre> + <p>The point of the sample above is just to show that the object instance of DataContext passed into the Container is used to create the Class3, Class2, and Class1 objects.</p> <hr /> <h4>Injecting Arrays of Services</h4> - <p>TODO</p> + <p>StructureMap has always supported Dependency Injection of arrays of dependency + objects. New in StructureMap 2.5+ is a policy that if any array of + dependencies is not explicitly specified, StructureMap will inject all possible + instances of that dependency type. The sample below illustrates this auto + wiring policy. I have a class called "ClassThatUsesValidators" that needs + an array of IValidator objects. Below, I've configured two different + Instances of ClassThatUsesValidator, one that explicitly configures its children + IValidator and another Instance that is just going to let auto wiring inject the + IValidator's.</p> <!-- {\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IValidator\par ??\cf0 \{\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 Validator\cf0 : \cf4 IValidator\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf3 string\cf0 _name;\par ??\par ?? \cf3 public\cf0 Validator(\cf3 string\cf0 name)\par ?? \{\par ?? _name = name;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 override\cf0 \cf3 string\cf0 ToString()\par ?? \{\par ?? \cf3 return\cf0 \cf3 string\cf0 .Format(\cf5 "Name: \{0\}"\cf0 , _name);\par ?? \}\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 ClassThatUsesValidators\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 IValidator\cf0 [] _validators;\par ??\par ?? \cf3 public\cf0 ClassThatUsesValidators(\cf4 IValidator\cf0 [] validators)\par ?? \{\par ?? _validators = validators;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf3 void\cf0 Write()\par ?? \{\par ?? \cf3 foreach\cf0 (\cf4 IValidator\cf0 validator \cf3 in\cf0 _validators)\par ?? \{\par ?? \cf4 Debug\cf0 .WriteLine(validator);\par ?? \}\par ?? \}\par ?? \}\par ??\par ?? [\cf4 TestFixture\cf0 ]\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 ValidatorExamples\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf4 Container\cf0 container;\par ??\par ?? [\cf4 SetUp\cf0 ]\par ?? \cf3 public\cf0 \cf3 void\cf0 SetUp()\par ?? \{\par ?? container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.ForRequestedType<\cf4 IValidator\cf0 >().AddInstances(o =>\par ?? \{\par ?? o.OfConcreteType<\cf4 Validator\cf0 >().WithCtorArg(\cf5 "name"\cf0 ).EqualTo(\cf5 "Red"\cf0 ).WithName(\cf5 "Red"\cf0 );\par ?? o.OfConcreteType<\cf4 Validator\cf0 >().WithCtorArg(\cf5 "name"\cf0 ).EqualTo(\cf5 "Blue"\cf0 ).WithName(\cf5 "Blue"\cf0 );\par ?? o.OfConcreteType<\cf4 Validator\cf0 >().WithCtorArg(\cf5 "name"\cf0 ).EqualTo(\cf5 "Purple"\cf0 ).WithName(\cf5 "Purple"\cf0 );\par ?? o.OfConcreteType<\cf4 Validator\cf0 >().WithCtorArg(\cf5 "name"\cf0 ).EqualTo(\cf5 "Green"\cf0 ).WithName(\cf5 "Green"\cf0 );\par ?? \});\par ??\par ?? x.ForRequestedType<\cf4 ClassThatUsesValidators\cf0 >().AddInstances(o =>\par ?? \{\par ?? \cf6 // Define an Instance of ClassThatUsesValidators that depends on AutoWiring\par ??\cf0 o.OfConcreteType<\cf4 ClassThatUsesValidators\cf0 >().WithName(\cf5 "WithAutoWiring"\cf0 );\par ??\par ?? \cf6 // Define an Instance of ClassThatUsesValidators that overrides AutoWiring\par ??\cf0 o.OfConcreteType<\cf4 ClassThatUsesValidators\cf0 >().WithName(\cf5 "ExplicitArray"\cf0 )\par ?? .TheArrayOf<\cf4 IValidator\cf0 >().Contains(y =>\par ?? \{\par ?? y.TheInstanceNamed(\cf5 "Red"\cf0 );\par ?? y.TheInstanceNamed(\cf5 "Green"\cf0 );\par ?? \});\par ?? \});\par ?? \});\par ?? \}\par ??\par ?? [\cf4 Test\cf0 ]\par ?? \cf3 public\cf0 \cf3 void\cf0 what_are_the_validators()\par ?? \{\par ?? \cf4 Debug\cf0 .WriteLine(\cf5 "With Auto Wiring"\cf0 );\par ?? container.GetInstance<\cf4 ClassThatUsesValidators\cf0 >(\cf5 "WithAutoWiring"\cf0 ).Write();\par ?? \cf4 Debug\cf0 .WriteLine(\cf5 "================================="\cf0 );\par ?? \cf4 Debug\cf0 .WriteLine(\cf5 "With Explicit Configuration"\cf0 );\par ?? container.GetInstance<\cf4 ClassThatUsesValidators\cf0 >(\cf5 "ExplicitArray"\cf0 ).Write();\par ?? \}\par ?? \}} --> @@ -454,8 +666,18 @@ }</p> </div> <!--EndFragment--> -<p> </p> - <p> </p> +<p>The output of what_are_the_validators() is:</p> +<pre> +With Auto Wiring +Name: Red +Name: Blue +Name: Purple +Name: Green +================================= +With Explicit Configuration +Name: Red +Name: Green +</pre> <hr /> </body> </html> \ No newline at end of file Modified: trunk/Source/HTML/Default.htm =================================================================== --- trunk/Source/HTML/Default.htm 2009-01-03 00:07:32 UTC (rev 214) +++ trunk/Source/HTML/Default.htm 2009-01-04 02:55:42 UTC (rev 215) @@ -90,53 +90,6 @@ <p> </p> <p> </p> - <h3>Feature List</h3> - <UL> - <li> - Creates objects using the <a href="http://picocontainer.codehaus.org/Constructor+Injection"> - Constructor Injection pattern</a> </li> - <LI> - Optionally, attach dependencies and other properties through Setter Injection - (v0.90) - <LI> - Runtime linking of object dependencies - <LI> - Configurable object <a href="Scoping.htm">lifecycle - scoping</a> (v1.0)<LI> - Optional support for an - <a href="SingletonInjection.htm">Injected Singleton</a> (v0.90) - <LI> - Generalized support for the - <a href="Concepts.htm#Plugin">Plugin</a> pattern using (almost) any type of class or - interface - <LI> - Configurable either implicitly through - <a href="Attributes.htm">custom attributes</a> or explicitly through - XML configuration - <LI> - Optional log4net integration - <LI> - <EM>Mock Injection</EM> using built in support for <a href="http://sourceforge.net/projects/nmock/"> - NMock</a> - <LI> - Runtime injection of a static mock or stub (v0.90) - <LI> - Machine level overrides of default configuration - <LI> - Profile overrides of default configuration -- i.e. "Remote" vs "Local" vs - "Stubbed" dependency profiles - <LI> - NAnt tasks for diagnostic verification of configuration and deployment - utilities for easier continuous integration (v0.90) - <LI> - Command line utility for troubleshooting runtime configuration issues - (v0.90) - <LI> - Diagnostic WinForms tool for exploring and - troubleshooting configuration (v1.0)<LI> - Uses Reflection.Emit namespace classes to create IL code on the fly for - performance superior to Reflection based approaches</LI> - </UL> </body> </html> \ No newline at end of file Modified: trunk/Source/HTML/FeatureList.htm =================================================================== --- trunk/Source/HTML/FeatureList.htm 2009-01-03 00:07:32 UTC (rev 214) +++ trunk/Source/HTML/FeatureList.htm 2009-01-04 02:55:42 UTC (rev 215) @@ -8,5 +8,59 @@ </head> <body> + <p> + StructureMap includes all of the basic capabilities of an IoC tool, plus much, + much more:</p> + <UL> + <li> + Creates objects using the <a href="http://picocontainer.codehaus.org/Constructor+Injection"> + Constructor Injection pattern</a> + <UL> + <li>Constructor function selection can be overriden programmatically or with an + attribute</li> + </UL> + </li> + <LI> + Optionally, attach dependencies and other properties through Setter Injection. + Properties can be configured to be mandatory dependencies or optional + dependencies.<UL> + <LI>Convention based setter injection policies</UL> + <LI> + Runtime linking of object dependencies + with auto wiring<LI> + "Build Up" using setter injection to attach dependencies to an externally + constructed object<LI> + Can be configured to create or resolve objects by:<UL> + <LI>Calling constructor functions<LI>Lambda expressions<LI>Cloning a prototype + object<LI>Loading a UserControl<LI>UUsing an externally created object<LI> + Conditional Construction of objects<LI>Custom method of construction objects</UL> + <LI>Object graphs can be configured inline to override auto wiringLI>Contextual + construction of objects<LI>"Missing Instance" handling<LI>Passing + explicit arguments into the Container<LI> + Configurable object <a href="Scoping.htm">lifecycle + scoping</a> (singleton, transient, HttpContext, ThreadLocal)<LI> + Auto registration with pluggable type convention rules<LI>Generalized support for the + <a href="Concepts.htm#Plugin">Plugin</a> pattern using (almost) any type of class or + interface + <LI>Configurable either implicitly through + a programmatic DSL, <a href="UsingAttributes.htm">custom attributes</a>, or explicitly through + XML configuration + <LI>Very modular configuration options. Mix and match any form of + configuration at one time.<LI>Configuration can be added at runtime<LI>Supports type registration of open generic types<LI>Interception capabilities to + apply runtime AOP or decorators<LI>Extensible + object creation<LI><EM>Mock Injection</EM> with Containers + <LI>Runtime injection of a static mock or stub<LI>An Auto Mocking Container that + can be used with any .Net mocking framework. Rhino Mocks "Classic", Rhino + Mocks AAA, and Moq are supported out of the box<LI>Machine level overrides of default configuration + <LI>Profile overrides of default configuration -- i.e. "Remote" vs "Local" vs + "Stubbed" dependency profiles + <LI>Command line utility for troubleshooting runtime configuration issues<UL> + <LI>Diagnostic querying of the Container configuration (Linq to StructureMap, sort + of)<LI>"Assert" configuration + is valid<LI>Environment Test Support<LI>Custom Debugger</UL> + <LI>Uses Reflection.Emit namespace classes to create IL code on the fly for + performance superior to Reflection based approaches</LI> + </UL> + </body> </html> \ No newline at end of file Modified: trunk/Source/HTML/Generics.htm =================================================================== --- trunk/Source/HTML/Generics.htm 2009-01-03 00:07:32 UTC (rev 214) +++ trunk/Source/HTML/Generics.htm 2009-01-04 02:55:42 UTC (rev 215) @@ -2,8 +2,342 @@ <html> <head> <title>Using Open Generic Types</title> + <link rel="stylesheet" type="text/css" href="style.css" /> + <script type="text/javascript" src="jquery-1.2.6.js"></script> + <script type="text/javascript" src="structuremap.js"></script> </head> <body> - + <p>StructureMap directly supports open generic types[LINK]*. This is most + easily explained by a demonstration. I'm currently working on an MVC + application that uses a lot of semi-RESTful services that return Json. + These Json service methods are implemented by methods on a Controller class that + by convention, all return a single object:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 FindAddressController\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf4 Address\cf0 FindAddress(\cf3 long\cf0 id)\par ?? \{\par ?? \cf3 return\cf0 \cf3 null\cf0 ;\par ?? \}\par ??\par ?? \cf3 public\cf0 \cf4 Continuation\cf0 WhatShouldTheUserDoNext()\par ?? \{\par ?? \cf3 return\cf0 \cf3 null\cf0 ;\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">FindAddressController</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: #2b91af;">Address</span> FindAddress(<span + style="color: blue;">long</span> id){}</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: #2b91af;">Continuation</span> WhatShouldTheUserDoNext() {}</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>When these methods are executed in our MVC applications, the output objects + (Address or Continuation) are serialized to Json by other code and sent down to + the client. It's worked out well, but there's one little wrinkle from the + code above that we stumbled upon:</p> + <ol> + <li>Continuation is basically a dumb Data Transfer Object[LINK] class that's + perfectly suited for being Json serialized and consumed by JavaScript on the + client</li> + <li>Address is an Entity[LINK] class in our Domain Model, and very poorly suited to + Json serialization. Besides the fact that we probably wouldn't want the + shape of our Domain Model classes to be coupled to the client JavaScript, the + Entity classes are jagged, have lots of lazy loaded members, and contain a fair + amount of data we may not want to send down to the client (plus the Json + serialization does poorly with bidirectional dependencies). Direct Json + serialization is out.</li> + </ol> + <p>What we needed to do was convert the Entity objects (and any other object that + wasn't suited to Json serialization and client usage) into a UI-friendly Data + Transfer Object. Other objects like Continuation that were already Json + friendly, we could just use as is. The solution we came up with was the + "ObjectFlattener:"</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 ObjectFlattener\par ??\cf0 \{\par ?? \cf3 private\cf0 \cf3 readonly\cf0 \cf4 IContainer\cf0 _container;\par ??\par ?? \cf5 // You can inject the IContainer itself into an object by the way...\par ??\cf0 \cf3 public\cf0 ObjectFlattener(\cf4 IContainer\cf0 container)\par ?? \{\par ?? _container = container;\par ?? \}\par ??\par ?? \cf5 // This method can "flatten" any object\par ??\cf0 \cf3 public\cf0 \cf3 object\cf0 Flatten(\cf3 object\cf0 input)\par ?? \{\par ?? \cf3 var\cf0 flattener = _container.ForGenericType(\cf3 typeof\cf0 (\cf4 IFlattener\cf0 <>))\par ?? .WithParameters(input.GetType())\par ?? .GetInstanceAs<\cf4 IFlattener\cf0 >();\par ??\par ?? \cf3 return\cf0 flattener.ToDto(input);\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">ObjectFlattener</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">private</span> + <span style="color: blue;">readonly</span> <span style="color: #2b91af;"> + IContainer</span> _container;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// You can inject the + IContainer itself into an object by the way...</span></p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + ObjectFlattener(<span style="color: #2b91af;">IContainer</span> container)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + _container = container;</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;">// This method can + "flatten" any object</span></p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">object</span> Flatten(<span style="color: blue;">object</span> + input)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> flattener = _container.ForGenericType(<span style="color: blue;">typeof</span> + (<span style="color: #2b91af;">IFlattener</span><>))</p> + <p style="margin: 0px;"> + + .WithParameters(input.GetType())</p> + <p style="margin: 0px;"> + + .GetInstanceAs<<span style="color: #2b91af;">IFlattener</span>>();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> + return</span> flattener.ToDto(input);</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>The ObjectFlattener can take in any object, select a strategy for "flattening" + that object into something Json friendly, and return the Json friendly object. + ObjectFlattener is dirt simple. It simply finds the correct IFlattener for + the object type passed into the Flatten(object) method:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IFlattener\par ??\cf0 \{\par ?? \cf3 object\cf0 ToDto(\cf3 object\cf0 input);\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">interface</span> + <span style="color: #2b91af;">IFlattener</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">object</span> ToDto(<span + style="color: blue;">object</span> input);</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>ObjectFlattener needs to find the corrent IFlattener for the object Type passed + in, so it's really looking for the type:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IFlattener\cf0 <T> : \cf4 IFlattener\par ??\cf0 \{\par ?? \par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">interface</span> + <span style="color: #2b91af;">IFlattener</span><T> : + <span style="color: #2b91af;">IFlattener</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>where "T" is the type of object passed into the ToDto(object) method. When + an Address object is passed into ToDto(), ObjectFlattener finds the default + instance of IFlattener<Address>. The + "ForGenericType().WithParameters().GetInstanceAs<T>()" syntax is a helper + expression to create and request a closed generic type from an open generic + template and the appropriate generic parameter types.</p> + <p>Now, we said that many objects like Continuation in our system are DTO's to begin + with and don't need to be "flattened." For those objects, we use a "Nullo" + implementation of IFlattener that just returns the object passed in without any + transformation:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 PassthroughFlattener\cf0 <T> : \cf4 IFlattener\cf0 <T>\par ?? \{\par ?? \cf3 public\cf0 \cf3 object\cf0 ToDto(\cf3 object\cf0 input)\par ?? \{\par ?? \cf3 return\cf0 input;\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">PassthroughFlattener</span><T> : + <span style="color: #2b91af;">IFlattener</span><T></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">object</span> ToDto(<span style="color: blue;">object</span> + input)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + return</span> input;</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>The Address class needs some transformation, so we'll create an AddressFlattener + class:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 AddressFlattener\cf0 : \cf4 IFlattener\cf0 <\cf4 Address\cf0 >\par ?? \{\par ?? \cf3 public\cf0 \cf3 object\cf0 ToDto(\cf3 object\cf0 input)\par ?? \{\par ?? \cf3 var\cf0 dto = createDTO((\cf4 Address\cf0 ) input);\par ?? \cf3 return\cf0 dto;\par ?? \}\par ??\par ?? \cf3 private\cf0 \cf3 object\cf0 createDTO(\cf4 Address\cf0 input)\par ?? \{\par ?? \cf5 // creates the AddressDTO object from the \par ??\cf0 \cf5 // Address object passed in\par ??\cf0 \cf3 throw\cf0 \cf3 new\cf0 System.\cf4 NotImplementedException\cf0 ();\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">AddressFlattener</span> : + <span style="color: #2b91af;">IFlattener</span><<span style="color: #2b91af;">Address</span>></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">object</span> ToDto(<span style="color: blue;">object</span> + input)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> dto = createDTO((<span style="color: #2b91af;">Address</span>) + input);</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + return</span> dto;</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;">private</span> + <span style="color: blue;">object</span> createDTO(<span + style="color: #2b91af;">Address</span> input)</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: green;"> + // creates the AddressDTO object from the </span> + </p> + <p style="margin: 0px;"> + <span style="color: green;"> + // Address object passed in</span></p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>Great, but now let's move on to registering these classes with a Container. + This unit test fixture from the code illustrates this very scenario:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red0\green128\blue0;}??\fs20 [\cf3 SetUp\cf0 ]\par ?? \cf4 public\cf0 \cf4 void\cf0 SetUp()\par ?? \{\par ?? container = \cf4 new\cf0 \cf3 Container\cf0 (x =>\par ?? \{\par ?? \cf5 // Define the basic open type for IFlattener<>\par ??\cf0 x.ForRequestedType(\cf4 typeof\cf0 (\cf3 IFlattener\cf0 <>)).TheDefaultIsConcreteType(\cf4 typeof\cf0 (\cf3 PassthroughFlattener\cf0 <>));\par ?? \par ?? \cf5 // Explicitly Register a specific closed type for Address\par ??\cf0 x.ForRequestedType<\cf3 IFlattener\cf0 <\cf3 Address\cf0 >>().TheDefaultIsConcreteType<\cf3 AddressFlattener\cf0 >();\par ?? \});\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">SetUp</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> SetUp()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + container = + <span style="color: blue;">new</span> <span style="color: #2b91af;">Container</span>(x + =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + <span style="color: green;">// Define the basic open type for IFlattener<></span></p> + <p style="margin: 0px;"> + + x.ForRequestedType(<span style="color: blue;">typeof</span> (<span + style="color: #2b91af;">IFlattener</span><>)).TheDefaultIsConcreteType(<span + style="color: blue;">typeof</span> (<span style="color: #2b91af;">PassthroughFlattener</span><>));</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// Explicitly Register a specific closed type for + Address</span></p> + <p style="margin: 0px;"> + + x.ForRequestedType<<span style="color: #2b91af;">IFlattener</span><<span + style="color: #2b91af;">Address</span>>>().TheDefaultIsConcreteType<<span + style="color: #2b91af;">AddressFlattener</span>>();</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>In the code above we registered a specific concrete type for IFlattener<Address>, + and the open generic type PassthroughFlattener<T> for requests to IFlattener<T>. + When we request an instance of IFlattener<Address>, StructureMap behaves as + expected and returns a AddressFlattener object:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 [\cf3 Test\cf0 ]\par ?? \cf4 public\cf0 \cf4 void\cf0 asking_for_a_closed_type_that_is_explicitly_registered_returns_the_explicitly_defined_type()\par ?? \{\par ?? container.GetInstance<\cf3 IFlattener\cf0 <\cf3 Address\cf0 >>()\par ?? .ShouldBeOfType<\cf3 AddressFlattener\cf0 >();\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Test</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> + asking_for_a_closed_type_that_is_explicitly_registered_returns_the_explicitly_defined_type()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + container.GetInstance<<span + style="color: #2b91af;">IFlattener</span><<span style="color: #2b91af;">Address</span>>>()</p> + <p style="margin: 0px;"> + + .ShouldBeOfType<<span style="color: #2b91af;">AddressFlattener</span>>();</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>Now, we'll ask for an instance of IFlattener<Continuation>. You'll notice + that we didn't explicitly register that specific type. When the Container + gets the request for IFlattener<Continuation>, it first looks to see if it + already knows how to build that specific type. In this case the Container + doesn't already know about IFlattener<Continuation>, but it does know about the + open type IFlattener<T> template, so it can use that configuration to create the + closed type IFlattener<Continuation>:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 [\cf3 Test\cf0 ]\par ?? \cf4 public\cf0 \cf4 void\cf0 asking_for_a_closed_type_that_is_not_explicitly_registered_will_close_the_open_type_template()\par ?? \{\par ?? container.GetInstance<\cf3 IFlattener\cf0 <\cf3 Continuation\cf0 >>()\par ?? .ShouldBeOfType<\cf3 PassthroughFlattener\cf0 <\cf3 Continuation\cf0 >>();\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Test</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> + asking_for_a_closed_type_that_is_not_explicitly_registered_will_close_the_open_type_template()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + container.GetInstance<<span + style="color: #2b91af;">IFlattener</span><<span style="color: #2b91af;">Continuation</span>>>()</p> + <p style="margin: 0px;"> + + .ShouldBeOfType<<span style="color: #2b91af;">PassthroughFlattener</span><<span + style="color: #2b91af;">Continuation</span>>>();</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<hr /> + <p> + </p> + <p> + * Anytime I read one of those "look I'm so clever I can write my own IoC + container in 50 lines of code" blog posts, my immediate response is "oh yeah, + can you handle open generic types smart guy?"</p> + </body> </html> \ No newline at end of file Modified: trunk/Source/HTML/HTML.csproj =================================================================== --- trunk/Source/HTML/HTML.csproj 2009-01-03 00:07:32 UTC (rev 214) +++ trunk/Source/HTML/HTML.csproj 2009-01-04 02:55:42 UTC (rev 215) @@ -65,7 +65,6 @@ <Content Include="ModularConfiguration.htm" /> <Content Include="Profiles.htm" /> <Content Include="Scoping.htm" /> - <Content Include="SmartInstance.htm" /> <Content Include="UsingAttributes.htm" /> <Content Include="AutoWiring.htm" /> <Content Include="ConfiguringStructureMap.htm" /> Modified: trunk/Source/HTML/Menu.htm =================================================================== --- trunk/Source/HTML/Menu.htm 2009-01-03 00:07:32 UTC (rev 214) +++ trunk/Source/HTML/Menu.htm 2009-01-04 02:55:42 UTC (rev 215) @@ -66,12 +66,13 @@ <li><a href="../../UsingTheContainerOutsideOfObjectFactory.htm">... [truncated message content] |
From: <jer...@us...> - 2009-01-11 21:16:22
|
Revision: 218 http://structuremap.svn.sourceforge.net/structuremap/?rev=218&view=rev Author: jeremydmiller Date: 2009-01-11 21:16:13 +0000 (Sun, 11 Jan 2009) Log Message: ----------- documentation update and BuildUp fix Modified Paths: -------------- trunk/Source/HTML/ConstructorAndSetterInjection.htm trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs trunk/Source/StructureMap/ConfigurationExpression.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs trunk/Source/StructureMap/Interceptors/EnrichmentInterceptor.cs trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs trunk/Source/StructureMap/Interceptors/Interceptors.cs trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/SmartInstance.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/TypeExtensions.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs trunk/Source/StructureMap.Testing/Graph/ConventionBasedSetterInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/MockTypeInterceptor.cs trunk/Source/StructureMap.Testing/Pipeline/InstanceTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/TestData/AttributeNormalized.xml trunk/Source/StructureMap.Testing/TestData/ObjectMother.config Added Paths: ----------- trunk/Source/StructureMap.Testing/Examples/Interception.cs trunk/Source/StructureMap.Testing/TestData/ProfileSample.xml Modified: trunk/Source/HTML/ConstructorAndSetterInjection.htm =================================================================== --- trunk/Source/HTML/ConstructorAndSetterInjection.htm 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/HTML/ConstructorAndSetterInjection.htm 2009-01-11 21:16:13 UTC (rev 218) @@ -265,7 +265,7 @@ --> <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> <p style="margin: 0px;"> - [<span style="color: #2b91af;">Test</span>]/p> + [<span style="color: #2b91af;">Test</span>] <p style="margin: 0px;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span> optional_setter_injection_with_string()</p> @@ -553,18 +553,60 @@ --> <!--EndFragment--> <hr /> - <h4>Applying Setter Injection to an Existing Object (BuildUp)</h4> + <h2>Applying Setter Injection to an Existing Object (BuildUp)</h2> <p>asdf</p> <hr /> - <h4><a name="SetterPolicies"></a>Creating Policies for Setter Injection</h4> + <h2><a name="SetterPolicies"></a>Creating Policies for Setter Injection</h2> <p>New in StructureMap 2.5.2+ is the ability to create setter injection policies. What this means is that you create conventions to define which public setter - properties will be mandatory in the construction of objects. </p> + properties will be mandatory in the construction of objects. Setter + Injection policies are set with the new "SetAllProperties" method in the + Registry DSL:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red163\green21\blue21;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 x.SetAllProperties(policy =>\par ?? \{\par ?? policy.WithAnyTypeFromNamespace(\cf3 "StructureMap.Testing.Widget3"\cf0 );\par ??\par ?? policy.Matching(prop =>\par ?? \{\par ?? \cf4 return\cf0 prop.PropertyType.CanBeCastTo(\cf4 typeof\cf0 (\cf5 IService\cf0 ))\par ?? && !prop.Name.Contains(\cf3 "Ignore"\cf0 );\par ?? \});\par ?? \});} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + + x.SetAllProperties(policy =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + policy.Matching(prop =></p> + <p style="margin: 0px;"> + + {</p> + <p style="margin: 0px;"> + + <span style="color: blue;">return</span> prop.PropertyType.CanBeCastTo(<span + style="color: blue;">typeof</span> (<span style="color: #2b91af;">IService</span>))</p> + <p style="margin: 0px;"> + + && !prop.Name.Contains(<span style="color: #a31515;">"Ignore"</span>);</p> + <p style="margin: 0px;"> + + });</p> + <p style="margin: 0px;"> + });</p> + </div> +<!--EndFragment--> +<p>In the end, all you're doing is telling StructureMap that any public Setter that + matches a Predicate<PropertyInfo> policy should be a mandatory Setter. You + can make multiple declarations inside the + <a href="http://martinfowler.com/dslwip/NestedClosure.html">nested closure</a> + for SetAllProperties. <b>Any additional calls to SetAllProperties() are + purely additive.</b></p> + <p>In the sections below we'll look at some helper methods inside + SetAllProperties():</p> + <hr /> <h4>Specify a Setter Policy by Property Name</h4> <p>The sample below will make all public setter properties mandatory where the property name is suffixed by "Service." The call to NameMatches() takes in - a Predicate<string> that is a test against the property name.</p> + a Predicate<string> that is a test against the property name. The + NameMatches() method just applies a Predicate<string> test against the name of a + public setter.</p> <!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.SetAllProperties(policy =>\par ?? \{\par ?? policy.NameMatches(name => name.EndsWith(\cf5 "Name"\cf0 ));\par ?? \});\par ?? \});} --> @@ -591,8 +633,36 @@ <!--EndFragment--> <hr /> <h4>Specify a Setter Policy by Property Type</h4> - <p> </p> + <p>Setter injection policies can also be defined by a simple test against the + PropertyInfo.PropertyType. Here's the shorthand method:</p> <!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.ForRequestedType<\cf4 IService\cf0 >().TheDefault.Is.Object(theService);\par ?? x.ForRequestedType<\cf4 IGateway\cf0 >().TheDefaultIsConcreteType<\cf4 DefaultGateway\cf0 >();\par ??\par ?? x.SetAllProperties(policy =>\par ?? \{\par ?? policy.TypeMatches(type => type == \cf3 typeof\cf0 (\cf4 IService\cf0 ));\par ?? \});\par ?? \});} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.SetAllProperties(policy =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + policy.TypeMatches(type => type == <span style="color: blue;">typeof</span> (<span + style="color: #2b91af;">IService</span>));</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + });</p> + </div> +<!--EndFragment--> +<p>The "OfType<T>" method is shorthand for: policy.Matching( property => + typeof(T).IsAssignableTo(property.PropertyInfo) )</p> +<!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.SetAllProperties(policy =>\par ?? \{\par ?? policy.OfType<\cf3 string\cf0 >();\par ?? policy.OfType<\cf4 IGateway\cf0 >();\par ?? \});\par ?? \});} --> <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> @@ -619,7 +689,10 @@ });</p> </div> <!--EndFragment--> -<p> </p> +<p>You can also specify that all setter dependencies where the property type is + inside a namespace should be a mandatory setter (this check holds true for + subfolders of a namespace). This can be handy if you place all services in + a well known namespace.</p> <!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.SetAllProperties(policy =>\par ?? \{\par ?? policy.WithAnyTypeFromNamespaceContainingType<\cf4 ClassWithNamedProperties\cf0 >();\par ?? \});\par ?? \});} --> @@ -644,7 +717,7 @@ });</p> </div> <!--EndFragment--> -<p> </p> +<p>Here's another way to specify the namespace:</p> <!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.SetAllProperties(policy =>\par ?? \{\par ?? policy.WithAnyTypeFromNamespace(\cf5 "StructureMap.Testing.Widget3"\cf0 );\par ?? \});\par ?? \});} --> @@ -669,12 +742,9 @@ });</p> </div> <!--EndFragment--> -<p> </p> - <p> </p> +<hr /> - <hr /> - - <h4>Defining Setter Properties with Attributes</h4><p>Just use the [StructureMap.Attributes.SetterProperty] to denote properties that + <h2>Defining Setter Properties with Attributes</h2><p>Just use the [StructureMap.Attributes.SetterProperty] to denote properties that need to be filled by StructureMap. Marking a property with the [SetterProperty] makes the setter mandatory. StructureMap will throw an exception if the "ShouldCache" property isn't specified for the concrete type @@ -737,7 +807,7 @@ </div> <!--EndFragment--> <hr /> - <h4>Defining Setter Properties in Xml</h4> + <h2>Defining Setter Properties in Xml</h2> <p>Setter properties can be defined in the Xml configuration by explicitly directing StructureMap to use setter properties while building a concrete type. In the Xml, Setter configuration is done with the exact syntax as constructor Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/BuildSession.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -174,7 +174,7 @@ public virtual object ApplyInterception(Type pluginType, object actualValue) { if (actualValue == null) return null; - return _interceptorLibrary.FindInterceptor(actualValue.GetType()).Process(actualValue); + return _interceptorLibrary.FindInterceptor(actualValue.GetType()).Process(actualValue, this); } public virtual void RegisterDefault(Type pluginType, object defaultObject) Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -142,14 +142,56 @@ return target; }; - var interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); + var interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), (c, o) => + { + handler((PLUGINTYPE) o); + return o; + }); + graph.InterceptorLibrary.AddInterceptor(interceptor); }); return this; } + public CreatePluginFamilyExpression<PLUGINTYPE> InterceptWith(InstanceInterceptor interceptor) + { + _children.Add( + graph => + { + var typeInterceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), (c, o) => interceptor.Process(o, c)); + graph.InterceptorLibrary.AddInterceptor(typeInterceptor); + }); + + return this; + } + /// <summary> + /// Register an Action to run against any object of this PluginType immediately after + /// it is created, but before the new object is passed back to the caller + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> OnCreation(Action<IContext, PLUGINTYPE> handler) + { + _children.Add( + graph => + { + Func<IContext, object, object> function = (c, o) => + { + handler(c, (PLUGINTYPE)o); + return o; + }; + + var interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), function); + + graph.InterceptorLibrary.AddInterceptor(interceptor); + }); + + return this; + } + + /// <summary> /// Register a Func to run against any object of this PluginType immediately after it is created, /// but before the new object is passed back to the caller. Unlike <see cref="OnCreation">OnCreation()</see>, /// EnrichWith() gives the the ability to return a different object. Use this method for runtime AOP @@ -162,7 +204,7 @@ _children.Add( graph => { - Func<object, object> function = target => handler((PLUGINTYPE) target); + Func<IContext, object, object> function = (context, target) => handler((PLUGINTYPE) target); var interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); graph.InterceptorLibrary.AddInterceptor(interceptor); @@ -172,6 +214,26 @@ } /// <summary> + /// Register a Func to run against any object of this PluginType immediately after it is created, + /// but before the new object is passed back to the caller. Unlike <see cref="OnCreation">OnCreation()</see>, + /// EnrichWith() gives the the ability to return a different object. Use this method for runtime AOP + /// scenarios or to return a decorator. + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> EnrichWith(ContextEnrichmentHandler<PLUGINTYPE> handler) + { + _children.Add( + graph => + { + var interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), (c, o) => handler(c, (PLUGINTYPE)o)); + graph.InterceptorLibrary.AddInterceptor(interceptor); + }); + + return this; + } + + /// <summary> /// Shortcut method to add an additional Instance to this Plugin Type /// as just a Concrete Type. This will only work if the Concrete Type /// has no primitive constructor or mandatory Setter arguments. @@ -209,6 +271,19 @@ } /// <summary> + /// Registers an IBuildInterceptor for this Plugin Type that executes before + /// any object of this PluginType is created. IBuildInterceptor's can be + /// used to create a custom scope + /// </summary> + /// <param name="interceptor"></param> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> BuildPolicyIs(IBuildInterceptor interceptor) + { + _alterations.Add(family => family.AddInterceptor(interceptor)); + return this; + } + + /// <summary> /// Largely deprecated and unnecessary with the ability to add Xml configuration files /// </summary> /// <param name="source"></param> Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -113,6 +113,25 @@ { _registry.addExpression(graph => { + var interceptor = new PluginTypeInterceptor(_pluginType, (c, o) => func(o)); + graph.InterceptorLibrary.AddInterceptor(interceptor); + }); + + return this; + } + + /// <summary> + /// Register a Func to run against any object of this PluginType immediately after it is created, + /// but before the new object is passed back to the caller. Unlike <see cref="OnCreation">OnCreation()</see>, + /// EnrichWith() gives the the ability to return a different object. Use this method for runtime AOP + /// scenarios or to return a decorator. + /// </summary> + /// <param name="func"></param> + /// <returns></returns> + public GenericFamilyExpression EnrichWith(Func<IContext, object, object> func) + { + _registry.addExpression(graph => + { var interceptor = new PluginTypeInterceptor(_pluginType, func); graph.InterceptorLibrary.AddInterceptor(interceptor); }); Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq.Expressions; using StructureMap.Configuration.DSL.Expressions; using StructureMap.Graph; using StructureMap.Interceptors; @@ -36,6 +37,14 @@ // Controlling Setter Injection Behavior CreatePluginFamilyExpression<PLUGINTYPE> FillAllPropertiesOfType<PLUGINTYPE>(); void SetAllProperties(Action<SetterConvention> action); + + /// <summary> + /// Use to programmatically select the constructor function of a concrete + /// class. Applies globally to all Containers in a single AppDomain. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="func"></param> + void SelectConstructor<T>(Expression<Func<T>> expression); } /// <summary> @@ -337,5 +346,16 @@ { action(new SetterConvention()); } + + /// <summary> + /// Use to programmatically select the constructor function of a concrete + /// class. Applies globally to all Containers in a single AppDomain. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="func"></param> + public void SelectConstructor<T>(Expression<Func<T>> expression) + { + PluginCache.GetPlugin(typeof(T)).UseConstructor(expression); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -19,6 +19,17 @@ { Matching(prop => prop.PropertyType == typeof (T)); } + + /// <summary> + /// Directs StructureMap to tread all public setters with + /// a PropertyType that matches the predicate as a + /// mandatory setter + /// </summary> + /// <param name="predicate"></param> + public void TypeMatches(Predicate<Type> predicate) + { + Matching(prop => predicate(prop.PropertyType)); + } /// <summary> /// Directs StructureMap to treat all public setters that match the Modified: trunk/Source/StructureMap/ConfigurationExpression.cs =================================================================== --- trunk/Source/StructureMap/ConfigurationExpression.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/ConfigurationExpression.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -86,16 +86,7 @@ return builder.Build(); } - /// <summary> - /// Use to programmatically select the constructor function of a concrete - /// class. Applies globally to all Containers in a single AppDomain. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="func"></param> - public void SelectConstructor<T>(Expression<Func<T>> expression) - { - PluginCache.GetPlugin(typeof (T)).UseConstructor(expression); - } + } Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -67,7 +67,7 @@ _writer.AddDivider('-'); var contents = new[] { - pluginType.PluginType.AssemblyQualifiedName ?? pluginType.PluginType.Name, + "{0} ({1})".ToFormat(pluginType.PluginType.GetName(), pluginType.PluginType.GetFullName()), string.Empty, string.Empty }; Modified: trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs =================================================================== --- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -5,7 +5,7 @@ public class FindAllTypesFilter : TypeRules, ITypeScanner { private readonly Type _pluginType; - private Func<Type, string> _getName = type => type.FullName; + private Func<Type, string> _getName = type => PluginCache.GetPlugin(type).ConcreteKey; public FindAllTypesFilter(Type pluginType) { Modified: trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Interceptors/CompoundInterceptor.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -17,12 +17,12 @@ #region InstanceInterceptor Members - public object Process(object target) + public object Process(object target, IContext context) { object returnValue = target; foreach (InstanceInterceptor interceptor in _interceptors) { - returnValue = interceptor.Process(returnValue); + returnValue = interceptor.Process(returnValue, context); } return returnValue; Modified: trunk/Source/StructureMap/Interceptors/EnrichmentInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/EnrichmentInterceptor.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Interceptors/EnrichmentInterceptor.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -1,20 +1,21 @@ namespace StructureMap.Interceptors { + // TODO -- gotta change to use IContext public class EnrichmentInterceptor<T> : InstanceInterceptor { - private readonly EnrichmentHandler<T> _handler; + private readonly ContextEnrichmentHandler<T> _handler; - public EnrichmentInterceptor(EnrichmentHandler<T> handler) + public EnrichmentInterceptor(ContextEnrichmentHandler<T> handler) { _handler = handler; } #region InstanceInterceptor Members - public object Process(object target) + public object Process(object target, IContext context) { - return _handler((T) target); + return _handler(context, (T) target); } #endregion Modified: trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -22,10 +22,10 @@ /// </summary> public class PluginTypeInterceptor : TypeInterceptor { - private readonly Func<object, object> _function; + private readonly Func<IContext, object, object> _function; private readonly Type _pluginType; - public PluginTypeInterceptor(Type pluginType, Func<object, object> function) + public PluginTypeInterceptor(Type pluginType, Func<IContext, object, object> function) { _pluginType = pluginType; _function = function; @@ -38,9 +38,9 @@ return TypeRules.CanBeCast(_pluginType, type); } - public object Process(object target) + public object Process(object target, IContext context) { - return _function(target); + return _function(context, target); } #endregion Modified: trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Interceptors/InstanceInterceptor.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -8,6 +8,6 @@ /// </summary> public interface InstanceInterceptor { - object Process(object target); + object Process(object target, IContext context); } } \ No newline at end of file Modified: trunk/Source/StructureMap/Interceptors/Interceptors.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/Interceptors.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Interceptors/Interceptors.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -1,4 +1,5 @@ namespace StructureMap.Interceptors { public delegate object EnrichmentHandler<T>(T target); + public delegate object ContextEnrichmentHandler<T>(IContext context, T target); } \ No newline at end of file Modified: trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Interceptors/MatchedTypeInterceptor.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -5,9 +5,9 @@ public class MatchedTypeInterceptor : TypeInterceptor { private readonly Predicate<Type> _match; - private Func<object, object> _interception; + private Func<IContext, object, object> _interception; - internal MatchedTypeInterceptor(Predicate<Type> match) + public MatchedTypeInterceptor(Predicate<Type> match) { _match = match; } @@ -19,16 +19,32 @@ return _match(type); } - public object Process(object target) + public object Process(object target, IContext context) { - return _interception(target); + return _interception(context, target); } #endregion + /// <summary> + /// Specify how objects matching the Type predicate + /// will be intercepted + /// </summary> + /// <param name="interception"></param> public void InterceptWith(Func<object, object> interception) { + _interception = (context, o) => interception(o); + } + + /// <summary> + /// Specify how objects matching the Type predicate + /// will be intercepted + /// </summary> + /// <param name="interception"></param> + public void InterceptWith(Func<IContext, object, object> interception) + { _interception = interception; } + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Interceptors/NulloInterceptor.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -4,7 +4,7 @@ { #region InstanceInterceptor Members - public object Process(object target) + public object Process(object target, IContext context) { return target; } Modified: trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs =================================================================== --- trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Interceptors/StartupInterceptor.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -4,18 +4,18 @@ { public class StartupInterceptor<T> : InstanceInterceptor { - private readonly Action<T> _handler; + private readonly Action<IContext, T> _handler; - public StartupInterceptor(Action<T> handler) + public StartupInterceptor(Action<IContext, T> handler) { _handler = handler; } #region InstanceInterceptor Members - public object Process(object target) + public object Process(object target, IContext context) { - _handler((T) target); + _handler(context, (T) target); return target; } Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -21,6 +21,21 @@ /// <returns></returns> public ConfiguredInstance OnCreation<TYPE>(Action<TYPE> handler) { + var interceptor = new StartupInterceptor<TYPE>((c, o) => handler(o)); + Interceptor = interceptor; + + return this; + } + + /// <summary> + /// Register an Action to perform on the object created by this Instance + /// before it is returned to the caller + /// </summary> + /// <typeparam name="TYPE"></typeparam> + /// <param name="handler"></param> + /// <returns></returns> + public ConfiguredInstance OnCreation<TYPE>(Action<IContext, TYPE> handler) + { var interceptor = new StartupInterceptor<TYPE>(handler); Interceptor = interceptor; @@ -35,6 +50,20 @@ /// <returns></returns> public ConfiguredInstance EnrichWith<TYPE>(EnrichmentHandler<TYPE> handler) { + var interceptor = new EnrichmentInterceptor<TYPE>((c, o) => handler(o)); + Interceptor = interceptor; + + return this; + } + + /// <summary> + /// Register a Func to potentially enrich or substitute for the object + /// created by this Instance before it is returned to the caller + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> + public ConfiguredInstance EnrichWith<TYPE>(ContextEnrichmentHandler<TYPE> handler) + { var interceptor = new EnrichmentInterceptor<TYPE>(handler); Interceptor = interceptor; Modified: trunk/Source/StructureMap/Pipeline/Instance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Instance.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Pipeline/Instance.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -106,7 +106,7 @@ // Allow the Interceptor a chance to enhance, configure, // wrap with a decorator, or even replace the rawValue - object finalValue = applyInterception(rawValue, pluginType); + object finalValue = applyInterception(rawValue, pluginType, session); markBuildStackFinish(session); @@ -172,12 +172,12 @@ } - private object applyInterception(object rawValue, Type pluginType) + private object applyInterception(object rawValue, Type pluginType, IContext context) { try { // Intercept with the Instance-specific InstanceInterceptor - return _interceptor.Process(rawValue); + return _interceptor.Process(rawValue, context); } catch (Exception e) { @@ -234,7 +234,7 @@ /// <returns></returns> public T OnCreation<TYPE>(Action<TYPE> handler) { - var interceptor = new StartupInterceptor<TYPE>(handler); + var interceptor = new StartupInterceptor<TYPE>((c, o) => handler(o)); Interceptor = interceptor; return thisInstance; @@ -249,6 +249,21 @@ /// <returns></returns> public T EnrichWith<TYPE>(EnrichmentHandler<TYPE> handler) { + var interceptor = new EnrichmentInterceptor<TYPE>((c, o) => handler(o)); + Interceptor = interceptor; + + return thisInstance; + } + + /// <summary> + /// Register a Func to potentially enrich or substitute for the object + /// created by this Instance before it is returned to the caller + /// </summary> + /// <typeparam name="TYPE"></typeparam> + /// <param name="handler"></param> + /// <returns></returns> + public T EnrichWith<TYPE>(ContextEnrichmentHandler<TYPE> handler) + { var interceptor = new EnrichmentInterceptor<TYPE>(handler); Interceptor = interceptor; Modified: trunk/Source/StructureMap/Pipeline/SmartInstance.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SmartInstance.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/Pipeline/SmartInstance.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -39,6 +39,21 @@ /// <returns></returns> public SmartInstance<T> OnCreation(Action<T> handler) { + var interceptor = new StartupInterceptor<T>((c, o) => handler(o)); + Interceptor = interceptor; + + return this; + } + + /// <summary> + /// Register an Action to perform on the object created by this Instance + /// before it is returned to the caller + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="handler"></param> + /// <returns></returns> + public SmartInstance<T> OnCreation(Action<IContext, T> handler) + { var interceptor = new StartupInterceptor<T>(handler); Interceptor = interceptor; @@ -53,7 +68,7 @@ /// <returns></returns> public SmartInstance<T> EnrichWith(EnrichmentHandler<T> handler) { - var interceptor = new EnrichmentInterceptor<T>(handler); + var interceptor = new EnrichmentInterceptor<T>((c, o) => handler(o)); Interceptor = interceptor; return this; @@ -67,6 +82,34 @@ /// <returns></returns> public SmartInstance<T> EnrichWith<PLUGINTYPE>(EnrichmentHandler<PLUGINTYPE> handler) { + var interceptor = new EnrichmentInterceptor<PLUGINTYPE>((c, o) => handler(o)); + Interceptor = interceptor; + + return this; + } + + /// <summary> + /// Register a Func to potentially enrich or substitute for the object + /// created by this Instance before it is returned to the caller + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> + public SmartInstance<T> EnrichWith(ContextEnrichmentHandler<T> handler) + { + var interceptor = new EnrichmentInterceptor<T>(handler); + Interceptor = interceptor; + + return this; + } + + /// <summary> + /// Register a Func to potentially enrich or substitute for the object + /// created by this Instance before it is returned to the caller + /// </summary> + /// <param name="handler"></param> + /// <returns></returns> + public SmartInstance<T> EnrichWith<PLUGINTYPE>(ContextEnrichmentHandler<PLUGINTYPE> handler) + { var interceptor = new EnrichmentInterceptor<PLUGINTYPE>(handler); Interceptor = interceptor; Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -103,8 +103,6 @@ /// </summary> public static void ResetAll() { - PluginCache.ResetAll(); - _sealed = false; _log = new GraphLog(); @@ -115,7 +113,6 @@ UseDefaultStructureMapConfigFile = false; IgnoreStructureMapConfig = false; - PluginCache.ResetAll(); ObjectFactory.Reset(); } Modified: trunk/Source/StructureMap/TypeExtensions.cs =================================================================== --- trunk/Source/StructureMap/TypeExtensions.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap/TypeExtensions.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -67,5 +67,29 @@ return null; } + public static string GetName(this Type type) + { + if (type.IsGenericType) + { + string[] parameters = Array.ConvertAll(type.GetGenericArguments(), t => t.GetName()); + var parameterList = string.Join(", ", parameters); + return "{0}<{1}>".ToFormat(type.Name, parameterList); + } + + return type.Name; + } + + public static string GetFullName(this Type type) + { + if (type.IsGenericType) + { + string[] parameters = Array.ConvertAll(type.GetGenericArguments(), t => t.GetName()); + var parameterList = string.Join(", ", parameters); + return "{0}<{1}>".ToFormat(type.Name, parameterList); + } + + return type.FullName; + } + } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptAllInstancesOfPluginTypeTester.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -1,6 +1,7 @@ using System; using NUnit.Framework; using StructureMap.Configuration.DSL; +using StructureMap.Interceptors; using StructureMap.Testing.Widget3; namespace StructureMap.Testing.Configuration.DSL @@ -79,12 +80,39 @@ } [Test] + public void custom_interceptor_for_all() + { + var interceptor = new MockInterceptor(); + IService service = getService("Green", r => + { + r.ForRequestedType<IService>().InterceptWith(interceptor) + .AddInstances(x => { x.ConstructedBy(() => new ColorService("Green")).WithName("Green"); }); + }); + + interceptor.Target.ShouldBeTheSameAs(service); + } + + public class MockInterceptor : InstanceInterceptor + { + public object Process(object target, IContext context) + { + Target = target; + return target; + } + + public object Target { get; set; } + } + + [Test] public void OnStartupForAll() { - Action<Registry> action = r => + Action<Registry> action = registry => { - r.ForRequestedType<IService>().OnCreation(s => _lastService = s) - .AddInstances(x => { x.ConstructedBy(() => new ColorService("Green")).WithName("Green"); }); + registry.ForRequestedType<IService>().OnCreation(s => _lastService = s) + .AddInstances(x => + { + x.ConstructedBy(() => new ColorService("Green")).WithName("Green"); + }); }; Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/InterceptorTesting.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -14,31 +14,50 @@ public void SetUp() { _lastService = null; + recorder = new ContextRecorder(); - _container = new Container(r => r.ForRequestedType<IService>().AddInstances(x => + _container = new Container(r => { - x.OfConcreteType<ColorService>() - .OnCreation(s => _lastService = s) - .WithName("Intercepted") - .WithCtorArg("color").EqualTo("Red"); + r.ForRequestedType<ContextRecorder>().TheDefault.IsThis(recorder); - x.OfConcreteType<ColorService>() - .WithName("NotIntercepted") - .WithCtorArg("color").EqualTo("Blue"); + r.ForRequestedType<IService>().AddInstances(x => + { + x.OfConcreteType<ColorService>() + .OnCreation(s => _lastService = s) + .WithName("Intercepted") + .WithCtorArg("color").EqualTo("Red"); - x.Object(new ColorService("Yellow")) - .WithName("Yellow") - .OnCreation<ColorService>(s => _lastService = s); + x.OfConcreteType<ColorService>() + .OnCreation((c, s) => c.GetInstance<ContextRecorder>().WasTouched = true) + .WithName("InterceptedWithContext") + .WithCtorArg("color").EqualTo("Red"); - x.ConstructedBy(() => new ColorService("Purple")).WithName("Purple") - .EnrichWith<IService>(s => new DecoratorService(s)); + x.OfConcreteType<ColorService>() + .WithName("NotIntercepted") + .WithCtorArg("color").EqualTo("Blue"); - x.OfConcreteType<ColorService>().WithName("Decorated").EnrichWith<IService>(s => new DecoratorService(s)) - .WithCtorArg("color").EqualTo("Orange"); + x.Object(new ColorService("Yellow")) + .WithName("Yellow") + .OnCreation<ColorService>(s => _lastService = s); - x.Object(new ColorService("Yellow")).WithName("Bad") - .OnCreation<ColorService>(obj => { throw new ApplicationException("Bad!"); }); - })); + x.ConstructedBy(() => new ColorService("Purple")).WithName("Purple") + .EnrichWith<IService>(s => new DecoratorService(s)); + + x.ConstructedBy(() => new ColorService("Purple")).WithName("DecoratedWithContext") + .EnrichWith<IService>((c, s) => + { + c.GetInstance<ContextRecorder>().WasTouched = true; + return new DecoratorService(s); + }); + + x.OfConcreteType<ColorService>().WithName("Decorated").EnrichWith<IService>( + s => new DecoratorService(s)) + .WithCtorArg("color").EqualTo("Orange"); + + x.Object(new ColorService("Yellow")).WithName("Bad") + .OnCreation<ColorService>(obj => { throw new ApplicationException("Bad!"); }); + }); + }); } #endregion @@ -46,8 +65,23 @@ private ColorService _lastService; private IContainer _container; + private ContextRecorder recorder; [Test] + public void call_the_build_context_with_startup() + { + _container.GetInstance<IService>("InterceptedWithContext"); + recorder.WasTouched.ShouldBeTrue(); + } + + [Test] + public void call_the_build_context_with_enrich() + { + _container.GetInstance<IService>("DecoratedWithContext"); + recorder.WasTouched.ShouldBeTrue(); + } + + [Test] public void DecorateAConstructedService() { var service = _container.GetInstance<IService>("Purple"); @@ -120,4 +154,9 @@ get { return _inner; } } } + + public class ContextRecorder + { + public bool WasTouched { get; set; } + } } \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Examples/Interception.cs =================================================================== --- trunk/Source/StructureMap.Testing/Examples/Interception.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Examples/Interception.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -0,0 +1,203 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices.ComTypes; +using System.Text; +using NUnit.Framework; +using StructureMap.Configuration.DSL; +using StructureMap.Interceptors; +using StructureMap; + +namespace StructureMap.Testing.Examples +{ + public interface IConnectionListener + { + void StartConnection(); + } + + public class ClassThatNeedsSomeBootstrapping : IConnectionListener + { + public void Start() + { + + } + + public void Connect(IConnectionPoint connection) + { + + } + + public void StartConnection() + { + throw new NotImplementedException(); + } + } + + public class LoggingDecorator : IConnectionListener + { + private readonly IConnectionListener _inner; + + public LoggingDecorator(IConnectionListener inner) + { + _inner = inner; + } + + public IConnectionListener Inner + { + get { return _inner; } + } + + public void StartConnection() + { + + } + } + + public class InterceptionRegistry : Registry + { + public InterceptionRegistry() + { + // Perform an Action<T> upon the object of type T + // just created before it is returned to the caller + ForRequestedType<ClassThatNeedsSomeBootstrapping>().TheDefault.Is + .OfConcreteType<ClassThatNeedsSomeBootstrapping>() + .OnCreation(x => x.Start()); + + // or... + + // You can also register an Action<IContext, T> to get access + // to all the services and capabilities of the BuildSession + ForRequestedType<ClassThatNeedsSomeBootstrapping>().TheDefault.Is + .OfConcreteType<ClassThatNeedsSomeBootstrapping>() + .OnCreation((context, x) => + { + var connection = context.GetInstance<IConnectionPoint>(); + x.Connect(connection); + }); + + + ForRequestedType<IConnectionListener>().TheDefault.Is + .OfConcreteType<ClassThatNeedsSomeBootstrapping>() + .EnrichWith(x => new LoggingDecorator(x)); + + ForRequestedType<IConnectionListener>().TheDefault.Is + .OfConcreteType<ClassThatNeedsSomeBootstrapping>() + .EnrichWith((context, x) => + { + var connection = context.GetInstance<IConnectionPoint>(); + x.Connect(connection); + + return new LoggingDecorator(x); + }); + + + ForRequestedType<IConnectionListener>().TheDefault.Is + .OfConcreteType<ClassThatNeedsSomeBootstrapping>() + .InterceptWith(new CustomInterceptor()); + + + + // Place the Interception at the PluginType level + ForRequestedType<IConnectionListener>() + .OnCreation(x => x.StartConnection()) // OnCreation + .EnrichWith(x => new LoggingDecorator(x)) // Enrich + .InterceptWith(new CustomInterceptor()) // Custom Interceptor + + + .TheDefaultIsConcreteType<ClassThatNeedsSomeBootstrapping>(); + + } + } + + [TestFixture, Explicit] + public class InterceptionRegistryInAction + { + [Test] + public void see_the_enrichment_with_a_decorator_in_action() + { + var container = new Container(new InterceptionRegistry()); + container.GetInstance<IConnectionListener>() + .ShouldBeOfType<LoggingDecorator>() + .Inner.ShouldBeOfType<ClassThatNeedsSomeBootstrapping>(); + } + } + + public class CustomInterceptor : InstanceInterceptor + { + public object Process(object target, IContext context) + { + // manipulate the target object and return a wrapped version + return wrapTarget(target); + } + + private object wrapTarget(object target) + { + throw new NotImplementedException(); + } + } + + + + + public interface IEventListener<T> + { + void ProcessEvent(T @event); + } + + public interface IEventAggregator + { + void RegisterListener<T>(IEventListener<T> listener); + void PublishEvent<T>(T @event); + } + + + + public class ListenerInterceptor : TypeInterceptor + { + public object Process(object target, IContext context) + { + // Assuming that "target" is an implementation of IEventListener<T>, + // we'll do a little bit of generics sleight of hand + // to register "target" with IEventAggregator + var eventType = target.GetType().FindInterfaceThatCloses(typeof (IEventListener<>)).GetGenericArguments()[0]; + var type = typeof (Registration<>).MakeGenericType(eventType); + Registration registration = (Registration) Activator.CreateInstance(type); + registration.RegisterListener(context, target); + + // we didn't change the target object, so just return it + return target; + } + + public bool MatchesType(Type type) + { + // ImplementsInterfaceTemplate is an Extension method in the + // StructureMap namespace that basically says: + // does this type implement any closed type of the open template type? + return type.ImplementsInterfaceTemplate(typeof (IEventListener<>)); + } + + // The inner type and interface is just a little trick to + // grease the generic wheels + public interface Registration + { + void RegisterListener(IContext context, object listener); + } + + public class Registration<T> : Registration + { + public void RegisterListener(IContext context, object listener) + { + var aggregator = context.GetInstance<IEventAggregator>(); + aggregator.RegisterListener<T>((IEventListener<T>) listener); + } + } + } + + public class ListeningRegistry : Registry + { + public ListeningRegistry() + { + RegisterInterceptor(new ListenerInterceptor()); + } + } +} Modified: trunk/Source/StructureMap.Testing/Graph/ConventionBasedSetterInjectionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ConventionBasedSetterInjectionTester.cs 2009-01-08 13:28:57 UTC (rev 217) +++ trunk/Source/StructureMap.Testing/Graph/ConventionBasedSetterInjectionTester.cs 2009-01-11 21:16:13 UTC (rev 218) @@ -88,6 +88,27 @@ } [Test] + public void fill_all_properties_of_types_in_namespace_by_generic() + { + + var container = new Container(x => + { + x.SetAllProperties(policy => + { + policy.WithAnyTypeFromNamespaceContainingType<IService>(); + }); + }); + + var plugin = PluginCache.GetPlugin(typeof(ClassWithNamedProperties)); + + plugin.Setters.IsMandatory("Age").ShouldBeFalse(); + plugin.Setters.IsMandatory("FirstName").ShouldBeFalse(); + plugin.Setters.IsMandatory("LastName").ShouldBeFalse(); + plugin.Setters.IsMandatory("Gateway").ShouldBeTrue(); + plugin.Setters.IsMandatory("Service").ShouldBeTrue(); + } + + [Test] public void specify_setter_policy_and_construct_an_object() { var theService = new ColorService("red"); @@ -108,7 +129,30 @@ target.Gateway.ShouldBeOfType<DefaultGateway>(); } + [Test] + public void specify_setter_policy_by_a_predicate_on_property_type() + { + var theService = new ColorService("red"); + var container = new Container(x => + { + x.ForRequestedType<IService>().TheDefault.Is.Object(theService); + x.ForRequestedType<IGateway>().TheDefaultIsConcreteType<DefaultGateway>(); + + x.SetAllProperties(policy => + { + policy.TypeMatches(type => type == typeof (IService)); + }); + }); + + var target = container.GetInstance<ClassWithNamedProperties>(); + target.Service.ShouldBeTheSameAs(theService); + target.Gateway.ShouldBeNull(); + + + } + + public class ClassWithNamedProperties { public int Age { get; set; } Modified: trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs =================================================================== ---... [truncated message content] |
From: <jer...@us...> - 2009-01-11 22:43:15
|
Revision: 219 http://structuremap.svn.sourceforge.net/structuremap/?rev=219&view=rev Author: jeremydmiller Date: 2009-01-11 22:43:11 +0000 (Sun, 11 Jan 2009) Log Message: ----------- adding TryGet****** to IContext/BuildSession Modified Paths: -------------- trunk/Source/HTML/ConstructorAndSetterInjection.htm trunk/Source/HTML/UsingSessionContext.htm trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/BuildUpIntegratedTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Examples/BuildUp.cs Modified: trunk/Source/HTML/ConstructorAndSetterInjection.htm =================================================================== --- trunk/Source/HTML/ConstructorAndSetterInjection.htm 2009-01-11 21:16:13 UTC (rev 218) +++ trunk/Source/HTML/ConstructorAndSetterInjection.htm 2009-01-11 22:43:11 UTC (rev 219) @@ -61,7 +61,8 @@ <!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;}??\fs20 \cf3 public\cf0 GreaterThanRule()\par ?? \{\par ?? \}\par ??\par ?? \cf3 public\cf0 GreaterThanRule(\cf3 string\cf0 Attribute, \cf3 int\cf0 Value)\par ?? \{\par ?? _Attribute = Attribute;\par ?? _Value = Value;\par ?? \}} --> - <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;" + class="code-sample"> <p style="margin: 0px;"> <span style="color: blue;">public</span> GreaterThanRule()</p> @@ -107,7 +108,8 @@ <!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;}??\fs20 [\cf3 DefaultConstructor\cf0 ]\par ?? \cf4 public\cf0 DataSession(\cf3 IDatabaseEngine\cf0 database)\par ?? : \cf4 this\cf0 (database,\par ?? \cf4 new\cf0 \cf3 CommandFactory\cf0 (database),\par ?? \cf4 new\cf0 \cf3 AutoCommitExecutionState\cf0 (database.GetConnection(), database.GetDataAdapter()),\par ?? \cf4 new\cf0 \cf3 TransactionalExecutionState\cf0 (database.GetConnection(), database.GetDataAdapter()))\par ?? \{\par ?? \}} --> - <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;"> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white;" + class="code-sample"> <p style="margin: 0px;"> [<span style="color: #2b91af;">DefaultConstructor</span>]</p> <p style="margin: 0px;"> @@ -386,7 +388,7 @@ <span style="color: #2b91af;">Rule</span>[] Rules { <span style="color: blue;"> get</span>; <span style="color: blue;">set</span>; }</p> <p style="margin: 0px;"> -& }</p> + }</p> </div> <!--EndFragment--> <p>I can explicitly configure what gets injected into the "Rule" property for a @@ -555,8 +557,192 @@ <hr /> <h2>Applying Setter Injection to an Existing Object (BuildUp)</h2> - <p>asdf</p> - <hr /> + <p>Many times you simply cannot control when an object is going to be created + (ASP.Net WebForms), but you may still want to inject dependencies and even + primitive values into an already constructed object. To fill this gap, + StructureMap 2.5.2+ introduces the "BuildUp()" method on Container and + ObjectFactory. BuildUp() works by finding the default Instance for the + concrete type passed into the BuildUp() method (or create a new Instance if one + does not already exist), then applying any setters from that Instance + configuration. At this time, StructureMap does not apply interception + inside of BuildUp().</p> + <p>Let's say that we have a class called "BuildTarget1" like + this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 BuildUpTarget1\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf4 IGateway\cf0 Gateway \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \cf3 public\cf0 \cf4 IService\cf0 Service \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">BuildUpTarget1</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: #2b91af;">IGateway</span> Gateway { + <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> + }</div> +<p>In usage, we'd like to have the Gateway dependency injected into a new instance of the BuildTarget1 class when we call BuildUp():</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red43\green145\blue175;\red0\green0\blue255;\red0\green128\blue0;}??\fs20 [\cf3 Test\cf0 ]\par ?? \cf4 public\cf0 \cf4 void\cf0 create_a_setter_rule_and_see_it_applied_in_BuildUp_through_ObjectFactory()\par ?? \{\par ?? \cf4 var\cf0 theGateway = \cf4 new\cf0 \cf3 DefaultGateway\cf0 ();\par ?? \cf3 ObjectFactory\cf0 .Initialize(x =>\par ?? \{\par ?? x.IgnoreStructureMapConfig = \cf4 true\cf0 ;\par ?? x.ForRequestedType<\cf3 IGateway\cf0 >().TheDefault.IsThis(theGateway);\par ?? \par ?? \cf5 // First we create a new Setter Injection Policy that\par ??\cf0 \cf5 // forces StructureMap to inject all public properties\par ??\cf0 \cf5 // where the PropertyType is IGateway\par ??\cf0 x.SetAllProperties(y =>\par ?? \{\par ?? y.OfType<\cf3 IGateway\cf0 >();\par ?? \});\par ?? \});\par ??\par ?? \cf5 // Create an instance of BuildUpTarget1\par ??\cf0 \cf4 var\cf0 target = \cf4 new\cf0 \cf3 BuildUpTarget1\cf0 ();\par ??\par ?? \cf5 // Now, call BuildUp() on target, and\par ??\cf0 \cf5 // we should see the Gateway property assigned\par ??\cf0 \cf3 ObjectFactory\cf0 .BuildUp(target);\par ??\par ?? target.Gateway.ShouldBeTheSameAs(theGateway);\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Test</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> + create_a_setter_rule_and_see_it_applied_in_BuildUp_through_ObjectFactory()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> theGateway = <span style="color: blue;">new</span> + <span style="color: #2b91af;">DefaultGateway</span>();</p> + <p style="margin: 0px;"> + <span style="color: #2b91af;"> + ObjectFactory</span>.Initialize(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.ForRequestedType<<span style="color: #2b91af;">IGateway</span>>().TheDefault.IsThis(theGateway);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + <span style="color: green;">// First we create a new Setter Injection Policy + that</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// forces StructureMap to inject all public + properties</span></p> + <p style="margin: 0px;"> + + <span style="color: green;">// where the PropertyType is IGateway</span></p> + <p style="margin: 0px;"> + + x.SetAllProperties(y =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + y.OfType<<span style="color: #2b91af;">IGateway</span>>();</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;"> + // Create an instance of BuildUpTarget1</span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> target = <span style="color: blue;">new</span> + <span style="color: #2b91af;">BuildUpTarget1</span>();</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: green;"> + // Now, call BuildUp() on target, and</span></p> + <p style="margin: 0px;"> + <span style="color: green;"> + // we should see the Gateway property assigned</span></p> + <p style="margin: 0px;"> + <span style="color: #2b91af;"> + ObjectFactory</span>.BuildUp(target);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + target.Gateway.ShouldBeTheSameAs(theGateway);</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<p>BuildUp() also works with primitive properties (but I'm not sure how useful this + will really be):</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red0\green128\blue0;\red163\green21\blue21;}??\fs20 \cf3 public\cf0 \cf3 class\cf0 \cf4 ClassThatHasConnection\par ??\cf0 \{\par ?? \cf3 public\cf0 \cf3 string\cf0 ConnectionString \{ \cf3 get\cf0 ; \cf3 set\cf0 ; \}\par ?? \}\par ??\par ?? [\cf4 TestFixture\cf0 ]\par ?? \cf3 public\cf0 \cf3 class\cf0 \cf4 demo_the_BuildUp\par ??\cf0 \{\par ?? [\cf4 Test\cf0 ]\par ?? \cf3 public\cf0 \cf3 void\cf0 push_in_a_string_property()\par ?? \{\par ?? \cf5 // There is a limitation to this. As of StructureMap 2.5.2,\par ??\cf0 \cf5 // you can only use the .WithProperty().EqualTo() syntax\par ??\cf0 \cf5 // for BuildUp()\par ??\cf0 \cf5 // SetProperty() will not work at this time.\par ??\cf0 \cf3 var\cf0 container = \cf3 new\cf0 \cf4 Container\cf0 (x =>\par ?? \{\par ?? x.ForConcreteType<\cf4 ClassThatHasConnection\cf0 >().Configure\par ?? .WithProperty(o => o.ConnectionString).EqualTo(\cf6 "connect1"\cf0 );\par ??\par ?? \});\par ??\par ?? \cf3 var\cf0 @class = \cf3 new\cf0 \cf4 ClassThatHasConnection\cf0 ();\par ?? container.BuildUp(@class);\par ??\par ?? @class.ConnectionString.ShouldEqual(\cf6 "connect1"\cf0 );\par ?? \}\par ?? \}} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">ClassThatHasConnection</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">string</span> ConnectionString { + <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">TestFixture</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> <span style="color: blue;">class</span> + <span style="color: #2b91af;">demo_the_BuildUp</span></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + [<span style="color: #2b91af;">Test</span>]</p> + <p style="margin: 0px;"> + <span style="color: blue;">public</span> + <span style="color: blue;">void</span> push_in_a_string_property()</p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + <span style="color: green;"> + // There is a limitation to this. As of StructureMap 2.5.2,</span></p> + <p style="margin: 0px;"> + <span style="color: green;"> + // you can only use the .WithProperty().EqualTo() syntax</span></p> + <p style="margin: 0px;"> + <span style="color: green;"> + // for BuildUp()</span></p> + <p style="margin: 0px;"> + <span style="color: green;"> + // SetProperty() will not work at this time.</span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> container = <span style="color: blue;">new</span> + <span style="color: #2b91af;">Container</span>(x =></p> + <p style="margin: 0px;"> + {</p> + <p style="margin: 0px;"> + + x.ForConcreteType<<span style="color: #2b91af;">ClassThatHasConnection</span>>().Configure</p> + <p style="margin: 0px;"> + + .WithProperty(o => o.ConnectionString).EqualTo(<span style="color: #a31515;">"connect1"</span>);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + });</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: blue;"> + var</span> @class = <span style="color: blue;">new</span> + <span style="color: #2b91af;">ClassThatHasConnection</span>();</p> + <p style="margin: 0px;"> + container.BuildUp(@class);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + + @class.ConnectionString.ShouldEqual(<span style="color: #a31515;">"connect1"</span>);</p> + <p style="margin: 0px;"> + }</p> + <p style="margin: 0px;"> + }</p> + </div> +<!--EndFragment--> +<hr /> <h2><a name="SetterPolicies"></a>Creating Policies for Setter Injection</h2> <p>New in StructureMap 2.5.2+ is the ability to create setter injection policies. What this means is that you create conventions to define which public setter Modified: trunk/Source/HTML/UsingSessionContext.htm =================================================================== --- trunk/Source/HTML/UsingSessionContext.htm 2009-01-11 21:16:13 UTC (rev 218) +++ trunk/Source/HTML/UsingSessionContext.htm 2009-01-11 22:43:11 UTC (rev 219) @@ -15,7 +15,7 @@ dependencies that will be used within that object request. The IContext interface is shown below:</p> <!-- -{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IContext\par ??\cf0 \{\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Gets a reference to the \cf5 <see cref="BuildStack">\cf6 BuildStack\cf5 </see>\cf6 for this build session\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 BuildStack\cf0 BuildStack \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 The concrete type of the immediate parent object in the object graph\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 Type\cf0 ParentType \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Get the object of type T that is valid for this build session.\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <typeparam name="T"></typeparam>\par ??\cf0 \cf5 ///\cf6 \cf5 <returns></returns>\par ??\cf0 T GetInstance<T>();\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Gets the root "frame" of the object request\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 BuildFrame\cf0 Root \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 The requested instance name of the object graph\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf3 string\cf0 RequestedName \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Register a default object for the given PluginType that will\par ??\cf0 \cf5 ///\cf6 be used throughout the rest of the current object request\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <param name="pluginType"></param>\par ??\cf0 \cf5 ///\cf6 \cf5 <param name="defaultObject"></param>\par ??\cf0 \cf3 void\cf0 RegisterDefault(\cf4 Type\cf0 pluginType, \cf3 object\cf0 defaultObject);\par ?? \}} +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IContext\par ??\cf0 \{\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Gets a reference to the \cf5 <see cref="BuildStack">\cf6 BuildStack\cf5 </see>\cf6 for this build session\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 BuildStack\cf0 BuildStack \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 The concrete type of the immediate parent object in the object graph\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 Type\cf0 ParentType \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Get the object of type T that is valid for this build session.\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <typeparam name="T"></typeparam>\par ??\cf0 \cf5 ///\cf6 \cf5 <returns></returns>\par ??\cf0 T GetInstance<T>();\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Get the object of type T that is valid for this build session by name.\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <typeparam name="T"></typeparam>\par ??\cf0 \cf5 ///\cf6 \cf5 <returns></returns>\par ??\cf0 T GetInstance<T>(\cf3 string\cf0 name);\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Gets the root "frame" of the object request\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 BuildFrame\cf0 Root \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 The requested instance name of the object graph\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf3 string\cf0 RequestedName \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Register a default object for the given PluginType that will\par ??\cf0 \cf5 ///\cf6 be used throughout the rest of the current object request\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <param name="pluginType"></param>\par ??\cf0 \cf5 ///\cf6 \cf5 <param name="defaultObject"></param>\par ??\cf0 \cf3 void\cf0 RegisterDefault(\cf4 Type\cf0 pluginType, \cf3 object\cf0 defaultObject);\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Same as GetInstance, but can gracefully return null if \par ??\cf0 \cf5 ///\cf6 the Type does not already exist\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <typeparam name="T"></typeparam>\par ??\cf0 \cf5 ///\cf6 \cf5 <returns></returns>\par ??\cf0 T TryGetInstance<T>() \cf3 where\cf0 T : \cf3 class\cf0 ;\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Same as GetInstance(name), but can gracefully return null if \par ??\cf0 \cf5 ///\cf6 the Type and name does not already exist\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <typeparam name="T"></typeparam>\par ??\cf0 \cf5 ///\cf6 \cf5 <param name="name"></param>\par ??\cf0 \cf5 ///\cf6 \cf5 <returns></returns>\par ??\cf0 T TryGetInstance<T>(\cf3 string\cf0 name) \cf3 where\cf0 T : \cf3 class\cf0 ;\par ?? \}} --> <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> <p style="margin: 0px;"> @@ -81,6 +81,28 @@ style="color: green;"> </span><span style="color: gray;"><summary></span></p> <p style="margin: 0px;"> <span style="color: gray;">///</span><span + style="color: green;"> Get the object of type T that is valid for this build + session by name.</span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"></summary></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><typeparam + name="T"></typeparam></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><returns></returns></span></p> + <p style="margin: 0px;"> + T GetInstance<T>(<span style="color: blue;">string</span> + name);</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><summary></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span style="color: green;"> Gets the root "frame" of the object request</span></p> <p style="margin: 0px;"> <span style="color: gray;">///</span><span @@ -131,10 +153,71 @@ RegisterDefault(<span style="color: #2b91af;">Type</span> pluginType, <span style="color: blue;">object</span> defaultObject);</p> <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><summary></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> Same as GetInstance, but can gracefully return null + if </span> + </p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> the Type does not already exist</span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"></summary></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><typeparam + name="T"></typeparam></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><returns></returns></span></p> + <p style="margin: 0px;"> + T TryGetInstance<T>() <span style="color: blue;"> + where</span> T : <span style="color: blue;">class</span>;</p> + <p style="margin: 0px;"> + </p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><summary></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> Same as GetInstance(name), but can gracefully return + null if </span> + </p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> the Type and name does not already exist</span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"></summary></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><typeparam + name="T"></typeparam></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><param + name="name"></param></span></p> + <p style="margin: 0px;"> + <span style="color: gray;">///</span><span + style="color: green;"> </span><span style="color: gray;"><returns></returns></span></p> + <p style="margin: 0px;"> + T TryGetInstance<T>(<span style="color: blue;">string</span> + name) <span style="color: blue;">where</span> T : <span style="color: blue;"> + class</span>;</p> + <p style="margin: 0px;"> }</p> </div> <!--EndFragment--> <!-- +{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IContext\par ??\cf0 \{\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Gets a reference to the \cf5 <see cref="BuildStack">\cf6 BuildStack\cf5 </see>\cf6 for this build session\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 BuildStack\cf0 BuildStack \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 The concrete type of the immediate parent object in the object graph\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 Type\cf0 ParentType \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Get the object of type T that is valid for this build session.\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <typeparam name="T"></typeparam>\par ??\cf0 \cf5 ///\cf6 \cf5 <returns></returns>\par ??\cf0 T GetInstance<T>();\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Gets the root "frame" of the object request\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 BuildFrame\cf0 Root \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 The requested instance name of the object graph\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf3 string\cf0 RequestedName \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Register a default object for the given PluginType that will\par ??\cf0 \cf5 ///\cf6 be used throughout the rest of the current object request\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <param name="pluginType"></param>\par ??\cf0 \cf5 ///\cf6 \cf5 <param name="defaultObject"></param>\par ??\cf0 \cf3 void\cf0 RegisterDefault(\cf4 Type\cf0 pluginType, \cf3 object\cf0 defaultObject);\par ?? \}} +--> +<!--EndFragment--> +<!-- {\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue255;\red43\green145\blue175;\red128\green128\blue128;\red0\green128\blue0;}??\fs20 \cf3 public\cf0 \cf3 interface\cf0 \cf4 IContext\par ??\cf0 \{\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Gets a reference to the \cf5 <see cref="BuildStack">\cf6 BuildStack\cf5 </see>\cf6 for this build session\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 BuildStack\cf0 BuildStack \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 The concrete type of the immediate parent object in the object graph\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 Type\cf0 ParentType \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Get the object of type T that is valid for this build session.\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf5 ///\cf6 \cf5 <typeparam name="T"></typeparam>\par ??\cf0 \cf5 ///\cf6 \cf5 <returns></returns>\par ??\cf0 T GetInstance<T>();\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 Gets the root "frame" of the object request\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf4 BuildFrame\cf0 Root \{ \cf3 get\cf0 ; \}\par ??\par ?? \cf5 ///\cf6 \cf5 <summary>\par ??\cf0 \cf5 ///\cf6 The requested instance name of the object graph\par ??\cf0 \cf5 ///\cf6 \cf5 </summary>\par ??\cf0 \cf3 string\cf0 RequestedName \{ \cf3 get\cf0 ; \}\par ?? \}} --> <!--EndFragment--> Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2009-01-11 21:16:13 UTC (rev 218) +++ trunk/Source/StructureMap/BuildSession.cs 2009-01-11 22:43:11 UTC (rev 219) @@ -27,6 +27,13 @@ T GetInstance<T>(); /// <summary> + /// Get the object of type T that is valid for this build session by name. + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + T GetInstance<T>(string name); + + /// <summary> /// Gets the root "frame" of the object request /// </summary> BuildFrame Root { get; } @@ -43,6 +50,23 @@ /// <param name="pluginType"></param> /// <param name="defaultObject"></param> void RegisterDefault(Type pluginType, object defaultObject); + + /// <summary> + /// Same as GetInstance, but can gracefully return null if + /// the Type does not already exist + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + T TryGetInstance<T>() where T : class; + + /// <summary> + /// Same as GetInstance(name), but can gracefully return null if + /// the Type and name does not already exist + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="name"></param> + /// <returns></returns> + T TryGetInstance<T>(string name) where T : class; } public class BuildSession : IContext @@ -105,6 +129,11 @@ return (T) CreateInstance(typeof (T)); } + public T GetInstance<T>(string name) + { + return (T) CreateInstance(typeof (T), name); + } + BuildFrame IContext.Root { get { return _buildStack.Root; } @@ -182,7 +211,24 @@ _defaults[pluginType] = defaultObject; } + public T TryGetInstance<T>() where T : class + { + if (_defaults.Has(typeof(T))) + { + return (T) _defaults[typeof (T)]; + } + return _pipelineGraph.HasDefaultForPluginType(typeof (T)) + ? ((IContext) this).GetInstance<T>() + : null; + } + + public T TryGetInstance<T>(string name) where T : class + { + return _pipelineGraph.HasInstance(typeof (T), name) ? ((IContext) this).GetInstance<T>(name) : null; + } + + private IInstanceFactory forType(Type pluginType) { return _pipelineGraph.ForType(pluginType); Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2009-01-11 21:16:13 UTC (rev 218) +++ trunk/Source/StructureMap/Container.cs 2009-01-11 22:43:11 UTC (rev 219) @@ -228,7 +228,7 @@ /// <returns></returns> public object TryGetInstance(Type pluginType, string instanceKey) { - return _pipelineGraph.ForType(pluginType).FindInstance(instanceKey) == null + return !_pipelineGraph.HasInstance(pluginType, instanceKey) ? null : GetInstance(pluginType, instanceKey); } @@ -240,7 +240,7 @@ /// <returns></returns> public object TryGetInstance(Type pluginType) { - return !_pipelineGraph.PluginTypes.Any(p => p.PluginType == pluginType) + return !_pipelineGraph.HasDefaultForPluginType(pluginType) ? null : GetInstance(pluginType); } Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2009-01-11 21:16:13 UTC (rev 218) +++ trunk/Source/StructureMap/PipelineGraph.cs 2009-01-11 22:43:11 UTC (rev 219) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Pipeline; @@ -206,5 +207,16 @@ return list; } + + public bool HasDefaultForPluginType(Type pluginType) + { + PluginTypeConfiguration configuration = PluginTypes.FirstOrDefault(p => p.PluginType == pluginType); + return configuration == null ? false : configuration.Default != null; + } + + public bool HasInstance(Type pluginType, string instanceKey) + { + return ForType(pluginType).FindInstance(instanceKey) != null; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2009-01-11 21:16:13 UTC (rev 218) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2009-01-11 22:43:11 UTC (rev 219) @@ -187,6 +187,61 @@ session.CreateInstance(typeof (IGateway)); }); } + + [Test] + public void when_retrieving_with_try_get_instance_for_instance_that_does_not_exists() + { + var session = new BuildSession(new PluginGraph()); + session.TryGetInstance<IService>().ShouldBeNull(); + } + + [Test] + public void when_retrieving_by_try_get_instance_for_instance_that_does_exist() + { + var session = new BuildSession(); + var theService = new ColorService("red"); + session.RegisterDefault(typeof(IService), theService); + + session.TryGetInstance<IService>().ShouldBeTheSameAs(theService); + } + + [Test] + public void when_retrieving_by_try_get_named_instance_that_does_not_exist() + { + var session = new BuildSession(); + session.TryGetInstance<IService>("red").ShouldBeNull(); + } + + [Test] + public void when_retrieving_by_try_get_named_instance_that_does_exist() + { + var red = new ColorService("red"); + var green = new ColorService("green"); + + PluginGraph graph = new PluginGraph(); + PluginFamily family = graph.FindFamily(typeof(IService)); + family.AddInstance(new LiteralInstance(red).WithName("red")); + family.AddInstance(new LiteralInstance(green).WithName("green")); + + var session = new BuildSession(graph); + session.TryGetInstance<IService>("red").ShouldBeTheSameAs(red); + session.TryGetInstance<IService>("green").ShouldBeTheSameAs(green); + } + + [Test] + public void when_retrieving_an_object_by_name() + { + var red = new ColorService("red"); + var green = new ColorService("green"); + + PluginGraph graph = new PluginGraph(); + PluginFamily family = graph.FindFamily(typeof(IService)); + family.AddInstance(new LiteralInstance(red).WithName("red")); + family.AddInstance(new LiteralInstance(green).WithName("green")); + + var session = new BuildSession(graph); + session.GetInstance<IService>("red").ShouldBeTheSameAs(red); + } } public interface IClassWithRule Modified: trunk/Source/StructureMap.Testing/BuildUpIntegratedTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildUpIntegratedTester.cs 2009-01-11 21:16:13 UTC (rev 218) +++ trunk/Source/StructureMap.Testing/BuildUpIntegratedTester.cs 2009-01-11 22:43:11 UTC (rev 219) @@ -57,13 +57,21 @@ { x.IgnoreStructureMapConfig = true; x.ForRequestedType<IGateway>().TheDefault.IsThis(theGateway); + + // First we create a new Setter Injection Policy that + // forces StructureMap to inject all public properties + // where the PropertyType is IGateway x.SetAllProperties(y => { y.OfType<IGateway>(); }); }); + // Create an instance of BuildUpTarget1 var target = new BuildUpTarget1(); + + // Now, call BuildUp() on target, and + // we should see the Gateway property assigned ObjectFactory.BuildUp(target); target.Gateway.ShouldBeTheSameAs(theGateway); Added: trunk/Source/StructureMap.Testing/Examples/BuildUp.cs =================================================================== --- trunk/Source/StructureMap.Testing/Examples/BuildUp.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Examples/BuildUp.cs 2009-01-11 22:43:11 UTC (rev 219) @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; + +namespace StructureMap.Testing.Examples +{ + public class ClassThatHasConnection + { + public string ConnectionString { get; set; } + } + + [TestFixture] + public class demo_the_BuildUp + { + [Test] + public void push_in_a_string_property() + { + // There is a limitation to this. As of StructureMap 2.5.2, + // you can only use the .WithProperty().EqualTo() syntax + // for BuildUp() + // SetProperty() will not work at this time. + var container = new Container(x => + { + x.ForConcreteType<ClassThatHasConnection>().Configure + .WithProperty(o => o.ConnectionString).EqualTo("connect1"); + + }); + + var @class = new ClassThatHasConnection(); + container.BuildUp(@class); + + @class.ConnectionString.ShouldEqual("connect1"); + } + } +} Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-01-11 21:16:13 UTC (rev 218) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-01-11 22:43:11 UTC (rev 219) @@ -222,6 +222,7 @@ <Compile Include="Examples.cs"> <SubType>Form</SubType> </Compile> + <Compile Include="Examples\BuildUp.cs" /> <Compile Include="Examples\CustomInstance.cs" /> <Compile Include="Examples\Interception.cs" /> <Compile Include="Examples\RegisteringWithTheAPI.cs" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2009-01-31 20:03:26
|
Revision: 228 http://structuremap.svn.sourceforge.net/structuremap/?rev=228&view=rev Author: jeremydmiller Date: 2009-01-31 20:03:15 +0000 (Sat, 31 Jan 2009) Log Message: ----------- beginning of the Prism bootstrapper, some work for diagnostics "pretty-ifying" Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs trunk/Source/StructureMap/Graph/Constructor.cs trunk/Source/StructureMap/Pipeline/BuildPolicy.cs trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs trunk/Source/StructureMap/TypeExtensions.cs trunk/Source/StructureMap.sln Added Paths: ----------- trunk/Source/StructureMap.Prism/ trunk/Source/StructureMap.Prism/DefaultRegistry.cs trunk/Source/StructureMap.Prism/PrismBootstrapper.cs trunk/Source/StructureMap.Prism/StructureMapContainerFacade.cs trunk/Source/StructureMap.Prism/structuremap.snk trunk/Source/StructureMap.Testing.Prism/ trunk/Source/StructureMap.Testing.Prism/DefaultRegistryTester.cs trunk/Source/StructureMap.Testing.Prism/StructureMapContainerFacadeTester.cs Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -47,6 +47,7 @@ void SelectConstructor<T>(Expression<Func<T>> expression); } + /// <summary> /// A Registry class provides methods and grammars for configuring a Container or ObjectFactory. /// Using a Registry subclass is the recommended way of configuring a StructureMap Container. @@ -74,6 +75,7 @@ /// You can overide this method as a place to put the Registry DSL /// declarations. This is not mandatory. /// </summary> + [Obsolete("configure() is unnecessary. All declarations can be made in the constructor of a Registry or any other method")] protected virtual void configure() { // no-op; @@ -152,6 +154,16 @@ } /// <summary> + /// Convenience method. Equivalent of ForRequestedType[PluginType]().AsSingletons() + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> ForSingletonOf<PLUGINTYPE>() + { + return ForRequestedType<PLUGINTYPE>().AsSingletons(); + } + + /// <summary> /// Uses the configuration expressions of this Registry to create a PluginGraph /// object that could be used to initialize a Container. This method is /// mostly for internal usage, but might be helpful for diagnostics @@ -357,5 +369,7 @@ { PluginCache.GetPlugin(typeof(T)).UseConstructor(expression); } + + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -79,7 +79,7 @@ _writer.AddText(contents); - _writer.AddContent("Built by: " + pluginType.Policy); + _writer.AddContent("Scoped as: " + pluginType.Policy); foreach (IInstance instance in pluginType.Instances) { Modified: trunk/Source/StructureMap/Graph/Constructor.cs =================================================================== --- trunk/Source/StructureMap/Graph/Constructor.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/Graph/Constructor.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -94,12 +94,33 @@ public void Visit(IArgumentVisitor visitor) { - foreach (ParameterInfo info in _ctor.GetParameters()) + try { - Type parameterType = info.ParameterType; - - visitParameter(info, parameterType, visitor); + foreach (ParameterInfo info in _ctor.GetParameters()) + { + try + { + Type parameterType = info.ParameterType; + visitParameter(info, parameterType, visitor); + } + catch (Exception e) + { + string message = + "Trying to visit parameter {0} of type {1} in the constructor for {2}".ToFormat(info.Name, + info. + ParameterType, + _pluggedType. + AssemblyQualifiedName); + throw new ApplicationException(message, e); + } + } } + catch (Exception e) + { + string message = "Failed while trying to visit the constructor for " + + _pluggedType.AssemblyQualifiedName; + throw new ApplicationException(message, e); + } } private void visitParameter(ParameterInfo info, Type parameterType, IArgumentVisitor visitor) Modified: trunk/Source/StructureMap/Pipeline/BuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -1,4 +1,5 @@ using System; +using StructureMap.Attributes; namespace StructureMap.Pipeline { @@ -54,5 +55,10 @@ { return 0; } + + public override string ToString() + { + return InstanceScope.PerRequest.ToString(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -2,6 +2,7 @@ using System.Collections; using System.Web; using System.Web.SessionState; +using StructureMap.Attributes; namespace StructureMap.Pipeline { @@ -49,6 +50,11 @@ { return this; } + + public override string ToString() + { + return InstanceScope.HttpContext.ToString(); + } } public class HttpSessionBuildPolicy : HttpContextBuildPolicy @@ -57,6 +63,11 @@ { return new SessionWrapper(HttpContext.Current.Session); } + + public override string ToString() + { + return InstanceScope.HttpSession.ToString(); + } } public class SessionWrapper : IDictionary Modified: trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -1,4 +1,5 @@ using System; +using StructureMap.Attributes; namespace StructureMap.Pipeline { @@ -60,6 +61,11 @@ { return new HybridBuildPolicy(){InnerPolicy = InnerPolicy.Clone()}; } + + public override string ToString() + { + return InstanceScope.Hybrid.ToString(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -1,4 +1,5 @@ using System; +using StructureMap.Attributes; namespace StructureMap.Pipeline { @@ -43,5 +44,10 @@ { return new SingletonPolicy(); } + + public override string ToString() + { + return InstanceScope.Singleton.ToString(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -1,4 +1,5 @@ using System; +using StructureMap.Attributes; namespace StructureMap.Pipeline { @@ -36,5 +37,10 @@ { return this; } + + public override string ToString() + { + return InstanceScope.Hybrid.ToString(); + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/TypeExtensions.cs =================================================================== --- trunk/Source/StructureMap/TypeExtensions.cs 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap/TypeExtensions.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -17,6 +17,11 @@ return new ReferencedInstance(key); } + public static bool IsSimple(this Type type) + { + return new TypeRules().IsSimple(type); + } + public static bool IsConcrete(this Type type) { return new TypeRules().IsConcrete(type); Added: trunk/Source/StructureMap.Prism/DefaultRegistry.cs =================================================================== --- trunk/Source/StructureMap.Prism/DefaultRegistry.cs (rev 0) +++ trunk/Source/StructureMap.Prism/DefaultRegistry.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -0,0 +1,17 @@ +using Microsoft.Practices.Composite; +using Microsoft.Practices.Composite.Events; +using Microsoft.Practices.Composite.Wpf.Regions; +using StructureMap.Configuration.DSL; + +namespace StructureMap.Prism +{ + public class DefaultRegistry : Registry + { + public DefaultRegistry() + { + ForSingletonOf<IContainerFacade>().TheDefaultIsConcreteType<StructureMapContainerFacade>(); + ForSingletonOf<IEventAggregator>().TheDefaultIsConcreteType<EventAggregator>(); + ForSingletonOf<RegionAdapterMappings>().TheDefaultIsConcreteType<RegionAdapterMappings>(); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Prism/PrismBootstrapper.cs =================================================================== --- trunk/Source/StructureMap.Prism/PrismBootstrapper.cs (rev 0) +++ trunk/Source/StructureMap.Prism/PrismBootstrapper.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -0,0 +1,62 @@ +using System.Collections.Generic; +using System.Linq; +using System.Text; +using StructureMap.Configuration.DSL; + +namespace StructureMap.Prism +{ + public abstract class PrismBootstrapper<THIS> : IBootstrapper where THIS : IBootstrapper, new() + { + private static bool _hasStarted = false; + + public static void Restart() + { + + } + + public void Bootstrap(string profile) + { + Bootstrap(); + } + + public void Bootstrap() + { + + } + + public PrismBootstrapper(string defaultProfofile) + { + } + + public PrismBootstrapper() : this(string.Empty) + { + } + + + public void BootstrapStructureMap() + { + throw new System.NotImplementedException(); + } + + // TODO + // 1.) Calls all Startables at end + // 2.) applies Profile + // 3.) adds the basic types + // 4.) create the shell + // 5.) tie into debuggers + } + + // test this + + public interface IStartable + { + void Execute(IContainer container); + } + + public class PrismRegistry : Registry + { + // TODO + // 1.) OnStartUp method + // 2.) + } +} Added: trunk/Source/StructureMap.Prism/StructureMapContainerFacade.cs =================================================================== --- trunk/Source/StructureMap.Prism/StructureMapContainerFacade.cs (rev 0) +++ trunk/Source/StructureMap.Prism/StructureMapContainerFacade.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -0,0 +1,30 @@ +using System; +using Microsoft.Practices.Composite; + +namespace StructureMap.Prism +{ + public class StructureMapContainerFacade : IContainerFacade + { + private readonly IContainer _container; + + public StructureMapContainerFacade(IContainer container) + { + _container = container; + } + + public object Resolve(Type type) + { + return _container.GetInstance(type); + } + + public object TryResolve(Type type) + { + return _container.TryGetInstance(type); + } + + public IContainer Container + { + get { return _container; } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Prism/structuremap.snk =================================================================== (Binary files differ) Property changes on: trunk/Source/StructureMap.Prism/structuremap.snk ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/Source/StructureMap.Testing.Prism/DefaultRegistryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing.Prism/DefaultRegistryTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing.Prism/DefaultRegistryTester.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -0,0 +1,54 @@ +using Microsoft.Practices.Composite; +using Microsoft.Practices.Composite.Events; +using Microsoft.Practices.Composite.Wpf.Regions; +using NUnit.Framework; +using StructureMap.Prism; + +namespace StructureMap.Testing.Prism +{ + [TestFixture] + public class DefaultRegistryTester + { + #region Setup/Teardown + + [SetUp] + public void SetUp() + { + container = new Container(new DefaultRegistry()); + } + + #endregion + + private Container container; + + [Test] + public void sets_up_the_default_event_aggregator_as_a_singleton() + { + container.GetInstance<IEventAggregator>().ShouldBeOfType<EventAggregator>(); + container.GetInstance<IEventAggregator>().ShouldBeTheSameAs(container.GetInstance<IEventAggregator>()); + } + + [Test] + public void sets_up_the_default_region_adapter_as_a_singleton() + { + container.GetInstance<RegionAdapterMappings>().ShouldBeOfType<RegionAdapterMappings>(); + container.GetInstance<RegionAdapterMappings>().ShouldBeTheSameAs( + container.GetInstance<RegionAdapterMappings>()); + } + + [Test] + public void sets_up_the_icontainerfacade_to_wrap_itself() + { + var theView = new TheView(); + container.Inject(theView); + + container.GetInstance<IContainerFacade>() + .ShouldBeOfType<StructureMapContainerFacade>() + .Container.ShouldBeTheSameAs(container); + } + } + + public class TheView + { + } +} \ No newline at end of file Added: trunk/Source/StructureMap.Testing.Prism/StructureMapContainerFacadeTester.cs =================================================================== --- trunk/Source/StructureMap.Testing.Prism/StructureMapContainerFacadeTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing.Prism/StructureMapContainerFacadeTester.cs 2009-01-31 20:03:15 UTC (rev 228) @@ -0,0 +1,42 @@ +using NUnit.Framework; +using StructureMap.Prism; + +namespace StructureMap.Testing.Prism +{ + [TestFixture] + public class StructureMapContainerFacadeTester + { + [Test] + public void can_use_inner_container_to_resolve_a_type() + { + var container = new Container(x => { x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); }); + + var facade = new StructureMapContainerFacade(container); + facade.Resolve(typeof (IView)).ShouldBeOfType<View>(); + } + + [Test] + public void can_use_inner_container_to_try_resolve_successfully() + { + var container = new Container(x => { x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); }); + + var facade = new StructureMapContainerFacade(container); + facade.TryResolve(typeof (IView)).ShouldBeOfType<View>(); + } + + [Test] + public void can_use_inner_container_to_try_resolve_when_type_is_not_there() + { + var facade = new StructureMapContainerFacade(new Container()); + facade.TryResolve(typeof (IView)).ShouldBeNull(); + } + } + + public interface IView + { + } + + public class View : IView + { + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.sln =================================================================== --- trunk/Source/StructureMap.sln 2009-01-22 22:33:20 UTC (rev 227) +++ trunk/Source/StructureMap.sln 2009-01-31 20:03:15 UTC (rev 228) @@ -57,6 +57,10 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TableOfContentsBuilder", "TableOfContentsBuilder\TableOfContentsBuilder.csproj", "{8A9EAE91-F3F5-4919-86FC-6D98D00FC77F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.Prism", "StructureMap.Prism\StructureMap.Prism.csproj", "{150CACB1-7F59-4C68-8830-F277E0E98A3F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.Testing.Prism", "StructureMap.Testing.Prism\StructureMap.Testing.Prism.csproj", "{7F72EFA9-B575-462A-855F-132F8DBC6E9D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Build|.NET = Build|.NET @@ -292,6 +296,36 @@ {8A9EAE91-F3F5-4919-86FC-6D98D00FC77F}.Release|Any CPU.Build.0 = Release|Any CPU {8A9EAE91-F3F5-4919-86FC-6D98D00FC77F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {8A9EAE91-F3F5-4919-86FC-6D98D00FC77F}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|.NET.ActiveCfg = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|Any CPU.ActiveCfg = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|Any CPU.Build.0 = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|Mixed Platforms.ActiveCfg = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|Mixed Platforms.Build.0 = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|.NET.ActiveCfg = Debug|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|.NET.ActiveCfg = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|Any CPU.Build.0 = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|.NET.ActiveCfg = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|Any CPU.ActiveCfg = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|Any CPU.Build.0 = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|Mixed Platforms.ActiveCfg = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|Mixed Platforms.Build.0 = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|.NET.ActiveCfg = Debug|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|.NET.ActiveCfg = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|Any CPU.Build.0 = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|Mixed Platforms.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2009-02-01 20:02:18
|
Revision: 231 http://structuremap.svn.sourceforge.net/structuremap/?rev=231&view=rev Author: jeremydmiller Date: 2009-02-01 20:02:05 +0000 (Sun, 01 Feb 2009) Log Message: ----------- added <Registry> to the xml configuration. Finishing the 2.5.3 release Modified Paths: -------------- trunk/Source/HTML/XmlConfiguration.htm trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Configuration/ConfigurationParser.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/Configuration/IGraphBuilder.cs trunk/Source/StructureMap/Configuration/XmlConstants.cs trunk/Source/StructureMap/PluginGraphBuilder.cs trunk/Source/StructureMap/StructureMapException.resx trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj Added Paths: ----------- trunk/Source/StructureMap.Testing/Examples/AddRegistryInXml.xml trunk/Source/StructureMap.Testing/ReadingRegistriesFromXmlTester.cs Modified: trunk/Source/HTML/XmlConfiguration.htm =================================================================== --- trunk/Source/HTML/XmlConfiguration.htm 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/HTML/XmlConfiguration.htm 2009-02-01 20:02:05 UTC (rev 231) @@ -542,8 +542,43 @@ </div> <!--EndFragment--> <hr /> - + <h2>Referencing Registries from Xml</h2> + <p>StructureMap 2.5.3 adds the ability to include Registry configuration through Xml + configuration. This may be valuable in systems where you might be + completely unable to do programmatic bootstrapping or modify the application + startup to add bootstrapping. Just add a <Registry> node to Xml + configuration and put the assembly qualified name of the Registry class into the + @Type attribute like this:</p> +<!-- +{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red163\green21\blue21;\red255\green0\blue0;\red0\green0\blue0;\red0\green128\blue0;}??\fs20 \cf1 <?\cf3 xml\cf1 \cf4 version\cf1 =\cf0 "\cf1 1.0\cf0 "\cf1 \cf4 encoding\cf1 =\cf0 "\cf1 utf-8\cf0 "\cf1 ?>\par ??<\cf3 StructureMap\cf1 >\par ?? <!--\cf6 Configure a Registry by just specifying the Assembly Qualified Name of a Registry Type \cf1 -->\par ?? <\cf3 Registry\cf1 \cf4 Type\cf1 =\cf0 "\cf1 StructureMap.Testing.XmlFileRegistry, StructureMap.Testing\cf0 "\cf1 ></\cf3 Registry\cf1 >\par ??</\cf3 StructureMap\cf1 >} +--> + <div style="font-family: Courier New; font-size: 10pt; color: black; background: white; border: black thin solid;"> + <p style="margin: 0px;"> + <span style="color: blue;"><?</span><span style="color: #a31515;">xml</span><span + style="color: blue;"> </span><span style="color: red;">version</span><span + style="color: blue;">=</span>"<span style="color: blue;">1.0</span>"<span + style="color: blue;"> </span><span style="color: red;">encoding</span><span + style="color: blue;">=</span>"<span style="color: blue;">utf-8</span>"<span + style="color: blue;"> ?></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"><</span><span style="color: #a31515;">StructureMap</span><span + style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <!--</span><span style="color: green;"> + Configure a Registry by just specifying the Assembly Qualified Name of a + Registry Type </span><span style="color: blue;">--></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"> <</span><span style="color: #a31515;">Registry</span><span + style="color: blue;"> </span><span style="color: red;">Type</span><span + style="color: blue;">=</span>"<span style="color: blue;">StructureMap.Testing.XmlFileRegistry, + StructureMap.Testing</span>"<span style="color: blue;">></</span><span + style="color: #a31515;">Registry</span><span style="color: blue;">></span></p> + <p style="margin: 0px;"> + <span style="color: blue;"></</span><span style="color: #a31515;">StructureMap</span><span + style="color: blue;">></span></p> + </div> +<!--EndFragment--> +<hr /> - </body> </html> \ No newline at end of file Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap/BuildSession.cs 2009-02-01 20:02:05 UTC (rev 231) @@ -123,7 +123,11 @@ public Type ParentType { - get { return _buildStack.Parent.ConcreteType; } + get + { + if (_buildStack.Parent != null) return _buildStack.Parent.ConcreteType; + return null; + } } T IContext.GetInstance<T>() Modified: trunk/Source/StructureMap/Configuration/ConfigurationParser.cs =================================================================== --- trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap/Configuration/ConfigurationParser.cs 2009-02-01 20:02:05 UTC (rev 231) @@ -96,7 +96,12 @@ _structureMapNode.ForTextInChild("Assembly/@Name").Do(name => builder.AddAssembly(name)); } + public void ParseRegistries(IGraphBuilder builder) + { + _structureMapNode.ForTextInChild("Registry/@Type").Do(name => builder.AddRegistry(name)); + } + private XmlExtensions.XmlNodeExpression forEachNode(string xpath) { return _structureMapNode.ForEachChild(xpath); Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-02-01 20:02:05 UTC (rev 231) @@ -152,6 +152,11 @@ return this; } + /// <summary> + /// Adds an Interceptor to only this PluginType + /// </summary> + /// <param name="interceptor"></param> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> InterceptWith(InstanceInterceptor interceptor) { _children.Add( @@ -302,6 +307,11 @@ }); } + /// <summary> + /// Forces StructureMap to always use a unique instance to + /// stop the "BuildSession" caching + /// </summary> + /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> AlwaysUnique() { return InterceptConstructionWith(new UniquePerRequestInterceptor()); Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2009-02-01 20:02:05 UTC (rev 231) @@ -58,6 +58,16 @@ } } + public void AddRegistry(string registryTypeName) + { + _pluginGraph.Log.Try(()=> + { + var type = new TypePath(registryTypeName).FindType(); + Registry registry = (Registry) Activator.CreateInstance(type); + registry.ConfigurePluginGraph(_pluginGraph); + }).AndReportErrorAs(290, registryTypeName); + } + public IProfileBuilder GetProfileBuilder() { return new ProfileBuilder(_pluginGraph); Modified: trunk/Source/StructureMap/Configuration/IGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap/Configuration/IGraphBuilder.cs 2009-02-01 20:02:05 UTC (rev 231) @@ -17,6 +17,7 @@ { PluginGraph PluginGraph { get; } void AddAssembly(string assemblyName); + void AddRegistry(string registryTypeName); void FinishFamilies(); Modified: trunk/Source/StructureMap/Configuration/XmlConstants.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlConstants.cs 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap/Configuration/XmlConstants.cs 2009-02-01 20:02:05 UTC (rev 231) @@ -32,5 +32,6 @@ public const string SCOPE = "Scope"; public const string STRUCTUREMAP = "StructureMap"; public const string TYPE_ATTRIBUTE = "Type"; + public const string REGISTRY = "Registry"; } } \ No newline at end of file Modified: trunk/Source/StructureMap/PluginGraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/PluginGraphBuilder.cs 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap/PluginGraphBuilder.cs 2009-02-01 20:02:05 UTC (rev 231) @@ -62,6 +62,7 @@ { _graph.Log.StartSource(p.Description); p.ParseAssemblies(graphBuilder); + p.ParseRegistries(graphBuilder); }); forAllParsers(p => p.Parse(graphBuilder)); Modified: trunk/Source/StructureMap/StructureMapException.resx =================================================================== --- trunk/Source/StructureMap/StructureMapException.resx 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap/StructureMapException.resx 2009-02-01 20:02:05 UTC (rev 231) @@ -268,4 +268,7 @@ <data name="285" xml:space="preserve"> <value>Only open generic types can be used in the call to Container.ForGenericType(type)</value> </data> + <data name="290" xml:space="preserve"> + <value>Could not load the designated Registry class '{0}'</value> + </data> </root> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/Examples/AddRegistryInXml.xml =================================================================== --- trunk/Source/StructureMap.Testing/Examples/AddRegistryInXml.xml (rev 0) +++ trunk/Source/StructureMap.Testing/Examples/AddRegistryInXml.xml 2009-02-01 20:02:05 UTC (rev 231) @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8" ?> +<StructureMap> + <!-- Configure a Registry by just specifying the Assembly Qualified Name of a Registry Type --> + <Registry Type="StructureMap.Testing.XmlFileRegistry, StructureMap.Testing"></Registry> +</StructureMap> \ No newline at end of file Added: trunk/Source/StructureMap.Testing/ReadingRegistriesFromXmlTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/ReadingRegistriesFromXmlTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/ReadingRegistriesFromXmlTester.cs 2009-02-01 20:02:05 UTC (rev 231) @@ -0,0 +1,78 @@ +using System; +using System.Diagnostics; +using System.Xml; +using NUnit.Framework; +using StructureMap.Configuration; +using StructureMap.Configuration.DSL; +using StructureMap.Graph; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing +{ + [TestFixture] + public class ReadingRegistriesFromXmlTester + { + [SetUp] + public void SetUp() + { + } + + public void TheXmlFileRegistryWasLoadedInto(IContainer container) + { + container.GetInstance<ColorRule>().Color.ShouldEqual("Cornflower"); + } + + [Test] + public void graphbuilder_can_add_a_registry_directly() + { + var graph = new PluginGraph(); + var builder = new GraphBuilder(new Registry[0], graph); + builder.AddRegistry(typeof(XmlFileRegistry).AssemblyQualifiedName); + + var container = new Container(graph); + TheXmlFileRegistryWasLoadedInto(container); + } + + [Test] + public void handles_failures_gracefully_if_the_registry_cannot_be_loaded() + { + //290 + var graph = new PluginGraph(); + var builder = new GraphBuilder(new Registry[0], graph); + builder.AddRegistry("an invalid type name"); + + graph.Log.ErrorCount.ShouldEqual(1); + graph.Log.AssertHasError(290); + + } + + [Test] + public void read_registry_from_xml() + { + var document = new XmlDocument(); + document.LoadXml("<StructureMap><Registry></Registry></StructureMap>"); + document.DocumentElement.FirstChild.ShouldBeOfType<XmlElement>().SetAttribute("Type", + typeof (XmlFileRegistry). + AssemblyQualifiedName); + + Debug.WriteLine(document.OuterXml); + + var container = new Container(x => + { + x.AddConfigurationFromNode(document.DocumentElement); + }); + + TheXmlFileRegistryWasLoadedInto(container); + + } + + } + + public class XmlFileRegistry : Registry + { + public XmlFileRegistry() + { + ForConcreteType<ColorRule>().Configure.WithCtorArg("color").EqualTo("Cornflower"); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-02-01 18:34:03 UTC (rev 230) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-02-01 20:02:05 UTC (rev 231) @@ -367,6 +367,7 @@ <DesignTimeSharedInput>True</DesignTimeSharedInput> <DependentUpon>Settings.settings</DependentUpon> </Compile> + <Compile Include="ReadingRegistriesFromXmlTester.cs" /> <Compile Include="SpecificationExtensions.cs" /> <Compile Include="StructureMapConfigCreator.cs" /> <Compile Include="StructureMapConfigurationDefensiveChecksTester.cs" /> @@ -444,6 +445,7 @@ <EmbeddedResource Include="TestData\PluggedTypeTest.xml" /> </ItemGroup> <ItemGroup> + <Content Include="Examples\AddRegistryInXml.xml" /> <Content Include="Sample.xml" /> <Content Include="TestData\ProfileSample.xml" /> <EmbeddedResource Include="TestData\ShortInstance.xml" /> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2009-06-03 16:21:06
|
Revision: 247 http://structuremap.svn.sourceforge.net/structuremap/?rev=247&view=rev Author: jeremydmiller Date: 2009-06-03 16:21:03 +0000 (Wed, 03 Jun 2009) Log Message: ----------- initial work on nested containers, some little syntactical sugar in the registry DSL Modified Paths: -------------- trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/InstanceCache.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/Pipeline/BuildStack.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/Util/Cache.cs trunk/Source/StructureMap.Testing/BuildSessionTester.cs trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.sln Added Paths: ----------- trunk/Source/StructureMap/Pipeline/ILifecycle.cs trunk/Source/StructureMap/Pipeline/IObjectCache.cs trunk/Source/StructureMap/Pipeline/Lifecycles.cs trunk/Source/StructureMap/Pipeline/MainObjectCache.cs trunk/Source/StructureMap/Pipeline/NulloObjectCache.cs trunk/Source/StructureMap/Pipeline/ObjectBuilder.cs trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs trunk/Source/StructureMap.Testing/Util/ trunk/Source/StructureMap.Testing/Util/CacheTester.cs Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/BuildSession.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -8,18 +8,17 @@ { public class BuildSession : IContext { - private readonly BuildStack _buildStack = new BuildStack(); + private BuildStack _buildStack = new BuildStack(); private readonly InstanceCache _cache = new InstanceCache(); private readonly Cache<Type, Func<object>> _defaults; private readonly PipelineGraph _pipelineGraph; private readonly ObjectBuilder _builder; - public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) + public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary, IObjectCache cache) { + _builder = new ObjectBuilder(pipelineGraph, interceptorLibrary, cache); _pipelineGraph = pipelineGraph; - _builder = new ObjectBuilder(_pipelineGraph, interceptorLibrary, new NulloObjectCache()); - _defaults = new Cache<Type, Func<object>>(t => { Instance instance = _pipelineGraph.GetDefault(t); @@ -34,7 +33,7 @@ } public BuildSession(PluginGraph graph) - : this(new PipelineGraph(graph), graph.InterceptorLibrary) + : this(new PipelineGraph(graph), graph.InterceptorLibrary, new NulloObjectCache()) { } @@ -43,6 +42,10 @@ { } + protected void clearBuildStack() + { + _buildStack = new BuildStack(); + } protected PipelineGraph pipelineGraph { Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -103,6 +103,16 @@ } /// <summary> + /// Shorthand way of saying TheDefaultIsConcreteType<> + /// </summary> + /// <typeparam name="CONCRETETYPE"></typeparam> + /// <returns></returns> + public CreatePluginFamilyExpression<PLUGINTYPE> Use<CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE + { + return TheDefaultIsConcreteType<CONCRETETYPE>(); + } + + /// <summary> /// Sets the object creation of the instances of the PluginType. For example: PerRequest, /// Singleton, ThreadLocal, HttpContext, or Hybrid /// </summary> Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -51,6 +51,16 @@ return instance; } + + /// <summary> + /// Shorter way to call TheDefaultIsConcreteType + /// </summary> + /// <param name="concreteType"></param> + /// <returns></returns> + public ConfiguredInstance Use(Type concreteType) + { + return TheDefaultIsConcreteType(concreteType); + } /// <summary> /// Shortcut method to add an additional Instance to this Plugin Type Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -47,7 +47,20 @@ void SelectConstructor<T>(Expression<Func<T>> expression); } + public static class RegistryExtensions + { + public static CreatePluginFamilyExpression<PLUGINTYPE> For<PLUGINTYPE>(this IRegistry registry) + { + return registry.ForRequestedType<PLUGINTYPE>(); + } + public static GenericFamilyExpression For(this IRegistry registry, Type pluginType) + { + return registry.ForRequestedType(pluginType); + } + } + + /// <summary> /// A Registry class provides methods and grammars for configuring a Container or ObjectFactory. /// Using a Registry subclass is the recommended way of configuring a StructureMap Container. Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Container.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -7,16 +7,15 @@ using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; -using System.Linq; namespace StructureMap { public class Container : TypeRules, IContainer { private InterceptorLibrary _interceptorLibrary; - private Model _model; private PipelineGraph _pipelineGraph; private PluginGraph _pluginGraph; + private IObjectCache _transientCache = new NulloObjectCache(); public Container(Action<ConfigurationExpression> action) { @@ -26,11 +25,13 @@ construct(expression.BuildGraph()); } - public Container(Registry registry) : this(registry.Build()) + public Container(Registry registry) + : this(registry.Build()) { } - public Container() : this(new PluginGraph()) + public Container() + : this(new PluginGraph()) { } @@ -44,25 +45,16 @@ construct(pluginGraph); } - protected MissingFactoryFunction onMissingFactory - { - set { _pipelineGraph.OnMissingFactory = value; } - } + protected MissingFactoryFunction onMissingFactory { set { _pipelineGraph.OnMissingFactory = value; } } + public PluginGraph PluginGraph { get { return _pluginGraph; } } + #region IContainer Members - public PluginGraph PluginGraph - { - get { return _pluginGraph; } - } - /// <summary> /// Provides queryable access to the configured PluginType's and Instances of this Container /// </summary> - public IModel Model - { - get { return _model; } - } + public IModel Model { get { return new Model(_pipelineGraph); } } /// <summary> /// Creates or finds the named instance of T @@ -110,30 +102,12 @@ public object GetInstance(Type pluginType, ExplicitArguments args) { Instance defaultInstance = _pipelineGraph.GetDefault(pluginType); - var requestedName = Plugin.DEFAULT; + string requestedName = Plugin.DEFAULT; return buildInstanceWithArgs(pluginType, defaultInstance, args, requestedName); } - private object buildInstanceWithArgs(Type pluginType, Instance defaultInstance, ExplicitArguments args, string requestedName) - { - if (defaultInstance == null && pluginType.IsConcrete()) - { - defaultInstance = new ConfiguredInstance(pluginType); - } - BasicInstance basicInstance = defaultInstance as BasicInstance; - - Instance instance = basicInstance == null ? defaultInstance : new ExplicitInstance(pluginType, args, basicInstance); - - BuildSession session = withNewSession(requestedName); - - args.RegisterDefaults(session); - - return session.CreateInstance(pluginType, instance); - } - - /// <summary> /// Gets all configured instances of type T using explicitly configured arguments from the "args" /// </summary> @@ -146,7 +120,7 @@ args.RegisterDefaults(session); - var instances = session.CreateInstanceArray(type, null); + Array instances = session.CreateInstanceArray(type, null); return new ArrayList(instances); } @@ -241,9 +215,9 @@ /// <returns></returns> public object TryGetInstance(Type pluginType, string instanceKey) { - return !_pipelineGraph.HasInstance(pluginType, instanceKey) - ? null - : GetInstance(pluginType, instanceKey); + return !_pipelineGraph.HasInstance(pluginType, instanceKey) + ? null + : GetInstance(pluginType, instanceKey); } /// <summary> @@ -253,9 +227,9 @@ /// <returns></returns> public object TryGetInstance(Type pluginType) { - return !_pipelineGraph.HasDefaultForPluginType(pluginType) - ? null - : GetInstance(pluginType); + return !_pipelineGraph.HasDefaultForPluginType(pluginType) + ? null + : GetInstance(pluginType); } /// <summary> @@ -265,7 +239,7 @@ /// <returns></returns> public T TryGetInstance<T>() { - return (T)(TryGetInstance(typeof (T)) ?? default(T)); + return (T) (TryGetInstance(typeof (T)) ?? default(T)); } /// <summary> @@ -276,11 +250,11 @@ /// <param name="target"></param> public void BuildUp(object target) { - var pluggedType = target.GetType(); - IConfiguredInstance instance = _pipelineGraph.GetDefault(pluggedType) as IConfiguredInstance - ?? new ConfiguredInstance(pluggedType); + Type pluggedType = target.GetType(); + IConfiguredInstance instance = _pipelineGraph.GetDefault(pluggedType) as IConfiguredInstance + ?? new ConfiguredInstance(pluggedType); - var builder = PluginCache.FindBuilder(pluggedType); + InstanceBuilder builder = PluginCache.FindBuilder(pluggedType); builder.BuildUp(instance, withNewSession(Plugin.DEFAULT), target); } @@ -291,7 +265,7 @@ /// <returns></returns> public T TryGetInstance<T>(string instanceKey) { - return (T)(TryGetInstance(typeof(T), instanceKey) ?? default(T)); + return (T) (TryGetInstance(typeof (T), instanceKey) ?? default(T)); } /// <summary> @@ -365,7 +339,7 @@ /// <returns></returns> public IList GetAllInstances(Type pluginType) { - var instances = withNewSession(Plugin.DEFAULT).CreateInstanceArray(pluginType, null); + Array instances = withNewSession(Plugin.DEFAULT).CreateInstanceArray(pluginType, null); return new ArrayList(instances); } @@ -434,15 +408,7 @@ return new ExplicitArgsExpression(this).With(argName); } - public ExplicitArgsExpression With(Action<ExplicitArgsExpression> action) - { - var expression = new ExplicitArgsExpression(this); - action(expression); - return expression; - } - - /// <summary> /// Use with caution! Does a full environment test of the configuration of this container. Will try to create every configured /// instance and afterward calls any methods marked with the [ValidationMethod] attribute @@ -467,8 +433,95 @@ _pipelineGraph.EjectAllInstancesOf<T>(); } + /// <summary> + /// Convenience method to request an object using an Open Generic + /// Type and its parameter Types + /// </summary> + /// <param name="templateType"></param> + /// <returns></returns> + /// <example> + /// IFlattener flattener1 = container.ForGenericType(typeof (IFlattener<>)) + /// .WithParameters(typeof (Address)).GetInstanceAs<IFlattener>(); + /// </example> + public OpenGenericTypeExpression ForGenericType(Type templateType) + { + return new OpenGenericTypeExpression(templateType, this); + } + + /// <summary> + /// Shortcut syntax for using an object to find a service that handles + /// that type of object by using an open generic type + /// </summary> + /// <example> + /// IHandler handler = container.ForObject(shipment) + /// .GetClosedTypeOf(typeof (IHandler<>)) + /// .As<IHandler>(); + /// </example> + /// <param name="subject"></param> + /// <returns></returns> + public CloseGenericTypeExpression ForObject(object subject) + { + return new CloseGenericTypeExpression(subject, this); + } + + /// <summary> + /// Starts a "Nested" Container for atomic, isolated access + /// </summary> + /// <returns></returns> + public IContainer GetNestedContainer() + { + return new Container() + { + _interceptorLibrary = _interceptorLibrary, + _pipelineGraph = _pipelineGraph.Clone(), + _transientCache = new MainObjectCache() + }; + } + + /// <summary> + /// Starts a new "Nested" Container for atomic, isolated service location. Opens + /// </summary> + /// <param name="profileName"></param> + /// <returns></returns> + public IContainer GetNestedContainer(string profileName) + { + var container = GetNestedContainer(); + container.SetDefaultsToProfile(profileName); + + return container; + } + #endregion + private object buildInstanceWithArgs(Type pluginType, Instance defaultInstance, ExplicitArguments args, + string requestedName) + { + if (defaultInstance == null && pluginType.IsConcrete()) + { + defaultInstance = new ConfiguredInstance(pluginType); + } + + var basicInstance = defaultInstance as BasicInstance; + + Instance instance = basicInstance == null + ? defaultInstance + : new ExplicitInstance(pluginType, args, basicInstance); + + BuildSession session = withNewSession(requestedName); + + args.RegisterDefaults(session); + + return session.CreateInstance(pluginType, instance); + } + + public ExplicitArgsExpression With(Action<ExplicitArgsExpression> action) + { + var expression = new ExplicitArgsExpression(this); + action(expression); + + return expression; + } + private void construct(PluginGraph pluginGraph) { _interceptorLibrary = pluginGraph.InterceptorLibrary; @@ -482,7 +535,6 @@ pluginGraph.Log.AssertFailures(); _pipelineGraph = new PipelineGraph(pluginGraph); - _model = new Model(_pipelineGraph); PluginCache.Compile(); @@ -492,7 +544,7 @@ private IList<T> getListOfTypeWithSession<T>(BuildSession session) { var list = new List<T>(); - foreach (T instance in session.CreateInstanceArray(typeof(T), null)) + foreach (T instance in session.CreateInstanceArray(typeof (T), null)) { list.Add(instance); } @@ -512,30 +564,27 @@ private BuildSession withNewSession(string name) { - return new BuildSession(_pipelineGraph, _interceptorLibrary){RequestedName = name}; + return new BuildSession(_pipelineGraph, _interceptorLibrary, _transientCache) + { + RequestedName = name + }; } - /// <summary> - /// Convenience method to request an object using an Open Generic - /// Type and its parameter Types - /// </summary> - /// <param name="templateType"></param> - /// <returns></returns> - /// <example> - /// IFlattener flattener1 = container.ForGenericType(typeof (IFlattener<>)) - /// .WithParameters(typeof (Address)).GetInstanceAs<IFlattener>(); - /// </example> - public OpenGenericTypeExpression ForGenericType(Type templateType) + #region Nested type: GetInstanceAsExpression + + public interface GetInstanceAsExpression { - return new OpenGenericTypeExpression(templateType, this); + T GetInstanceAs<T>(); } - + #endregion + #region Nested type: OpenGenericTypeExpression + public class OpenGenericTypeExpression : GetInstanceAsExpression { + private readonly Container _container; private readonly Type _templateType; - private readonly Container _container; private Type _pluginType; public OpenGenericTypeExpression(Type templateType, Container container) @@ -549,39 +598,22 @@ _container = container; } - public GetInstanceAsExpression WithParameters(params Type[] parameterTypes) - { - _pluginType = _templateType.MakeGenericType(parameterTypes); - return this; - } + #region GetInstanceAsExpression Members public T GetInstanceAs<T>() { return (T) _container.GetInstance(_pluginType); } - } - public interface GetInstanceAsExpression - { - T GetInstanceAs<T>(); + #endregion + + public GetInstanceAsExpression WithParameters(params Type[] parameterTypes) + { + _pluginType = _templateType.MakeGenericType(parameterTypes); + return this; + } } - /// <summary> - /// Shortcut syntax for using an object to find a service that handles - /// that type of object by using an open generic type - /// </summary> - /// <example> - /// IHandler handler = container.ForObject(shipment) - /// .GetClosedTypeOf(typeof (IHandler<>)) - /// .As<IHandler>(); - /// </example> - /// <param name="subject"></param> - /// <returns></returns> - public CloseGenericTypeExpression ForObject(object subject) - { - return new CloseGenericTypeExpression(subject, this); - } + #endregion } - - } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -17,7 +17,7 @@ private List<IInstance> _explicitInstances; public ValidationBuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary) - : base(pipelineGraph, interceptorLibrary) + : base(pipelineGraph, interceptorLibrary, new NulloObjectCache()) { } @@ -47,6 +47,7 @@ try { + //clearBuildStack(); return base.CreateInstance(pluginType, instance); } catch (StructureMapException ex) Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -7,13 +7,18 @@ { public class GenericsPluginGraph { - private readonly Cache<Type, PluginFamily> _families; + private Cache<Type, PluginFamily> _families; public GenericsPluginGraph() { _families = new Cache<Type, PluginFamily>(pluginType => new PluginFamily(pluginType)); } + public GenericsPluginGraph Clone() + { + return new GenericsPluginGraph(){_families = _families.Clone()}; + } + public int FamilyCount { get { return _families.Count; } Modified: trunk/Source/StructureMap/IContainer.cs =================================================================== --- trunk/Source/StructureMap/IContainer.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/IContainer.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -268,5 +268,23 @@ /// <param name="subject"></param> /// <returns></returns> CloseGenericTypeExpression ForObject(object subject); + + + + /// <summary> + /// Starts a "Nested" Container for atomic, isolated access + /// </summary> + /// <returns></returns> + IContainer GetNestedContainer(); + + /// <summary> + /// Starts a new "Nested" Container for atomic, isolated service location. Opens + /// </summary> + /// <param name="profileName"></param> + /// <returns></returns> + IContainer GetNestedContainer(string profileName); } + + + } \ No newline at end of file Modified: trunk/Source/StructureMap/IInstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/IInstanceFactory.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/IInstanceFactory.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -12,19 +12,19 @@ public interface IInstanceFactory { Type PluginType { get; } - IEnumerable<IInstance> Instances { get; } - Instance MissingInstance { get; set; } + Instance MissingInstance { get; } + Instance[] AllInstances { get; } + // need to override this void AddInstance(Instance instance); - Instance AddType<T>(); + Instance FindInstance(string name); - void ImportFrom(PluginFamily family); [Obsolete("Kill!!!!")] @@ -32,6 +32,7 @@ ILifecycle Lifecycle {get; } + IInstanceFactory Clone(); + } - } } \ No newline at end of file Modified: trunk/Source/StructureMap/InstanceCache.cs =================================================================== --- trunk/Source/StructureMap/InstanceCache.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/InstanceCache.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -25,6 +25,16 @@ public object Get(Type pluginType, Instance instance) { + if (pluginType == null) + { + throw new ArgumentNullException("pluginType"); + } + + if (instance == null) + { + throw new ArgumentNullException("instance", "Trying to find an Instance of type " + pluginType.AssemblyQualifiedName); + } + Dictionary<Instance, object> cache = getCache(pluginType); if (cache.ContainsKey(instance)) { Modified: trunk/Source/StructureMap/InstanceFactory.cs =================================================================== --- trunk/Source/StructureMap/InstanceFactory.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/InstanceFactory.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -12,7 +12,7 @@ /// </summary> public class InstanceFactory : IInstanceFactory { - private readonly Cache<string, Instance> _instances = + private Cache<string, Instance> _instances = new Cache<string, Instance>(delegate { return null; }); private readonly Type _pluginType; @@ -82,11 +82,6 @@ get { return _pluginType; } } - public IEnumerable<IInstance> Instances - { - get { return _instances.GetAll(); } - } - public Instance[] AllInstances { get @@ -102,17 +97,6 @@ } - [Obsolete] - public Instance AddType<T>() - { - ConfiguredInstance instance = - new ConfiguredInstance(typeof (T)).WithName(TypePath.GetAssemblyQualifiedName(typeof (T))); - - AddInstance(instance); - - return instance; - } - public Instance FindInstance(string name) { return _instances[name] ?? MissingInstance; @@ -149,7 +133,18 @@ get { return _lifecycle; } set { _lifecycle = value; } } + + public IInstanceFactory Clone() + { + var factory = new InstanceFactory(_pluginType); + factory.MissingInstance = MissingInstance; + factory._lifecycle = _lifecycle; + factory._instances = _instances.Clone(); + + return factory; + } + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/BuildStack.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/BuildStack.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Pipeline/BuildStack.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -64,5 +64,10 @@ _current = _current.Detach(); if (_current == null) _root = null; } + + public void Clear() + { + _current = _root = null; + } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -206,6 +206,15 @@ protected void setChildArray(string name, Instance[] array) { + for (int i = 0; i < array.Length; i++) + { + if (array[i] == null) + { + throw new ApplicationException("There is a null value in the array of child Instances"); + } + + } + _arrays.Add(name, array); } Added: trunk/Source/StructureMap/Pipeline/ILifecycle.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ILifecycle.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ILifecycle.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -0,0 +1,8 @@ +namespace StructureMap.Pipeline +{ + public interface ILifecycle + { + void EjectAll(); + IObjectCache FindCache(); + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/IObjectCache.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/IObjectCache.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/IObjectCache.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -0,0 +1,18 @@ +using System; + +namespace StructureMap.Pipeline +{ + public interface IObjectCache + { + object Locker { get; } + + int Count + { + get; + } + + object Get(Type pluginType, Instance instance); + void Set(Type pluginType, Instance instance, object value); + void DisposeAndClear(); + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/Lifecycles.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/Lifecycles.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/Lifecycles.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -0,0 +1,37 @@ +using System; +using StructureMap.Attributes; + +namespace StructureMap.Pipeline +{ + public static class Lifecycles + { + public static ILifecycle GetLifecycle(InstanceScope scope) + { + switch (scope) + { + case InstanceScope.PerRequest: + return null; + + case InstanceScope.Singleton: + return new SingletonLifecycle(); + + case InstanceScope.HttpContext: + return new HttpContextLifecycle(); + + case InstanceScope.ThreadLocal: + return new ThreadLocalStorageLifecycle(); + + case InstanceScope.Hybrid: + return new HybridLifecycle(); + + case InstanceScope.HttpSession: + return new HttpSessionLifecycle(); + + case InstanceScope.HybridHttpSession: + return new HybridSessionLifecycle(); + } + + throw new ArgumentOutOfRangeException("scope"); + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/MainObjectCache.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/MainObjectCache.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/MainObjectCache.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; + +namespace StructureMap.Pipeline +{ + public class MainObjectCache : IObjectCache + { + private readonly IDictionary<InstanceKey, object> _objects = new Dictionary<InstanceKey,object>(); + private readonly object _locker = new object(); + + public object Locker + { + get { return _locker; } + } + + public int Count + { + get { return _objects.Count; } + } + + public object Get(Type pluginType, Instance instance) + { + var key = new InstanceKey(instance, pluginType); + return _objects.ContainsKey(key) ? _objects[key] : null; + } + + public void Set(Type pluginType, Instance instance, object value) + { + var key = new InstanceKey(instance, pluginType); + _objects.Add(key, value); + } + + public void DisposeAndClear() + { + lock (Locker) + { + foreach (var @object in _objects.Values) + { + IDisposable disposable = @object as IDisposable; + if (disposable != null) + { + try + { + disposable.Dispose(); + } + catch (Exception) { } + } + } + + _objects.Clear(); + } + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/NulloObjectCache.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/NulloObjectCache.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/NulloObjectCache.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -0,0 +1,32 @@ +using System; + +namespace StructureMap.Pipeline +{ + public class NulloObjectCache : IObjectCache + { + public object Locker + { + get { return new object(); } + } + + public int Count + { + get { return 0; } + } + + public object Get(Type pluginType, Instance instance) + { + return null; + } + + public void Set(Type pluginType, Instance instance, object value) + { + // no-op + } + + public void DisposeAndClear() + { + // no-op + } + } +} \ No newline at end of file Added: trunk/Source/StructureMap/Pipeline/ObjectBuilder.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ObjectBuilder.cs (rev 0) +++ trunk/Source/StructureMap/Pipeline/ObjectBuilder.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -0,0 +1,69 @@ +using System; +using StructureMap.Interceptors; + +namespace StructureMap.Pipeline +{ + public class ObjectBuilder + { + private readonly PipelineGraph _pipeline; + private readonly InterceptorLibrary _library; + private readonly IObjectCache _defaultCache; + + public ObjectBuilder(PipelineGraph pipeline, InterceptorLibrary library, IObjectCache defaultCache) + { + if (pipeline == null) throw new ArgumentNullException("pipeline"); + + _pipeline = pipeline; + _library = library; + _defaultCache = defaultCache; + } + + public object Resolve(Type pluginType, Instance instance, BuildSession session) + { + var cache = FindCache(pluginType, instance, session); + lock (cache.Locker) + { + var returnValue = cache.Get(pluginType, instance); + if (returnValue == null) + { + returnValue = ConstructNew(pluginType, instance, session); + + + cache.Set(pluginType, instance, returnValue); + } + + return returnValue; + } + } + + public object ConstructNew(Type pluginType, Instance instance, BuildSession session) + { + object returnValue = instance.Build(pluginType, session); + return ApplyInterception(pluginType, returnValue, session, instance); + } + + public virtual object ApplyInterception(Type pluginType, object actualValue, BuildSession session, Instance instance) + { + if (actualValue == null) return null; + + try + { + return _library.FindInterceptor(actualValue.GetType()).Process(actualValue, session); + } + catch (Exception e) + { + throw new StructureMapException(308, e, instance.Name, actualValue.GetType()); + } + + + } + + public IObjectCache FindCache(Type pluginType, Instance instance, BuildSession session) + { + var lifecycle = _pipeline.ForType(pluginType).Lifecycle; + return lifecycle == null + ? _defaultCache + : lifecycle.FindCache(); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs =================================================================== --- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -224,6 +224,19 @@ CurrentProfile = CurrentProfile; } + public ProfileManager Clone() + { + var clone = new ProfileManager() + { + DefaultMachineProfileName = DefaultMachineProfileName, + DefaultProfileName = DefaultProfileName + }; + + clone.ImportFrom(this); + + return clone; + } + public void EjectAllInstancesOf<T>() { _currentProfile.Remove<T>(); Modified: trunk/Source/StructureMap/PipelineGraph.cs =================================================================== --- trunk/Source/StructureMap/PipelineGraph.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/PipelineGraph.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -41,6 +41,27 @@ } } + private PipelineGraph(ProfileManager profileManager, GenericsPluginGraph genericsGraph) + { + _profileManager = profileManager; + _genericsGraph = genericsGraph; + } + + public PipelineGraph Clone() + { + var clone = new PipelineGraph(_profileManager.Clone(), _genericsGraph.Clone()) + { + _missingFactory = _missingFactory + }; + + foreach (var pair in _factories) + { + clone._factories.Add(pair.Key, pair.Value); + } + + return clone; + } + public GraphLog Log { get { return _log; } @@ -76,7 +97,7 @@ Default = _profileManager.GetDefault(factory.PluginType), PluginType = factory.PluginType, Lifecycle = factory.Lifecycle, - Instances = factory.Instances + Instances = factory.AllInstances }; } } @@ -152,22 +173,12 @@ _profileManager.SetDefault(pluginType, instance); } - public Instance AddInstance<PLUGINTYPE, PLUGGEDTYPE>() - { - return ForType(typeof (PLUGINTYPE)).AddType<PLUGGEDTYPE>(); - } public void AddInstance<T>(Instance instance) { ForType(typeof (T)).AddInstance(instance); } - public void AddDefaultInstance<PLUGINTYPE, PLUGGEDTYPE>() - { - Instance instance = AddInstance<PLUGINTYPE, PLUGGEDTYPE>(); - _profileManager.SetDefault(typeof (PLUGINTYPE), instance); - } - public void Inject<PLUGINTYPE>(PLUGINTYPE instance) { var literalInstance = new LiteralInstance(instance); @@ -190,7 +201,7 @@ if (_factories.ContainsKey(pluginType)) { - return _factories[pluginType].Instances; + return _factories[pluginType].AllInstances; } return new IInstance[0]; @@ -202,7 +213,7 @@ foreach (var pair in _factories) { - list.AddRange(pair.Value.Instances); + list.AddRange(pair.Value.AllInstances); } return list; Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/StructureMap.csproj 2009-06-03 16:21:03 UTC (rev 247) @@ -404,7 +404,12 @@ <Compile Include="Pipeline\HttpLifecycleBase.cs" /> <Compile Include="Pipeline\HttpSessionLifecycle.cs" /> <Compile Include="Pipeline\HybridSessionLifecycle.cs" /> - <Compile Include="Pipeline\Lifecycle.cs" /> + <Compile Include="Pipeline\ILifecycle.cs" /> + <Compile Include="Pipeline\IObjectCache.cs" /> + <Compile Include="Pipeline\Lifecycles.cs" /> + <Compile Include="Pipeline\MainObjectCache.cs" /> + <Compile Include="Pipeline\NulloObjectCache.cs" /> + <Compile Include="Pipeline\ObjectBuilder.cs" /> <Compile Include="Pipeline\SessionWrapper.cs" /> <Compile Include="Pipeline\SingletonLifecycle.cs" /> <Compile Include="Pipeline\ThreadLocalStorageLifecycle.cs" /> Modified: trunk/Source/StructureMap/Util/Cache.cs =================================================================== --- trunk/Source/StructureMap/Util/Cache.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap/Util/Cache.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -9,8 +9,6 @@ private readonly object _locker = new object(); private readonly IDictionary<KEY, VALUE> _values; - private Func<VALUE, KEY> _getKey = delegate { throw new NotImplementedException(); }; - private Func<KEY, VALUE> _onMissing = delegate(KEY key) { string message = string.Format("Key '{0}' could not be found", key); @@ -38,22 +36,11 @@ _values = dictionary; } - public object Locker - { - get { return _locker; } - } - public Func<KEY, VALUE> OnMissing { set { _onMissing = value; } } - public Func<VALUE, KEY> GetKey - { - get { return _getKey; } - set { _getKey = value; } - } - public int Count { get { return _values.Count; } @@ -135,19 +122,6 @@ _values.Add(key, value); } - public bool TryRetrieve(KEY key, out VALUE value) - { - value = default(VALUE); - - if (_values.ContainsKey(key)) - { - value = _values[key]; - return true; - } - - return false; - } - public void Each(Action<VALUE> action) { lock (_locker) @@ -214,5 +188,13 @@ { _values.Clear(); } + + public Cache<KEY, VALUE> Clone() + { + var clone = new Cache<KEY, VALUE>(_onMissing); + Each((k, v) => clone[k] = v); + + return clone; + } } } Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -151,7 +151,7 @@ assertActionThrowsErrorCode(200, delegate { - var session = new BuildSession(graph, null); + var session = new BuildSession(graph, null, new NulloObjectCache()); session.CreateInstance(typeof (IGateway), "Gateway that is not configured"); }); } @@ -183,7 +183,7 @@ assertActionThrowsErrorCode(202, delegate { - var session = new BuildSession(graph, null); + var session = new BuildSession(graph, null, new NulloObjectCache()); session.CreateInstance(typeof (IGateway)); }); } Modified: trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -71,7 +71,7 @@ factory.EjectAllInstances(); - factory.Instances.Count().ShouldEqual(0); + factory.AllInstances.Count().ShouldEqual(0); lifecycle.AssertWasCalled(x => x.EjectAll()); } @@ -143,4 +143,58 @@ } + + [TestFixture] + public class when_cloning_an_InstanceFactory + { + private InstanceFactory factory; + private IInstanceFactory clone; + + [SetUp] + public void SetUp() + { + factory = new InstanceFactory(typeof(IGateway)); + factory.AddInstance(new SmartInstance<DefaultGateway>()); + factory.AddInstance(new SmartInstance<DefaultGateway>()); + + var lifecycle = MockRepository.GenerateMock<ILifecycle>(); + factory.Lifecycle = lifecycle; + factory.MissingInstance = new SmartInstance<DefaultGateway>(); + + clone = factory.Clone(); + } + + [Test] + public void missing_instance_is_copied() + { + clone.MissingInstance.ShouldBeTheSameAs(factory.MissingInstance); + } + + [Test] + public void lifecycle_is_copied() + { + clone.Lifecycle.ShouldBeTheSameAs(factory.Lifecycle); + } + + [Test] + public void plugin_type_is_set_on_the_clone() + { + clone.PluginType.ShouldEqual(typeof (IGateway)); + } + + [Test] + public void the_instances_are_copied() + { + clone.AllInstances.Count().ShouldEqual(2); + } + + [Test] + public void the_instances_are_cloned_so_that_new_instances_are_NOT_injected_into_() + { + clone.AddInstance(new LiteralInstance(new DefaultGateway())); + + factory.AllInstances.Count().ShouldEqual(2); + clone.AllInstances.Count().ShouldEqual(3); + } + } } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -30,7 +30,7 @@ PluginGraph graph = registry.Build(); var pipelineGraph = new PipelineGraph(graph); - _session = new BuildSession(pipelineGraph, graph.InterceptorLibrary); + _session = new BuildSession(pipelineGraph, graph.InterceptorLibrary, new NulloObjectCache()); } #endregion Added: trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -0,0 +1,131 @@ +using NUnit.Framework; +using StructureMap.Attributes; +using StructureMap.Configuration.DSL; +using StructureMap.Testing.GenericWidgets; +using StructureMap.Testing.Widget; + +namespace StructureMap.Testing.Pipeline +{ + [TestFixture] + public class NestedContainerSupportTester + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void transient_service_in_the_parent_container_is_effectively_a_singleton_for_the_nested_container() + { + var parent = new Container(x => + { + x.For<IWidget>().Use<AWidget>(); + }); + + var child = parent.GetNestedContainer(); + + var childWidget1 = child.GetInstance<IWidget>(); + var childWidget2 = child.GetInstance<IWidget>(); + var childWidget3 = child.GetInstance<IWidget>(); + + var parentWidget = parent.GetInstance<IWidget>(); + + childWidget1.ShouldBeTheSameAs(childWidget2); + childWidget1.ShouldBeTheSameAs(childWidget3); + childWidget1.ShouldNotBeTheSameAs(parentWidget); + } + + [Test] + public void singleton_service_in_the_parent_is_found_by_the_child() + { + var parent = new Container(x => + { + x.ForSingletonOf<IWidget>().Use<AWidget>(); + }); + + var parentWidget = parent.GetInstance<IWidget>(); + + var child = parent.GetNestedContainer(); + + var childWidget1 = child.GetInstance<IWidget>(); + var childWidget2 = child.GetInstance<IWidget>(); + + parentWidget.ShouldBeTheSameAs(childWidget1); + parentWidget.ShouldBeTheSameAs(childWidget2); + } + + [Test] + public void transient_open_generics_service_in_the_parent_container_is_effectively_a_singleton_for_the_nested_container() + { + var parent = new Container(x => + { + x.For(typeof(IService<>)).Use(typeof(Service<>)); + }); + + var child = parent.GetNestedContainer(); + + var childWidget1 = child.GetInstance<IService<string>>(); + var childWidget2 = child.GetInstance<IService<string>>(); + var childWidget3 = child.GetInstance<IService<string>>(); + + var parentWidget = parent.GetInstance<IService<string>>(); + + childWidget1.ShouldBeTheSameAs(childWidget2); + childWidget1.ShouldBeTheSameAs(childWidget3); + childWidget1.ShouldNotBeTheSameAs(parentWidget); + } + + [Test] + public void singleton_service_from_open_type_in_the_parent_is_found_by_the_child() + { + var parent = new Container(x => + { + x.For(typeof(IService<>)).CacheBy(InstanceScope.Singleton).Use(typeof(Service<>)); + }); + + var child = parent.GetNestedContainer(); + + var childWidget1 = child.GetInstance<IService<string>>(); + var childWidget2 = child.GetInstance<IService<string>>(); + var childWidget3 = child.GetInstance<IService<string>>(); + + var parentWidget = parent.GetInstance<IService<string>>(); + + childWidget1.ShouldBeTheSameAs(childWidget2); + childWidget1.ShouldBeTheSameAs(childWidget3); + childWidget1.ShouldBeTheSameAs(parentWidget); + } + + [Test] + public void get_a_nested_container_for_a_profile() + { + var parent = new Container(x => + { + x.For<IWidget>().TheDefault.Is.OfConcreteType<ColorWidget>() + .WithCtorArg("color").EqualTo("red"); + + x.CreateProfile("green", o => + { + o.Type<IWidget>().Is.OfConcreteType<ColorWidget>() + .WithCtorArg("color").EqualTo("green"); + }); + + }); + + var child = parent.GetNestedContainer("green"); + + var childWidget1 = child.GetInstance<IWidget>(); + var childWidget2 = child.GetInstance<IWidget>(); + var childWidget3 = child.GetInstance<IWidget>(); + + var parentWidget = parent.GetInstance<IWidget>(); + + childWidget1.ShouldBeTheSameAs(childWidget2); + childWidget1.ShouldBeTheSameAs(childWidget3); + childWidget1.ShouldNotBeTheSameAs(parentWidget); + + parentWidget.ShouldBeOfType<ColorWidget>().Color.ShouldEqual("red"); + childWidget1.ShouldBeOfType<ColorWidget>().Color.ShouldEqual("green"); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj =================================================================== --- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-06-03 16:21:03 UTC (rev 247) @@ -353,6 +353,7 @@ <Compile Include="Pipeline\InstanceTester.cs" /> <Compile Include="Pipeline\LiteralInstanceTester.cs" /> <Compile Include="Pipeline\MissingInstanceTester.cs" /> + <Compile Include="Pipeline\NestedContainerSupportTester.cs" /> <Compile Include="Pipeline\ObjectBuilderTester.cs" /> <Compile Include="Pipeline\OptionalSetterInjectionTester.cs" /> <Compile Include="Pipeline\ProfileManagerMergeTester.cs" /> @@ -383,6 +384,7 @@ <Compile Include="TestUtility.cs" /> <Compile Include="Diagnostics\ValidationBuildSessionTester.cs" /> <Compile Include="TypeExtensionsTester.cs" /> + <Compile Include="Util\CacheTester.cs" /> <Compile Include="XmlWriting\ElementChecker.cs"> <SubType>Code</SubType> </Compile> Added: trunk/Source/StructureMap.Testing/Util/CacheTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Util/CacheTester.cs (rev 0) +++ trunk/Source/StructureMap.Testing/Util/CacheTester.cs 2009-06-03 16:21:03 UTC (rev 247) @@ -0,0 +1,35 @@ +using NUnit.Framework; +using StructureMap.Testing.Widget; +using StructureMap.Util; + +namespace StructureMap.Testing.Util +{ + [TestFixture] + public class CacheTester + { + [SetUp] + public void SetUp() + { + } + + [Test] + public void cloning_test() + { + var cache = new Cache<string, IWidget>(x => new ColorWidget(x)); + + var red = cache["red"]; + var blue = cache["blue"]; + var green = cache["green"]; + + var clone = cache.Clone(); + + clone["red"].ShouldBeTheSameAs(red); + clone["blue"].ShouldBeTheSameAs(blue); + clone["green"].ShouldBeTheSameAs(green); + + clone["purple"].ShouldBeOfType<ColorWidget>().Color.ShouldEqual("purple"); + + clone["purple"].ShouldNotBeTheSameAs(cache["purple"]); + } + } +} \ No newline at end of file Modified: trunk/Source/StructureMap.sln =================================================================== --- trunk/Source/StructureMap.sln 2009-06-03 03:04:58 UTC (rev 246) +++ trunk/Source/StructureMap.sln 2009-06-03 16:21:03 UTC (rev 247) @@ -4,7 +4,6 @@ ProjectSection(SolutionItems) = preProject ..\Docs\Attributes.htm = ..\Docs\Attributes.htm ..\Docs\Basic Architecture.htm = ..\Docs\Basic Architecture.htm - CommonAssemblyInfo.cs = CommonAssemblyInfo.cs ..\Docs\Concepts.htm = ..\Docs\Concepts.htm ..\Docs\Configuration.htm = ..\Docs\Configuration.htm ..\Docs\ConfigurationManagement.htm = ..\Docs\ConfigurationManagement.htm This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jer...@us...> - 2009-12-26 05:46:06
|
Revision: 296 http://structuremap.svn.sourceforge.net/structuremap/?rev=296&view=rev Author: jeremydmiller Date: 2009-12-26 05:45:56 +0000 (Sat, 26 Dec 2009) Log Message: ----------- Big R# code cleanup after the big re-architecture Modified Paths: -------------- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs trunk/Source/StructureMap/BuildSession.cs trunk/Source/StructureMap/CloseGenericTypeExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/Configuration/XmlConstants.cs trunk/Source/StructureMap/ConfigurationExpression.cs trunk/Source/StructureMap/Construction/InstanceBuilder.cs trunk/Source/StructureMap/Container.cs trunk/Source/StructureMap/Diagnostics/Doctor.cs trunk/Source/StructureMap/Diagnostics/GraphLog.cs trunk/Source/StructureMap/Diagnostics/InstanceToken.cs trunk/Source/StructureMap/Exceptions/StructureMapException.cs trunk/Source/StructureMap/ExplicitArgsExpression.cs trunk/Source/StructureMap/Extensions.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs trunk/Source/StructureMap/Graph/IPluginFamily.cs trunk/Source/StructureMap/Graph/Plugin.cs trunk/Source/StructureMap/Graph/PluginCache.cs trunk/Source/StructureMap/Graph/PluginFamily.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/Graph/SetterProperty.cs trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs trunk/Source/StructureMap/Graph/TypePath.cs trunk/Source/StructureMap/IContainer.cs trunk/Source/StructureMap/IContext.cs trunk/Source/StructureMap/IInstanceFactory.cs trunk/Source/StructureMap/InitializationExpression.cs trunk/Source/StructureMap/InstanceCache.cs trunk/Source/StructureMap/InstanceFactory.cs trunk/Source/StructureMap/InstanceMemento.cs trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs trunk/Source/StructureMap/MementoSource.cs trunk/Source/StructureMap/MemoryInstanceMemento.cs trunk/Source/StructureMap/Model.cs trunk/Source/StructureMap/ObjectFactory.cs trunk/Source/StructureMap/Pipeline/BuildFrame.cs trunk/Source/StructureMap/Pipeline/BuildStack.cs trunk/Source/StructureMap/Pipeline/ConditionalInstance.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs trunk/Source/StructureMap/Pipeline/ConstructorInstance.cs trunk/Source/StructureMap/Pipeline/DefaultInstance.cs trunk/Source/StructureMap/Pipeline/EnumerableInstance.cs trunk/Source/StructureMap/Pipeline/ExplicitArguments.cs trunk/Source/StructureMap/Pipeline/IEnumerableCoercion.cs trunk/Source/StructureMap/Pipeline/IObjectCache.cs trunk/Source/StructureMap/Pipeline/Instance.cs trunk/Source/StructureMap/Pipeline/LambdaInstance.cs trunk/Source/StructureMap/Pipeline/NulloObjectCache.cs trunk/Source/StructureMap/Pipeline/ObjectBuilder.cs trunk/Source/StructureMap/Pipeline/ObjectInstance.cs trunk/Source/StructureMap/Pipeline/Profile.cs trunk/Source/StructureMap/Pipeline/ProfileManager.cs trunk/Source/StructureMap/Pipeline/PropertyExpression.cs trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs trunk/Source/StructureMap/Pipeline/ReferencedInstance.cs trunk/Source/StructureMap/Pipeline/SerializedInstance.cs trunk/Source/StructureMap/Pipeline/SmartInstance.cs trunk/Source/StructureMap/Pipeline/ThreadLocalStorageLifecycle.cs trunk/Source/StructureMap/PipelineGraph.cs trunk/Source/StructureMap/Properties/AssemblyInfo.cs trunk/Source/StructureMap/ReflectionHelper.cs trunk/Source/StructureMap/Source/DirectoryXmlMementoSource.cs trunk/Source/StructureMap/Source/SingleEmbeddedXmlMementoSource.cs trunk/Source/StructureMap/Source/TemplatedMementoSource.cs trunk/Source/StructureMap/Source/XmlAttributeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlFileMementoSource.cs trunk/Source/StructureMap/Source/XmlMementoSource.cs trunk/Source/StructureMap/Source/XmlNodeInstanceMemento.cs trunk/Source/StructureMap/Source/XmlTemplater.cs trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap/SystemRegistry.cs trunk/Source/StructureMap/TypeExtensions.cs trunk/Source/StructureMap/Util/Cache.cs trunk/Source/StructureMap.AutoMocking/AutoMockedContainer.cs trunk/Source/StructureMap.AutoMocking/AutoMocker.cs trunk/Source/StructureMap.AutoMocking/MoqFactory.cs trunk/Source/StructureMap.AutoMocking/RhinoAutoMocker.cs trunk/Source/StructureMap.AutoMocking/RhinoMockRepositoryProxy.cs trunk/Source/StructureMap.AutoMocking/ServiceLocator.cs trunk/Source/StructureMap.DebuggerVisualizers/ContainerDetail.cs trunk/Source/StructureMap.DebuggerVisualizers/ContainerForm.cs trunk/Source/StructureMap.DebuggerVisualizers/ContainerVisualizer.cs trunk/Source/StructureMap.DebuggerVisualizers/ContainerVisualizerObjectSource.cs trunk/Source/StructureMap.DebuggerVisualizers/DisplayHelper.cs trunk/Source/StructureMap.DebuggerVisualizers/Properties/AssemblyInfo.cs trunk/Source/StructureMap.DebuggerVisualizers.Testing/Program.cs trunk/Source/StructureMap.DebuggerVisualizers.Testing/Properties/AssemblyInfo.cs trunk/Source/StructureMap.DebuggerVisualizers.Testing/SampleTypes.cs trunk/Source/StructureMap.DebuggerVisualizers.Testing/VisualizerTests.cs trunk/Source/StructureMap.DeploymentTasks/AddAssembly.cs trunk/Source/StructureMap.DeploymentTasks/SetOverrideTask.cs trunk/Source/StructureMap.DeploymentTasks/SubstitutionTask.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/CheckVersionTask.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedDirectory.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DeployedFile.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/DotNetAssembly.cs trunk/Source/StructureMap.DeploymentTasks/Versioning/GenerateVersionReport.cs trunk/Source/StructureMap.Testing/AutoMocking/MoqAutoMockerTester.cs trunk/Source/StructureMap.Testing/AutoWiringExamples.cs trunk/Source/StructureMap.Testing/Bugs/BuildUpBug.cs trunk/Source/StructureMap.Testing/Bugs/IDictionaryAndXmlBugTester.cs trunk/Source/StructureMap.Testing/Bugs/SingletonShouldBeLazy.cs trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeInConfigureTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs trunk/Source/StructureMap.Testing/Examples/BuildUp.cs trunk/Source/StructureMap.Testing/Examples/Interception.cs trunk/Source/StructureMap.Testing/Examples/RegisteringWithTheAPI.cs trunk/Source/StructureMap.Testing/Examples.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/GenericsIntegrationTester.cs trunk/Source/StructureMap.Testing/Graph/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/ConventionBasedSetterInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/FillDependenciesTester.cs trunk/Source/StructureMap.Testing/Graph/FullStackFacadeTester.cs trunk/Source/StructureMap.Testing/Graph/GenericsPluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Graph/InstanceTarget.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/CompoundInterceptorTester.cs trunk/Source/StructureMap.Testing/Graph/Interceptors/TypeInterceptionTester.cs trunk/Source/StructureMap.Testing/Graph/ParameterInfoCollection.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/Graph/SetterInjectionEmittingTester.cs trunk/Source/StructureMap.Testing/Graph/SingleImplementationScannerTester.cs trunk/Source/StructureMap.Testing/Graph/Source/XmlMementoSourceTester.cs trunk/Source/StructureMap.Testing/Graph/TestExplicitArguments.cs trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs trunk/Source/StructureMap.Testing/InstanceCacheTester.cs trunk/Source/StructureMap.Testing/InstanceMementoInstanceCreationTester.cs trunk/Source/StructureMap.Testing/MementoTester.cs trunk/Source/StructureMap.Testing/ModelQueryTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryTester.cs trunk/Source/StructureMap.Testing/PerRequestInterceptorTester.cs trunk/Source/StructureMap.Testing/Pipeline/BuildStackTester.cs trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConditionalInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConstructorInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/ContainerDisposalTester.cs trunk/Source/StructureMap.Testing/Pipeline/ContainerIsInTheContainerTester.cs trunk/Source/StructureMap.Testing/Pipeline/DefaultInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/EnumerableInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/GenericsHelperExpressionTester.cs trunk/Source/StructureMap.Testing/Pipeline/HybridBuildLifecycleTester.cs trunk/Source/StructureMap.Testing/Pipeline/MissingInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs trunk/Source/StructureMap.Testing/Pipeline/ObjectBuilderTester.cs trunk/Source/StructureMap.Testing/Pipeline/OptionalSetterInjectionTester.cs trunk/Source/StructureMap.Testing/Pipeline/ProfileManagerTester.cs trunk/Source/StructureMap.Testing/Pipeline/PrototypeInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/RedirectTester.cs trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/StubBuildSession.cs trunk/Source/StructureMap.Testing/Pipeline/ThreadLocalStorageLifecycleTester.cs trunk/Source/StructureMap.Testing/PrimitiveArrayTester.cs trunk/Source/StructureMap.Testing/ReadingRegistriesFromXmlTester.cs trunk/Source/StructureMap.Testing/SpecificationExtensions.cs trunk/Source/StructureMap.Testing/StructureMapConfigurationTester.cs trunk/Source/StructureMap.Testing/TestData/DataMother.cs trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs trunk/Source/StructureMap.Testing/Util/CacheTester.cs trunk/Source/StructureMap.Testing/XmlWriting/ElementChecker.cs trunk/Source/StructureMap.Testing.GenericWidgets/Widgets.cs trunk/Source/StructureMap.Testing.Widget/ArrayConstruction.cs trunk/Source/StructureMap.Testing.Widget/Columns.cs trunk/Source/StructureMap.Testing.Widget/Hierarchy.cs trunk/Source/StructureMap.Testing.Widget/IWidget.cs trunk/Source/StructureMap.Testing.Widget/Rule.cs trunk/Source/StructureMap.Testing.Widget/WidgetMaker.cs trunk/Source/StructureMap.Testing.Widget3/Gateways.cs trunk/Source/StructureMap.Testing.Widget3/IService.cs trunk/Source/StructureMap.Testing.Widget5/AutoFilledGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/BasicGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/CannotBeAutoFilledGridColumn.cs trunk/Source/StructureMap.Testing.Widget5/OtherGridColumn.cs trunk/Source/StructureMapDoctor/Program.cs trunk/Source/TableOfContentsBuilder/Program.cs trunk/Source/TableOfContentsBuilder/Properties/AssemblyInfo.cs Modified: trunk/Source/StructureMap/Attributes/PluggableAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -26,7 +26,7 @@ /// <returns></returns> public static bool MarkedAsPluggable(Type objectType) { - PluggableAttribute att = GetCustomAttribute(objectType, typeof (PluggableAttribute), false) as PluggableAttribute; + var att = GetCustomAttribute(objectType, typeof (PluggableAttribute), false) as PluggableAttribute; return (att != null); } } Modified: trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs =================================================================== --- trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Attributes/PluginFamilyAttribute.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -26,11 +26,7 @@ /// If set, determines the shared "scope" of the instance -- PerRequest, Singleton, ThreadLocal, /// HttpContext, etc. /// </summary> - public InstanceScope Scope - { - get { return _scope; } - set { _scope = value; } - } + public InstanceScope Scope { get { return _scope; } set { _scope = value; } } public Type SourceType { get; set; } @@ -38,20 +34,13 @@ /// InstanceKey of the default instance. Used to implicitly define the default without /// declaring the instance in StructureMap.config /// </summary> - public string DefaultKey - { - get { return _default; } - } + public string DefaultKey { get { return _default; } } /// <summary> /// Declares the target to be built by StructureMap as a Singleton. One object instance will /// be created for each named instance /// </summary> - public bool IsSingleton - { - get { return _scope == InstanceScope.Singleton; } - set { _scope = value ? InstanceScope.Singleton : InstanceScope.PerRequest; } - } + public bool IsSingleton { get { return _scope == InstanceScope.Singleton; } set { _scope = value ? InstanceScope.Singleton : InstanceScope.PerRequest; } } /// <summary> Modified: trunk/Source/StructureMap/BuildSession.cs =================================================================== --- trunk/Source/StructureMap/BuildSession.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/BuildSession.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -1,21 +1,20 @@ using System; -using System.Collections; using System.Collections.Generic; +using System.Linq; using StructureMap.Graph; using StructureMap.Interceptors; using StructureMap.Pipeline; using StructureMap.Util; -using System.Linq; namespace StructureMap { public class BuildSession : IContext { - protected BuildStack _buildStack = new BuildStack(); + private readonly ObjectBuilder _builder; private readonly InstanceCache _cache = new InstanceCache(); private readonly Cache<Type, Func<object>> _defaults; private readonly PipelineGraph _pipelineGraph; - private readonly ObjectBuilder _builder; + protected BuildStack _buildStack = new BuildStack(); public BuildSession(PipelineGraph pipelineGraph, InterceptorLibrary interceptorLibrary, IObjectCache cache) { @@ -45,28 +44,13 @@ { } - protected void clearBuildStack() - { - _buildStack = new BuildStack(); - } + protected PipelineGraph pipelineGraph { get { return _pipelineGraph; } } - protected PipelineGraph pipelineGraph - { - get { return _pipelineGraph; } - } - #region IContext Members - public string RequestedName - { - get; - set; - } + public string RequestedName { get; set; } - public BuildStack BuildStack - { - get { return _buildStack; } - } + public BuildStack BuildStack { get { return _buildStack; } } public Type ParentType { @@ -87,10 +71,7 @@ return (T) CreateInstance(typeof (T), name); } - BuildFrame IContext.Root - { - get { return _buildStack.Root; } - } + BuildFrame IContext.Root { get { return _buildStack.Root; } } public virtual void RegisterDefault(Type pluginType, object defaultObject) { @@ -122,9 +103,17 @@ return list; } + #endregion + public IEnumerable<T> GetAllInstances<T>() + { + return forType(typeof (T)).AllInstances.Select(x => GetInstance<T>()); + } - #endregion + protected void clearBuildStack() + { + _buildStack = new BuildStack(); + } public virtual object CreateInstance(Type pluginType, string name) { @@ -147,7 +136,7 @@ result = _builder.Resolve(pluginType, instance, this); // TODO: HACK ATTACK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - var isUnique = forType(pluginType).Lifecycle is UniquePerRequestLifecycle; + bool isUnique = forType(pluginType).Lifecycle is UniquePerRequestLifecycle; if (!isUnique) { _cache.Set(pluginType, instance, result); @@ -176,11 +165,6 @@ return array; } - public IEnumerable<T> GetAllInstances<T>() - { - return forType(typeof (T)).AllInstances.Select(x => GetInstance<T>()); - } - public IEnumerable<object> GetAllInstances(Type pluginType) { return forType(pluginType).AllInstances.Select(x => CreateInstance(pluginType, x)); Modified: trunk/Source/StructureMap/CloseGenericTypeExpression.cs =================================================================== --- trunk/Source/StructureMap/CloseGenericTypeExpression.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/CloseGenericTypeExpression.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -15,10 +15,11 @@ IList<T> As<T>(); } - public class CloseGenericTypeExpression : OpenGenericTypeSpecificationExpression, OpenGenericTypeListSpecificationExpression + public class CloseGenericTypeExpression : OpenGenericTypeSpecificationExpression, + OpenGenericTypeListSpecificationExpression { + private readonly IContainer _container; private readonly object _subject; - private readonly IContainer _container; private Type _pluginType; public CloseGenericTypeExpression(object subject, IContainer container) @@ -27,7 +28,29 @@ _container = container; } + IList<T> OpenGenericTypeListSpecificationExpression.As<T>() + { + IList list = _container.With(_subject.GetType(), _subject).GetAllInstances(_pluginType); + var returnValue = new List<T>(); + foreach (object o in list) + { + returnValue.Add((T) o); + } + + return returnValue; + } + /// <summary> + /// specify what type you'd like the service returned as + /// </summary> + /// <typeparam name="T"></typeparam> + /// <returns></returns> + T OpenGenericTypeSpecificationExpression.As<T>() + { + return (T) _container.With(_subject.GetType(), _subject).GetInstance(_pluginType); + } + + /// <summary> /// Specify the open generic type that should have a single generic parameter /// </summary> /// <param name="type"></param> @@ -48,32 +71,10 @@ _pluginType = type.MakeGenericType(_subject.GetType()); } - /// <summary> - /// specify what type you'd like the service returned as - /// </summary> - /// <typeparam name="T"></typeparam> - /// <returns></returns> - T OpenGenericTypeSpecificationExpression.As<T>() - { - return (T) _container.With(_subject.GetType(), _subject).GetInstance(_pluginType); - } - public OpenGenericTypeListSpecificationExpression GetAllClosedTypesOf(Type type) { closeType(type); return this; } - - IList<T> OpenGenericTypeListSpecificationExpression.As<T>() - { - IList list = _container.With(_subject.GetType(), _subject).GetAllInstances(_pluginType); - var returnValue = new List<T>(); - foreach (var o in list) - { - returnValue.Add((T) o); - } - - return returnValue; - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -33,18 +33,9 @@ /// <summary> /// Define the Default Instance for this PluginType /// </summary> - public IsExpression<PLUGINTYPE> TheDefault - { - get { return new InstanceExpression<PLUGINTYPE>(i => registerDefault(i)); } - } + public IsExpression<PLUGINTYPE> TheDefault { get { return new InstanceExpression<PLUGINTYPE>(i => registerDefault(i)); } } - public InstanceExpression<PLUGINTYPE> MissingNamedInstanceIs - { - get - { - return new InstanceExpression<PLUGINTYPE>(i => _alterations.Add(family => family.MissingInstance = i)); - } - } + public InstanceExpression<PLUGINTYPE> MissingNamedInstanceIs { get { return new InstanceExpression<PLUGINTYPE>(i => _alterations.Add(family => family.MissingInstance = i)); } } /// <summary> /// Add multiple Instance's to this PluginType @@ -93,7 +84,7 @@ { throw new StructureMapException(231); } - + return alterAndContinue(family => { ConfiguredInstance instance = @@ -113,9 +104,9 @@ // This is *my* team's naming convention for generic parameters // I know you may not like it, but it's my article so there var instance = new SmartInstance<CONCRETETYPE>(); - + registerDefault(instance); - + return instance; } @@ -223,7 +214,8 @@ _children.Add( graph => { - var typeInterceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), (c, o) => interceptor.Process(o, c)); + var typeInterceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), + (c, o) => interceptor.Process(o, c)); graph.InterceptorLibrary.AddInterceptor(typeInterceptor); }); @@ -243,11 +235,11 @@ { Func<IContext, object, object> function = (c, o) => { - handler(c, (PLUGINTYPE)o); + handler(c, (PLUGINTYPE) o); return o; }; - var interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), function); + var interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), function); graph.InterceptorLibrary.AddInterceptor(interceptor); }); @@ -290,7 +282,8 @@ _children.Add( graph => { - var interceptor = new PluginTypeInterceptor(typeof(PLUGINTYPE), (c, o) => handler(c, (PLUGINTYPE)o)); + var interceptor = new PluginTypeInterceptor(typeof (PLUGINTYPE), + (c, o) => handler(c, (PLUGINTYPE) o)); graph.InterceptorLibrary.AddInterceptor(interceptor); }); @@ -306,7 +299,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> AddConcreteType<PLUGGEDTYPE>() { - if (!PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).CanBeAutoFilled) + if (!PluginCache.GetPlugin(typeof (PLUGGEDTYPE)).CanBeAutoFilled) { throw new StructureMapException(231); } @@ -363,7 +356,7 @@ /// <returns></returns> public CreatePluginFamilyExpression<PLUGINTYPE> AlwaysUnique() { - return this.LifecycleIs(new UniquePerRequestLifecycle()); + return LifecycleIs(new UniquePerRequestLifecycle()); } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -80,7 +80,7 @@ return instance; } - + /// <summary> /// Shortcut method to add an additional Instance to this Plugin Type /// as just a Concrete Type. This will only work if the Concrete Type Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -166,7 +166,7 @@ /// <param name="template"></param> /// <returns></returns> SerializedInstance SerializedCopyOf(T template); - + /// <summary> /// Creates an Instance that will load an ASCX user control from the url /// </summary> @@ -183,7 +183,7 @@ ConditionalInstance<T> Conditional(Action<ConditionalInstance<T>.ConditionalInstanceExpression> configuration); } - public class InstanceExpression<T> : IInstanceExpression<T>, ThenItExpression<T> + public class InstanceExpression<T> : IInstanceExpression<T>, ThenItExpression<T> { private readonly Action<Instance> _action; @@ -194,10 +194,7 @@ #region IsExpression<T> Members - IInstanceExpression<T> IsExpression<T>.Is - { - get { return this; } - } + IInstanceExpression<T> IsExpression<T>.Is { get { return this; } } public void IsThis(Instance instance) { @@ -216,12 +213,6 @@ _action(instance); } - private INSTANCE returnInstance<INSTANCE>(INSTANCE instance) where INSTANCE : Instance - { - Instance(instance); - return instance; - } - public SmartInstance<PLUGGEDTYPE> OfConcreteType<PLUGGEDTYPE>() where PLUGGEDTYPE : T { return returnInstance(new SmartInstance<PLUGGEDTYPE>()); @@ -272,15 +263,19 @@ return returnInstance(new UserControlInstance(url)); } - public ConditionalInstance<T> Conditional(Action<ConditionalInstance<T>.ConditionalInstanceExpression> configuration) + public ConditionalInstance<T> Conditional( + Action<ConditionalInstance<T>.ConditionalInstanceExpression> configuration) { return returnInstance(new ConditionalInstance<T>(configuration)); } - IsExpression<T> ThenItExpression<T>.ThenIt + IsExpression<T> ThenItExpression<T>.ThenIt { get { return this; } } + + private INSTANCE returnInstance<INSTANCE>(INSTANCE instance) where INSTANCE : Instance { - get { return this; } + Instance(instance); + return instance; } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ProfileExpression.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -3,8 +3,6 @@ namespace StructureMap.Configuration.DSL.Expressions { - - /// <summary> /// Expression class to help define a runtime Profile /// </summary> @@ -39,13 +37,9 @@ /// <returns></returns> public IsExpression<T> Type<T>() { - return new InstanceExpression<T>(instance => - { - _registry.addExpression(graph => - { - graph.SetDefault(_profileName, typeof(T), instance); - }); - }); + return + new InstanceExpression<T>( + instance => { _registry.addExpression(graph => { graph.SetDefault(_profileName, typeof (T), instance); }); }); } /// <summary> @@ -117,7 +111,6 @@ #region Nested type: InstanceDefaultExpression - /// <summary> /// Expression Builder within defining a Profile /// </summary> @@ -194,7 +187,6 @@ var instance = new ConfiguredInstance(typeof (CONCRETETYPE)); return Use(instance); } - } #endregion Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -8,8 +8,6 @@ namespace StructureMap.Configuration.DSL { - - /// <summary> /// A Registry class provides methods and grammars for configuring a Container or ObjectFactory. /// Using a Registry subclass is the recommended way of configuring a StructureMap Container. @@ -203,7 +201,7 @@ internal static bool IsPublicRegistry(Type type) { - if (type.Assembly == typeof(Registry).Assembly) + if (type.Assembly == typeof (Registry).Assembly) { return false; } @@ -295,30 +293,7 @@ return ForRequestedType<PLUGINTYPE>(); } - #region Nested type: BuildWithExpression - /// <summary> - /// Define the constructor and setter arguments for the default T - /// </summary> - /// <typeparam name="T"></typeparam> - public class BuildWithExpression<T> - { - private readonly SmartInstance<T> _instance; - - public BuildWithExpression(SmartInstance<T> instance) - { - _instance = instance; - } - - public SmartInstance<T> Configure - { - get { return _instance; } - } - } - - #endregion - - /// <summary> /// Creates automatic "policies" for which public setters are considered mandatory /// properties by StructureMap that will be "setter injected" as part of the /// construction process. @@ -337,7 +312,7 @@ /// <param name="expression"></param> public void SelectConstructor<T>(Expression<Func<T>> expression) { - PluginCache.GetPlugin(typeof(T)).UseConstructor(expression); + PluginCache.GetPlugin(typeof (T)).UseConstructor(expression); } public void Forward<FROM, TO>() where FROM : class where TO : class @@ -401,10 +376,32 @@ { var raw = c.GetInstance<U>(); var t = raw as T; - if (t == null) throw new ApplicationException(raw.GetType().AssemblyQualifiedName + " could not be cast to " + typeof(T).AssemblyQualifiedName); + if (t == null) + throw new ApplicationException(raw.GetType().AssemblyQualifiedName + " could not be cast to " + + typeof (T).AssemblyQualifiedName); return t; - }); + }); } + + #region Nested type: BuildWithExpression + + /// <summary> + /// Define the constructor and setter arguments for the default T + /// </summary> + /// <typeparam name="T"></typeparam> + public class BuildWithExpression<T> + { + private readonly SmartInstance<T> _instance; + + public BuildWithExpression(SmartInstance<T> instance) + { + _instance = instance; + } + + public SmartInstance<T> Configure { get { return _instance; } } + } + + #endregion } } \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -1,7 +1,6 @@ using System; using System.Reflection; using StructureMap.Graph; -using StructureMap; using StructureMap.TypeRules; namespace StructureMap.Configuration.DSL @@ -20,7 +19,7 @@ { Matching(prop => prop.PropertyType == typeof (T)); } - + /// <summary> /// Directs StructureMap to tread all public setters with /// a PropertyType that matches the predicate as a @@ -59,7 +58,7 @@ /// <typeparam name="T"></typeparam> public void WithAnyTypeFromNamespaceContainingType<T>() { - WithAnyTypeFromNamespace(typeof(T).Namespace); + WithAnyTypeFromNamespace(typeof (T).Namespace); } /// <summary> Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -14,7 +14,8 @@ private readonly PluginGraph _systemGraph; - public GraphBuilder(Registry[] registries) : this(registries, new PluginGraph()) + public GraphBuilder(Registry[] registries) + : this(registries, new PluginGraph()) { } @@ -40,10 +41,7 @@ _pluginGraph.Seal(); } - public PluginGraph PluginGraph - { - get { return _pluginGraph; } - } + public PluginGraph PluginGraph { get { return _pluginGraph; } } public void AddAssembly(string assemblyName) { @@ -60,10 +58,10 @@ public void AddRegistry(string registryTypeName) { - _pluginGraph.Log.Try(()=> + _pluginGraph.Log.Try(() => { - var type = new TypePath(registryTypeName).FindType(); - Registry registry = (Registry) Activator.CreateInstance(type); + Type type = new TypePath(registryTypeName).FindType(); + var registry = (Registry) Activator.CreateInstance(type); registry.ConfigurePluginGraph(_pluginGraph); }).AndReportErrorAs(290, registryTypeName); } Modified: trunk/Source/StructureMap/Configuration/XmlConstants.cs =================================================================== --- trunk/Source/StructureMap/Configuration/XmlConstants.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Configuration/XmlConstants.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -29,9 +29,9 @@ public const string PLUGIN_NODE = "Plugin"; public const string PLUGIN_TYPE = "PluginType"; public const string PROFILE_NODE = "Profile"; + public const string REGISTRY = "Registry"; public const string SCOPE = "Scope"; public const string STRUCTUREMAP = "StructureMap"; public const string TYPE_ATTRIBUTE = "Type"; - public const string REGISTRY = "Registry"; } } \ No newline at end of file Modified: trunk/Source/StructureMap/ConfigurationExpression.cs =================================================================== --- trunk/Source/StructureMap/ConfigurationExpression.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/ConfigurationExpression.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -1,6 +1,4 @@ -using System; using System.Collections.Generic; -using System.Linq.Expressions; using System.Xml; using StructureMap.Configuration; using StructureMap.Configuration.DSL; @@ -33,10 +31,7 @@ /// If true, directs StructureMap to look for configuration in the App.config. /// The default value is false. /// </summary> - public bool IncludeConfigurationFromConfigFile - { - set { _parserBuilder.UseAndEnforceExistenceOfDefaultFile = value; } - } + public bool IncludeConfigurationFromConfigFile { set { _parserBuilder.UseAndEnforceExistenceOfDefaultFile = value; } } /// <summary> /// Creates and adds a Registry object of type T. @@ -85,11 +80,5 @@ return builder.Build(); } - - } - - - - } \ No newline at end of file Modified: trunk/Source/StructureMap/Construction/InstanceBuilder.cs =================================================================== --- trunk/Source/StructureMap/Construction/InstanceBuilder.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Construction/InstanceBuilder.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -1,5 +1,4 @@ using System; -using StructureMap.Pipeline; namespace StructureMap.Construction { @@ -16,22 +15,19 @@ /// </summary> public class InstanceBuilder : IInstanceBuilder { - private readonly Type _pluggedType; - private readonly Func<IArguments, object> _constructor; private readonly Action<IArguments, object> _buildUp; + private readonly Func<IArguments, object> _constructor; + private readonly Type _pluggedType; - public InstanceBuilder(Type pluggedType, Func<IArguments, object> constructor, Action<IArguments, object> buildUp) + public InstanceBuilder(Type pluggedType, Func<IArguments, object> constructor, + Action<IArguments, object> buildUp) { _pluggedType = pluggedType; _constructor = constructor; _buildUp = buildUp; } - public Type PluggedType { get - { - return _pluggedType; - } - } + public Type PluggedType { get { return _pluggedType; } } public virtual object BuildInstance(IArguments args) { Modified: trunk/Source/StructureMap/Container.cs =================================================================== --- trunk/Source/StructureMap/Container.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Container.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -145,7 +145,6 @@ } - /// <summary> /// Creates or finds the default instance of type T /// </summary> @@ -163,7 +162,6 @@ } - /// <summary> /// Creates or resolves all registered instances of type T /// </summary> @@ -302,7 +300,6 @@ } - /// <summary> /// Creates or resolves all registered instances of the pluginType /// </summary> @@ -475,6 +472,55 @@ #endregion + /// <summary> + /// Injects the given object into a Container by name for the designated + /// pluginType. Mostly used for temporarily setting up return values of the Container + /// to introduce mocks or stubs during automated testing scenarios + /// </summary> + /// <typeparam name="T"></typeparam> + /// <param name="name"></param> + /// <param name="object"></param> + public void Inject<T>(string name, T @object) + { + ObjectInstance instance = new ObjectInstance(@object).WithName(name); + _transientCache.Set(typeof (T), instance, @object); + _pipelineGraph.AddInstance<T>(instance); + } + + /// <summary> + /// Injects the given object into a Container as the default for the designated + /// pluginType. Mostly used for temporarily setting up return values of the Container + /// to introduce mocks or stubs during automated testing scenarios + /// </summary> + /// <param name="pluginType"></param> + /// <param name="object"></param> + public void Inject(Type pluginType, object @object) + { + if (!@object.GetType().CanBeCastTo(pluginType)) + { + throw new StructureMapException(220, pluginType.FullName, + @object.GetType().FullName); + } + + + var instance = new ObjectInstance(@object); + _transientCache.Set(pluginType, instance, @object); + _pipelineGraph.SetDefault(pluginType, instance); + } + + /// <summary> + /// Injects the given object into a Container as the default for the designated + /// PLUGINTYPE. Mostly used for temporarily setting up return values of the Container + /// to introduce mocks or stubs during automated testing scenarios + /// </summary> + /// <typeparam name="PLUGINTYPE"></typeparam> + /// <param name="object"></param> + public void Inject<PLUGINTYPE>(PLUGINTYPE @object) + { + Instance instance = _pipelineGraph.Inject(@object); + _transientCache.Set(typeof (PLUGINTYPE), instance, @object); + } + private object buildInstanceWithArgs(Type pluginType, Instance defaultInstance, ExplicitArguments args, string requestedName) { @@ -534,7 +580,6 @@ } - private BuildSession withNewSession(string name) { return new BuildSession(_pipelineGraph, _interceptorLibrary, _transientCache) @@ -543,6 +588,16 @@ }; } + /// <summary> + /// Sets the default instance for the PluginType + /// </summary> + /// <param name="pluginType"></param> + /// <param name="instance"></param> + public void Inject(Type pluginType, Instance instance) + { + _pipelineGraph.SetDefault(pluginType, instance); + } + #region Nested type: GetInstanceAsExpression public interface GetInstanceAsExpression @@ -588,65 +643,5 @@ } #endregion - - - /// <summary> - /// Injects the given object into a Container by name for the designated - /// pluginType. Mostly used for temporarily setting up return values of the Container - /// to introduce mocks or stubs during automated testing scenarios - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="name"></param> - /// <param name="object"></param> - public void Inject<T>(string name, T @object) - { - ObjectInstance instance = new ObjectInstance(@object).WithName(name); - _transientCache.Set(typeof(T), instance, @object); - _pipelineGraph.AddInstance<T>(instance); - } - - /// <summary> - /// Sets the default instance for the PluginType - /// </summary> - /// <param name="pluginType"></param> - /// <param name="instance"></param> - public void Inject(Type pluginType, Instance instance) - { - _pipelineGraph.SetDefault(pluginType, instance); - } - - /// <summary> - /// Injects the given object into a Container as the default for the designated - /// pluginType. Mostly used for temporarily setting up return values of the Container - /// to introduce mocks or stubs during automated testing scenarios - /// </summary> - /// <param name="pluginType"></param> - /// <param name="object"></param> - public void Inject(Type pluginType, object @object) - { - if (!@object.GetType().CanBeCastTo(pluginType)) - { - throw new StructureMapException(220, pluginType.FullName, - @object.GetType().FullName); - } - - - var instance = new ObjectInstance(@object); - _transientCache.Set(pluginType, instance, @object); - _pipelineGraph.SetDefault(pluginType, instance); - } - - /// <summary> - /// Injects the given object into a Container as the default for the designated - /// PLUGINTYPE. Mostly used for temporarily setting up return values of the Container - /// to introduce mocks or stubs during automated testing scenarios - /// </summary> - /// <typeparam name="PLUGINTYPE"></typeparam> - /// <param name="object"></param> - public void Inject<PLUGINTYPE>(PLUGINTYPE @object) - { - var instance = _pipelineGraph.Inject(@object); - _transientCache.Set(typeof(PLUGINTYPE), instance, @object); - } } } \ No newline at end of file Modified: trunk/Source/StructureMap/Diagnostics/Doctor.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/Doctor.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Diagnostics/Doctor.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -21,7 +21,11 @@ try { - var setup = new AppDomainSetup {ApplicationBase = BinaryPath, ConfigurationFile = ConfigFile}; + var setup = new AppDomainSetup + { + ApplicationBase = BinaryPath, + ConfigurationFile = ConfigFile + }; if (BinaryPath != null) setup.PrivateBinPath = BinaryPath; domain = AppDomain.CreateDomain("StructureMap-Diagnostics", null, setup); var doctor = Modified: trunk/Source/StructureMap/Diagnostics/GraphLog.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Diagnostics/GraphLog.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -14,15 +14,9 @@ private readonly List<string> _sources = new List<string>(); private string _currentSource; - public int ErrorCount - { - get { return _errors.Count; } - } + public int ErrorCount { get { return _errors.Count; } } - public string[] Sources - { - get { return _sources.ToArray(); } - } + public string[] Sources { get { return _sources.ToArray(); } } public void StartSource(string description) { Modified: trunk/Source/StructureMap/Diagnostics/InstanceToken.cs =================================================================== --- trunk/Source/StructureMap/Diagnostics/InstanceToken.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Diagnostics/InstanceToken.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -14,15 +14,9 @@ } - public string Name - { - get { return _name; } - } + public string Name { get { return _name; } } - public string Description - { - get { return _description; } - } + public string Description { get { return _description; } } #region IEquatable<InstanceToken> Members Modified: trunk/Source/StructureMap/Exceptions/StructureMapException.cs =================================================================== --- trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Exceptions/StructureMapException.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -14,8 +14,9 @@ private readonly string _msg; - protected StructureMapException(SerializationInfo info, StreamingContext context) : - base(info, context) + protected StructureMapException(SerializationInfo info, StreamingContext context) + : + base(info, context) { _errorCode = info.GetInt32("errorCode"); _msg = info.GetString("msg"); @@ -37,15 +38,9 @@ _msg += ErrorMessages.GetMessage(ErrorCode, args); } - public override string Message - { - get { return _msg; } - } + public override string Message { get { return _msg; } } - public int ErrorCode - { - get { return _errorCode; } - } + public int ErrorCode { get { return _errorCode; } } public override void GetObjectData(SerializationInfo info, StreamingContext context) Modified: trunk/Source/StructureMap/ExplicitArgsExpression.cs =================================================================== --- trunk/Source/StructureMap/ExplicitArgsExpression.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/ExplicitArgsExpression.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -116,6 +116,5 @@ { return _container.GetAllInstances(type, _args); } - } } \ No newline at end of file Modified: trunk/Source/StructureMap/Extensions.cs =================================================================== --- trunk/Source/StructureMap/Extensions.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Extensions.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -1,7 +1,5 @@ -using System; +using System; using System.Collections.Generic; -using System.Linq; -using System.Text; namespace StructureMap { @@ -33,4 +31,4 @@ return array; } } -} +} \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-12-26 05:37:13 UTC (rev 295) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-12-26 05:45:56 UTC (rev 296) @@ -47,7 +47,7 @@ /// </summary> /// <param name="path"></param> void AssembliesFromPath(string path); - + /// <summary> /// Sweep the designated path and add any Assembly's found in this folder to the /// scanning operation. The assemblyFilter can be used to filter or limit the @@ -72,8 +72,6 @@ #endregion - // ... Other methods - #region Adding TypeScanners /// <summary> @@ -83,6 +81,7 @@ void With(ITypeScanner scanner); void With(IHeavyweightTypeScanner heavyweightScanner); + /// <summary> /// Adds the DefaultConventionScanner to the scanning operations. I.e., a concrete /// class named "Something" that implements "ISomething" will be automatically @@ -173,8 +172,11 @@ void ExcludeType<T>(); // ... Other methods + #endregion + // ... Other methods + /// <summary> /// Scans for PluginType's and Concrete Types that close the given open generic type /// </summary> @@ -189,9 +191,9 @@ { private readonly List<Assembly> _assemblies = new List<Assembly>(); private readonly List<Predicate<Type>> _excludes = new List<Predicate<Type>>(); + private readonly List<IHeavyweightTypeScanner> _heavyweightScanners = new List<IHeavyweightTypeScanner>(); private readonly List<Predicate<Type>> _includes = new List<Predicate<Type>>(); private readonly List<ITypeScanner> _scanners = new List<ITypeScanner>(); - private readonly List<IHeavyweightTypeScanner> _heavyweightScanners = new List<IHeavyweightTypeScanner>(); public AssemblyScanner() { @@ -199,81 +201,9 @@ With<PluggableAttributeScanner>(); } - public int Count - { - get { return _assemblies.Count; } - } + public int Count { get { return _assemblies.Count; } } - internal void ScanForAll(PluginGraph pluginGraph) - { - var heavyweightScan = configureHeavyweightScan(); - - _assemblies.ForEach(assem => scanTypesInAssembly(assem, pluginGraph)); - - performHeavyweightScan(pluginGraph, heavyweightScan); - } - - private void scanTypesInAssembly(Assembly assembly, PluginGraph graph) - { - try - { - foreach (var type in assembly.GetExportedTypes()) - { - if (!isInTheIncludes(type)) continue; - if (isInTheExcludes(type)) continue; - - _scanners.ForEach(scanner => scanner.Process(type, graph)); - } - } - catch (Exception ex) - { - graph.Log.RegisterError(170, ex, assembly.FullName); - } - } - - private TypeMapBuilder configureHeavyweightScan() - { - var typeMapBuilder = new TypeMapBuilder(); - if (_heavyweightScanners.Count > 0) - { - With(typeMapBuilder); - } - return typeMapBuilder; - } - - private void performHeavyweightScan(PluginGraph pluginGraph, TypeMapBuilder typeMapBuilder) - { - var typeMaps = typeMapBuilder.GetTypeMaps(); - _heavyweightScanners.ForEach(scanner => scanner.Process(pluginGraph, typeMaps)); - typeMapBuilder.Dispose(); - } - - private bool isInTheExcludes(Type type) - { - if (_excludes.Count == 0) return false; - - foreach (var exclude in _excludes) - { - if (exclude(type)) return true; - } - - return false; - } - - private bool isInTheIncludes(Type type) - { - if (_includes.Count == 0) return true; - - - foreach (var include in _includes) - { - if (include(type)) return true; - } - - return false; - } - public void Assembly(Assembly assembly) { if (!_assemblies.Contains(assembly)) @@ -287,26 +217,13 @@ Assembly(AppDomain.CurrentDomain.Load(assemblyName)); } - public bool Contains(string assemblyName) - { - foreach (Assembly assembly in _assemblies) - { - if (assembly.GetName().Name == assemblyName) - { - return true; - } - } - - return false; - } - public void With(ITypeScanner scanner) { if (_scanners.Contains(scanner)) return; _scanners.Add(scanner); } - + public void With(IHeavyweightTypeScanner heavyweightScanner) { if (_heavyweightScanners.Contains(heavyweightScanner)) return; @@ -345,25 +262,6 @@ } } - private static Assembly findTheCallingAssembly() - { - var trace = new StackTrace(false); - - Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); - Assembly callingAssembly = null; - for (int i = 0; i < trace.FrameCount; i++) - { - StackFrame frame = trace.GetFrame(i); - Assembly assembly = frame.GetMethod().DeclaringType.Assembly; - if (assembly != thisAssembly) - { - callingAssembly = assembly; - break; - } - } - return callingAssembly; - } - public void AssemblyContainingType<T>() { _assemblies.Add(typeof (T).Assembly); @@ -441,16 +339,14 @@ public void AssembliesFromApplicationBaseDirectory(Predicate<Assembly> assemblyFilter) { - var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; + string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; AssembliesFromPath(baseDirectory, assemblyFilter); - var binPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath; + string binPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath; if (Directory.Exists(binPath)) { AssembliesFromPath(binPath, assemblyFilter); } - - } public void AssembliesFromPath(string path) @@ -460,14 +356,16 @@ public void AssembliesFromPath(string path, Predicate<Assembly> assemblyFilter) { - var assemblyPaths = System.IO.Directory.GetFiles(path).Where(file => - System.IO.Path.GetExtension(file).Equals( - ".exe", StringComparison.OrdinalIgnoreCase) - || - System.IO.Path.GetExtension(file).Equals( - ".dll", StringComparison.OrdinalIgnoreCase)); + IEnumerable<string> assemblyPaths = Directory.GetFiles(path).Where(file => + Path.GetExtension(file).Equals( + ".exe", + StringComparison.OrdinalIgnoreCase) + || + Path.GetExtension(file).Equals( + ".dll", + StringComparison.OrdinalIgnoreCase)); - foreach (var assemblyPath in assemblyPaths) + foreach (string assemblyPath in assemblyPaths) { ... [truncated message content] |