You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
|
Feb
(5) |
Mar
(9) |
Apr
(9) |
May
(4) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
| 2008 |
Jan
(11) |
Feb
(6) |
Mar
|
Apr
(16) |
May
(28) |
Jun
(13) |
Jul
(3) |
Aug
(19) |
Sep
(11) |
Oct
(37) |
Nov
(1) |
Dec
(17) |
| 2009 |
Jan
(16) |
Feb
(6) |
Mar
|
Apr
(6) |
May
(1) |
Jun
(10) |
Jul
(4) |
Aug
(4) |
Sep
(4) |
Oct
(8) |
Nov
(3) |
Dec
(45) |
| 2010 |
Jan
(8) |
Feb
(21) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
|
From: <jer...@us...> - 2009-12-03 20:55:01
|
Revision: 275
http://structuremap.svn.sourceforge.net/structuremap/?rev=275&view=rev
Author: jeremydmiller
Date: 2009-12-03 20:54:50 +0000 (Thu, 03 Dec 2009)
Log Message:
-----------
convenience method on ChildInstance. Other convenience stuff for Dovetail
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Container.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/StructureMapException.resx
trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs
trunk/Source/StructureMap.Testing/PerRequestInterceptorTester.cs
trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs
trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap/Example.cs
trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeOnOpenGenericsTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -109,7 +109,13 @@
/// <returns></returns>
public SmartInstance<CONCRETETYPE> Use<CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE
{
- return TheDefault.Is.OfConcreteType<CONCRETETYPE>();
+ // 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;
}
/// <summary>
@@ -147,13 +153,37 @@
/// Convenience method to mark a PluginFamily as a Singleton
/// </summary>
/// <returns></returns>
- public CreatePluginFamilyExpression<PLUGINTYPE> AsSingletons()
+ public CreatePluginFamilyExpression<PLUGINTYPE> Singleton()
{
- _alterations.Add(family => family.SetScopeTo(InstanceScope.Singleton));
+ return lifecycleIs(InstanceScope.Singleton);
+ }
+
+ private CreatePluginFamilyExpression<PLUGINTYPE> lifecycleIs(InstanceScope lifecycle)
+ {
+ _alterations.Add(family => family.SetScopeTo(lifecycle));
return this;
}
/// <summary>
+ /// Convenience method to mark a PluginFamily as a Hybrid lifecycle
+ /// </summary>
+ /// <returns></returns>
+ public CreatePluginFamilyExpression<PLUGINTYPE> HybridHttpOrThreadLocalScoped()
+ {
+ return lifecycleIs(InstanceScope.Hybrid);
+ }
+
+ /// <summary>
+ /// Convenience method to mark a PluginFamily as HttpContext scoped
+ /// </summary>
+ /// <returns></returns>
+ public CreatePluginFamilyExpression<PLUGINTYPE> HttpContextScoped()
+ {
+ return lifecycleIs(InstanceScope.HttpContext);
+ }
+
+
+ /// <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>
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -169,7 +169,7 @@
/// <returns></returns>
public CreatePluginFamilyExpression<PLUGINTYPE> ForSingletonOf<PLUGINTYPE>()
{
- return ForRequestedType<PLUGINTYPE>().AsSingletons();
+ return ForRequestedType<PLUGINTYPE>().Singleton();
}
/// <summary>
@@ -412,7 +412,7 @@
/// <returns></returns>
public CreatePluginFamilyExpression<PLUGINTYPE> For<PLUGINTYPE>()
{
- return ForRequestedType<PLUGINTYPE>();
+ return new CreatePluginFamilyExpression<PLUGINTYPE>(this);
}
/// <summary>
Modified: trunk/Source/StructureMap/Container.cs
===================================================================
--- trunk/Source/StructureMap/Container.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap/Container.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -23,7 +23,15 @@
var expression = new ConfigurationExpression();
action(expression);
- construct(expression.BuildGraph());
+ // As explained later in the article,
+ // PluginGraph is part of the Semantic Model
+ // of StructureMap
+ PluginGraph graph = expression.BuildGraph();
+
+ // Take the PluginGraph object graph and
+ // dynamically emit classes to build the
+ // configured objects
+ construct(graph);
}
public Container(Registry registry)
Added: trunk/Source/StructureMap/Example.cs
===================================================================
--- trunk/Source/StructureMap/Example.cs (rev 0)
+++ trunk/Source/StructureMap/Example.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -0,0 +1,101 @@
+using System;
+
+namespace StructureMap
+{
+ public interface IMessageSender
+ {
+ void SendMessage(string text, string sender, string receiver);
+ }
+
+ public class FluentMessageSender
+ {
+ private readonly IMessageSender _messageSender;
+
+ public FluentMessageSender(IMessageSender sender)
+ {
+ _messageSender = sender;
+ }
+
+ public SendExpression SendText(string text)
+ {
+ return new SendExpression(text, _messageSender);
+ }
+
+ public class SendExpression : ToExpression
+ {
+ private readonly string _text;
+ private readonly IMessageSender _messageSender;
+ private string _sender;
+
+ public SendExpression(string text, IMessageSender messageSender)
+ {
+ _text = text;
+ _messageSender = messageSender;
+ }
+
+ public ToExpression From(string sender)
+ {
+ _sender = sender;
+ return this;
+ }
+
+ void ToExpression.To(string receiver)
+ {
+ _messageSender.SendMessage(_text, _sender, receiver);
+ }
+ }
+
+ public interface ToExpression
+ {
+ void To(string receiver);
+ }
+ }
+
+ public class SendMessageRequest
+ {
+ public string Text { get; set; }
+ public string Sender { get; set; }
+ public string Receiver { get; set; }
+ }
+
+ public class ParameterObjectMessageSender
+ {
+ public void Send(SendMessageRequest request)
+ {
+ // send the message
+ }
+ }
+
+ public class APIConsumer
+ {
+ // Snippet from a class that uses IMessageSender
+ public void SendMessage(IMessageSender sender)
+ {
+ // Is this right?
+ sender.SendMessage("the message body", "PARTNER001", "PARTNER002");
+
+ // or this?
+ sender.SendMessage("PARTNER001", "the message body", "PARTNER002");
+
+ // or this?
+ sender.SendMessage("PARTNER001", "PARTNER002", "the message body");
+ }
+
+ public void SendMessageFluently(FluentMessageSender sender)
+ {
+ sender
+ .SendText("the message body")
+ .From("PARTNER001").To("PARTNER002");
+ }
+
+ public void SendMessageAsParameter(ParameterObjectMessageSender sender)
+ {
+ sender.Send(new SendMessageRequest()
+ {
+ Text = "the message body",
+ Receiver = "PARTNER001",
+ Sender = "PARTNER002"
+ });
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -116,14 +116,27 @@
/// <returns></returns>
public ChildInstanceExpression Child<CONSTRUCTORARGUMENTTYPE>()
{
- string propertyName = findPropertyName<CONSTRUCTORARGUMENTTYPE>();
+ Type dependencyType = typeof(CONSTRUCTORARGUMENTTYPE);
+ return Child(dependencyType);
+ }
+
+ /// <summary>
+ /// Start the definition of a child instance for type CONSTRUCTORARGUMENTTYPE
+ /// </summary>
+ /// <typeparam name="CONSTRUCTORARGUMENTTYPE"></typeparam>
+ /// <returns></returns>
+ public ChildInstanceExpression Child(Type dependencyType)
+ {
+ string propertyName = findPropertyName(dependencyType);
+
ChildInstanceExpression child = Child(propertyName);
- child.ChildType = typeof (CONSTRUCTORARGUMENTTYPE);
+ child.ChildType = dependencyType;
return child;
}
+
/// <summary>
/// Inline definition of a constructor or a setter property dependency
/// </summary>
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -226,12 +226,19 @@
protected string findPropertyName<PLUGINTYPE>()
{
+ Type dependencyType = typeof(PLUGINTYPE);
+
+ return findPropertyName(dependencyType);
+ }
+
+ protected string findPropertyName(Type dependencyType)
+ {
var plugin = new Plugin(_pluggedType);
- string propertyName = plugin.FindArgumentNameForType<T>();
+ string propertyName = plugin.FindArgumentNameForType(dependencyType);
if (string.IsNullOrEmpty(propertyName))
{
- throw new StructureMapException(305, typeof(PLUGINTYPE));
+ throw new StructureMapException(305, dependencyType);
}
return propertyName;
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap/StructureMap.csproj 2009-12-03 20:54:50 UTC (rev 275)
@@ -390,6 +390,7 @@
<Compile Include="Emitting\BuildUpMethod.cs" />
<Compile Include="Emitting\Parameters\Methods.cs" />
<Compile Include="ErrorMessages.cs" />
+ <Compile Include="Example.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Graph\FamilyAttributeScanner.cs" />
<Compile Include="Graph\FindAllTypesFilter.cs" />
Modified: trunk/Source/StructureMap/StructureMapException.resx
===================================================================
--- trunk/Source/StructureMap/StructureMapException.resx 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap/StructureMapException.resx 2009-12-03 20:54:50 UTC (rev 275)
@@ -277,4 +277,7 @@
<data name="245" xml:space="preserve">
<value>Error while trying to create an InstanceBuilder for {0}</value>
</data>
+ <data name="25" xml:space="preserve">
+ <value>Only a concrete type may be used here</value>
+ </data>
</root>
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeOnOpenGenericsTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeOnOpenGenericsTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Bugs/SpecifyScopeOnOpenGenericsTester.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -0,0 +1,27 @@
+using NUnit.Framework;
+using StructureMap.Attributes;
+
+namespace StructureMap.Testing.Bugs
+{
+ [TestFixture]
+ public class SpecifyScopeOnOpenGenericsTester
+ {
+
+ [Test]
+ public void should_obey_scope_set_on_open_type()
+ {
+ var container = new Container(x =>
+ {
+ x.For(typeof (IOpenType<>)).CacheBy(InstanceScope.Singleton).Use(typeof (OpenType<>));
+ });
+
+ var o1 = container.GetInstance<IOpenType<string>>();
+ var o2 = container.GetInstance<IOpenType<string>>();
+
+ o1.ShouldBeTheSameAs(o2);
+ }
+ }
+
+ public interface IOpenType<T>{}
+ public class OpenType<T> : IOpenType<T>{}
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -145,7 +145,7 @@
{
var registry = new Registry();
CreatePluginFamilyExpression<IGateway> expression =
- registry.BuildInstancesOf<IGateway>().AsSingletons();
+ registry.BuildInstancesOf<IGateway>().Singleton();
Assert.IsNotNull(expression);
PluginGraph pluginGraph = registry.Build();
Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap.Testing/Configuration/DSL/InjectArrayTester.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -200,7 +200,7 @@
{
IContainer container = new Container(r =>
{
- r.ForRequestedType<Processor>().TheDefault.Is.OfConcreteType<Processor>()
+ r.For<Processor>().Use<Processor>()
.WithCtorArg("name").EqualTo("Jeremy")
.TheArrayOf<IHandler>().Contains(x =>
{
Modified: trunk/Source/StructureMap.Testing/PerRequestInterceptorTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/PerRequestInterceptorTester.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap.Testing/PerRequestInterceptorTester.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -59,17 +59,17 @@
ObjectFactory.Initialize(
x =>
{
- x.BuildInstancesOf<Session>()
+ x.ForRequestedType<Session>()
.AlwaysUnique()
.TheDefaultIsConcreteType<Session>();
- x.BuildInstancesOf<Model1>()
+ x.ForRequestedType<Model1>()
.TheDefaultIsConcreteType<Model1>();
- x.BuildInstancesOf<Model2>()
+ x.ForRequestedType<Model2>()
.TheDefaultIsConcreteType<Model2>();
- x.BuildInstancesOf<Shell>()
+ x.ForRequestedType<Shell>()
.TheDefaultIsConcreteType<Shell>();
});
Modified: trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap.Testing/Pipeline/BuildStrategiesTester.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -46,7 +46,7 @@
{
var container = new Container(x =>
{
- x.ForRequestedType<IService>().AsSingletons().AddInstances(o =>
+ x.ForRequestedType<IService>().Singleton().AddInstances(o =>
{
o.Is.ConstructedBy(() => new ColorService("Red")).WithName("Red");
o.Is.ConstructedBy(() => new ColorService("Green")).WithName("Green");
Modified: trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs 2009-12-03 20:54:50 UTC (rev 275)
@@ -4,6 +4,7 @@
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
using StructureMap.Pipeline;
+using StructureMap.Testing.Configuration.DSL;
using StructureMap.Testing.GenericWidgets;
using StructureMap.Testing.Widget;
using StructureMap.Testing.Widget2;
@@ -63,7 +64,6 @@
var instance = new ConfiguredInstance(GetType());
-
using (mocks.Record())
{
Expect.Call(builder.BuildInstance(instance, session)).Return(theObjectBuilt);
@@ -277,5 +277,20 @@
instance.Build(GetType(), new StubBuildSession(), builder);
});
}
+
+ [Test]
+ public void use_the_child_function()
+ {
+ var theRule = new ARule();
+
+ var container = new Container(x =>
+ {
+ x.For(typeof (ClassWithDependency)).Use(typeof (ClassWithDependency)).Child(typeof (Rule)).Is(theRule);
+ });
+
+ container.GetInstance<ClassWithDependency>().Rule.ShouldBeTheSameAs(theRule);
+ }
}
+
+
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-11-13 17:33:27 UTC (rev 274)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-12-03 20:54:50 UTC (rev 275)
@@ -187,6 +187,7 @@
<Compile Include="Bugs\ScanIndexerBugTester.cs" />
<Compile Include="Bugs\SingletonShouldBeLazy.cs" />
<Compile Include="Bugs\SpecifyScopeInConfigureTester.cs" />
+ <Compile Include="Bugs\SpecifyScopeOnOpenGenericsTester.cs" />
<Compile Include="Bugs\StaticPropertyCausesJITExceptionTester.cs" />
<Compile Include="BuildSessionTester.cs" />
<Compile Include="BuildUpIntegratedTester.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2009-11-13 17:50:20
|
Revision: 274
http://structuremap.svn.sourceforge.net/structuremap/?rev=274&view=rev
Author: flimflan
Date: 2009-11-13 17:33:27 +0000 (Fri, 13 Nov 2009)
Log Message:
-----------
Fix crash when calling WhatDoIHave() on a nested container.
Modified Paths:
--------------
trunk/Source/StructureMap/PipelineGraph.cs
trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs
trunk/Source/StructureMap.Testing/SpecificationExtensions.cs
Modified: trunk/Source/StructureMap/PipelineGraph.cs
===================================================================
--- trunk/Source/StructureMap/PipelineGraph.cs 2009-11-02 15:07:59 UTC (rev 273)
+++ trunk/Source/StructureMap/PipelineGraph.cs 2009-11-13 17:33:27 UTC (rev 274)
@@ -41,15 +41,16 @@
}
}
- private PipelineGraph(ProfileManager profileManager, GenericsPluginGraph genericsGraph)
+ private PipelineGraph(ProfileManager profileManager, GenericsPluginGraph genericsGraph, GraphLog log)
{
_profileManager = profileManager;
_genericsGraph = genericsGraph;
+ _log = log;
}
public PipelineGraph Clone()
{
- var clone = new PipelineGraph(_profileManager.Clone(), _genericsGraph.Clone())
+ var clone = new PipelineGraph(_profileManager.Clone(), _genericsGraph.Clone(), _log)
{
_missingFactory = _missingFactory
};
Modified: trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs 2009-11-02 15:07:59 UTC (rev 273)
+++ trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs 2009-11-13 17:33:27 UTC (rev 274)
@@ -1,7 +1,7 @@
using NUnit.Framework;
using StructureMap.Attributes;
-using StructureMap.Configuration.DSL;
using StructureMap.Testing.GenericWidgets;
+using StructureMap.Testing.Graph;
using StructureMap.Testing.Widget;
namespace StructureMap.Testing.Pipeline
@@ -190,5 +190,17 @@
parentWidget.ShouldBeOfType<ColorWidget>().Color.ShouldEqual("red");
childWidget1.ShouldBeOfType<ColorWidget>().Color.ShouldEqual("green");
}
+
+ [Test]
+ public void allow_nested_container_to_report_what_it_has()
+ {
+ var container = new Container(x => x.For<IAutomobile>().Use<Mustang>());
+
+ var nestedContainer = container.GetNestedContainer();
+ nestedContainer.Inject<IEngine>(new PushrodEngine());
+
+ container.WhatDoIHave().ShouldNotBeEmpty().ShouldNotContain(typeof(IEngine).Name);
+ nestedContainer.WhatDoIHave().ShouldNotBeEmpty().ShouldContain(typeof(IEngine).Name);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/SpecificationExtensions.cs
===================================================================
--- trunk/Source/StructureMap.Testing/SpecificationExtensions.cs 2009-11-02 15:07:59 UTC (rev 273)
+++ trunk/Source/StructureMap.Testing/SpecificationExtensions.cs 2009-11-13 17:33:27 UTC (rev 274)
@@ -106,9 +106,10 @@
Assert.IsNotEmpty(collection);
}
- public static void ShouldNotBeEmpty(this string aString)
+ public static string ShouldNotBeEmpty(this string aString)
{
Assert.IsNotEmpty(aString);
+ return aString;
}
public static void ShouldContain(this string actual, string expected)
@@ -116,6 +117,12 @@
StringAssert.Contains(expected, actual);
}
+ public static string ShouldNotContain(this string actual, string expected)
+ {
+ Assert.IsTrue(!actual.Contains(expected));
+ return actual;
+ }
+
public static string ShouldBeEqualIgnoringCase(this string actual, string expected)
{
StringAssert.AreEqualIgnoringCase(expected, actual);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2009-11-02 15:08:09
|
Revision: 273
http://structuremap.svn.sourceforge.net/structuremap/?rev=273&view=rev
Author: flimflan
Date: 2009-11-02 15:07:59 +0000 (Mon, 02 Nov 2009)
Log Message:
-----------
Move TypeExtensions to StructureMap.TypeRules namespace so that it is not automatically imported by consumers.
Modified Paths:
--------------
trunk/Source/StructureMap/CloseGenericTypeExpression.cs
trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs
trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs
trunk/Source/StructureMap/Container.cs
trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs
trunk/Source/StructureMap/Graph/AssemblyScanner.cs
trunk/Source/StructureMap/Graph/Constructor.cs
trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs
trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs
trunk/Source/StructureMap/Graph/ITypeScanner.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/SetterProperty.cs
trunk/Source/StructureMap/InstanceBuilderList.cs
trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs
trunk/Source/StructureMap/Pipeline/LiteralInstance.cs
trunk/Source/StructureMap/Pipeline/PropertyExpression.cs
trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs
trunk/Source/StructureMap/Pipeline/UserControlInstance.cs
trunk/Source/StructureMap/TypeExtensions.cs
trunk/Source/StructureMap.Testing/Examples/Interception.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs
trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs
Modified: trunk/Source/StructureMap/CloseGenericTypeExpression.cs
===================================================================
--- trunk/Source/StructureMap/CloseGenericTypeExpression.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/CloseGenericTypeExpression.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using StructureMap.TypeRules;
namespace StructureMap
{
Modified: trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,5 +1,6 @@
using System;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap.Configuration.DSL
{
Modified: trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Configuration/DSL/SetterConvention.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -2,6 +2,7 @@
using System.Reflection;
using StructureMap.Graph;
using StructureMap;
+using StructureMap.TypeRules;
namespace StructureMap.Configuration.DSL
{
Modified: trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -2,6 +2,7 @@
using System.Xml;
using StructureMap.Graph;
using StructureMap.Pipeline;
+using StructureMap.TypeRules;
namespace StructureMap.Configuration
{
Modified: trunk/Source/StructureMap/Container.cs
===================================================================
--- trunk/Source/StructureMap/Container.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Container.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -7,6 +7,7 @@
using StructureMap.Graph;
using StructureMap.Interceptors;
using StructureMap.Pipeline;
+using StructureMap.TypeRules;
namespace StructureMap
{
Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs
===================================================================
--- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -2,6 +2,7 @@
using System.IO;
using System.Text;
using StructureMap.Pipeline;
+using StructureMap.TypeRules;
namespace StructureMap.Diagnostics
{
Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Reflection;
+using StructureMap.TypeRules;
namespace StructureMap.Graph
{
Modified: trunk/Source/StructureMap/Graph/Constructor.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Constructor.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Graph/Constructor.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,6 +1,7 @@
using System;
using System.Linq.Expressions;
using System.Reflection;
+using StructureMap.TypeRules;
namespace StructureMap.Graph
{
Modified: trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs
===================================================================
--- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,4 +1,5 @@
using System;
+using StructureMap.TypeRules;
namespace StructureMap.Graph
{
Modified: trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
+using StructureMap.TypeRules;
using StructureMap.Util;
namespace StructureMap.Graph
Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,4 +1,5 @@
using System;
+using StructureMap.TypeRules;
namespace StructureMap.Graph
{
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using StructureMap.Attributes;
using StructureMap.Pipeline;
+using StructureMap.TypeRules;
using StructureMap.Util;
namespace StructureMap.Graph
Modified: trunk/Source/StructureMap/Graph/SetterProperty.cs
===================================================================
--- trunk/Source/StructureMap/Graph/SetterProperty.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Graph/SetterProperty.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using StructureMap.Attributes;
+using StructureMap.TypeRules;
namespace StructureMap.Graph
{
Modified: trunk/Source/StructureMap/InstanceBuilderList.cs
===================================================================
--- trunk/Source/StructureMap/InstanceBuilderList.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/InstanceBuilderList.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using StructureMap.Emitting;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap
{
Modified: trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,5 +1,6 @@
using System;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap.Interceptors
{
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,5 +1,6 @@
using System;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap.Pipeline
{
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap.Pipeline
{
Modified: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,5 +1,6 @@
using System;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap.Pipeline
{
Modified: trunk/Source/StructureMap/Pipeline/PropertyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,4 +1,5 @@
using System.Configuration;
+using StructureMap.TypeRules;
namespace StructureMap.Pipeline
{
Modified: trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,5 +1,6 @@
using System;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap.Pipeline
{
Modified: trunk/Source/StructureMap/Pipeline/UserControlInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,6 +1,7 @@
using System;
using System.Web.UI;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap.Pipeline
{
Modified: trunk/Source/StructureMap/TypeExtensions.cs
===================================================================
--- trunk/Source/StructureMap/TypeExtensions.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap/TypeExtensions.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -4,189 +4,192 @@
namespace StructureMap
{
- public static class TypeExtensions
+ namespace TypeRules
{
- public static bool IsInNamespace(this Type type, string nameSpace)
+ public static class TypeExtensions
{
- return type.Namespace.StartsWith(nameSpace);
- }
+ public static bool IsInNamespace(this Type type, string nameSpace)
+ {
+ return type.Namespace.StartsWith(nameSpace);
+ }
- public static ReferencedInstance GetReferenceTo(this Type type)
- {
- string key = PluginCache.GetPlugin(type).ConcreteKey;
- return new ReferencedInstance(key);
- }
+ public static ReferencedInstance GetReferenceTo(this Type type)
+ {
+ string key = PluginCache.GetPlugin(type).ConcreteKey;
+ return new ReferencedInstance(key);
+ }
- public static bool IsGeneric(this Type type)
- {
- return type.IsGenericTypeDefinition || type.ContainsGenericParameters;
- }
+ public static bool IsGeneric(this Type type)
+ {
+ return type.IsGenericTypeDefinition || type.ContainsGenericParameters;
+ }
- public static bool IsConcreteAndAssignableTo(this Type pluggedType, Type pluginType)
- {
- return pluggedType.IsConcrete() && pluginType.IsAssignableFrom(pluggedType);
- }
+ public static bool IsConcreteAndAssignableTo(this Type pluggedType, Type pluginType)
+ {
+ return pluggedType.IsConcrete() && pluginType.IsAssignableFrom(pluggedType);
+ }
- public static bool ImplementsInterfaceTemplate(this Type pluggedType, Type templateType)
- {
- if (!pluggedType.IsConcrete()) return false;
+ public static bool ImplementsInterfaceTemplate(this Type pluggedType, Type templateType)
+ {
+ if (!pluggedType.IsConcrete()) return false;
- foreach (var interfaceType in pluggedType.GetInterfaces())
+ foreach (var interfaceType in pluggedType.GetInterfaces())
+ {
+ if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == templateType)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static Type FindInterfaceThatCloses(this Type pluggedType, Type templateType)
{
- if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == templateType)
+ if (!pluggedType.IsConcrete()) return null;
+
+ foreach (var interfaceType in pluggedType.GetInterfaces())
{
- return true;
+ if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == templateType)
+ {
+ return interfaceType;
+ }
}
+
+ return pluggedType.BaseType == typeof(object) ? null : pluggedType.BaseType.FindInterfaceThatCloses(templateType);
}
- return false;
- }
+ public static bool IsNullable(this Type type)
+ {
+ return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
+ }
- public static Type FindInterfaceThatCloses(this Type pluggedType, Type templateType)
- {
- if (!pluggedType.IsConcrete()) return null;
+ public static Type GetInnerTypeFromNullable(this Type nullableType)
+ {
+ return nullableType.GetGenericArguments()[0];
+ }
- foreach (var interfaceType in pluggedType.GetInterfaces())
+ public static string GetName(this Type type)
{
- if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == templateType)
+ if (type.IsGenericType)
{
- return interfaceType;
+ string[] parameters = Array.ConvertAll(type.GetGenericArguments(), t => t.GetName());
+ var parameterList = String.Join(", ", parameters);
+ return "{0}<{1}>".ToFormat(type.Name, parameterList);
}
+
+ return type.Name;
}
- return pluggedType.BaseType == typeof(object) ? null : pluggedType.BaseType.FindInterfaceThatCloses(templateType);
- }
+ 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);
+ }
- public static bool IsNullable(this Type type)
- {
- return type.IsGenericType && type.GetGenericTypeDefinition() == typeof (Nullable<>);
- }
+ return type.FullName;
+ }
- public static Type GetInnerTypeFromNullable(this Type nullableType)
- {
- return nullableType.GetGenericArguments()[0];
- }
+ /// <summary>
+ /// Determines if the pluggedType can be upcast to the pluginType
+ /// </summary>
+ /// <param name="pluginType"></param>
+ /// <param name="pluggedType"></param>
+ /// <returns></returns>
+ public static bool CanBeCastTo(this Type pluggedType, Type pluginType)
+ {
+ if (pluggedType.IsInterface || pluggedType.IsAbstract)
+ {
+ return false;
+ }
- 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);
+ if (noPublicConstructors(pluggedType))
+ {
+ return false;
+ }
+
+ if (IsGeneric(pluginType))
+ {
+ return GenericsPluginGraph.CanBeCast(pluginType, pluggedType);
+ }
+
+ if (IsGeneric(pluggedType))
+ {
+ return false;
+ }
+
+
+ return pluginType.IsAssignableFrom(pluggedType);
}
- return type.Name;
- }
- public static string GetFullName(this Type type)
- {
- if (type.IsGenericType)
+ /// <summary>
+ /// Determines if the PluggedType is a valid Plugin into the
+ /// PluginType
+ /// </summary>
+ /// <param name="pluginType"></param>
+ /// <param name="pluggedType"></param>
+ /// <returns></returns>
+ public static bool IsExplicitlyMarkedAsPlugin(this Type pluggedType, Type pluginType)
{
- string[] parameters = Array.ConvertAll(type.GetGenericArguments(), t => t.GetName());
- var parameterList = String.Join(", ", parameters);
- return "{0}<{1}>".ToFormat(type.Name, parameterList);
+ bool returnValue = false;
+
+ bool markedAsPlugin = PluggableAttribute.MarkedAsPluggable(pluggedType);
+ if (markedAsPlugin)
+ {
+ returnValue = CanBeCastTo(pluggedType, pluginType);
+ }
+
+ return returnValue;
}
- return type.FullName;
- }
+ private static bool noPublicConstructors(Type pluggedType)
+ {
+ return pluggedType.GetConstructors().Length == 0;
+ }
- /// <summary>
- /// Determines if the pluggedType can be upcast to the pluginType
- /// </summary>
- /// <param name="pluginType"></param>
- /// <param name="pluggedType"></param>
- /// <returns></returns>
- public static bool CanBeCastTo(this Type pluggedType, Type pluginType)
- {
- if (pluggedType.IsInterface || pluggedType.IsAbstract)
+ public static bool IsString(this Type type)
{
- return false;
+ return type.Equals(typeof(string));
}
- if (noPublicConstructors(pluggedType))
+ public static bool IsPrimitive(this Type type)
{
- return false;
+ return type.IsPrimitive && !IsString(type) && type != typeof(IntPtr);
}
- if (IsGeneric(pluginType))
+ public static bool IsSimple(this Type type)
{
- return GenericsPluginGraph.CanBeCast(pluginType, pluggedType);
+ return type.IsPrimitive || IsString(type) || type.IsEnum;
}
- if (IsGeneric(pluggedType))
+ public static bool IsChild(this Type type)
{
- return false;
+ return IsPrimitiveArray(type) || (!type.IsArray && !IsSimple(type));
}
+ public static bool IsChildArray(this Type type)
+ {
+ return type.IsArray && !IsSimple(type.GetElementType());
+ }
- return pluginType.IsAssignableFrom(pluggedType);
- }
+ public static bool IsPrimitiveArray(this Type type)
+ {
+ return type.IsArray && IsSimple(type.GetElementType());
+ }
+ public static bool IsConcrete(this Type type)
+ {
+ return !type.IsAbstract;
+ }
- /// <summary>
- /// Determines if the PluggedType is a valid Plugin into the
- /// PluginType
- /// </summary>
- /// <param name="pluginType"></param>
- /// <param name="pluggedType"></param>
- /// <returns></returns>
- public static bool IsExplicitlyMarkedAsPlugin(this Type pluggedType, Type pluginType)
- {
- bool returnValue = false;
-
- bool markedAsPlugin = PluggableAttribute.MarkedAsPluggable(pluggedType);
- if (markedAsPlugin)
+ public static bool IsAutoFillable(this Type type)
{
- returnValue = CanBeCastTo(pluggedType, pluginType);
+ return IsChild(type) || IsChildArray(type);
}
-
- return returnValue;
}
-
- private static bool noPublicConstructors(Type pluggedType)
- {
- return pluggedType.GetConstructors().Length == 0;
- }
-
- public static bool IsString(this Type type)
- {
- return type.Equals(typeof (string));
- }
-
- public static bool IsPrimitive(this Type type)
- {
- return type.IsPrimitive && !IsString(type) && type != typeof (IntPtr);
- }
-
- public static bool IsSimple(this Type type)
- {
- return type.IsPrimitive || IsString(type) || type.IsEnum;
- }
-
- public static bool IsChild(this Type type)
- {
- return IsPrimitiveArray(type) || (!type.IsArray && !IsSimple(type));
- }
-
- public static bool IsChildArray(this Type type)
- {
- return type.IsArray && !IsSimple(type.GetElementType());
- }
-
- public static bool IsPrimitiveArray(this Type type)
- {
- return type.IsArray && IsSimple(type.GetElementType());
- }
-
- public static bool IsConcrete(this Type type)
- {
- return !type.IsAbstract;
- }
-
- public static bool IsAutoFillable(this Type type)
- {
- return IsChild(type) || IsChildArray(type);
- }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Examples/Interception.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Examples/Interception.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap.Testing/Examples/Interception.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -7,6 +7,7 @@
using StructureMap.Configuration.DSL;
using StructureMap.Interceptors;
using StructureMap;
+using StructureMap.TypeRules;
namespace StructureMap.Testing.Examples
{
Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -4,6 +4,7 @@
using StructureMap.Graph;
using StructureMap.Pipeline;
using StructureMap.Testing.GenericWidgets;
+using StructureMap.TypeRules;
namespace StructureMap.Testing
{
Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -7,6 +7,7 @@
using StructureMap.Testing.Widget;
using System.Linq;
using StructureMap.Testing.Widget5;
+using StructureMap.TypeRules;
namespace StructureMap.Testing.Graph
{
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -9,6 +9,7 @@
using StructureMap.Pipeline;
using StructureMap.Testing.Widget;
using StructureMap.Testing.Widget3;
+using StructureMap.TypeRules;
using Rule=StructureMap.Testing.Widget.Rule;
namespace StructureMap.Testing.Graph
Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -11,6 +11,7 @@
using StructureMap.Testing.Widget;
using StructureMap.Testing.Widget2;
using StructureMap.Testing.Widget3;
+using StructureMap.TypeRules;
namespace StructureMap.Testing.Graph
{
Modified: trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using NUnit.Framework;
using StructureMap.Graph;
+using StructureMap.TypeRules;
namespace StructureMap.Testing.Graph
{
Modified: trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs 2009-11-02 00:32:15 UTC (rev 272)
+++ trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs 2009-11-02 15:07:59 UTC (rev 273)
@@ -2,6 +2,7 @@
using StructureMap.Testing.GenericWidgets;
using StructureMap.Testing.Widget2;
using StructureMap.Testing.Widget3;
+using StructureMap.TypeRules;
namespace StructureMap.Testing
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2009-11-02 00:32:25
|
Revision: 272
http://structuremap.svn.sourceforge.net/structuremap/?rev=272&view=rev
Author: flimflan
Date: 2009-11-02 00:32:15 +0000 (Mon, 02 Nov 2009)
Log Message:
-----------
Moved all functionality from TypeRules base class to TypeExtensions
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs
trunk/Source/StructureMap/Container.cs
trunk/Source/StructureMap/Graph/Constructor.cs
trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs
trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs
trunk/Source/StructureMap/Graph/ITypeScanner.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/SetterProperty.cs
trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs
trunk/Source/StructureMap/InstanceBuilderList.cs
trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs
trunk/Source/StructureMap/Model.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs
trunk/Source/StructureMap/Pipeline/LiteralInstance.cs
trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs
trunk/Source/StructureMap/Pipeline/UserControlInstance.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/TypeExtensions.cs
trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs
Removed Paths:
-------------
trunk/Source/StructureMap/Graph/TypeRules.cs
trunk/Source/StructureMap.Testing/Pipeline/TypeRulesTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -28,7 +28,7 @@
throw new StructureMapException(180, _pluggedType.AssemblyQualifiedName);
}
- if (!TypeRules.CanBeCast(pluginType, _pluggedType))
+ if (!_pluggedType.CanBeCastTo(pluginType))
{
throw new StructureMapException(
303,
Modified: trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Configuration/PrimitiveArrayReader.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -5,13 +5,13 @@
namespace StructureMap.Configuration
{
- public class PrimitiveArrayReader : TypeRules, ITypeReader
+ public class PrimitiveArrayReader : ITypeReader
{
#region ITypeReader Members
public bool CanProcess(Type pluginType)
{
- return IsPrimitiveArray(pluginType);
+ return pluginType.IsPrimitiveArray();
}
public Instance Read(XmlNode node, Type pluginType)
Modified: trunk/Source/StructureMap/Container.cs
===================================================================
--- trunk/Source/StructureMap/Container.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Container.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -10,7 +10,7 @@
namespace StructureMap
{
- public class Container : TypeRules, IContainer
+ public class Container : IContainer
{
private InterceptorLibrary _interceptorLibrary;
private PipelineGraph _pipelineGraph;
@@ -276,7 +276,7 @@
[Obsolete("Please use GetInstance(Type) instead")]
public object FillDependencies(Type type)
{
- if (!IsConcrete(type))
+ if (!type.IsConcrete())
{
throw new StructureMapException(230, type.FullName);
}
@@ -614,7 +614,7 @@
/// <param name="object"></param>
public void Inject(Type pluginType, object @object)
{
- if (!CanBeCast(pluginType, @object.GetType()))
+ if (!@object.GetType().CanBeCastTo(pluginType))
{
throw new StructureMapException(220, pluginType.FullName,
@object.GetType().FullName);
Modified: trunk/Source/StructureMap/Graph/Constructor.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Constructor.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/Constructor.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -4,7 +4,7 @@
namespace StructureMap.Graph
{
- public class Constructor : TypeRules
+ public class Constructor
{
private ConstructorInfo _ctor;
private readonly Type _pluggedType;
@@ -69,7 +69,7 @@
foreach (ParameterInfo parameter in _ctor.GetParameters())
{
- if (!IsAutoFillable(parameter.ParameterType))
+ if (!parameter.ParameterType.IsAutoFillable())
{
return false;
}
@@ -125,11 +125,11 @@
private void visitParameter(ParameterInfo info, Type parameterType, IArgumentVisitor visitor)
{
- if (IsPrimitive(parameterType)) visitor.PrimitiveParameter(info);
- if (IsChild(parameterType)) visitor.ChildParameter(info);
- if (IsChildArray(parameterType)) visitor.ChildArrayParameter(info);
- if (IsEnum(parameterType)) visitor.EnumParameter(info);
- if (IsString(parameterType)) visitor.StringParameter(info);
+ if (parameterType.IsPrimitive()) visitor.PrimitiveParameter(info);
+ if (parameterType.IsChild()) visitor.ChildParameter(info);
+ if (parameterType.IsChildArray()) visitor.ChildArrayParameter(info);
+ if (parameterType.IsEnum) visitor.EnumParameter(info);
+ if (parameterType.IsString()) visitor.StringParameter(info);
}
public bool HasArguments()
Modified: trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs
===================================================================
--- trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/FindAllTypesFilter.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -2,7 +2,7 @@
namespace StructureMap.Graph
{
- public class FindAllTypesFilter : TypeRules, ITypeScanner
+ public class FindAllTypesFilter : ITypeScanner
{
private readonly Type _pluginType;
private Func<Type, string> _getName = type => PluginCache.GetPlugin(type).ConcreteKey;
Modified: trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -24,13 +24,13 @@
public Type PluginType { get; private set; }
}
- internal class TypeMapBuilder : TypeRules, ITypeScanner, IDisposable
+ internal class TypeMapBuilder : ITypeScanner, IDisposable
{
private readonly Cache<Type, List<Type>> _implementations = new Cache<Type, List<Type>>(t => new List<Type>());
public void Process(Type type, PluginGraph graph)
{
- if (!IsConcrete(type) || !Constructor.HasConstructors(type)) return;
+ if (!type.IsConcrete() || !Constructor.HasConstructors(type)) return;
var pluginTypes = FindPluginTypes(type);
foreach (var pluginType in pluginTypes)
Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -7,13 +7,13 @@
void Process(Type type, PluginGraph graph);
}
- public class DefaultConventionScanner : TypeRules, ITypeScanner
+ public class DefaultConventionScanner : ITypeScanner
{
#region ITypeScanner Members
public void Process(Type type, PluginGraph graph)
{
- if (!IsConcrete(type)) return;
+ if (!type.IsConcrete()) return;
Type pluginType = FindPluginType(type);
if (pluginType != null && Constructor.HasConstructors(type))
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -11,7 +11,7 @@
/// PluginFamily\x92s PluginType. The properties of a Plugin are the CLR Type of the concrete class,
/// and the human-friendly concrete key that StructureMap will use to identify the Type.
/// </summary>
- public class Plugin : TypeRules
+ public class Plugin
{
public static readonly string DEFAULT = "DEFAULT";
private readonly Constructor _constructor;
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -11,7 +11,7 @@
/// the system. A PluginFamily defines a CLR Type that StructureMap can build, and all of the possible
/// Plugin\x92s implementing the CLR Type.
/// </summary>
- public class PluginFamily : TypeRules, IPluginFamily
+ public class PluginFamily : IPluginFamily
{
private readonly Cache<string, Instance> _instances = new Cache<string, Instance>(delegate { return null; });
private readonly List<InstanceMemento> _mementoList = new List<InstanceMemento>();
@@ -173,7 +173,7 @@
private void assertPluggability(Type pluggedType)
{
- if (!CanBeCast(_pluginType, pluggedType))
+ if (!pluggedType.CanBeCastTo(_pluginType))
{
throw new StructureMapException(104, pluggedType, _pluginType);
}
@@ -291,7 +291,7 @@
public void AddType(Type concreteType)
{
- if (!CanBeCast(_pluginType, concreteType)) return;
+ if (!concreteType.CanBeCastTo(_pluginType)) return;
if (FindPlugin(concreteType) == null)
{
@@ -301,7 +301,7 @@
public void AddType(Type concreteType, string name)
{
- if (!CanBeCast(_pluginType, concreteType)) return;
+ if (!concreteType.CanBeCastTo(_pluginType)) return;
if (FindPlugin(name) == null)
{
Modified: trunk/Source/StructureMap/Graph/SetterProperty.cs
===================================================================
--- trunk/Source/StructureMap/Graph/SetterProperty.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/SetterProperty.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -7,7 +7,7 @@
/// <summary>
/// Represents a PropertyInfo of a Plugin.PluggedType that is filled by Setter Injection
/// </summary>
- public class SetterProperty : TypeRules
+ public class SetterProperty
{
private readonly PropertyInfo _property;
@@ -34,7 +34,7 @@
public bool CanBeAutoFilled
{
- get { return IsAutoFillable(_property.PropertyType); }
+ get { return _property.PropertyType.IsAutoFillable(); }
}
public void Visit(IArgumentVisitor visitor)
@@ -44,11 +44,11 @@
// 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);
- if (IsEnum(propertyType)) visitor.EnumSetter(_property, IsMandatory);
- if (IsString(propertyType)) visitor.StringSetter(_property, IsMandatory);
+ if (propertyType.IsPrimitive()) visitor.PrimitiveSetter(_property, IsMandatory);
+ if (propertyType.IsChild()) visitor.ChildSetter(_property, IsMandatory);
+ if (propertyType.IsChildArray()) visitor.ChildArraySetter(_property, IsMandatory);
+ if (propertyType.IsEnum) visitor.EnumSetter(_property, IsMandatory);
+ if (propertyType.IsString()) visitor.StringSetter(_property, IsMandatory);
}
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -3,7 +3,7 @@
namespace StructureMap.Graph
{
- public class SingleImplementationScanner : TypeRules, IHeavyweightTypeScanner
+ public class SingleImplementationScanner : IHeavyweightTypeScanner
{
public void Process(PluginGraph graph, IEnumerable<TypeMap> typeMaps)
{
Deleted: trunk/Source/StructureMap/Graph/TypeRules.cs
===================================================================
--- trunk/Source/StructureMap/Graph/TypeRules.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Graph/TypeRules.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -1,117 +0,0 @@
-using System;
-
-namespace StructureMap.Graph
-{
- public class TypeRules
- {
- /// <summary>
- /// Determines if the pluggedType can be upcast to the pluginType
- /// </summary>
- /// <param name="pluginType"></param>
- /// <param name="pluggedType"></param>
- /// <returns></returns>
- public static bool CanBeCast(Type pluginType, Type pluggedType)
- {
- if (pluggedType.IsInterface || pluggedType.IsAbstract)
- {
- return false;
- }
-
- if (noPublicConstructors(pluggedType))
- {
- return false;
- }
-
- if (IsGeneric(pluginType))
- {
- return GenericsPluginGraph.CanBeCast(pluginType, pluggedType);
- }
-
- if (IsGeneric(pluggedType))
- {
- return false;
- }
-
-
- return pluginType.IsAssignableFrom(pluggedType);
- }
-
- public static bool IsGeneric(Type pluggedType)
- {
- return pluggedType.IsGenericTypeDefinition || pluggedType.ContainsGenericParameters;
- }
-
- /// <summary>
- /// Determines if the PluggedType is a valid Plugin into the
- /// PluginType
- /// </summary>
- /// <param name="pluginType"></param>
- /// <param name="pluggedType"></param>
- /// <returns></returns>
- public static bool IsExplicitlyMarkedAsPlugin(Type pluginType, Type pluggedType)
- {
- bool returnValue = false;
-
- bool markedAsPlugin = PluggableAttribute.MarkedAsPluggable(pluggedType);
- if (markedAsPlugin)
- {
- returnValue = CanBeCast(pluginType, pluggedType);
- }
-
- return returnValue;
- }
-
- private static bool noPublicConstructors(Type pluggedType)
- {
- return pluggedType.GetConstructors().Length == 0;
- }
-
- protected bool IsString(Type type)
- {
- return type.Equals(typeof (string));
- }
-
- protected bool IsPrimitive(Type type)
- {
- return type.IsPrimitive && !IsString(type) && type != typeof (IntPtr);
- }
-
- protected internal bool IsSimple(Type type)
- {
- return type.IsPrimitive || IsString(type) || IsEnum(type);
- }
-
- protected bool IsEnum(Type type)
- {
- return type.IsEnum;
- }
-
- protected bool IsChild(Type type)
- {
- return IsPrimitiveArray(type) || (!type.IsArray && !IsSimple(type));
- }
-
- protected bool IsChildArray(Type type)
- {
- return type.IsArray && !IsSimple(type.GetElementType());
- }
-
- protected bool IsPrimitiveArray(Type type)
- {
- return type.IsArray && IsSimple(type.GetElementType());
- }
-
- protected internal bool IsConcrete(Type type)
- {
- return !type.IsInterface && !type.IsAbstract;
- }
-
-
- protected bool IsAutoFillable(Type type)
- {
- return IsChild(type) || IsChildArray(type);
- }
- }
-
-
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap/InstanceBuilderList.cs
===================================================================
--- trunk/Source/StructureMap/InstanceBuilderList.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/InstanceBuilderList.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -42,7 +42,7 @@
}
// Add a missing PluggedType if we can
- if (TypeRules.CanBeCast(_pluginType, pluggedType))
+ if (pluggedType.CanBeCastTo(_pluginType))
{
var plugin = new Plugin(pluggedType);
processPlugin(plugin);
Modified: trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs
===================================================================
--- trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Interceptors/FilteredInstanceInterceptor.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -35,7 +35,7 @@
public bool MatchesType(Type type)
{
- return TypeRules.CanBeCast(_pluginType, type);
+ return type.CanBeCastTo(_pluginType);
}
public object Process(object target, IContext context)
Modified: trunk/Source/StructureMap/Model.cs
===================================================================
--- trunk/Source/StructureMap/Model.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Model.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -64,7 +64,7 @@
bool HasImplementationsFor<T>();
}
- public class Model : TypeRules, IModel
+ public class Model : IModel
{
private readonly PipelineGraph _graph;
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -62,7 +62,7 @@
Type specificType = _pluggedType.IsGenericTypeDefinition
? _pluggedType.MakeGenericType(templateTypes)
: _pluggedType;
- if (TypeRules.CanBeCast(family.PluginType, specificType))
+ if (specificType.CanBeCastTo(family.PluginType))
{
var instance = new ConfiguredInstance(specificType);
instance._arrays = _arrays;
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstanceBase.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -178,7 +178,7 @@
protected override bool canBePartOfPluginFamily(PluginFamily family)
{
- return TypeRules.CanBeCast(family.PluginType, _pluggedType);
+ return _pluggedType.CanBeCastTo(family.PluginType);
}
internal override bool Matches(Plugin plugin)
Modified: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -36,7 +36,7 @@
protected override bool canBePartOfPluginFamily(PluginFamily family)
{
- return TypeRules.CanBeCast(family.PluginType, _object.GetType());
+ return _object.GetType().CanBeCastTo(family.PluginType);
}
protected override string getDescription()
Modified: trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Pipeline/PrototypeInstance.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -27,7 +27,7 @@
protected override bool canBePartOfPluginFamily(PluginFamily family)
{
- return TypeRules.CanBeCast(family.PluginType, _prototype.GetType());
+ return _prototype.GetType().CanBeCastTo(family.PluginType);
}
protected override string getDescription()
Modified: trunk/Source/StructureMap/Pipeline/UserControlInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/Pipeline/UserControlInstance.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -29,7 +29,7 @@
Control control = new Page().LoadControl(_url);
Type pluggedType = control.GetType();
- if (!TypeRules.CanBeCast(pluginType, pluggedType))
+ if (!pluggedType.CanBeCastTo(pluginType))
{
throw new StructureMapException(303, pluginType, pluggedType);
}
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/StructureMap.csproj 2009-11-02 00:32:15 UTC (rev 272)
@@ -151,7 +151,6 @@
<Compile Include="Graph\IArgumentVisitor.cs" />
<Compile Include="Graph\IPluginFamily.cs" />
<Compile Include="Graph\AssemblyScanner.cs" />
- <Compile Include="Graph\TypeRules.cs" />
<Compile Include="InstanceBuilderList.cs" />
<Compile Include="InstanceCache.cs" />
<Compile Include="InstanceFamily.cs" />
Modified: trunk/Source/StructureMap/TypeExtensions.cs
===================================================================
--- trunk/Source/StructureMap/TypeExtensions.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap/TypeExtensions.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -17,26 +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);
- }
-
public static bool IsGeneric(this Type type)
{
return type.IsGenericTypeDefinition || type.ContainsGenericParameters;
}
- public static bool CanBeCastTo(this Type pluggedType, Type pluginType)
- {
- return TypeRules.CanBeCast(pluginType, pluggedType);
- }
-
public static bool IsConcreteAndAssignableTo(this Type pluggedType, Type pluginType)
{
return pluggedType.IsConcrete() && pluginType.IsAssignableFrom(pluggedType);
@@ -87,7 +72,7 @@
if (type.IsGenericType)
{
string[] parameters = Array.ConvertAll(type.GetGenericArguments(), t => t.GetName());
- var parameterList = string.Join(", ", parameters);
+ var parameterList = String.Join(", ", parameters);
return "{0}<{1}>".ToFormat(type.Name, parameterList);
}
@@ -99,12 +84,109 @@
if (type.IsGenericType)
{
string[] parameters = Array.ConvertAll(type.GetGenericArguments(), t => t.GetName());
- var parameterList = string.Join(", ", parameters);
+ var parameterList = String.Join(", ", parameters);
return "{0}<{1}>".ToFormat(type.Name, parameterList);
}
return type.FullName;
}
+ /// <summary>
+ /// Determines if the pluggedType can be upcast to the pluginType
+ /// </summary>
+ /// <param name="pluginType"></param>
+ /// <param name="pluggedType"></param>
+ /// <returns></returns>
+ public static bool CanBeCastTo(this Type pluggedType, Type pluginType)
+ {
+ if (pluggedType.IsInterface || pluggedType.IsAbstract)
+ {
+ return false;
+ }
+
+ if (noPublicConstructors(pluggedType))
+ {
+ return false;
+ }
+
+ if (IsGeneric(pluginType))
+ {
+ return GenericsPluginGraph.CanBeCast(pluginType, pluggedType);
+ }
+
+ if (IsGeneric(pluggedType))
+ {
+ return false;
+ }
+
+
+ return pluginType.IsAssignableFrom(pluggedType);
+ }
+
+
+ /// <summary>
+ /// Determines if the PluggedType is a valid Plugin into the
+ /// PluginType
+ /// </summary>
+ /// <param name="pluginType"></param>
+ /// <param name="pluggedType"></param>
+ /// <returns></returns>
+ public static bool IsExplicitlyMarkedAsPlugin(this Type pluggedType, Type pluginType)
+ {
+ bool returnValue = false;
+
+ bool markedAsPlugin = PluggableAttribute.MarkedAsPluggable(pluggedType);
+ if (markedAsPlugin)
+ {
+ returnValue = CanBeCastTo(pluggedType, pluginType);
+ }
+
+ return returnValue;
+ }
+
+ private static bool noPublicConstructors(Type pluggedType)
+ {
+ return pluggedType.GetConstructors().Length == 0;
+ }
+
+ public static bool IsString(this Type type)
+ {
+ return type.Equals(typeof (string));
+ }
+
+ public static bool IsPrimitive(this Type type)
+ {
+ return type.IsPrimitive && !IsString(type) && type != typeof (IntPtr);
+ }
+
+ public static bool IsSimple(this Type type)
+ {
+ return type.IsPrimitive || IsString(type) || type.IsEnum;
+ }
+
+ public static bool IsChild(this Type type)
+ {
+ return IsPrimitiveArray(type) || (!type.IsArray && !IsSimple(type));
+ }
+
+ public static bool IsChildArray(this Type type)
+ {
+ return type.IsArray && !IsSimple(type.GetElementType());
+ }
+
+ public static bool IsPrimitiveArray(this Type type)
+ {
+ return type.IsArray && IsSimple(type.GetElementType());
+ }
+
+ public static bool IsConcrete(this Type type)
+ {
+ return !type.IsAbstract;
+ }
+
+ public static bool IsAutoFillable(this Type type)
+ {
+ return IsChild(type) || IsChildArray(type);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -137,11 +137,10 @@
[Test]
public void CanPlugGenericConcreteClassIntoGenericInterfaceWithNoGenericParametersSpecified()
{
- bool canPlug = TypeRules.CanBeCast(typeof (IGenericService<>), typeof (GenericService<>));
+ bool canPlug = typeof (GenericService<>).CanBeCastTo(typeof (IGenericService<>));
Assert.IsTrue(canPlug);
}
-
[Test]
public void Define_profile_with_generics_and_concrete_type()
{
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -181,7 +181,7 @@
var family = new PluginFamily(typeof (IGateway), graph);
var instance = new ConfiguredInstance(typeof (ColorRule));
- Assert.IsFalse(TypeRules.CanBeCast(typeof (IGateway), typeof (Rule)));
+ Assert.IsFalse(typeof (Rule).CanBeCastTo(typeof (IGateway)));
family.AddInstance(instance);
Modified: trunk/Source/StructureMap.Testing/Graph/PluginTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap.Testing/Graph/PluginTester.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -97,13 +97,13 @@
[Test]
public void BadPluginToAbstractClass()
{
- Assert.AreEqual(false, TypeRules.CanBeCast(_widgetmaker, _colorWidget), "ColorWidget is NOT a WidgetMaker");
+ Assert.AreEqual(false, _colorWidget.CanBeCastTo(_widgetmaker), "ColorWidget is NOT a WidgetMaker");
}
[Test]
public void BadPluginToInterface()
{
- Assert.AreEqual(false, TypeRules.CanBeCast(_iwidget, _moneywidgetmaker),
+ Assert.AreEqual(false, _moneywidgetmaker.CanBeCastTo(_iwidget),
"MoneyWidgetMaker is NOT an IWidget");
}
@@ -190,15 +190,13 @@
[Test]
public void CanNotPluginWithoutAttribute()
{
- string msg = "NotPluggableWidget cannot plug into IWidget automatically";
- Assert.AreEqual(false, TypeRules.IsExplicitlyMarkedAsPlugin(_iwidget, typeof (NotPluggable)), msg);
+ Assert.IsFalse(typeof (NotPluggable).IsExplicitlyMarkedAsPlugin(_iwidget), "NotPluggableWidget cannot plug into IWidget automatically");
}
[Test]
public void CanPluginWithAttribute()
{
- Assert.AreEqual(true, TypeRules.IsExplicitlyMarkedAsPlugin(_iwidget, _colorWidget),
- "ColorWidget plugs into IWidget");
+ Assert.IsTrue(_colorWidget.IsExplicitlyMarkedAsPlugin(_iwidget), "ColorWidget plugs into IWidget");
}
@@ -300,14 +298,14 @@
[Test]
public void GoodPluginToAbstractClass()
{
- Assert.AreEqual(true, TypeRules.CanBeCast(_widgetmaker, _moneywidgetmaker),
+ Assert.AreEqual(true, _moneywidgetmaker.CanBeCastTo(_widgetmaker),
"MoneyWidgetMaker is a WidgetMaker");
}
[Test]
public void GoodPluginToInterface()
{
- Assert.AreEqual(true, TypeRules.CanBeCast(_iwidget, _colorWidget), "ColorWidget is an IWidget");
+ Assert.AreEqual(true, _colorWidget.CanBeCastTo(_iwidget), "ColorWidget is an IWidget");
}
[Test]
Modified: trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -31,7 +31,7 @@
[Test]
public void DoNotFindPluginWithNoPublicCTOR()
{
- Assert.IsFalse(TypeRules.CanBeCast(typeof (TypeIWantToFind), typeof (GreenType)));
+ Assert.IsFalse(typeof (GreenType).CanBeCastTo(typeof (TypeIWantToFind)));
}
Deleted: trunk/Source/StructureMap.Testing/Pipeline/TypeRulesTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/TypeRulesTester.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap.Testing/Pipeline/TypeRulesTester.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -1,86 +0,0 @@
-using NUnit.Framework;
-using StructureMap.Graph;
-using StructureMap.Testing.Widget2;
-using StructureMap.Testing.Widget3;
-
-namespace StructureMap.Testing.Pipeline
-{
- [TestFixture]
- public class TypeRulesTester : TypeRules
- {
- #region Setup/Teardown
-
- [SetUp]
- public void SetUp()
- {
- }
-
- #endregion
-
- [Test]
- public void IsChild()
- {
- Assert.IsFalse(IsChild(typeof (int)));
- Assert.IsFalse(IsChild(typeof (bool)));
- Assert.IsFalse(IsChild(typeof (double)));
- Assert.IsFalse(IsChild(typeof (string)));
- Assert.IsFalse(IsChild(typeof (BreedEnum)));
- Assert.IsFalse(IsChild(typeof (IGateway[])));
- Assert.IsTrue(IsChild(typeof (IGateway)));
- }
-
- [Test]
- public void IsChildArray()
- {
- Assert.IsFalse(IsChildArray(typeof (int)));
- Assert.IsFalse(IsChildArray(typeof (bool)));
- Assert.IsFalse(IsChildArray(typeof (double)));
- Assert.IsFalse(IsChildArray(typeof (double[])));
- Assert.IsFalse(IsChildArray(typeof (string)));
- Assert.IsFalse(IsChildArray(typeof (string[])));
- Assert.IsFalse(IsChildArray(typeof (BreedEnum)));
- Assert.IsTrue(IsChildArray(typeof (IGateway[])));
- Assert.IsFalse(IsChildArray(typeof (IGateway)));
- }
-
- [Test]
- public void IsEnum()
- {
- Assert.IsFalse(IsEnum(typeof (int)));
- Assert.IsFalse(IsEnum(typeof (bool)));
- Assert.IsFalse(IsEnum(typeof (double)));
- Assert.IsFalse(IsEnum(typeof (string)));
- Assert.IsTrue(IsEnum(typeof (BreedEnum)));
- Assert.IsFalse(IsEnum(typeof (IGateway)));
- }
-
- [Test]
- public void IsPrimitive()
- {
- Assert.IsTrue(IsPrimitive(typeof (int)));
- Assert.IsTrue(IsPrimitive(typeof (bool)));
- Assert.IsTrue(IsPrimitive(typeof (double)));
- Assert.IsFalse(IsPrimitive(typeof (string)));
- Assert.IsFalse(IsPrimitive(typeof (BreedEnum)));
- Assert.IsFalse(IsPrimitive(typeof (IGateway)));
- }
-
- [Test]
- public void IsSimple()
- {
- Assert.IsTrue(IsSimple(typeof (int)));
- Assert.IsTrue(IsSimple(typeof (bool)));
- Assert.IsTrue(IsSimple(typeof (double)));
- Assert.IsTrue(IsSimple(typeof (string)));
- Assert.IsTrue(IsSimple(typeof (BreedEnum)));
- Assert.IsFalse(IsSimple(typeof (IGateway)));
- }
-
- [Test]
- public void IsString()
- {
- Assert.IsTrue(IsString(typeof (string)));
- Assert.IsFalse(IsString(typeof (int)));
- }
- }
-}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-11-02 00:32:15 UTC (rev 272)
@@ -374,7 +374,6 @@
<Compile Include="Pipeline\SmartInstanceTester.cs" />
<Compile Include="Pipeline\StubBuildSession.cs" />
<Compile Include="Pipeline\ThreadLocalStorageLifecycleTester.cs" />
- <Compile Include="Pipeline\TypeRulesTester.cs" />
<Compile Include="PrimitiveArrayTester.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
Modified: trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs 2009-10-24 23:19:17 UTC (rev 271)
+++ trunk/Source/StructureMap.Testing/TypeExtensionsTester.cs 2009-11-02 00:32:15 UTC (rev 272)
@@ -1,9 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using NUnit.Framework;
+using NUnit.Framework;
using StructureMap.Testing.GenericWidgets;
+using StructureMap.Testing.Widget2;
+using StructureMap.Testing.Widget3;
namespace StructureMap.Testing
{
@@ -39,5 +37,61 @@
typeof(Service2).FindInterfaceThatCloses(typeof(IService<>))
.ShouldBeNull();
}
+
+ [Test]
+ public void IsChild()
+ {
+ Assert.IsFalse(TypeExtensions.IsChild(typeof(int)));
+ Assert.IsFalse(TypeExtensions.IsChild(typeof(bool)));
+ Assert.IsFalse(TypeExtensions.IsChild(typeof(double)));
+ Assert.IsFalse(TypeExtensions.IsChild(typeof(string)));
+ Assert.IsFalse(TypeExtensions.IsChild(typeof(BreedEnum)));
+ Assert.IsFalse(TypeExtensions.IsChild(typeof(IGateway[])));
+ Assert.IsTrue(TypeExtensions.IsChild(typeof(IGateway)));
+ }
+
+ [Test]
+ public void IsChildArray()
+ {
+ Assert.IsFalse(TypeExtensions.IsChildArray(typeof(int)));
+ Assert.IsFalse(TypeExtensions.IsChildArray(typeof(bool)));
+ Assert.IsFalse(TypeExtensions.IsChildArray(typeof(double)));
+ Assert.IsFalse(TypeExtensions.IsChildArray(typeof(double[])));
+ Assert.IsFalse(TypeExtensions.IsChildArray(typeof(string)));
+ Assert.IsFalse(TypeExtensions.IsChildArray(typeof(string[])));
+ Assert.IsFalse(TypeExtensions.IsChildArray(typeof(BreedEnum)));
+ Assert.IsTrue(TypeExtensions.IsChildArray(typeof(IGateway[])));
+ Assert.IsFalse(TypeExtensions.IsChildArray(typeof(IGateway)));
+ }
+
+ [Test]
+ public void IsPrimitive()
+ {
+ Assert.IsTrue(typeof(int).IsPrimitive());
+ Assert.IsTrue(typeof(bool).IsPrimitive());
+ Assert.IsTrue(typeof(double).IsPrimitive());
+ Assert.IsFalse(typeof(string).IsPrimitive());
+ Assert.IsFalse(typeof(BreedEnum).IsPrimitive());
+ Assert.IsFalse(typeof(IGateway).IsPrimitive());
+ }
+
+ [Test]
+ public void IsSimple()
+ {
+ Assert.IsTrue(TypeExtensions.IsSimple(typeof(int)));
+ Assert.IsTrue(TypeExtensions.IsSimple(typeof(bool)));
+ Assert.IsTrue(TypeExtensions.IsSimple(typeof(double)));
+ Assert.IsTrue(TypeExtensions.IsSimple(typeof(string)));
+ Assert.IsTrue(TypeExtensions.IsSimple(typeof(BreedEnum)));
+ Assert.IsFalse(TypeExtensions.IsSimple(typeof(IGateway)));
+ }
+
+ [Test]
+ public void IsString()
+ {
+ Assert.IsTrue(TypeExtensions.IsString(typeof(string)));
+ Assert.IsFalse(TypeExtensions.IsString(typeof(int)));
+ }
+
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2009-10-24 23:19:26
|
Revision: 271
http://structuremap.svn.sourceforge.net/structuremap/?rev=271&view=rev
Author: flimflan
Date: 2009-10-24 23:19:17 +0000 (Sat, 24 Oct 2009)
Log Message:
-----------
Resolved Code Access Security issue when running under ASP.NET attempting to read default config file (reported by Eric Sowell).
- When configuration your container, you must specify IgnoreDefaultFile = true
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs
trunk/Source/StructureMap/Emitting/DynamicAssembly.cs
Modified: trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2009-10-19 02:59:11 UTC (rev 270)
+++ trunk/Source/StructureMap/Configuration/ConfigurationParserBuilder.cs 2009-10-24 23:19:17 UTC (rev 271)
@@ -126,9 +126,10 @@
private void addConfigurationFromStructureMapConfig(ICollection<ConfigurationParser> list)
{
-// Pick up the configuration in the default StructureMap.config
- string pathToStructureMapConfig = GetStructureMapConfigurationPath();
- if (shouldUseStructureMapConfigFileAt(pathToStructureMapConfig))
+ if (_ignoreDefaultFile) return;
+ // Pick up the configuration in the default StructureMap.config
+ var pathToStructureMapConfig = GetStructureMapConfigurationPath();
+ if ((_useAndEnforceExistenceOfDefaultFile || File.Exists(pathToStructureMapConfig)))
{
_log.Try(() =>
{
@@ -138,14 +139,7 @@
}
}
- private bool shouldUseStructureMapConfigFileAt(string pathToStructureMapConfig)
- {
- return
- (_useAndEnforceExistenceOfDefaultFile ||
- File.Exists(pathToStructureMapConfig)) && !_ignoreDefaultFile;
- }
-
public static ConfigurationParser[] GetParsers(XmlNode node, GraphLog log)
{
var builder = new ConfigurationParserBuilder(log);
Modified: trunk/Source/StructureMap/Emitting/DynamicAssembly.cs
===================================================================
--- trunk/Source/StructureMap/Emitting/DynamicAssembly.cs 2009-10-19 02:59:11 UTC (rev 270)
+++ trunk/Source/StructureMap/Emitting/DynamicAssembly.cs 2009-10-24 23:19:17 UTC (rev 271)
@@ -16,7 +16,6 @@
private AssemblyBuilder _assemblyBuilder;
private bool _isCompiled;
private ModuleBuilder _module;
- private string DLLName;
public DynamicAssembly(string name)
{
@@ -46,14 +45,9 @@
assemName.CultureInfo = new CultureInfo("en");
assemName.SetPublicKeyToken(null);
- DLLName = Name + ".dll";
- _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, AssemblyBuilderAccess.RunAndSave);
- //_assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, AssemblyBuilderAccess.Run);
+ _assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, AssemblyBuilderAccess.Run);
- _module = _assemblyBuilder.DefineDynamicModule(Name, DLLName);
-
-
- //_module = _assemblyBuilder.DefineDynamicModule(Name);
+ _module = _assemblyBuilder.DefineDynamicModule(Name);
}
@@ -84,13 +78,8 @@
newClass.Bake();
}
- //_assemblyBuilder.Save(_name + ".dll");
-
- //assemBuilder.Save(DLLName);
- //Assembly assem = AppDomain.CurrentDomain.Load(this.Name);
_isCompiled = true;
return _assemblyBuilder;
- //return assem;
}
}
}
\ 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...> - 2009-10-19 02:59:24
|
Revision: 270
http://structuremap.svn.sourceforge.net/structuremap/?rev=270&view=rev
Author: flimflan
Date: 2009-10-19 02:59:11 +0000 (Mon, 19 Oct 2009)
Log Message:
-----------
Experimental support for type scanning which needs to know about all available plugin/concrete types when making a decision.
SingleImplementationScanner automatically registers a concrete type if it is the only implementation of an interface.
All names/API subject to change...
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/AssemblyScanner.cs
trunk/Source/StructureMap/Graph/ITypeScanner.cs
trunk/Source/StructureMap/StructureMap.csproj
trunk/Source/StructureMap/Util/Cache.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs
trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs
trunk/Source/StructureMap.Testing/Graph/SingleImplementationScannerTester.cs
Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-10-08 16:44:14 UTC (rev 269)
+++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-10-19 02:59:11 UTC (rev 270)
@@ -81,6 +81,7 @@
/// <param name="scanner"></param>
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
@@ -189,6 +190,7 @@
private readonly List<Predicate<Type>> _excludes = new List<Predicate<Type>>();
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()
{
@@ -204,7 +206,11 @@
internal void ScanForAll(PluginGraph pluginGraph)
{
+ var heavyweightScan = configureHeavyweightScan();
+
_assemblies.ForEach(assem => scanTypesInAssembly(assem, pluginGraph));
+
+ performHeavyweightScan(pluginGraph, heavyweightScan);
}
private void scanTypesInAssembly(Assembly assembly, PluginGraph graph)
@@ -225,6 +231,23 @@
}
}
+ 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;
@@ -282,7 +305,14 @@
_scanners.Add(scanner);
}
+
+ public void With(IHeavyweightTypeScanner heavyweightScanner)
+ {
+ if (_heavyweightScanners.Contains(heavyweightScanner)) return;
+ _heavyweightScanners.Add(heavyweightScanner);
+ }
+
public void WithDefaultConventions()
{
With<DefaultConventionScanner>();
Added: trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs (rev 0)
+++ trunk/Source/StructureMap/Graph/IHeavyweightTypeScanner.cs 2009-10-19 02:59:11 UTC (rev 270)
@@ -0,0 +1,58 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using StructureMap.Util;
+
+namespace StructureMap.Graph
+{
+ public interface IHeavyweightTypeScanner
+ {
+ void Process(PluginGraph graph, IEnumerable<TypeMap> typeMaps);
+ }
+
+
+ public class TypeMap
+ {
+ internal TypeMap(Type pluginType, IList<Type> concreteTypes)
+ {
+ PluginType = pluginType;
+ ConcreteTypes = new ReadOnlyCollection<Type>(concreteTypes);
+ }
+
+ public IList<Type> ConcreteTypes { get; private set; }
+ public Type PluginType { get; private set; }
+ }
+
+ internal class TypeMapBuilder : TypeRules, ITypeScanner, IDisposable
+ {
+ private readonly Cache<Type, List<Type>> _implementations = new Cache<Type, List<Type>>(t => new List<Type>());
+
+ public void Process(Type type, PluginGraph graph)
+ {
+ if (!IsConcrete(type) || !Constructor.HasConstructors(type)) return;
+ var pluginTypes = FindPluginTypes(type);
+
+ foreach (var pluginType in pluginTypes)
+ {
+ _implementations[pluginType].Add(type);
+ }
+ }
+
+ private IEnumerable<Type> FindPluginTypes(Type type)
+ {
+ // lets not worry about abstract base classes for now
+ return type.GetInterfaces().Where(t => t.IsPublic);
+ }
+
+ public IEnumerable<TypeMap> GetTypeMaps()
+ {
+ return _implementations.Contents().Select(pair => new TypeMap(pair.Key, pair.Value));
+ }
+
+ public void Dispose()
+ {
+ _implementations.Clear();
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Graph/ITypeScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-10-08 16:44:14 UTC (rev 269)
+++ trunk/Source/StructureMap/Graph/ITypeScanner.cs 2009-10-19 02:59:11 UTC (rev 270)
@@ -1,5 +1,4 @@
using System;
-using StructureMap;
namespace StructureMap.Graph
{
Added: trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs (rev 0)
+++ trunk/Source/StructureMap/Graph/SingleImplementationScanner.cs 2009-10-19 02:59:11 UTC (rev 270)
@@ -0,0 +1,16 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace StructureMap.Graph
+{
+ public class SingleImplementationScanner : TypeRules, IHeavyweightTypeScanner
+ {
+ public void Process(PluginGraph graph, IEnumerable<TypeMap> typeMaps)
+ {
+ foreach(var map in typeMaps.Where(map => map.ConcreteTypes.Count == 1))
+ {
+ graph.AddType(map.PluginType, map.ConcreteTypes[0]);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap/StructureMap.csproj
===================================================================
--- trunk/Source/StructureMap/StructureMap.csproj 2009-10-08 16:44:14 UTC (rev 269)
+++ trunk/Source/StructureMap/StructureMap.csproj 2009-10-19 02:59:11 UTC (rev 270)
@@ -395,9 +395,11 @@
<Compile Include="Graph\FamilyAttributeScanner.cs" />
<Compile Include="Graph\FindAllTypesFilter.cs" />
<Compile Include="Graph\FindRegistriesScanner.cs" />
+ <Compile Include="Graph\IHeavyweightTypeScanner.cs" />
<Compile Include="Graph\ITypeScanner.cs" />
<Compile Include="Graph\PluggableAttributeScanner.cs" />
<Compile Include="Graph\PluginCache.cs" />
+ <Compile Include="Graph\SingleImplementationScanner.cs" />
<Compile Include="IContext.cs" />
<Compile Include="Pipeline\ConditionalInstance.cs" />
<Compile Include="Pipeline\HttpContextLifecycle.cs" />
Modified: trunk/Source/StructureMap/Util/Cache.cs
===================================================================
--- trunk/Source/StructureMap/Util/Cache.cs 2009-10-08 16:44:14 UTC (rev 269)
+++ trunk/Source/StructureMap/Util/Cache.cs 2009-10-19 02:59:11 UTC (rev 270)
@@ -176,6 +176,11 @@
return returnValue;
}
+ public IDictionary<KEY, VALUE> Contents()
+ {
+ return _values;
+ }
+
public void Remove(KEY key)
{
if (_values.ContainsKey(key))
Added: trunk/Source/StructureMap.Testing/Graph/SingleImplementationScannerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/SingleImplementationScannerTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Graph/SingleImplementationScannerTester.cs 2009-10-19 02:59:11 UTC (rev 270)
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using StructureMap.Graph;
+using StructureMap.Util;
+
+namespace StructureMap.Testing.Graph
+{
+ [TestFixture]
+ public class SingleImplementationScannerTester
+ {
+ [Test]
+ public void registers_plugins_that_only_have_a_single_implementation()
+ {
+ var container = new Container(registry =>
+ {
+ registry.Scan(x =>
+ {
+ x.TheCallingAssembly();
+ x.IncludeNamespaceContainingType<SingleImplementationScannerTester>();
+ x.With(new SingleImplementationScanner());
+ });
+ });
+
+ container.GetInstance<IOnlyHaveASingleConcreteImplementation>()
+ .ShouldBeOfType<MyNameIsNotConventionallyRelatedToMyInterface>();
+ }
+
+ [Test]
+ public void other()
+ {
+ typeof(Type).IsValueType.ShouldBeFalse();
+ }
+ }
+
+
+ public interface IOnlyHaveASingleConcreteImplementation
+ {
+
+ }
+ public class MyNameIsNotConventionallyRelatedToMyInterface : IOnlyHaveASingleConcreteImplementation
+ {
+
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-10-08 16:44:14 UTC (rev 269)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-10-19 02:59:11 UTC (rev 270)
@@ -252,6 +252,7 @@
<Compile Include="Graph\ExceptionHandling\StructureMapExceptionTester.cs">
<SubType>Code</SubType>
</Compile>
+ <Compile Include="Graph\SingleImplementationScannerTester.cs" />
<Compile Include="Graph\TestExplicitArguments.cs" />
<Compile Include="Graph\FillDependenciesTester.cs">
<SubType>Code</SubType>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2009-10-08 16:44:21
|
Revision: 269
http://structuremap.svn.sourceforge.net/structuremap/?rev=269&view=rev
Author: flimflan
Date: 2009-10-08 16:44:14 +0000 (Thu, 08 Oct 2009)
Log Message:
-----------
Removed code that tried to parse ClassName/AssemblyName independently - just work with AssemblyQualifiedName directly
- fixes bug when specifying assembly qualified generics in XML configuration
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Configuration/FamilyParser.cs
trunk/Source/StructureMap/Diagnostics/ValidationError.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/Graph/TypePath.cs
trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs
trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs
trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs
trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap/Configuration/DSL/ExpressionValidator.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -32,8 +32,8 @@
{
throw new StructureMapException(
303,
- TypePath.GetAssemblyQualifiedName(_pluggedType),
- TypePath.GetAssemblyQualifiedName(pluginType));
+ _pluggedType.AssemblyQualifiedName,
+ pluginType.AssemblyQualifiedName);
}
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -104,7 +104,7 @@
{
if (graph.Registries.Contains(this)) return;
- graph.Log.StartSource("Registry: " + TypePath.GetAssemblyQualifiedName(GetType()));
+ graph.Log.StartSource("Registry: " + GetType().AssemblyQualifiedName);
_basicActions.ForEach(action => action());
_actions.ForEach(action => action(graph));
Modified: trunk/Source/StructureMap/Configuration/FamilyParser.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/FamilyParser.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap/Configuration/FamilyParser.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -94,7 +94,7 @@
InstanceMemento sourceMemento = new XmlAttributeInstanceMemento(node);
string context = string.Format("MementoSource for {0}\n{1}",
- TypePath.GetAssemblyQualifiedName(family.PluginType), node.OuterXml);
+ family.PluginType.AssemblyQualifiedName, node.OuterXml);
_builder.WithSystemObject<MementoSource>(sourceMemento, context,
source => family.AddMementoSource(source));
});
@@ -121,8 +121,7 @@
private void attachInterceptors(PluginFamily family, XmlElement familyElement)
{
- string contextBase = string.Format("creating an InstanceInterceptor for {0}\n",
- TypePath.GetAssemblyQualifiedName(family.PluginType));
+ string contextBase = string.Format("creating an InstanceInterceptor for {0}\n", family.PluginType.AssemblyQualifiedName);
familyElement.ForEachChild("*/Interceptor").Do(element =>
{
var interceptorMemento = new XmlAttributeInstanceMemento(element);
Modified: trunk/Source/StructureMap/Diagnostics/ValidationError.cs
===================================================================
--- trunk/Source/StructureMap/Diagnostics/ValidationError.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap/Diagnostics/ValidationError.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -29,7 +29,7 @@
writer.WriteLine(
"-----------------------------------------------------------------------------------------------------");
writer.WriteLine("Validation Error in Method {0} of Instance '{1}' ({2})\n in PluginType {3}", MethodName,
- Instance.Name, description, TypePath.GetAssemblyQualifiedName(PluginType));
+ Instance.Name, description, PluginType.AssemblyQualifiedName);
writer.WriteLine();
writer.WriteLine(Exception.ToString());
writer.WriteLine();
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -218,7 +218,7 @@
{
if (string.IsNullOrEmpty(memento.InstanceKey))
{
- memento.InstanceKey = "DefaultInstanceOf" + TypePath.GetAssemblyQualifiedName(PluginType);
+ memento.InstanceKey = "DefaultInstanceOf" + PluginType.AssemblyQualifiedName;
}
AddInstance(memento);
Modified: trunk/Source/StructureMap/Graph/TypePath.cs
===================================================================
--- trunk/Source/StructureMap/Graph/TypePath.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap/Graph/TypePath.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -10,45 +10,23 @@
[Serializable]
public class TypePath
{
- private readonly string _assemblyName = string.Empty;
- private readonly string _className;
-
public TypePath(string assemblyName, string className)
{
- _className = className;
- _assemblyName = assemblyName;
+ AssemblyQualifiedName = className + "," + assemblyName;
}
public TypePath(Type type)
{
- _className = type.FullName;
- _assemblyName = type.Assembly.GetName().Name;
+ AssemblyQualifiedName = type.AssemblyQualifiedName;
}
public TypePath(string assemblyQualifiedName)
{
- string[] parts = assemblyQualifiedName.Split(',');
-
- _className = parts[0].Trim();
-
- if (parts.Length > 1) _assemblyName = parts[1].Trim();
+ AssemblyQualifiedName = assemblyQualifiedName;
}
- public string AssemblyQualifiedName
- {
- get { return _className + "," + _assemblyName; }
- }
+ public string AssemblyQualifiedName { get; private set; }
- public string AssemblyName
- {
- get { return _assemblyName; }
- }
-
- public string ClassName
- {
- get { return _className; }
- }
-
public static TypePath CreateFromXmlNode(XmlNode node)
{
string typeName = node.Attributes[XmlConstants.TYPE_ATTRIBUTE].Value;
@@ -63,12 +41,6 @@
element.SetAttribute(XmlConstants.ASSEMBLY, type.Assembly.GetName().Name);
}
- public static string GetAssemblyQualifiedName(Type type)
- {
- var path = new TypePath(type);
- return path.AssemblyQualifiedName;
- }
-
public Type FindType()
{
try
Modified: trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap.Testing/Configuration/DictionaryAndArrayArgumentTester.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -23,7 +23,7 @@
";
XmlElement element = DataMother.BuildDocument(xml).DocumentElement;
- element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof (ClassWithStringAndIntArray)));
+ element.SetAttribute("PluggedType", typeof (ClassWithStringAndIntArray).AssemblyQualifiedName);
var memento = new XmlAttributeInstanceMemento(element);
var graph = new PluginGraph();
@@ -53,7 +53,7 @@
";
XmlElement element = DataMother.BuildDocument(xml).DocumentElement;
- element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof (ClassWithDictionary)));
+ element.SetAttribute("PluggedType", typeof (ClassWithDictionary).AssemblyQualifiedName);
var memento = new XmlNodeInstanceMemento(element, "Type", "Key");
@@ -84,7 +84,7 @@
";
XmlElement element = DataMother.BuildDocument(xml).DocumentElement;
- element.SetAttribute("PluggedType", TypePath.GetAssemblyQualifiedName(typeof (ClassWithDictionary)));
+ element.SetAttribute("PluggedType", typeof (ClassWithDictionary).AssemblyQualifiedName);
var memento = new XmlAttributeInstanceMemento(element);
Modified: trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap.Testing/Diagnostics/DoctorTester.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -154,7 +154,7 @@
{
if (typeof (IBootstrapper).IsAssignableFrom(type))
{
- Debug.WriteLine(TypePath.GetAssemblyQualifiedName(type));
+ Debug.WriteLine(type.AssemblyQualifiedName);
}
}
}
Modified: trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap.Testing/Graph/TypePathTester.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -1,5 +1,7 @@
using NUnit.Framework;
using StructureMap.Graph;
+using StructureMap.Testing.GenericWidgets;
+using StructureMap.Testing.Widget;
namespace StructureMap.Testing.Graph
{
@@ -21,5 +23,15 @@
var path = new TypePath(GetType());
path.FindType();
}
+
+ [Test]
+ public void can_parse_assembly_qualified_generics()
+ {
+ var sampleGenericType = typeof(IConcept<AWidget>);
+ var genericAssemblyQualifiedName = sampleGenericType.AssemblyQualifiedName;
+
+ var path = new TypePath(genericAssemblyQualifiedName);
+ path.FindType().ShouldEqual(sampleGenericType);
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2009-10-07 18:25:50 UTC (rev 268)
+++ trunk/Source/StructureMap.Testing/ImplicitPluginFromPluggedTypeAttributeTester.cs 2009-10-08 16:44:14 UTC (rev 269)
@@ -21,7 +21,7 @@
Type pluggedType = typeof (StubbedGateway);
var values = new NameValueCollection();
- values.Add(XmlConstants.PLUGGED_TYPE, TypePath.GetAssemblyQualifiedName(pluggedType));
+ values.Add(XmlConstants.PLUGGED_TYPE, pluggedType.AssemblyQualifiedName);
_memento = new MemoryInstanceMemento(string.Empty, "Frank", values);
_expectedPlugin = new Plugin(pluggedType);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2009-10-07 18:25:58
|
Revision: 268
http://structuremap.svn.sourceforge.net/structuremap/?rev=268&view=rev
Author: andreas_ohlund
Date: 2009-10-07 18:25:50 +0000 (Wed, 07 Oct 2009)
Log Message:
-----------
Fixed bug where FillAllPropertiesOfType didn't work for already configured instances
Added missing test for the JITException bug
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/PluginCache.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap.Testing/Bugs/FillAllPropertiesShouldWorkForAlreadyConfiguredPluginsBug.cs
trunk/Source/StructureMap.Testing/Bugs/StaticPropertyCausesJITExceptionTester.cs
Modified: trunk/Source/StructureMap/Graph/PluginCache.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginCache.cs 2009-10-07 17:17:56 UTC (rev 267)
+++ trunk/Source/StructureMap/Graph/PluginCache.cs 2009-10-07 18:25:50 UTC (rev 268)
@@ -106,7 +106,19 @@
public static void UseSetterRule(Predicate<PropertyInfo> predicate)
{
_setterRules.Add(predicate);
- _plugins.Each(plugin => plugin.UseSetterRule(predicate));
+ _plugins.Each(plugin =>
+ {
+ plugin.UseSetterRule(predicate);
+
+ //does any of the registered plugins have a setter matching the predicate?
+ if (plugin.PluggedType.GetProperties().Any(s => predicate(s)))
+ {
+ //rebuild the builder if nessesary
+ if (_builders[plugin.PluggedType] != null)
+ createAndStoreBuilders(new[] { plugin });
+ }
+ });
+
}
}
}
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/Bugs/FillAllPropertiesShouldWorkForAlreadyConfiguredPluginsBug.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Bugs/FillAllPropertiesShouldWorkForAlreadyConfiguredPluginsBug.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Bugs/FillAllPropertiesShouldWorkForAlreadyConfiguredPluginsBug.cs 2009-10-07 18:25:50 UTC (rev 268)
@@ -0,0 +1,51 @@
+using System.Collections.Generic;
+using NUnit.Framework;
+
+namespace StructureMap.Testing.Bugs
+{
+ [TestFixture]
+ public class FillAllPropertiesShouldWorkForAlreadyConfiguredPluginsBug
+ {
+
+ [Test]
+ public void Structuremap_should_autowire_setter_dependencies_regardless_of_order()
+ {
+ var container = new Container();
+
+ container.Configure(x =>
+ {
+ x.ForConcreteType<ClassWithSetterDependency>();
+ });
+
+
+ container.Configure(x =>
+ {
+ x.ForRequestedType<ISomeDependency>()
+ .TheDefaultIsConcreteType<ClassThatImplementsDependency>();
+
+ x.FillAllPropertiesOfType<ISomeDependency>();
+
+
+ });
+
+
+
+ container.GetInstance<ClassWithSetterDependency>().Dependency.ShouldNotBeNull();
+ }
+
+ }
+
+
+ public class ClassWithSetterDependency
+ {
+ public ISomeDependency Dependency { get; set; }
+ public IList<string> SystemDependency { get; set; }
+ }
+
+ public interface ISomeDependency { }
+
+ public class ClassThatImplementsDependency : ISomeDependency { }
+
+ public interface INonConfiguredInterface { }
+
+}
Added: trunk/Source/StructureMap.Testing/Bugs/StaticPropertyCausesJITExceptionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Bugs/StaticPropertyCausesJITExceptionTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Bugs/StaticPropertyCausesJITExceptionTester.cs 2009-10-07 18:25:50 UTC (rev 268)
@@ -0,0 +1,34 @@
+using NUnit.Framework;
+
+namespace StructureMap.Testing.Bugs
+{
+ [TestFixture]
+ public class StaticPropertyCausesJITExceptionTester
+ {
+ [Test]
+ public void Get_instance_should_work()
+ {
+ var container = new Container(x => x.ForConcreteType<ClassWithStaticProperty>());
+
+ container.GetInstance<ClassWithStaticProperty>();
+ }
+ }
+
+ public class ClassWithStaticProperty
+ {
+
+ private static volatile bool disabled;
+
+ public static bool Disabled
+ {
+ get
+ {
+ return disabled;
+ }
+ set
+ {
+ disabled = value;
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-10-07 17:17:56 UTC (rev 267)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-10-07 18:25:50 UTC (rev 268)
@@ -179,6 +179,7 @@
<Compile Include="AutoWiringExamples.cs" />
<Compile Include="BidirectionalDependencies.cs" />
<Compile Include="Bugs\BuildUpBug.cs" />
+ <Compile Include="Bugs\FillAllPropertiesShouldWorkForAlreadyConfiguredPluginsBug.cs" />
<Compile Include="Bugs\HttpSessionNullRefBug.cs" />
<Compile Include="Bugs\IDictionaryAndXmlBugTester.cs" />
<Compile Include="Bugs\LambdaCreatesNullBugTester.cs" />
@@ -186,6 +187,7 @@
<Compile Include="Bugs\ScanIndexerBugTester.cs" />
<Compile Include="Bugs\SingletonShouldBeLazy.cs" />
<Compile Include="Bugs\SpecifyScopeInConfigureTester.cs" />
+ <Compile Include="Bugs\StaticPropertyCausesJITExceptionTester.cs" />
<Compile Include="BuildSessionTester.cs" />
<Compile Include="BuildUpIntegratedTester.cs" />
<Compile Include="BuildUpTester.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2009-10-07 17:18:08
|
Revision: 267
http://structuremap.svn.sourceforge.net/structuremap/?rev=267&view=rev
Author: andreas_ohlund
Date: 2009-10-07 17:17:56 +0000 (Wed, 07 Oct 2009)
Log Message:
-----------
WithCtorArg can now be used with both simple and non simple types
Modified Paths:
--------------
trunk/Source/StructureMap/Pipeline/PropertyExpression.cs
trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs
Modified: trunk/Source/StructureMap/Pipeline/PropertyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2009-10-07 16:59:34 UTC (rev 266)
+++ trunk/Source/StructureMap/Pipeline/PropertyExpression.cs 2009-10-07 17:17:56 UTC (rev 267)
@@ -23,7 +23,12 @@
/// <returns></returns>
public T EqualTo(object propertyValue)
{
- _instance.SetProperty(_propertyName, propertyValue.ToString());
+ if(propertyValue.GetType().IsSimple())
+ _instance.SetProperty(_propertyName, propertyValue.ToString());
+ else
+ {
+ _instance.SetChild(_propertyName,new LiteralInstance(propertyValue));
+ }
return (T) _instance;
}
Modified: trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2009-10-07 16:59:34 UTC (rev 266)
+++ trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2009-10-07 17:17:56 UTC (rev 267)
@@ -98,8 +98,31 @@
});
}
+ [Test]
+ public void specify_ctorarg_with_non_simple_argument()
+ {
+ var widget = new ColorWidget("Red");
+ var container = new Container(x => x.ForRequestedType<ClassWithWidget>()
+ .TheDefault.Is.OfConcreteType<ClassWithWidget>()
+ .WithCtorArg("widget").EqualTo(widget));
+ Assert.AreSame(widget, container.GetInstance<ClassWithWidget>().Widget);
+ }
+
+
[Test]
+ public void specify_a_non_simple_property_with_equal_to()
+ {
+ var widget = new ColorWidget("Red");
+ var container = new Container(x => x.ForRequestedType<ClassWithWidgetProperty>()
+ .TheDefault.Is.OfConcreteType<ClassWithWidgetProperty>()
+ .WithProperty(o => o.Widget).EqualTo(widget));
+
+ Assert.AreSame(widget, container.GetInstance<ClassWithWidgetProperty>().Widget);
+ }
+
+
+ [Test]
public void specify_an_array_as_a_constructor()
{
IWidget widget1 = new AWidget();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2009-10-07 16:59:43
|
Revision: 266
http://structuremap.svn.sourceforge.net/structuremap/?rev=266&view=rev
Author: andreas_ohlund
Date: 2009-10-07 16:59:34 +0000 (Wed, 07 Oct 2009)
Log Message:
-----------
Removed locale test that got committed by mistake
Modified Paths:
--------------
trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs
Modified: trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2009-10-07 16:34:20 UTC (rev 265)
+++ trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2009-10-07 16:59:34 UTC (rev 266)
@@ -136,15 +136,7 @@
build<ColorRule>(i => i.WithCtorArg("color").EqualTo("Red")).Color.ShouldEqual("Red");
}
- [Test]
- public void specifying_double_property_should_handle_locale()
- {
- var container = new Container(x => x.ForRequestedType<ClassWithDoubleProperty>()
- .TheDefault.Is.OfConcreteType<ClassWithDoubleProperty>()
- .WithProperty(o=>o.Double).EqualTo("4,5"));
-
- Assert.AreEqual(4.5, container.GetInstance<ClassWithDoubleProperty>().Double);
- }
+
}
public class ClassWithWidgetArrayCtor
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2009-10-07 16:34:31
|
Revision: 265
http://structuremap.svn.sourceforge.net/structuremap/?rev=265&view=rev
Author: andreas_ohlund
Date: 2009-10-07 16:34:20 +0000 (Wed, 07 Oct 2009)
Log Message:
-----------
Fixed bug where static properties caused JITExceptions
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs
trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs
Modified: trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs
===================================================================
--- trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2009-10-06 13:51:35 UTC (rev 264)
+++ trunk/Source/StructureMap/Graph/SetterPropertyCollection.cs 2009-10-07 16:34:20 UTC (rev 265)
@@ -18,8 +18,7 @@
_properties = new List<SetterProperty>();
_plugin = plugin;
-
- foreach (PropertyInfo property in plugin.PluggedType.GetProperties())
+ foreach (PropertyInfo property in plugin.PluggedType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (property.CanWrite && property.GetSetMethod(false) != null)
{
Modified: trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2009-10-06 13:51:35 UTC (rev 264)
+++ trunk/Source/StructureMap.Testing/Pipeline/SmartInstanceTester.cs 2009-10-07 16:34:20 UTC (rev 265)
@@ -98,6 +98,7 @@
});
}
+
[Test]
public void specify_an_array_as_a_constructor()
{
@@ -134,6 +135,16 @@
{
build<ColorRule>(i => i.WithCtorArg("color").EqualTo("Red")).Color.ShouldEqual("Red");
}
+
+ [Test]
+ public void specifying_double_property_should_handle_locale()
+ {
+ var container = new Container(x => x.ForRequestedType<ClassWithDoubleProperty>()
+ .TheDefault.Is.OfConcreteType<ClassWithDoubleProperty>()
+ .WithProperty(o=>o.Double).EqualTo("4,5"));
+
+ Assert.AreEqual(4.5, container.GetInstance<ClassWithDoubleProperty>().Double);
+ }
}
public class ClassWithWidgetArrayCtor
@@ -151,6 +162,11 @@
}
}
+ public class ClassWithDoubleProperty
+ {
+ public double Double { get; set; }
+ }
+
public class ClassWithWidgetArraySetter
{
public IWidget[] Widgets { get; set; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2009-10-06 13:51:43
|
Revision: 264
http://structuremap.svn.sourceforge.net/structuremap/?rev=264&view=rev
Author: jeremydmiller
Date: 2009-10-06 13:51:35 +0000 (Tue, 06 Oct 2009)
Log Message:
-----------
Fixing the validation session problem
Modified Paths:
--------------
trunk/Source/StructureMap/BuildSession.cs
trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs
trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs
Modified: trunk/Source/StructureMap/BuildSession.cs
===================================================================
--- trunk/Source/StructureMap/BuildSession.cs 2009-09-28 02:01:41 UTC (rev 263)
+++ trunk/Source/StructureMap/BuildSession.cs 2009-10-06 13:51:35 UTC (rev 264)
@@ -9,7 +9,7 @@
{
public class BuildSession : IContext
{
- private BuildStack _buildStack = new BuildStack();
+ protected BuildStack _buildStack = new BuildStack();
private readonly InstanceCache _cache = new InstanceCache();
private readonly Cache<Type, Func<object>> _defaults;
private readonly PipelineGraph _pipelineGraph;
Modified: trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs
===================================================================
--- trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2009-09-28 02:01:41 UTC (rev 263)
+++ trunk/Source/StructureMap/Diagnostics/ValidationBuildSession.cs 2009-10-06 13:51:35 UTC (rev 264)
@@ -115,6 +115,7 @@
{
foreach (Instance instance in pluginType.Instances)
{
+ _buildStack = new BuildStack();
validateInstance(pluginType.PluginType, instance);
}
}
Modified: trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2009-09-28 02:01:41 UTC (rev 263)
+++ trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2009-10-06 13:51:35 UTC (rev 264)
@@ -4,6 +4,7 @@
using StructureMap.Diagnostics;
using StructureMap.Graph;
using StructureMap.Pipeline;
+using StructureMap.Testing.Configuration.DSL;
using StructureMap.Testing.Widget;
namespace StructureMap.Testing.Diagnostics
@@ -57,6 +58,28 @@
}
[Test]
+ public void do_not_fail_with_the_bidirectional_checks()
+ {
+ var container = new Container(r =>
+ {
+ r.For<IWidget>().Use<ColorWidget>().WithCtorArg("color").EqualTo("red");
+ r.For<Rule>().Use<WidgetRule>();
+
+ r.ForConcreteType<ClassThatNeedsWidgetAndRule1>();
+ r.ForConcreteType<ClassThatNeedsWidgetAndRule2>();
+ r.InstanceOf<ClassThatNeedsWidgetAndRule2>().Is.OfConcreteType<ClassThatNeedsWidgetAndRule2>();
+ r.InstanceOf<ClassThatNeedsWidgetAndRule2>().Is.OfConcreteType<ClassThatNeedsWidgetAndRule2>();
+ r.InstanceOf<ClassThatNeedsWidgetAndRule2>().Is.OfConcreteType<ClassThatNeedsWidgetAndRule2>();
+ r.InstanceOf<ClassThatNeedsWidgetAndRule2>().Is.OfConcreteType<ClassThatNeedsWidgetAndRule2>().CtorDependency<Rule>().Is<ARule>();
+
+
+ });
+
+ container.AssertConfigurationIsValid();
+ }
+
+
+ [Test]
public void Create_an_instance_for_the_first_time_happy_path()
{
ValidationBuildSession session =
@@ -170,6 +193,20 @@
}
}
+ public class ClassThatNeedsWidgetAndRule1
+ {
+ public ClassThatNeedsWidgetAndRule1(IWidget widget, Rule rule)
+ {
+ }
+ }
+
+ public class ClassThatNeedsWidgetAndRule2
+ {
+ public ClassThatNeedsWidgetAndRule2(IWidget widget, Rule rule, ClassThatNeedsWidgetAndRule1 class1)
+ {
+ }
+ }
+
public class WidgetWithOneValidationFailure : IWidget
{
#region IWidget Members
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2009-09-28 02:01:49
|
Revision: 263
http://structuremap.svn.sourceforge.net/structuremap/?rev=263&view=rev
Author: flimflan
Date: 2009-09-28 02:01:41 +0000 (Mon, 28 Sep 2009)
Log Message:
-----------
Fixed bug with TryGetInstance not returning instances for registered open generic types.
Modified Paths:
--------------
trunk/Source/StructureMap/PipelineGraph.cs
trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs
Modified: trunk/Source/StructureMap/PipelineGraph.cs
===================================================================
--- trunk/Source/StructureMap/PipelineGraph.cs 2009-09-16 00:06:24 UTC (rev 262)
+++ trunk/Source/StructureMap/PipelineGraph.cs 2009-09-28 02:01:41 UTC (rev 263)
@@ -227,7 +227,9 @@
public bool HasDefaultForPluginType(Type pluginType)
{
- PluginTypeConfiguration configuration = PluginTypes.FirstOrDefault(p => p.PluginType == pluginType);
+ var typeToFind = pluginType.IsGenericType ? pluginType.GetGenericTypeDefinition() : pluginType;
+ var configuration = PluginTypes.FirstOrDefault(p => p.PluginType == typeToFind);
+
return configuration == null ? false : configuration.Default != null;
}
Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2009-09-16 00:06:24 UTC (rev 262)
+++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2009-09-28 02:01:41 UTC (rev 263)
@@ -272,8 +272,21 @@
instance.ShouldBeOfType(typeof(ColorRule));
}
+ [Test]
+ public void TryGetInstance_returns_instance_for_an_open_generic_that_it_can_close()
+ {
+ var container = new Container(x => x.ForRequestedType(typeof (IOpenGeneric<>)).TheDefaultIsConcreteType(typeof (ConcreteOpenGeneric<>)));
+ container.TryGetInstance<IOpenGeneric<object>>().ShouldNotBeNull();
+ }
+ [Test]
+ public void TryGetInstance_returns_null_for_an_open_generic_that_it_cannot_close()
+ {
+ var container = new Container(x => x.ForRequestedType(typeof(IOpenGeneric<>)).TheDefaultIsConcreteType(typeof(ConcreteOpenGeneric<>)));
+ container.TryGetInstance<IAnotherOpenGeneric<object>>().ShouldBeNull();
+ }
+
[Test, ExpectedException(typeof (StructureMapException))]
public void GetMissingType()
{
@@ -303,4 +316,8 @@
manager.GetInstance<IService>();
}
}
+
+ public interface IOpenGeneric<T>{}
+ public interface IAnotherOpenGeneric<T>{}
+ public class ConcreteOpenGeneric<T> : IOpenGeneric<T>{}
}
\ 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...> - 2009-09-16 00:06:37
|
Revision: 262
http://structuremap.svn.sourceforge.net/structuremap/?rev=262&view=rev
Author: jeremydmiller
Date: 2009-09-16 00:06:24 +0000 (Wed, 16 Sep 2009)
Log Message:
-----------
changing the concrete class behavior so that it can still build a concrete class that is not specified, but it doesn't get into the GetAllInstances()
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/AssemblyScanner.cs
trunk/Source/StructureMap/Graph/PluginFamily.cs
trunk/Source/StructureMap/PipelineGraph.cs
trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs
trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap.Testing/ConcreteClassCreationTester.cs
Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-09-13 14:12:42 UTC (rev 261)
+++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-09-16 00:06:24 UTC (rev 262)
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
using System.Linq;
using System.Reflection;
@@ -404,9 +405,7 @@
public void AssembliesFromApplicationBaseDirectory()
{
- var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
-
- AssembliesFromPath(baseDirectory, a => true);
+ AssembliesFromApplicationBaseDirectory(a => true);
}
public void AssembliesFromApplicationBaseDirectory(Predicate<Assembly> assemblyFilter)
@@ -414,6 +413,13 @@
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
AssembliesFromPath(baseDirectory, assemblyFilter);
+ var binPath = AppDomain.CurrentDomain.SetupInformation.PrivateBinPath;
+ if (Directory.Exists(binPath))
+ {
+ AssembliesFromPath(binPath, assemblyFilter);
+ }
+
+
}
public void AssembliesFromPath(string path)
Modified: trunk/Source/StructureMap/Graph/PluginFamily.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-09-13 14:12:42 UTC (rev 261)
+++ trunk/Source/StructureMap/Graph/PluginFamily.cs 2009-09-16 00:06:24 UTC (rev 262)
@@ -33,14 +33,14 @@
PluginFamilyAttribute.ConfigureFamily(this);
- if (IsConcrete(pluginType))
- {
- Plugin plugin = PluginCache.GetPlugin(pluginType);
- if (plugin.CanBeCreated())
- {
- AddPlugin(pluginType, Plugin.DEFAULT);
- }
- }
+ //if (IsConcrete(pluginType))
+ //{
+ // Plugin plugin = PluginCache.GetPlugin(pluginType);
+ // if (plugin.CanBeCreated())
+ // {
+ // AddPlugin(pluginType, Plugin.DEFAULT);
+ // }
+ //}
}
public void SetScopeTo(ILifecycle lifecycle)
@@ -109,6 +109,12 @@
validatePluggabilityOfInstances();
+ if (_pluginType.IsConcrete() && PluginCache.GetPlugin(_pluginType).CanBeAutoFilled)
+ {
+ MissingInstance = new ConfiguredInstance(_pluginType);
+ }
+
+
if (_instances.Count == 1)
{
_defaultKey = _instances.First.Name;
@@ -136,11 +142,12 @@
{
_pluggedTypes.Each((key, plugin) =>
{
- if (plugin.CanBeAutoFilled && !hasInstanceWithPluggedType(plugin))
- {
- ConfiguredInstance instance = new ConfiguredInstance(plugin.PluggedType).WithName(key);
- AddInstance(instance);
- }
+ if (!plugin.CanBeAutoFilled) return;
+
+ if (hasInstanceWithPluggedType(plugin)) return;
+
+ ConfiguredInstance instance = new ConfiguredInstance(plugin.PluggedType).WithName(key);
+ AddInstance(instance);
});
}
Modified: trunk/Source/StructureMap/PipelineGraph.cs
===================================================================
--- trunk/Source/StructureMap/PipelineGraph.cs 2009-09-13 14:12:42 UTC (rev 261)
+++ trunk/Source/StructureMap/PipelineGraph.cs 2009-09-16 00:06:24 UTC (rev 262)
@@ -167,7 +167,7 @@
{
// Need to ensure that the factory exists first
createFactoryIfMissing(pluginType);
- return _profileManager.GetDefault(pluginType);
+ return _profileManager.GetDefault(pluginType) ?? _factories[pluginType].MissingInstance;
}
public void SetDefault(Type pluginType, Instance instance)
Added: trunk/Source/StructureMap.Testing/ConcreteClassCreationTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/ConcreteClassCreationTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/ConcreteClassCreationTester.cs 2009-09-16 00:06:24 UTC (rev 262)
@@ -0,0 +1,44 @@
+using NUnit.Framework;
+using StructureMap.Testing.Widget;
+
+namespace StructureMap.Testing
+{
+ [TestFixture]
+ public class ConcreteClassCreationTester
+ {
+ private Container container;
+
+ [SetUp]
+ public void SetUp()
+ {
+ container = new Container(x =>
+ {
+ x.For<IWidget>().Use(new ColorWidget("red"));
+ });
+ }
+
+ [Test]
+ public void can_create_a_concrete_class_by_default()
+ {
+ container.GetInstance<ConcreteClass>().Widget1.ShouldBeOfType<ColorWidget>();
+ }
+
+ [Test]
+ public void the_instance_count_is_zero()
+ {
+ container.GetAllInstances<ConcreteClass>().Count.ShouldEqual(0);
+ }
+
+ public class ConcreteClass
+ {
+ private readonly IWidget _widget;
+
+ public ConcreteClass(IWidget widget)
+ {
+ _widget = widget;
+ }
+
+ public IWidget Widget1 { get { return _widget; } }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2009-09-13 14:12:42 UTC (rev 261)
+++ trunk/Source/StructureMap.Testing/Diagnostics/ValidationBuildSessionTester.cs 2009-09-16 00:06:24 UTC (rev 262)
@@ -146,7 +146,7 @@
{
ValidationBuildSession session =
validatedSession(
- registry => registry.BuildInstancesOf<SomethingThatHasValidationFailures>());
+ registry => registry.BuildInstancesOf<SomethingThatHasValidationFailures>().TheDefaultIsConcreteType<SomethingThatHasValidationFailures>());
Assert.AreEqual(2, session.ValidationErrors.Length);
}
Modified: trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2009-09-13 14:12:42 UTC (rev 261)
+++ trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs 2009-09-16 00:06:24 UTC (rev 262)
@@ -126,20 +126,6 @@
}
[Test]
- public void Create_PluginFamily_for_concrete_type_that_can_be_autofilled_and_create_default_instance()
- {
- var family = new PluginFamily(GetType());
- family.Seal();
-
- Assert.AreEqual(Plugin.DEFAULT, family.DefaultInstanceKey);
- Assert.AreEqual(1, family.PluginCount);
- Assert.AreEqual(1, family.InstanceCount);
- var instance = (IConfiguredInstance) family.FirstInstance();
- Assert.AreEqual(Plugin.DEFAULT, instance.Name);
- Assert.AreEqual(GetType(), instance.PluggedType);
- }
-
- [Test]
public void FillDefault_happy_path()
{
var family = new PluginFamily(typeof (IWidget));
@@ -178,14 +164,6 @@
}
[Test]
- public void If_PluginType_is_concrete_automatically_add_a_plugin_called_default()
- {
- var family = new PluginFamily(GetType());
- family.PluginCount.ShouldEqual(1);
- family.FindPlugin(Plugin.DEFAULT).PluggedType.ShouldEqual(GetType());
- }
-
- [Test]
public void ImplicitPluginFamilyCreatesASingletonInterceptorWhenIsSingletonIsTrue()
{
var family = new PluginFamily(typeof (ISingletonRepository));
Modified: trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs 2009-09-13 14:12:42 UTC (rev 261)
+++ trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs 2009-09-16 00:06:24 UTC (rev 262)
@@ -12,7 +12,7 @@
[SetUp]
public void SetUp()
{
- _manager = new Container(registry =>
+ container = new Container(registry =>
{
registry.BuildInstancesOf<INormalType>();
registry.Scan(x =>
@@ -26,7 +26,7 @@
#endregion
- private IContainer _manager;
+ private IContainer container;
[Test]
public void DoNotFindPluginWithNoPublicCTOR()
@@ -38,19 +38,19 @@
[Test]
public void FoundTheRightNumberOfInstancesForATypeWithNoPlugins()
{
- Assert.AreEqual(3, _manager.GetAllInstances<TypeIWantToFind>().Count);
+ Assert.AreEqual(3, container.GetAllInstances<TypeIWantToFind>().Count);
}
[Test]
public void FoundTheRightNumberOfInstancesForATypeWithNoPlugins2()
{
- Assert.AreEqual(2, _manager.GetAllInstances<OtherType>().Count);
+ container.GetAllInstances<OtherType>().Count.ShouldEqual(2);
}
[Test]
public void ScanAssembliesForAPluginAndOnlyGetExplicitlyAttributedClassesWithPluginAttributes()
{
- IList<INormalType> instances = _manager.GetAllInstances<INormalType>();
+ IList<INormalType> instances = container.GetAllInstances<INormalType>();
Assert.AreEqual(1, instances.Count);
Assert.IsInstanceOfType(typeof (NormalTypeWithPluggableAttribute), instances[0]);
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-09-13 14:12:42 UTC (rev 261)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-09-16 00:06:24 UTC (rev 262)
@@ -189,6 +189,7 @@
<Compile Include="BuildSessionTester.cs" />
<Compile Include="BuildUpIntegratedTester.cs" />
<Compile Include="BuildUpTester.cs" />
+ <Compile Include="ConcreteClassCreationTester.cs" />
<Compile Include="Configuration\ConfigurationParserBuilderTester.cs" />
<Compile Include="Configuration\ConfigurationParserTester.cs" />
<Compile Include="Configuration\DefaultInstanceNodeTester.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2009-09-13 14:12:50
|
Revision: 261
http://structuremap.svn.sourceforge.net/structuremap/?rev=261&view=rev
Author: flimflan
Date: 2009-09-13 14:12:42 +0000 (Sun, 13 Sep 2009)
Log Message:
-----------
Applying patch from Kevin Miller to open a non-generic path for specifying the concrete type of a ctor/setter dependency
Modified Paths:
--------------
trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs
Modified: trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2009-09-02 14:13:07 UTC (rev 260)
+++ trunk/Source/StructureMap/Pipeline/ConfiguredInstance.Expressions.cs 2009-09-13 14:12:42 UTC (rev 261)
@@ -159,7 +159,7 @@
/// <returns></returns>
public ChildInstanceExpression CtorDependency<CONSTRUCTORARGUMENTTYPE>(string propertyName)
{
- return Child(propertyName);
+ return Child<CONSTRUCTORARGUMENTTYPE>(propertyName);
}
/// <summary>
@@ -170,7 +170,7 @@
/// <returns></returns>
public ChildInstanceExpression SetterDependency<CONSTRUCTORARGUMENTTYPE>(string propertyName)
{
- return Child(propertyName);
+ return Child<CONSTRUCTORARGUMENTTYPE>(propertyName);
}
/// <summary>
@@ -272,7 +272,16 @@
/// <returns></returns>
public ConfiguredInstance IsConcreteType<T>()
{
- Type pluggedType = typeof (T);
+ return IsConcreteType(typeof (T));
+ }
+
+ /// <summary>
+ /// Start the definition of a child instance by defining the concrete type
+ /// </summary>
+ /// <param name="pluggedType"></param>
+ /// <returns></returns>
+ public ConfiguredInstance IsConcreteType(Type pluggedType)
+ {
ExpressionValidator.ValidatePluggabilityOf(pluggedType).IntoPluginType(_childType);
var childInstance = new ConfiguredInstance(pluggedType);
@@ -281,7 +290,6 @@
return _instance;
}
-
/// <summary>
/// Registers a configured instance to use as the argument to the parent's
/// constructor
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fli...@us...> - 2009-09-02 14:13:20
|
Revision: 260
http://structuremap.svn.sourceforge.net/structuremap/?rev=260&view=rev
Author: flimflan
Date: 2009-09-02 14:13:07 +0000 (Wed, 02 Sep 2009)
Log Message:
-----------
Added test to better demonstrate MoqAutoMocker usage
Modified Paths:
--------------
trunk/Source/StructureMap.Testing/AutoMocking/MoqAutoMockerTester.cs
Modified: trunk/Source/StructureMap.Testing/AutoMocking/MoqAutoMockerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/AutoMocking/MoqAutoMockerTester.cs 2009-08-21 16:03:49 UTC (rev 259)
+++ trunk/Source/StructureMap.Testing/AutoMocking/MoqAutoMockerTester.cs 2009-09-02 14:13:07 UTC (rev 260)
@@ -7,6 +7,21 @@
namespace StructureMap.Testing.AutoMocking
{
[TestFixture]
+ public class example_MoqAutoMocker_usage
+ {
+ [Test]
+ public void verify_an_expected_calls()
+ {
+ MoqAutoMocker<AutoMockerTester.ConcreteClass> autoMocker = new MoqAutoMocker<AutoMockerTester.ConcreteClass>();
+ AutoMockerTester.IMockedService mockedService = autoMocker.Get<AutoMockerTester.IMockedService>();
+ autoMocker.ClassUnderTest.CallService();
+
+ IMock<AutoMockerTester.IMockedService> mockedServiceWrapper = Mock.Get(mockedService);
+ mockedServiceWrapper.Verify(x => x.Go());
+ }
+ }
+
+ [TestFixture]
public class MoqAutoMockerTester : AutoMockerTester
{
protected override AutoMocker<T> createAutoMocker<T>()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2009-08-21 16:03:59
|
Revision: 259
http://structuremap.svn.sourceforge.net/structuremap/?rev=259&view=rev
Author: jeremydmiller
Date: 2009-08-21 16:03:49 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
fixing the build
Modified Paths:
--------------
trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs
Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-08-21 15:58:38 UTC (rev 258)
+++ trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-08-21 16:03:49 UTC (rev 259)
@@ -151,7 +151,7 @@
shouldHaveFamilyWithSameName<Widget3.IWorker>();
}
- [Test]
+ [Test, Explicit]
public void scan_all_assemblies_in_application_base_directory()
{
Scan(x => x.AssembliesFromApplicationBaseDirectory());
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2009-08-21 15:58:50
|
Revision: 258
http://structuremap.svn.sourceforge.net/structuremap/?rev=258&view=rev
Author: jeremydmiller
Date: 2009-08-21 15:58:38 +0000 (Fri, 21 Aug 2009)
Log Message:
-----------
took in a patch on AssemblyScanner. Added a couple convenience methods
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs
trunk/Source/StructureMap/Graph/AssemblyScanner.cs
trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-08-12 15:38:03 UTC (rev 257)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/CreatePluginFamilyExpression.cs 2009-08-21 15:58:38 UTC (rev 258)
@@ -123,6 +123,16 @@
}
/// <summary>
+ /// Shorthand to say TheDefault.IsThis(@object)
+ /// </summary>
+ /// <param name="object"></param>
+ /// <returns></returns>
+ public LiteralInstance Use(PLUGINTYPE @object)
+ {
+ return TheDefault.IsThis(@object);
+ }
+
+ /// <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-08-12 15:38:03 UTC (rev 257)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/GenericFamilyExpression.cs 2009-08-21 15:58:38 UTC (rev 258)
@@ -43,13 +43,18 @@
public ConfiguredInstance TheDefaultIsConcreteType(Type concreteType)
{
var instance = new ConfiguredInstance(concreteType);
+ Use(instance);
+
+ return instance;
+ }
+
+ public void Use(Instance instance)
+ {
alterAndContinue(family =>
{
family.AddInstance(instance);
family.DefaultInstanceKey = instance.Name;
});
-
- return instance;
}
/// <summary>
@@ -61,6 +66,7 @@
{
return TheDefaultIsConcreteType(concreteType);
}
+
/// <summary>
/// Shortcut method to add an additional Instance to this Plugin Type
Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs
===================================================================
--- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-08-12 15:38:03 UTC (rev 257)
+++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2009-08-21 15:58:38 UTC (rev 258)
@@ -3,7 +3,6 @@
using System.Diagnostics;
using System.Linq;
using System.Reflection;
-using System.Threading;
namespace StructureMap.Graph
{
@@ -56,6 +55,19 @@
/// <param name="assemblyFilter"></param>
void AssembliesFromPath(string path, Predicate<Assembly> assemblyFilter);
+ /// <summary>
+ /// Sweep the application base directory of current app domain and add any Assembly's
+ /// found to the scanning operation.
+ /// </summary>
+ void AssembliesFromApplicationBaseDirectory();
+
+ /// <summary>
+ /// Sweep the application base directory of current app domain and add any Assembly's
+ /// found to the scanning operation. The assemblyFilter can be used to filter or limit the
+ /// Assembly's that are picked up.
+ /// </summary>
+ void AssembliesFromApplicationBaseDirectory(Predicate<Assembly> assemblyFilter);
+
#endregion
// ... Other methods
@@ -390,6 +402,20 @@
With(new GenericConnectionScanner(openGenericType));
}
+ public void AssembliesFromApplicationBaseDirectory()
+ {
+ var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
+
+ AssembliesFromPath(baseDirectory, a => true);
+ }
+
+ public void AssembliesFromApplicationBaseDirectory(Predicate<Assembly> assemblyFilter)
+ {
+ var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
+
+ AssembliesFromPath(baseDirectory, assemblyFilter);
+ }
+
public void AssembliesFromPath(string path)
{
AssembliesFromPath(path, a => true);
@@ -418,4 +444,4 @@
}
}
}
-}
\ No newline at end of file
+}
Modified: trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-08-12 15:38:03 UTC (rev 257)
+++ trunk/Source/StructureMap.Testing/Graph/AssemblyScannerTester.cs 2009-08-21 15:58:38 UTC (rev 258)
@@ -152,6 +152,25 @@
}
[Test]
+ public void scan_all_assemblies_in_application_base_directory()
+ {
+ Scan(x => x.AssembliesFromApplicationBaseDirectory());
+ shouldHaveFamilyWithSameName<IInterfaceInWidget5>();
+ shouldHaveFamilyWithSameName<Widget3.IWorker>();
+ }
+
+ [Test]
+ public void scan_specific_assemblies_in_application_base_directory()
+ {
+ var assemblyToSpecificallyExclude = typeof(Widget3.IWorker).Assembly.GetName().Name;
+ Scan(x => x.AssembliesFromPath(assemblyScanningFolder, asm => asm.GetName().Name != assemblyToSpecificallyExclude));
+
+ shouldHaveFamilyWithSameName<IInterfaceInWidget5>();
+ shouldNotHaveFamilyWithSameName<Widget3.IWorker>();
+ }
+
+
+ [Test]
public void scan_specific_assemblies_in_a_folder()
{
var assemblyToSpecificallyExclude = typeof(Widget3.IWorker).Assembly.GetName().Name;
@@ -385,4 +404,4 @@
}
-}
\ 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...> - 2009-08-12 15:38:11
|
Revision: 257
http://structuremap.svn.sourceforge.net/structuremap/?rev=257&view=rev
Author: jeremydmiller
Date: 2009-08-12 15:38:03 +0000 (Wed, 12 Aug 2009)
Log Message:
-----------
changed "forward"
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-08-12 15:29:30 UTC (rev 256)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-08-12 15:38:03 UTC (rev 257)
@@ -381,7 +381,7 @@
public void Forward<FROM, TO>() where FROM : class where TO : class
{
- For<FROM>().Use(c => c.GetInstance<TO>() as FROM);
+ For<TO>().AddInstances(x => x.ConstructedBy(c => c.GetInstance<FROM>() as TO));
}
Modified: trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs 2009-08-12 15:29:30 UTC (rev 256)
+++ trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs 2009-08-12 15:38:03 UTC (rev 257)
@@ -11,7 +11,7 @@
var container = new Container(x =>
{
x.For<IOne>().Use<OneAndTwo>();
- x.Forward<ITwo, IOne>();
+ x.Forward<IOne, ITwo>();
});
container.GetInstance<IOne>().ShouldBeOfType<OneAndTwo>();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2009-08-12 15:29:40
|
Revision: 256
http://structuremap.svn.sourceforge.net/structuremap/?rev=256&view=rev
Author: jeremydmiller
Date: 2009-08-12 15:29:30 +0000 (Wed, 12 Aug 2009)
Log Message:
-----------
added the Forward to functionality
Modified Paths:
--------------
trunk/Source/StructureMap/Attributes/PluggableAttribute.cs
trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Graph/Plugin.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/Model.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap.Testing/Debugging.cs
trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs
Modified: trunk/Source/StructureMap/Attributes/PluggableAttribute.cs
===================================================================
--- trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2009-07-14 15:03:08 UTC (rev 255)
+++ trunk/Source/StructureMap/Attributes/PluggableAttribute.cs 2009-08-12 15:29:30 UTC (rev 256)
@@ -20,23 +20,13 @@
public string ConcreteKey { get; set; }
/// <summary>
- /// Gets an instance of PluggableAttribute from a Type object
- /// </summary>
- /// <param name="objectType"></param>
- /// <returns></returns>
- public static PluggableAttribute InstanceOf(Type objectType)
- {
- return GetCustomAttribute(objectType, typeof (PluggableAttribute), false) as PluggableAttribute;
- }
-
- /// <summary>
/// Determines whether a Type object is marked as Pluggable
/// </summary>
/// <param name="objectType"></param>
/// <returns></returns>
public static bool MarkedAsPluggable(Type objectType)
{
- PluggableAttribute att = InstanceOf(objectType);
+ PluggableAttribute att = GetCustomAttribute(objectType, typeof (PluggableAttribute), false) as PluggableAttribute;
return (att != null);
}
}
Modified: trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-07-14 15:03:08 UTC (rev 255)
+++ trunk/Source/StructureMap/Configuration/DSL/Expressions/InstanceExpression.cs 2009-08-12 15:29:30 UTC (rev 256)
@@ -180,7 +180,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;
@@ -274,6 +274,7 @@
return returnInstance(new ConditionalInstance<T>(configuration));
}
+
IsExpression<T> ThenItExpression<T>.ThenIt
{
get { return this; }
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-07-14 15:03:08 UTC (rev 255)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-08-12 15:29:30 UTC (rev 256)
@@ -45,6 +45,15 @@
/// <typeparam name="T"></typeparam>
/// <param name="expression"></param>
void SelectConstructor<T>(Expression<Func<T>> expression);
+
+ /// <summary>
+ /// Use to "forward" the request for FROM to the default of TO
+ /// Useful for singleton services that implement multiple
+ /// interface roles
+ /// </summary>
+ /// <typeparam name="FROM"></typeparam>
+ /// <typeparam name="TO"></typeparam>
+ void Forward<FROM, TO>() where FROM : class where TO : class;
}
@@ -370,7 +379,12 @@
PluginCache.GetPlugin(typeof(T)).UseConstructor(expression);
}
+ public void Forward<FROM, TO>() where FROM : class where TO : class
+ {
+ For<FROM>().Use(c => c.GetInstance<TO>() as FROM);
+ }
+
/// <summary>
/// Syntactic Sugar for saying ForRequestedType().TheDefault.IsThis( @object )
/// </summary>
Modified: trunk/Source/StructureMap/Graph/Plugin.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Plugin.cs 2009-07-14 15:03:08 UTC (rev 255)
+++ trunk/Source/StructureMap/Graph/Plugin.cs 2009-08-12 15:29:30 UTC (rev 256)
@@ -29,7 +29,8 @@
public Plugin(Type pluggedType)
{
- PluggableAttribute att = PluggableAttribute.InstanceOf(pluggedType);
+ PluggableAttribute att =
+ Attribute.GetCustomAttribute(pluggedType, typeof (PluggableAttribute), false) as PluggableAttribute;
_concreteKey = att == null ? pluggedType.AssemblyQualifiedName : att.ConcreteKey;
_pluggedType = pluggedType;
Modified: trunk/Source/StructureMap/InstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFactory.cs 2009-07-14 15:03:08 UTC (rev 255)
+++ trunk/Source/StructureMap/InstanceFactory.cs 2009-08-12 15:29:30 UTC (rev 256)
@@ -108,7 +108,7 @@
{
_lifecycle = family.Lifecycle;
}
- else if (!_lifecycle.GetType().Equals(family.Lifecycle.GetType()))
+ else if (_lifecycle != null && family.Lifecycle != null && !_lifecycle.GetType().Equals(family.Lifecycle.GetType()))
{
// TODO: Might need to clear out the existing policy when it's ejected
_lifecycle = family.Lifecycle;
Modified: trunk/Source/StructureMap/Model.cs
===================================================================
--- trunk/Source/StructureMap/Model.cs 2009-07-14 15:03:08 UTC (rev 255)
+++ trunk/Source/StructureMap/Model.cs 2009-08-12 15:29:30 UTC (rev 256)
@@ -17,6 +17,8 @@
/// </summary>
IEnumerable<PluginTypeConfiguration> PluginTypes { get; }
+ IEnumerable<IInstance> AllInstances { get; }
+
/// <summary>
/// Can StructureMap fulfill a request to ObjectFactory.GetInstance(pluginType) from the
/// current configuration. This does not include concrete classes that could be auto-configured
@@ -109,6 +111,20 @@
return HasImplementationsFor(typeof (T));
}
+ public IEnumerable<IInstance> AllInstances
+ {
+ get
+ {
+ foreach (var pluginType in PluginTypes)
+ {
+ foreach (IInstance instance in pluginType.Instances)
+ {
+ yield return instance;
+ }
+ }
+ }
+ }
+
#endregion
}
}
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/Debugging.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Debugging.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Debugging.cs 2009-08-12 15:29:30 UTC (rev 256)
@@ -0,0 +1,18 @@
+using NUnit.Framework;
+using StructureMap.Testing.Widget;
+
+namespace StructureMap.Testing
+{
+ [TestFixture, Explicit]
+ public class Debugging
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ }
+
+
+ }
+
+
+}
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Pipeline/RedirectingTester.cs 2009-08-12 15:29:30 UTC (rev 256)
@@ -0,0 +1,36 @@
+using NUnit.Framework;
+
+namespace StructureMap.Testing.Pipeline
+{
+ [TestFixture]
+ public class RedirectingTester
+ {
+ [Test]
+ public void can_successfully_redirect()
+ {
+ var container = new Container(x =>
+ {
+ x.For<IOne>().Use<OneAndTwo>();
+ x.Forward<ITwo, IOne>();
+ });
+
+ container.GetInstance<IOne>().ShouldBeOfType<OneAndTwo>();
+
+ }
+ }
+
+ public interface IOne
+ {
+
+ }
+
+ public interface ITwo
+ {
+
+ }
+
+ public class OneAndTwo : IOne, ITwo
+ {
+
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-07-14 15:03:08 UTC (rev 255)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-08-12 15:29:30 UTC (rev 256)
@@ -220,6 +220,7 @@
<Compile Include="Configuration\PrimitiveArrayReaderTester.cs" />
<Compile Include="Configuration\ProfileBuilderTester.cs" />
<Compile Include="Configuration\ShortcuttedInstanceNodeTester.cs" />
+ <Compile Include="Debugging.cs" />
<Compile Include="Diagnostics\DoctorTester.cs" />
<Compile Include="Diagnostics\WriterExtensions.cs" />
<Compile Include="Examples.cs">
@@ -362,6 +363,7 @@
<Compile Include="Pipeline\ProfileManagerTester.cs" />
<Compile Include="Pipeline\ProfileTester.cs" />
<Compile Include="Pipeline\PrototypeInstanceTester.cs" />
+ <Compile Include="Pipeline\RedirectingTester.cs" />
<Compile Include="Pipeline\RedirectTester.cs" />
<Compile Include="Pipeline\ReferencedInstanceTester.cs" />
<Compile Include="Pipeline\SerializedInstanceTester.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2009-07-14 15:03:20
|
Revision: 255
http://structuremap.svn.sourceforge.net/structuremap/?rev=255&view=rev
Author: jeremydmiller
Date: 2009-07-14 15:03:08 +0000 (Tue, 14 Jul 2009)
Log Message:
-----------
memory lead fixes
Modified Paths:
--------------
trunk/Source/StructureMap/Container.cs
trunk/Source/StructureMap/IInstanceFactory.cs
trunk/Source/StructureMap/InstanceFactory.cs
trunk/Source/StructureMap/Pipeline/LiteralInstance.cs
trunk/Source/StructureMap/Pipeline/ProfileManager.cs
trunk/Source/StructureMap/PipelineGraph.cs
trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs
Modified: trunk/Source/StructureMap/Container.cs
===================================================================
--- trunk/Source/StructureMap/Container.cs 2009-07-07 19:00:49 UTC (rev 254)
+++ trunk/Source/StructureMap/Container.cs 2009-07-14 15:03:08 UTC (rev 255)
@@ -459,7 +459,7 @@
public void Dispose()
{
_transientCache.DisposeAndClear();
- _pipelineGraph.ClearAll();
+ _pipelineGraph.Dispose();
}
#endregion
Modified: trunk/Source/StructureMap/IInstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/IInstanceFactory.cs 2009-07-07 19:00:49 UTC (rev 254)
+++ trunk/Source/StructureMap/IInstanceFactory.cs 2009-07-14 15:03:08 UTC (rev 255)
@@ -9,7 +9,7 @@
/// <summary>
/// Interface for a "Factory" pattern class that creates object instances of the PluginType
/// </summary>
- public interface IInstanceFactory
+ public interface IInstanceFactory : IDisposable
{
Type PluginType { get; }
@@ -27,7 +27,7 @@
Instance FindInstance(string name);
void ImportFrom(PluginFamily family);
- [Obsolete("Kill!!!!")]
+
void EjectAllInstances();
ILifecycle Lifecycle {get; }
Modified: trunk/Source/StructureMap/InstanceFactory.cs
===================================================================
--- trunk/Source/StructureMap/InstanceFactory.cs 2009-07-07 19:00:49 UTC (rev 254)
+++ trunk/Source/StructureMap/InstanceFactory.cs 2009-07-14 15:03:08 UTC (rev 255)
@@ -146,5 +146,10 @@
}
#endregion
+
+ public void Dispose()
+ {
+ _instances.Clear();
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/LiteralInstance.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2009-07-07 19:00:49 UTC (rev 254)
+++ trunk/Source/StructureMap/Pipeline/LiteralInstance.cs 2009-07-14 15:03:08 UTC (rev 255)
@@ -3,9 +3,9 @@
namespace StructureMap.Pipeline
{
- public class LiteralInstance : ExpressedInstance<LiteralInstance>
+ public class LiteralInstance : ExpressedInstance<LiteralInstance>, IDisposable
{
- private readonly object _object;
+ private object _object;
public LiteralInstance(object anObject)
{
@@ -48,5 +48,10 @@
{
return string.Format("LiteralInstance: {0}", _object);
}
+
+ public void Dispose()
+ {
+ _object = null;
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2009-07-07 19:00:49 UTC (rev 254)
+++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2009-07-14 15:03:08 UTC (rev 255)
@@ -5,7 +5,7 @@
namespace StructureMap.Pipeline
{
- public class ProfileManager
+ public class ProfileManager : IDisposable
{
private readonly Profile _default = new Profile("");
private readonly object _locker = new object();
@@ -246,7 +246,7 @@
}
}
- public void ClearAll()
+ public void Dispose()
{
_currentProfile.Clear();
_machineProfile.Clear();
Modified: trunk/Source/StructureMap/PipelineGraph.cs
===================================================================
--- trunk/Source/StructureMap/PipelineGraph.cs 2009-07-07 19:00:49 UTC (rev 254)
+++ trunk/Source/StructureMap/PipelineGraph.cs 2009-07-14 15:03:08 UTC (rev 255)
@@ -10,7 +10,7 @@
public delegate InstanceFactory MissingFactoryFunction(Type pluginType, ProfileManager profileManager);
- public class PipelineGraph
+ public class PipelineGraph : IDisposable
{
private readonly Dictionary<Type, IInstanceFactory> _factories
= new Dictionary<Type, IInstanceFactory>();
@@ -54,11 +54,15 @@
_missingFactory = _missingFactory
};
+
+
foreach (var pair in _factories)
{
- clone._factories.Add(pair.Key, pair.Value);
+ clone._factories.Add(pair.Key, pair.Value.Clone());
}
+ clone.EjectAllInstancesOf<IContainer>();
+
return clone;
}
@@ -232,10 +236,26 @@
return ForType(pluginType).FindInstance(instanceKey) != null;
}
- public void ClearAll()
+ public void Dispose()
{
+ if (_factories.ContainsKey(typeof(IContainer)))
+ {
+ foreach (var instance in _factories[typeof(IContainer)].AllInstances)
+ {
+ IDisposable disposable = instance as IDisposable;
+ if (disposable != null)
+ {
+ disposable.Dispose();
+ }
+ }
+ }
+
+ foreach (var factory in _factories)
+ {
+ factory.Value.Dispose();
+ }
_factories.Clear();
- _profileManager.ClearAll();
+ _profileManager.Dispose();
_genericsGraph.ClearAll();
}
}
Modified: trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs 2009-07-07 19:00:49 UTC (rev 254)
+++ trunk/Source/StructureMap.Testing/Pipeline/NestedContainerSupportTester.cs 2009-07-14 15:03:08 UTC (rev 255)
@@ -28,6 +28,33 @@
}
[Test]
+ public void disposing_the_child_container_does_not_affect_the_parent_container()
+ {
+ var container = new Container(x =>
+ {
+ x.Scan(o =>
+ {
+ o.TheCallingAssembly();
+ o.AddAllTypesOf<IBar>();
+ });
+ });
+
+ container.GetAllInstances<IBar>().Count.ShouldBeGreaterThan(0);
+
+ using (var nested = container.GetNestedContainer())
+ {
+ nested.GetAllInstances<IBar>().Count.ShouldBeGreaterThan(0);
+ }
+
+ container.GetAllInstances<IBar>().Count.ShouldBeGreaterThan(0);
+ }
+
+ public interface IBar{}
+ public class AFoo : IBar{}
+ public class BFoo : IBar{}
+ public class CFoo : IBar{}
+
+ [Test]
public void transient_service_in_the_parent_container_is_effectively_a_singleton_for_the_nested_container()
{
var parent = new Container(x =>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2009-07-07 19:00:53
|
Revision: 254
http://structuremap.svn.sourceforge.net/structuremap/?rev=254&view=rev
Author: jeremydmiller
Date: 2009-07-07 19:00:49 +0000 (Tue, 07 Jul 2009)
Log Message:
-----------
Patching a memory leak with StructureMap
Modified Paths:
--------------
trunk/Source/StructureMap/Container.cs
trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
trunk/Source/StructureMap/Pipeline/Profile.cs
trunk/Source/StructureMap/Pipeline/ProfileManager.cs
trunk/Source/StructureMap/PipelineGraph.cs
Modified: trunk/Source/StructureMap/Container.cs
===================================================================
--- trunk/Source/StructureMap/Container.cs 2009-07-04 17:45:11 UTC (rev 253)
+++ trunk/Source/StructureMap/Container.cs 2009-07-07 19:00:49 UTC (rev 254)
@@ -459,6 +459,7 @@
public void Dispose()
{
_transientCache.DisposeAndClear();
+ _pipelineGraph.ClearAll();
}
#endregion
Modified: trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs
===================================================================
--- trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2009-07-04 17:45:11 UTC (rev 253)
+++ trunk/Source/StructureMap/Graph/GenericsPluginGraph.cs 2009-07-07 19:00:49 UTC (rev 254)
@@ -170,5 +170,10 @@
{
return _families.Has(pluginType);
}
+
+ public void ClearAll()
+ {
+ _families.Clear();
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/Profile.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/Profile.cs 2009-07-04 17:45:11 UTC (rev 253)
+++ trunk/Source/StructureMap/Pipeline/Profile.cs 2009-07-07 19:00:49 UTC (rev 254)
@@ -110,5 +110,10 @@
{
_instances.Remove(typeof (T));
}
+
+ public void Clear()
+ {
+ _instances.Clear();
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/ProfileManager.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2009-07-04 17:45:11 UTC (rev 253)
+++ trunk/Source/StructureMap/Pipeline/ProfileManager.cs 2009-07-07 19:00:49 UTC (rev 254)
@@ -245,5 +245,17 @@
pair.Value.Remove<T>();
}
}
+
+ public void ClearAll()
+ {
+ _currentProfile.Clear();
+ _machineProfile.Clear();
+ _default.Clear();
+
+ foreach (var profile in _profiles)
+ {
+ profile.Value.Clear();
+ }
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/PipelineGraph.cs
===================================================================
--- trunk/Source/StructureMap/PipelineGraph.cs 2009-07-04 17:45:11 UTC (rev 253)
+++ trunk/Source/StructureMap/PipelineGraph.cs 2009-07-07 19:00:49 UTC (rev 254)
@@ -231,5 +231,12 @@
{
return ForType(pluginType).FindInstance(instanceKey) != null;
}
+
+ public void ClearAll()
+ {
+ _factories.Clear();
+ _profileManager.ClearAll();
+ _genericsGraph.ClearAll();
+ }
}
}
\ 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...> - 2009-07-04 17:45:17
|
Revision: 253
http://structuremap.svn.sourceforge.net/structuremap/?rev=253&view=rev
Author: jeremydmiller
Date: 2009-07-04 17:45:11 +0000 (Sat, 04 Jul 2009)
Log Message:
-----------
added the Context.All functionality
Modified Paths:
--------------
trunk/Source/StructureMap/BuildSession.cs
trunk/Source/StructureMap/IContext.cs
trunk/Source/StructureMap/InstanceCache.cs
trunk/Source/StructureMap.Testing/BuildSessionTester.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap.Testing/InstanceCacheTester.cs
Modified: trunk/Source/StructureMap/BuildSession.cs
===================================================================
--- trunk/Source/StructureMap/BuildSession.cs 2009-07-04 17:12:20 UTC (rev 252)
+++ trunk/Source/StructureMap/BuildSession.cs 2009-07-04 17:45:11 UTC (rev 253)
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using StructureMap.Graph;
using StructureMap.Interceptors;
using StructureMap.Pipeline;
@@ -111,6 +112,14 @@
return _pipelineGraph.HasInstance(typeof (T), name) ? ((IContext) this).GetInstance<T>(name) : null;
}
+ public IEnumerable<T> All<T>() where T : class
+ {
+ var list = new List<T>();
+ _cache.Each<T>(list.Add);
+
+ return list;
+ }
+
#endregion
public virtual object CreateInstance(Type pluginType, string name)
Modified: trunk/Source/StructureMap/IContext.cs
===================================================================
--- trunk/Source/StructureMap/IContext.cs 2009-07-04 17:12:20 UTC (rev 252)
+++ trunk/Source/StructureMap/IContext.cs 2009-07-04 17:45:11 UTC (rev 253)
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using StructureMap.Pipeline;
namespace StructureMap
@@ -63,5 +64,13 @@
/// <param name="name"></param>
/// <returns></returns>
T TryGetInstance<T>(string name) where T : class;
+
+ /// <summary>
+ /// Gets all objects in the current object graph that can be cast
+ /// to T
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <returns></returns>
+ IEnumerable<T> All<T>() where T : class;
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/InstanceCache.cs
===================================================================
--- trunk/Source/StructureMap/InstanceCache.cs 2009-07-04 17:12:20 UTC (rev 252)
+++ trunk/Source/StructureMap/InstanceCache.cs 2009-07-04 17:45:11 UTC (rev 253)
@@ -61,5 +61,20 @@
}
cache.Add(Instance, result);
}
+
+ public void Each<T>(Action<T> action) where T : class
+ {
+ foreach (var dictionary in _objects.Values)
+ {
+ foreach (var o in dictionary.Values)
+ {
+ T t = o as T;
+ if (t != null)
+ {
+ action(t);
+ }
+ }
+ }
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/BuildSessionTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2009-07-04 17:12:20 UTC (rev 252)
+++ trunk/Source/StructureMap.Testing/BuildSessionTester.cs 2009-07-04 17:45:11 UTC (rev 253)
@@ -5,6 +5,7 @@
using StructureMap.Pipeline;
using StructureMap.Testing.Widget;
using StructureMap.Testing.Widget3;
+using System.Linq;
namespace StructureMap.Testing
{
@@ -242,8 +243,46 @@
var session = new BuildSession(graph);
session.GetInstance<IService>("red").ShouldBeTheSameAs(red);
}
+
+ [Test]
+ public void can_get_all_of_a_type_during_object_creation()
+ {
+ var container = new Container(x =>
+ {
+ x.For<IWidget>().AddInstances(o =>
+ {
+ o.OfConcreteType<AWidget>();
+ o.ConstructedBy(() => new ColorWidget("red"));
+ o.ConstructedBy(() => new ColorWidget("blue"));
+ o.ConstructedBy(() => new ColorWidget("green"));
+ });
+
+ x.ForConcreteType<TopClass>().Configure.OnCreation((c, top) =>
+ {
+ top.Widgets = c.All<IWidget>().ToArray();
+ });
+ });
+
+ container.GetInstance<TopClass>().Widgets.Count().ShouldEqual(4);
+ }
}
+ public class TopClass
+ {
+ public TopClass(ClassWithWidget classWithWidget)
+ {
+ }
+
+ public IWidget[] Widgets { get; set; }
+ }
+
+ public class ClassWithWidget
+ {
+ public ClassWithWidget(IWidget[] widgets)
+ {
+ }
+ }
+
public interface IClassWithRule
{
}
Added: trunk/Source/StructureMap.Testing/InstanceCacheTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/InstanceCacheTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/InstanceCacheTester.cs 2009-07-04 17:45:11 UTC (rev 253)
@@ -0,0 +1,42 @@
+using NUnit.Framework;
+using Rhino.Mocks;
+using StructureMap.Pipeline;
+
+namespace StructureMap.Testing
+{
+ [TestFixture]
+ public class InstanceCacheTester
+ {
+ [Test]
+ public void call_on_each_test()
+ {
+ var target1 = MockRepository.GenerateMock<ITypeTarget>();
+ var target2 = MockRepository.GenerateMock<ITypeTarget>();
+ var target3 = MockRepository.GenerateMock<ITypeTarget>();
+ var target4 = MockRepository.GenerateMock<ITypeTarget>();
+
+ var cache = new InstanceCache();
+ cache.Set(typeof(int), new SmartInstance<int>(), target1);
+ cache.Set(typeof(int), new SmartInstance<int>(), new object());
+ cache.Set(typeof(int), new SmartInstance<int>(), new object());
+ cache.Set(typeof(bool), new SmartInstance<int>(), target2);
+ cache.Set(typeof(bool), new SmartInstance<int>(), new object());
+ cache.Set(typeof(string), new SmartInstance<int>(), target3);
+ cache.Set(typeof(string), new SmartInstance<int>(), new object());
+ cache.Set(typeof(string), new SmartInstance<int>(), new object());
+ cache.Set(typeof(string), new SmartInstance<int>(), target4);
+
+ cache.Each<ITypeTarget>(x => x.Go());
+
+ target1.AssertWasCalled(x => x.Go());
+ target2.AssertWasCalled(x => x.Go());
+ target3.AssertWasCalled(x => x.Go());
+ target4.AssertWasCalled(x => x.Go());
+ }
+ }
+
+ public interface ITypeTarget
+ {
+ void Go();
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-07-04 17:12:20 UTC (rev 252)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-07-04 17:45:11 UTC (rev 253)
@@ -332,6 +332,7 @@
<Compile Include="Graph\TypePathTester.cs" />
<Compile Include="ImplicitPluginFromPluggedTypeAttributeTester.cs" />
<Compile Include="InstanceBuilderListTester.cs" />
+ <Compile Include="InstanceCacheTester.cs" />
<Compile Include="InstanceMementoInstanceCreationTester.cs" />
<Compile Include="MementoTester.cs" />
<Compile Include="MergingTester.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jer...@us...> - 2009-07-04 17:12:21
|
Revision: 252
http://structuremap.svn.sourceforge.net/structuremap/?rev=252&view=rev
Author: jeremydmiller
Date: 2009-07-04 17:12:20 +0000 (Sat, 04 Jul 2009)
Log Message:
-----------
the redirect shortcut
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
Added Paths:
-----------
trunk/Source/StructureMap.Testing/Pipeline/RedirectTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-06-26 14:34:44 UTC (rev 251)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-07-04 17:12:20 UTC (rev 252)
@@ -410,5 +410,26 @@
{
return ForRequestedType(pluginType);
}
+
+
+ /// <summary>
+ /// Shortcut to make StructureMap return the default object of U casted to T
+ /// whenever T is requested. I.e.:
+ /// For<T>().TheDefault.Is.ConstructedBy(c => c.GetInstance<U>() as T);
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <typeparam name="U"></typeparam>
+ /// <returns></returns>
+ public ConstructorInstance<T> Redirect<T, U>() where T : class where U : class
+ {
+ return For<T>().TheDefault.Is.ConstructedBy(c =>
+ {
+ 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);
+
+ return t;
+ });
+ }
}
}
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing/Pipeline/RedirectTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing/Pipeline/RedirectTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing/Pipeline/RedirectTester.cs 2009-07-04 17:12:20 UTC (rev 252)
@@ -0,0 +1,53 @@
+using System;
+using NUnit.Framework;
+
+namespace StructureMap.Testing.Pipeline
+{
+ [TestFixture]
+ public class RedirectTester
+ {
+ [Test]
+ public void successfully_redirect_from_one_type_to_another()
+ {
+ var container = new Container(x =>
+ {
+ x.For<ITarget>().Use<ClassThatImplementsBoth>();
+ x.Redirect<IOtherTarget, ITarget>();
+ });
+
+ container.GetInstance<IOtherTarget>().ShouldBeOfType<ClassThatImplementsBoth>();
+ }
+
+ [Test, ExpectedException(typeof(StructureMapException))]
+ public void fail_with_cast_failure_when_the_types_are_not_convertible()
+ {
+ var container = new Container(x =>
+ {
+ x.For<ITarget>().Use<ClassThatOnlyImplementsITarget>();
+ x.Redirect<IOtherTarget, ITarget>();
+ });
+
+ container.GetInstance<IOtherTarget>().ShouldBeOfType<ClassThatImplementsBoth>();
+ }
+ }
+
+ public interface ITarget
+ {
+
+ }
+
+ public interface IOtherTarget
+ {
+
+ }
+
+ public class ClassThatImplementsBoth : ITarget, IOtherTarget
+ {
+
+ }
+
+ public class ClassThatOnlyImplementsITarget : ITarget
+ {
+
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj
===================================================================
--- trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-06-26 14:34:44 UTC (rev 251)
+++ trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj 2009-07-04 17:12:20 UTC (rev 252)
@@ -361,6 +361,7 @@
<Compile Include="Pipeline\ProfileManagerTester.cs" />
<Compile Include="Pipeline\ProfileTester.cs" />
<Compile Include="Pipeline\PrototypeInstanceTester.cs" />
+ <Compile Include="Pipeline\RedirectTester.cs" />
<Compile Include="Pipeline\ReferencedInstanceTester.cs" />
<Compile Include="Pipeline\SerializedInstanceTester.cs" />
<Compile Include="Pipeline\SmartInstanceTester.cs" />
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cm...@us...> - 2009-06-26 14:34:51
|
Revision: 251
http://structuremap.svn.sourceforge.net/structuremap/?rev=251&view=rev
Author: cmyers
Date: 2009-06-26 14:34:44 +0000 (Fri, 26 Jun 2009)
Log Message:
-----------
Fixed a memory leak that would manifest when using nested containers (whether dynamic assemblies needed generating or not, PluginCache would create/compile/load an empty assembly every time a new container was created). Repeated calls to a nested container would result in an eventual out of memory situation.
Modified Paths:
--------------
trunk/Source/StructureMap/Graph/PluginCache.cs
Modified: trunk/Source/StructureMap/Graph/PluginCache.cs
===================================================================
--- trunk/Source/StructureMap/Graph/PluginCache.cs 2009-06-12 20:13:34 UTC (rev 250)
+++ trunk/Source/StructureMap/Graph/PluginCache.cs 2009-06-26 14:34:44 UTC (rev 251)
@@ -64,6 +64,15 @@
private static void createAndStoreBuilders(IEnumerable<Plugin> plugins)
{
+ // If this is a nested container and there are no new plugins,
+ // we don't need to create the InstanceBuilderAssembly
+ // This was causing OutOfMemoryExceptions when using nested containers
+ // repeatedly (i.e. every web request in a web app)
+ if (plugins == null || plugins.Count() == 0) return;
+
+ //NOTE: Calling 'Compile()' on a DynamicAssembly will actually
+ // compile it as a file on the disk and load it into the AppDomain.
+ // If you call it repeatedly, you will eventually run out of memory
var assembly = new InstanceBuilderAssembly(plugins);
assembly.Compile().ForEach(b => _builders[b.PluggedType] = b);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|