|
From: <jer...@us...> - 2009-01-31 20:03:26
|
Revision: 228
http://structuremap.svn.sourceforge.net/structuremap/?rev=228&view=rev
Author: jeremydmiller
Date: 2009-01-31 20:03:15 +0000 (Sat, 31 Jan 2009)
Log Message:
-----------
beginning of the Prism bootstrapper, some work for diagnostics "pretty-ifying"
Modified Paths:
--------------
trunk/Source/StructureMap/Configuration/DSL/Registry.cs
trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs
trunk/Source/StructureMap/Graph/Constructor.cs
trunk/Source/StructureMap/Pipeline/BuildPolicy.cs
trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs
trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs
trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs
trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs
trunk/Source/StructureMap/TypeExtensions.cs
trunk/Source/StructureMap.sln
Added Paths:
-----------
trunk/Source/StructureMap.Prism/
trunk/Source/StructureMap.Prism/DefaultRegistry.cs
trunk/Source/StructureMap.Prism/PrismBootstrapper.cs
trunk/Source/StructureMap.Prism/StructureMapContainerFacade.cs
trunk/Source/StructureMap.Prism/structuremap.snk
trunk/Source/StructureMap.Testing.Prism/
trunk/Source/StructureMap.Testing.Prism/DefaultRegistryTester.cs
trunk/Source/StructureMap.Testing.Prism/StructureMapContainerFacadeTester.cs
Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs
===================================================================
--- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -47,6 +47,7 @@
void SelectConstructor<T>(Expression<Func<T>> expression);
}
+
/// <summary>
/// A Registry class provides methods and grammars for configuring a Container or ObjectFactory.
/// Using a Registry subclass is the recommended way of configuring a StructureMap Container.
@@ -74,6 +75,7 @@
/// You can overide this method as a place to put the Registry DSL
/// declarations. This is not mandatory.
/// </summary>
+ [Obsolete("configure() is unnecessary. All declarations can be made in the constructor of a Registry or any other method")]
protected virtual void configure()
{
// no-op;
@@ -152,6 +154,16 @@
}
/// <summary>
+ /// Convenience method. Equivalent of ForRequestedType[PluginType]().AsSingletons()
+ /// </summary>
+ /// <typeparam name="PLUGINTYPE"></typeparam>
+ /// <returns></returns>
+ public CreatePluginFamilyExpression<PLUGINTYPE> ForSingletonOf<PLUGINTYPE>()
+ {
+ return ForRequestedType<PLUGINTYPE>().AsSingletons();
+ }
+
+ /// <summary>
/// Uses the configuration expressions of this Registry to create a PluginGraph
/// object that could be used to initialize a Container. This method is
/// mostly for internal usage, but might be helpful for diagnostics
@@ -357,5 +369,7 @@
{
PluginCache.GetPlugin(typeof(T)).UseConstructor(expression);
}
+
+
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs
===================================================================
--- trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/Diagnostics/WhatDoIHaveWriter.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -79,7 +79,7 @@
_writer.AddText(contents);
- _writer.AddContent("Built by: " + pluginType.Policy);
+ _writer.AddContent("Scoped as: " + pluginType.Policy);
foreach (IInstance instance in pluginType.Instances)
{
Modified: trunk/Source/StructureMap/Graph/Constructor.cs
===================================================================
--- trunk/Source/StructureMap/Graph/Constructor.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/Graph/Constructor.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -94,12 +94,33 @@
public void Visit(IArgumentVisitor visitor)
{
- foreach (ParameterInfo info in _ctor.GetParameters())
+ try
{
- Type parameterType = info.ParameterType;
-
- visitParameter(info, parameterType, visitor);
+ foreach (ParameterInfo info in _ctor.GetParameters())
+ {
+ try
+ {
+ Type parameterType = info.ParameterType;
+ visitParameter(info, parameterType, visitor);
+ }
+ catch (Exception e)
+ {
+ string message =
+ "Trying to visit parameter {0} of type {1} in the constructor for {2}".ToFormat(info.Name,
+ info.
+ ParameterType,
+ _pluggedType.
+ AssemblyQualifiedName);
+ throw new ApplicationException(message, e);
+ }
+ }
}
+ catch (Exception e)
+ {
+ string message = "Failed while trying to visit the constructor for " +
+ _pluggedType.AssemblyQualifiedName;
+ throw new ApplicationException(message, e);
+ }
}
private void visitParameter(ParameterInfo info, Type parameterType, IArgumentVisitor visitor)
Modified: trunk/Source/StructureMap/Pipeline/BuildPolicy.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/Pipeline/BuildPolicy.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -1,4 +1,5 @@
using System;
+using StructureMap.Attributes;
namespace StructureMap.Pipeline
{
@@ -54,5 +55,10 @@
{
return 0;
}
+
+ public override string ToString()
+ {
+ return InstanceScope.PerRequest.ToString();
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/Pipeline/HttpContextBuildPolicy.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -2,6 +2,7 @@
using System.Collections;
using System.Web;
using System.Web.SessionState;
+using StructureMap.Attributes;
namespace StructureMap.Pipeline
{
@@ -49,6 +50,11 @@
{
return this;
}
+
+ public override string ToString()
+ {
+ return InstanceScope.HttpContext.ToString();
+ }
}
public class HttpSessionBuildPolicy : HttpContextBuildPolicy
@@ -57,6 +63,11 @@
{
return new SessionWrapper(HttpContext.Current.Session);
}
+
+ public override string ToString()
+ {
+ return InstanceScope.HttpSession.ToString();
+ }
}
public class SessionWrapper : IDictionary
Modified: trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/Pipeline/HybridBuildPolicy.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -1,4 +1,5 @@
using System;
+using StructureMap.Attributes;
namespace StructureMap.Pipeline
{
@@ -60,6 +61,11 @@
{
return new HybridBuildPolicy(){InnerPolicy = InnerPolicy.Clone()};
}
+
+ public override string ToString()
+ {
+ return InstanceScope.Hybrid.ToString();
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/Pipeline/SingletonPolicy.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -1,4 +1,5 @@
using System;
+using StructureMap.Attributes;
namespace StructureMap.Pipeline
{
@@ -43,5 +44,10 @@
{
return new SingletonPolicy();
}
+
+ public override string ToString()
+ {
+ return InstanceScope.Singleton.ToString();
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs
===================================================================
--- trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/Pipeline/ThreadLocalStoragePolicy.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -1,4 +1,5 @@
using System;
+using StructureMap.Attributes;
namespace StructureMap.Pipeline
{
@@ -36,5 +37,10 @@
{
return this;
}
+
+ public override string ToString()
+ {
+ return InstanceScope.Hybrid.ToString();
+ }
}
}
\ No newline at end of file
Modified: trunk/Source/StructureMap/TypeExtensions.cs
===================================================================
--- trunk/Source/StructureMap/TypeExtensions.cs 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap/TypeExtensions.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -17,6 +17,11 @@
return new ReferencedInstance(key);
}
+ public static bool IsSimple(this Type type)
+ {
+ return new TypeRules().IsSimple(type);
+ }
+
public static bool IsConcrete(this Type type)
{
return new TypeRules().IsConcrete(type);
Added: trunk/Source/StructureMap.Prism/DefaultRegistry.cs
===================================================================
--- trunk/Source/StructureMap.Prism/DefaultRegistry.cs (rev 0)
+++ trunk/Source/StructureMap.Prism/DefaultRegistry.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -0,0 +1,17 @@
+using Microsoft.Practices.Composite;
+using Microsoft.Practices.Composite.Events;
+using Microsoft.Practices.Composite.Wpf.Regions;
+using StructureMap.Configuration.DSL;
+
+namespace StructureMap.Prism
+{
+ public class DefaultRegistry : Registry
+ {
+ public DefaultRegistry()
+ {
+ ForSingletonOf<IContainerFacade>().TheDefaultIsConcreteType<StructureMapContainerFacade>();
+ ForSingletonOf<IEventAggregator>().TheDefaultIsConcreteType<EventAggregator>();
+ ForSingletonOf<RegionAdapterMappings>().TheDefaultIsConcreteType<RegionAdapterMappings>();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap.Prism/PrismBootstrapper.cs
===================================================================
--- trunk/Source/StructureMap.Prism/PrismBootstrapper.cs (rev 0)
+++ trunk/Source/StructureMap.Prism/PrismBootstrapper.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -0,0 +1,62 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using StructureMap.Configuration.DSL;
+
+namespace StructureMap.Prism
+{
+ public abstract class PrismBootstrapper<THIS> : IBootstrapper where THIS : IBootstrapper, new()
+ {
+ private static bool _hasStarted = false;
+
+ public static void Restart()
+ {
+
+ }
+
+ public void Bootstrap(string profile)
+ {
+ Bootstrap();
+ }
+
+ public void Bootstrap()
+ {
+
+ }
+
+ public PrismBootstrapper(string defaultProfofile)
+ {
+ }
+
+ public PrismBootstrapper() : this(string.Empty)
+ {
+ }
+
+
+ public void BootstrapStructureMap()
+ {
+ throw new System.NotImplementedException();
+ }
+
+ // TODO
+ // 1.) Calls all Startables at end
+ // 2.) applies Profile
+ // 3.) adds the basic types
+ // 4.) create the shell
+ // 5.) tie into debuggers
+ }
+
+ // test this
+
+ public interface IStartable
+ {
+ void Execute(IContainer container);
+ }
+
+ public class PrismRegistry : Registry
+ {
+ // TODO
+ // 1.) OnStartUp method
+ // 2.)
+ }
+}
Added: trunk/Source/StructureMap.Prism/StructureMapContainerFacade.cs
===================================================================
--- trunk/Source/StructureMap.Prism/StructureMapContainerFacade.cs (rev 0)
+++ trunk/Source/StructureMap.Prism/StructureMapContainerFacade.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -0,0 +1,30 @@
+using System;
+using Microsoft.Practices.Composite;
+
+namespace StructureMap.Prism
+{
+ public class StructureMapContainerFacade : IContainerFacade
+ {
+ private readonly IContainer _container;
+
+ public StructureMapContainerFacade(IContainer container)
+ {
+ _container = container;
+ }
+
+ public object Resolve(Type type)
+ {
+ return _container.GetInstance(type);
+ }
+
+ public object TryResolve(Type type)
+ {
+ return _container.TryGetInstance(type);
+ }
+
+ public IContainer Container
+ {
+ get { return _container; }
+ }
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap.Prism/structuremap.snk
===================================================================
(Binary files differ)
Property changes on: trunk/Source/StructureMap.Prism/structuremap.snk
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/Source/StructureMap.Testing.Prism/DefaultRegistryTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing.Prism/DefaultRegistryTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing.Prism/DefaultRegistryTester.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -0,0 +1,54 @@
+using Microsoft.Practices.Composite;
+using Microsoft.Practices.Composite.Events;
+using Microsoft.Practices.Composite.Wpf.Regions;
+using NUnit.Framework;
+using StructureMap.Prism;
+
+namespace StructureMap.Testing.Prism
+{
+ [TestFixture]
+ public class DefaultRegistryTester
+ {
+ #region Setup/Teardown
+
+ [SetUp]
+ public void SetUp()
+ {
+ container = new Container(new DefaultRegistry());
+ }
+
+ #endregion
+
+ private Container container;
+
+ [Test]
+ public void sets_up_the_default_event_aggregator_as_a_singleton()
+ {
+ container.GetInstance<IEventAggregator>().ShouldBeOfType<EventAggregator>();
+ container.GetInstance<IEventAggregator>().ShouldBeTheSameAs(container.GetInstance<IEventAggregator>());
+ }
+
+ [Test]
+ public void sets_up_the_default_region_adapter_as_a_singleton()
+ {
+ container.GetInstance<RegionAdapterMappings>().ShouldBeOfType<RegionAdapterMappings>();
+ container.GetInstance<RegionAdapterMappings>().ShouldBeTheSameAs(
+ container.GetInstance<RegionAdapterMappings>());
+ }
+
+ [Test]
+ public void sets_up_the_icontainerfacade_to_wrap_itself()
+ {
+ var theView = new TheView();
+ container.Inject(theView);
+
+ container.GetInstance<IContainerFacade>()
+ .ShouldBeOfType<StructureMapContainerFacade>()
+ .Container.ShouldBeTheSameAs(container);
+ }
+ }
+
+ public class TheView
+ {
+ }
+}
\ No newline at end of file
Added: trunk/Source/StructureMap.Testing.Prism/StructureMapContainerFacadeTester.cs
===================================================================
--- trunk/Source/StructureMap.Testing.Prism/StructureMapContainerFacadeTester.cs (rev 0)
+++ trunk/Source/StructureMap.Testing.Prism/StructureMapContainerFacadeTester.cs 2009-01-31 20:03:15 UTC (rev 228)
@@ -0,0 +1,42 @@
+using NUnit.Framework;
+using StructureMap.Prism;
+
+namespace StructureMap.Testing.Prism
+{
+ [TestFixture]
+ public class StructureMapContainerFacadeTester
+ {
+ [Test]
+ public void can_use_inner_container_to_resolve_a_type()
+ {
+ var container = new Container(x => { x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); });
+
+ var facade = new StructureMapContainerFacade(container);
+ facade.Resolve(typeof (IView)).ShouldBeOfType<View>();
+ }
+
+ [Test]
+ public void can_use_inner_container_to_try_resolve_successfully()
+ {
+ var container = new Container(x => { x.ForRequestedType<IView>().TheDefaultIsConcreteType<View>(); });
+
+ var facade = new StructureMapContainerFacade(container);
+ facade.TryResolve(typeof (IView)).ShouldBeOfType<View>();
+ }
+
+ [Test]
+ public void can_use_inner_container_to_try_resolve_when_type_is_not_there()
+ {
+ var facade = new StructureMapContainerFacade(new Container());
+ facade.TryResolve(typeof (IView)).ShouldBeNull();
+ }
+ }
+
+ public interface IView
+ {
+ }
+
+ public class View : IView
+ {
+ }
+}
\ No newline at end of file
Modified: trunk/Source/StructureMap.sln
===================================================================
--- trunk/Source/StructureMap.sln 2009-01-22 22:33:20 UTC (rev 227)
+++ trunk/Source/StructureMap.sln 2009-01-31 20:03:15 UTC (rev 228)
@@ -57,6 +57,10 @@
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TableOfContentsBuilder", "TableOfContentsBuilder\TableOfContentsBuilder.csproj", "{8A9EAE91-F3F5-4919-86FC-6D98D00FC77F}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.Prism", "StructureMap.Prism\StructureMap.Prism.csproj", "{150CACB1-7F59-4C68-8830-F277E0E98A3F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructureMap.Testing.Prism", "StructureMap.Testing.Prism\StructureMap.Testing.Prism.csproj", "{7F72EFA9-B575-462A-855F-132F8DBC6E9D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Build|.NET = Build|.NET
@@ -292,6 +296,36 @@
{8A9EAE91-F3F5-4919-86FC-6D98D00FC77F}.Release|Any CPU.Build.0 = Release|Any CPU
{8A9EAE91-F3F5-4919-86FC-6D98D00FC77F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8A9EAE91-F3F5-4919-86FC-6D98D00FC77F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|.NET.ActiveCfg = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|Any CPU.ActiveCfg = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|Any CPU.Build.0 = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Build|Mixed Platforms.Build.0 = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|.NET.ActiveCfg = Debug|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|.NET.ActiveCfg = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {150CACB1-7F59-4C68-8830-F277E0E98A3F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|.NET.ActiveCfg = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|Any CPU.ActiveCfg = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|Any CPU.Build.0 = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Build|Mixed Platforms.Build.0 = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|.NET.ActiveCfg = Debug|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|.NET.ActiveCfg = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {7F72EFA9-B575-462A-855F-132F8DBC6E9D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|