|
From: <jer...@us...> - 2009-12-26 05:37:20
|
Revision: 295
http://structuremap.svn.sourceforge.net/structuremap/?rev=295&view=rev
Author: jeremydmiller
Date: 2009-12-26 05:37:13 +0000 (Sat, 26 Dec 2009)
Log Message:
-----------
The big, big, big switch from IL generation to dynamic Func's. Ding dong, the witch is dead.
Modified Paths:
--------------
trunk/Source/StructureMap/BuildSession.cs
trunk/Source/StructureMap/Container.cs
trunk/Source/StructureMap/IContext.cs
trunk/Source/StructureMap/InstanceMemento.cs
trunk/Source/StructureMap/PipelineGraph.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/TypeExtensions.cs
Removed Paths:
-------------
trunk/Source/StructureMap/InstanceBuilder.cs
trunk/Source/StructureMap/InstanceBuilderList.cs
trunk/Source/StructureMap/InstanceFamily.cs
Modified: trunk/Source/StructureMap/BuildSession.cs
===================================================================
--- trunk/Source/StructureMap/BuildSession.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/BuildSession.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -1,9 +1,11 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using StructureMap.Graph;
using StructureMap.Interceptors;
using StructureMap.Pipeline;
using StructureMap.Util;
+using System.Linq;
namespace StructureMap
{
@@ -75,7 +77,7 @@
}
}
- T IContext.GetInstance<T>()
+ public T GetInstance<T>()
{
return (T) CreateInstance(typeof (T));
}
@@ -120,6 +122,8 @@
return list;
}
+
+
#endregion
public virtual object CreateInstance(Type pluginType, string name)
@@ -172,6 +176,16 @@
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));
+ }
+
public virtual object CreateInstance(Type pluginType)
{
return _defaults[pluginType]();
Modified: trunk/Source/StructureMap/Container.cs
===================================================================
--- trunk/Source/StructureMap/Container.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/Container.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using StructureMap.Configuration.DSL;
+using StructureMap.Construction;
using StructureMap.Diagnostics;
using StructureMap.Exceptions;
using StructureMap.Graph;
@@ -241,8 +242,9 @@
IConfiguredInstance instance = _pipelineGraph.GetDefault(pluggedType) as IConfiguredInstance
?? new ConfiguredInstance(pluggedType);
- InstanceBuilder builder = PluginCache.FindBuilder(pluggedType);
- builder.BuildUp(instance, withNewSession(Plugin.DEFAULT), target);
+ IInstanceBuilder builder = PluginCache.FindBuilder(pluggedType);
+ var arguments = new Arguments(instance, withNewSession(Plugin.DEFAULT));
+ builder.BuildUp(arguments, target);
}
/// <summary>
@@ -481,11 +483,11 @@
defaultInstance = new ConfiguredInstance(pluginType);
}
- var basicInstance = defaultInstance as BasicInstance;
+ var basicInstance = defaultInstance as ConstructorInstance;
Instance instance = basicInstance == null
? defaultInstance
- : new ExplicitInstance(pluginType, args, basicInstance);
+ : basicInstance.Override(args);
BuildSession session = withNewSession(requestedName);
@@ -516,11 +518,10 @@
_pipelineGraph = new PipelineGraph(pluginGraph);
- PluginCache.Compile();
-
_pipelineGraph.Inject<IContainer>(this);
}
+ [Obsolete("delegate to something cleaner in BuildSession")]
private IList<T> getListOfTypeWithSession<T>(BuildSession session)
{
var list = new List<T>();
Modified: trunk/Source/StructureMap/IContext.cs
===================================================================
--- trunk/Source/StructureMap/IContext.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/IContext.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -67,10 +67,18 @@
/// <summary>
/// Gets all objects in the current object graph that can be cast
- /// to T
+ /// to T that have already been created
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
IEnumerable<T> All<T>() where T : class;
+
+
+ /// <summary>
+ /// Creates/Resolves every configured instance of PlutinType T
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns></returns>
+ IEnumerable<T> GetAllInstances<T>();
}
}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/InstanceBuilder.cs
===================================================================
--- trunk/Source/StructureMap/InstanceBuilder.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/InstanceBuilder.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -1,25 +0,0 @@
-using System;
-using StructureMap.Pipeline;
-
-namespace StructureMap
-{
-#pragma warning disable 169
- /// <summary>
- /// Base class for creating an object instance from an InstanceMemento. SubClasses are
- /// emitted for each concrete Plugin with constructor parameters.
- /// </summary>
- public abstract class InstanceBuilder
- {
- private Container _manager;
-
- // DO NOT ELIMINATE THIS METHOD
- public InstanceBuilder(){}
-
- public abstract Type PluggedType { get; }
-
- public abstract object BuildInstance(IConfiguredInstance instance, BuildSession session);
-
- public virtual void BuildUp(IConfiguredInstance instance, BuildSession session, object target) { }
- }
-#pragma warning restore 169
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/InstanceBuilderList.cs
===================================================================
--- trunk/Source/StructureMap/InstanceBuilderList.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/InstanceBuilderList.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -1,117 +0,0 @@
-using System;
-using System.Collections.Generic;
-using StructureMap.Emitting;
-using StructureMap.Graph;
-using StructureMap.TypeRules;
-
-namespace StructureMap
-{
- public class InstanceBuilderList
- {
- private readonly Dictionary<string, Type> _aliases = new Dictionary<string, Type>();
- private readonly Dictionary<Type, InstanceBuilder> _builders = new Dictionary<Type, InstanceBuilder>();
- private readonly Type _pluginType;
-
-
- public InstanceBuilderList(Type pluginType, IEnumerable<Plugin> plugins)
- {
- _pluginType = pluginType;
- processPlugins(plugins);
- }
-
- public InstanceBuilderList(Type pluginType)
- {
- _pluginType = pluginType;
- }
-
- public int BuilderCount
- {
- get { return _builders.Count; }
- }
-
-
- public InstanceBuilder FindByType(Type pluggedType)
- {
- if (pluggedType == null)
- {
- return null;
- }
-
- if (_builders.ContainsKey(pluggedType))
- {
- return _builders[pluggedType];
- }
-
- // Add a missing PluggedType if we can
- if (pluggedType.CanBeCastTo(_pluginType) && Constructor.HasConstructors(pluggedType))
- {
- var plugin = new Plugin(pluggedType);
- processPlugin(plugin);
-
- return _builders[pluggedType];
- }
-
- return null;
- }
-
- public InstanceBuilder FindByConcreteKey(string concreteKey)
- {
- if (_aliases.ContainsKey(concreteKey))
- {
- Type pluggedType = _aliases[concreteKey];
- return FindByType(pluggedType);
- }
-
- return null;
- }
-
- private void processPlugin(Plugin plugin)
- {
- processPlugins(new[] {plugin});
- }
-
- private void processPlugins(IEnumerable<Plugin> plugins)
- {
- foreach (Plugin plugin in plugins)
- {
- if (_aliases.ContainsKey(plugin.ConcreteKey))
- {
- continue;
- }
-
- _aliases.Add(plugin.ConcreteKey, plugin.PluggedType);
- }
-
- List<InstanceBuilder> list = createInstanceBuilders(plugins);
- foreach (InstanceBuilder builder in list)
- {
- _builders.Add(builder.PluggedType, builder);
- }
- }
-
- private List<InstanceBuilder> createInstanceBuilders(IEnumerable<Plugin> plugins)
- {
- var list = new List<Plugin>();
- foreach (Plugin plugin in plugins)
- {
- if (!_builders.ContainsKey(plugin.PluggedType))
- {
- list.Add(plugin);
- }
- }
-
- var builderAssembly = new InstanceBuilderAssembly(list);
- return builderAssembly.Compile();
- }
-
- public void Add(Plugin plugin)
- {
- Add(new[] {plugin});
- }
-
- public void Add(IEnumerable<Plugin> plugins)
- {
- processPlugins(plugins);
- }
- }
-}
\ No newline at end of file
Deleted: trunk/Source/StructureMap/InstanceFamily.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFamily.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/InstanceFamily.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -1,6 +0,0 @@
-namespace StructureMap
-{
- public class InstanceFamily
- {
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/InstanceMemento.cs
===================================================================
--- trunk/Source/StructureMap/InstanceMemento.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/InstanceMemento.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -193,7 +193,6 @@
return getPropertyValue(XmlConstants.PLUGGED_TYPE);
}
- // TODO -- this is where we can read other types
public Instance ReadInstance(PluginGraph pluginGraph, Type pluginType)
{
try
Modified: trunk/Source/StructureMap/PipelineGraph.cs
===================================================================
--- trunk/Source/StructureMap/PipelineGraph.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/PipelineGraph.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -132,6 +132,7 @@
return _factories[pluginType];
}
+ [Obsolete("Replace this with a Cache")]
private void createFactoryIfMissing(Type pluginType)
{
if (!_factories.ContainsKey(pluginType))
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/StructureMap.csproj 2009-12-26 05:37:13 UTC (rev 295)
@@ -144,16 +144,13 @@
<Compile Include="Diagnostics\TextLine.cs" />
<Compile Include="Diagnostics\TextReportWriter.cs" />
<Compile Include="Diagnostics\WhatDoIHaveWriter.cs" />
- <Compile Include="Emitting\ArgumentEmitter.cs" />
<Compile Include="Exceptions\StructureMapConfigurationException.cs" />
<Compile Include="ExplicitArgsExpression.cs" />
<Compile Include="Graph\Constructor.cs" />
<Compile Include="Graph\IArgumentVisitor.cs" />
<Compile Include="Graph\IPluginFamily.cs" />
<Compile Include="Graph\AssemblyScanner.cs" />
- <Compile Include="InstanceBuilderList.cs" />
<Compile Include="InstanceCache.cs" />
- <Compile Include="InstanceFamily.cs" />
<Compile Include="Interceptors\MatchedTypeInterceptor.cs" />
<Compile Include="PipelineGraph.cs" />
<Compile Include="Pipeline\ConfiguredInstance.cs" />
@@ -217,39 +214,6 @@
<Compile Include="Configuration\XmlConstants.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="Emitting\BuildInstanceMethod.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\ClassBuilder.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\DynamicAssembly.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\InstanceBuilderAssembly.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\Method.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\Parameters\ChildArrayParameterEmitter.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\Parameters\ChildParameterEmitter.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\Parameters\EnumParameterEmitter.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\Parameters\ParameterEmitter.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\Parameters\PrimitiveParameterEmitter.cs">
- <SubType>Code</SubType>
- </Compile>
- <Compile Include="Emitting\Parameters\StringParameterEmitter.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="Exceptions\InstancePropertyValueException.cs">
<SubType>Code</SubType>
</Compile>
@@ -285,9 +249,6 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="IContainer.cs" />
- <Compile Include="InstanceBuilder.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="InstanceFactory.cs">
<SubType>Code</SubType>
</Compile>
@@ -382,13 +343,16 @@
<Compile Include="Configuration\PrimitiveArrayReader.cs" />
<Compile Include="Configuration\TypeReaderFactory.cs" />
<Compile Include="Configuration\XmlExtensions.cs" />
+ <Compile Include="Construction\BuilderCompiler.cs" />
+ <Compile Include="Construction\ConstructorFunctionBuilder.cs" />
+ <Compile Include="Construction\IArguments.cs" />
+ <Compile Include="Construction\InstanceBuilder.cs" />
+ <Compile Include="Construction\SetterBuilder.cs" />
<Compile Include="Diagnostics\Doctor.cs" />
<Compile Include="Diagnostics\DoctorReport.cs" />
<Compile Include="Diagnostics\DoctorResult.cs" />
<Compile Include="Diagnostics\DoctorRunner.cs" />
<Compile Include="Diagnostics\ValidationError.cs" />
- <Compile Include="Emitting\BuildUpMethod.cs" />
- <Compile Include="Emitting\Parameters\Methods.cs" />
<Compile Include="ErrorMessages.cs" />
<Compile Include="Example.cs" />
<Compile Include="Extensions.cs" />
@@ -401,6 +365,7 @@
<Compile Include="Graph\PluginCache.cs" />
<Compile Include="Graph\SingleImplementationScanner.cs" />
<Compile Include="IContext.cs" />
+ <Compile Include="Pipeline\Arguments.cs" />
<Compile Include="Pipeline\ArrayCoercion.cs" />
<Compile Include="Pipeline\ConditionalInstance.cs" />
<Compile Include="Pipeline\ConstructorInstance.cs" />
Modified: trunk/Source/StructureMap/TypeExtensions.cs
===================================================================
--- trunk/Source/StructureMap/TypeExtensions.cs 2009-12-26 05:36:53 UTC (rev 294)
+++ trunk/Source/StructureMap/TypeExtensions.cs 2009-12-26 05:37:13 UTC (rev 295)
@@ -1,13 +1,41 @@
using System;
+using System.Collections.Generic;
using StructureMap.Graph;
using StructureMap.Pipeline;
namespace StructureMap
{
+ public static class BasicExtensions
+ {
+ public static void TryGet<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key,
+ Action<TValue> action)
+ {
+ TValue value;
+ if (dictionary.TryGetValue(key, out value))
+ {
+ action(value);
+ }
+ }
+
+ public static T As<T>(this object target) where T : class
+ {
+ return target as T;
+ }
+
+ public static bool IsIn<T>(this T target, IList<T> list)
+ {
+ return list.Contains(target);
+ }
+ }
+
namespace TypeRules
{
public static class TypeExtensions
{
+
+
+
+
public static bool Closes(this Type type, Type openType)
{
var baseType = type.BaseType;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|