|
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.
|