From: <jer...@us...> - 2008-10-01 18:30:02
|
Revision: 160 http://structuremap.svn.sourceforge.net/structuremap/?rev=160&view=rev Author: jeremydmiller Date: 2008-10-01 18:29:38 +0000 (Wed, 01 Oct 2008) Log Message: ----------- type scanning overhaul part #1 Modified Paths: -------------- trunk/Source/StructureMap/Configuration/DSL/Registry.cs trunk/Source/StructureMap/Configuration/GraphBuilder.cs trunk/Source/StructureMap/Graph/AssemblyScanner.cs trunk/Source/StructureMap/Graph/PluginGraph.cs trunk/Source/StructureMap/StructureMap.csproj trunk/Source/StructureMap/StructureMapConfiguration.cs trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs trunk/Source/StructureMap.Testing/Graph/ArrayConstructorTester.cs trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs trunk/Source/StructureMap.Testing/Graph/DynamicInjectionTester.cs trunk/Source/StructureMap.Testing/Graph/FillDependenciesTester.cs trunk/Source/StructureMap.Testing/Graph/InstanceFactoryTester.cs trunk/Source/StructureMap.Testing/Graph/IntegratedTester.cs trunk/Source/StructureMap.Testing/Graph/PluginFamilyTester.cs trunk/Source/StructureMap.Testing/Graph/PluginGraphBuilderTester.cs trunk/Source/StructureMap.Testing/Graph/PluginGraphTester.cs trunk/Source/StructureMap.Testing/Graph/PluginTester.cs trunk/Source/StructureMap.Testing/Graph/TypeFindingTester.cs trunk/Source/StructureMap.Testing/ObjectFactoryInitializeTester.cs trunk/Source/StructureMap.Testing/Pipeline/ConfiguredInstanceTester.cs trunk/Source/StructureMap.Testing/Pipeline/OptionalSetterInjectionTester.cs trunk/Source/StructureMap.Testing/StructureMap.Testing.csproj trunk/Source/StructureMap.Testing/StructureMapConfigurationDefensiveChecksTester.cs Removed Paths: ------------- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs trunk/Source/StructureMap.Testing/ObjectMother.cs Deleted: trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap/Configuration/DSL/Expressions/ScanAssembliesExpression.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -1,123 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Reflection; -using System.Threading; -using StructureMap.Graph; - -namespace StructureMap.Configuration.DSL.Expressions -{ - /// <summary> - /// Expression that directs StructureMap to scan the named assemblies - /// for [PluginFamily] and [Plugin] attributes - /// </summary> - public class ScanAssembliesExpression - { - private readonly List<Assembly> _assemblies = new List<Assembly>(); - private readonly Registry _registry; - - public ScanAssembliesExpression(Registry registry) - { - _registry = registry; - _registry.addExpression(graph => - { - foreach (Assembly assembly in _assemblies) - { - graph.Assemblies.Add(assembly); - } - }); - } - - public ScanAssembliesExpression IncludeTheCallingAssembly() - { - Assembly callingAssembly = findTheCallingAssembly(); - - if (callingAssembly != null) - { - _assemblies.Add(callingAssembly); - } - - return this; - } - - private static Assembly findTheCallingAssembly() - { - StackTrace trace = new StackTrace(Thread.CurrentThread, false); - - Assembly thisAssembly = Assembly.GetExecutingAssembly(); - Assembly callingAssembly = null; - for (int i = 0; i < trace.FrameCount; i++) - { - StackFrame frame = trace.GetFrame(i); - Assembly assembly = frame.GetMethod().DeclaringType.Assembly; - if (assembly != thisAssembly) - { - callingAssembly = assembly; - break; - } - } - return callingAssembly; - } - - public ScanAssembliesExpression IncludeAssemblyContainingType<T>() - { - _assemblies.Add(typeof (T).Assembly); - - return this; - } - - public ScanAssembliesExpression IncludeAssemblyContainingType(Type type) - { - _assemblies.Add(type.Assembly); - - return this; - } - - public ScanAssembliesExpression AddAllTypesOf<PLUGINTYPE>() - { - return AddAllTypesOf(typeof (PLUGINTYPE)); - } - - public ScanAssembliesExpression AddAllTypesOf(Type pluginType) - { - _registry.addExpression(pluginGraph => - { - pluginGraph.Assemblies.AddScanner(new FindAllTypesFilter(pluginType)); - }); - - return this; - } - - public ScanAssembliesExpression IncludeAssembly(string assemblyName) - { - Assembly assembly = AppDomain.CurrentDomain.Load(assemblyName); - _assemblies.Add(assembly); - - return this; - } - - public ScanAssembliesExpression With(ITypeScanner scanner) - { - _registry.addExpression(graph => graph.Assemblies.AddScanner(scanner)); - - - return this; - } - - public ScanAssembliesExpression With<T>() where T : ITypeScanner, new() - { - _registry.addExpression(graph => graph.Assemblies.AddScanner<T>()); - return this; - } - - // TODO: Need a test here - public ScanAssembliesExpression With<T>(Action<T> configure) where T : ITypeScanner, new() - { - T scanner = new T(); - configure(scanner); - - _registry.addExpression(graph => graph.Assemblies.AddScanner(scanner)); - return this; - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap/Configuration/DSL/Registry.cs =================================================================== --- trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap/Configuration/DSL/Registry.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -137,9 +137,12 @@ /// Programmatically determine Assembly's to be scanned for attribute configuration /// </summary> /// <returns></returns> - public ScanAssembliesExpression ScanAssemblies() + public void Scan(Action<AssemblyScanner> action) { - return new ScanAssembliesExpression(this); + var scanner = new AssemblyScanner(); + action(scanner); + + _actions.Add(graph => graph.AddScanner(scanner)); } [Obsolete("Like to get rid of this")] Modified: trunk/Source/StructureMap/Configuration/GraphBuilder.cs =================================================================== --- trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap/Configuration/GraphBuilder.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -1,7 +1,6 @@ using System; using System.Reflection; using StructureMap.Configuration.DSL; -using StructureMap.Diagnostics; using StructureMap.Graph; using StructureMap.Pipeline; @@ -9,8 +8,10 @@ { public class GraphBuilder : IGraphBuilder { + private readonly AssemblyScanner _assemblyScanner; private readonly PluginGraph _pluginGraph; private readonly PluginGraph _systemGraph; + private readonly AssemblyScanner _systemScanner; private Profile _profile; private Container _systemContainer; @@ -22,16 +23,19 @@ public GraphBuilder(Registry[] registries, PluginGraph pluginGraph) { _pluginGraph = pluginGraph; + _assemblyScanner = new AssemblyScanner(); + _pluginGraph.AddScanner(_assemblyScanner); + foreach (Registry registry in registries) { registry.ConfigurePluginGraph(_pluginGraph); } - AssemblyScanner scanner = new AssemblyScanner(new GraphLog()); - scanner.Add(Assembly.GetExecutingAssembly()); - scanner.IgnoreRegistries(); + _systemScanner = new AssemblyScanner(); + _systemScanner.Assembly(Assembly.GetExecutingAssembly()); + _systemScanner.IgnoreRegistries(); - _systemGraph = new PluginGraph(scanner); + _systemGraph = new PluginGraph(_systemScanner); } #region IGraphBuilder Members @@ -56,8 +60,8 @@ try { Assembly assembly = AppDomain.CurrentDomain.Load(assemblyName); - _pluginGraph.Assemblies.Add(assembly); - _systemGraph.Assemblies.Add(assembly); + _assemblyScanner.Assembly(assembly); + _systemScanner.Assembly(assembly); } catch (Exception ex) { @@ -94,7 +98,7 @@ { try { - T systemObject = (T) buildSystemObject(typeof (T), memento); + var systemObject = (T) buildSystemObject(typeof (T), memento); action(systemObject); } catch (Exception ex) Modified: trunk/Source/StructureMap/Graph/AssemblyScanner.cs =================================================================== --- trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap/Graph/AssemblyScanner.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -1,24 +1,23 @@ using System; using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; using System.Reflection; -using StructureMap.Configuration.DSL; +using System.Threading; using StructureMap.Diagnostics; -using System.Linq; namespace StructureMap.Graph { public class AssemblyScanner { private readonly List<Assembly> _assemblies = new List<Assembly>(); - private readonly GraphLog _log; private readonly List<ITypeScanner> _scanners = new List<ITypeScanner>(); - public AssemblyScanner(GraphLog log) + public AssemblyScanner() { - _log = log; - AddScanner<FamilyAttributeScanner>(); - AddScanner<PluggableAttributeScanner>(); - AddScanner<FindRegistriesScanner>(); + With<FamilyAttributeScanner>(); + With<PluggableAttributeScanner>(); + With<FindRegistriesScanner>(); } public int Count @@ -28,70 +27,26 @@ public void ScanForAll(PluginGraph pluginGraph) { - // Don't do this for SystemScan - scanTypes(type => - { - if (!Registry.IsPublicRegistry(type)) return; - - foreach (var previous in pluginGraph.Registries) - { - if (previous.GetType().Equals(type)) - { - return; - } - } - - Registry registry = (Registry) Activator.CreateInstance(type); - registry.ConfigurePluginGraph(pluginGraph); - }); - - runScanners(pluginGraph); + _assemblies.ForEach(assem => scanTypesInAssembly(assem, pluginGraph)); } - private void runScanners(PluginGraph graph) + private void scanTypesInAssembly(Assembly assembly, PluginGraph graph) { - scanTypes(type => _scanners.ForEach(scanner => scanner.Process(type, graph))); - } - - public void ScanForStructureMapObjects(PluginGraph pluginGraph) - { - // I think this just needs to look for attributes only - throw new NotImplementedException(); - } - - private void scanTypes(Action<Type> action) - { - scanTypes(new[] {action}); - } - - private void scanTypes(IEnumerable<Action<Type>> actions) - { - foreach (Assembly assembly in _assemblies.ToArray()) - { - scanTypesInAssembly(assembly, actions); - } - } - - private void scanTypesInAssembly(Assembly assembly, IEnumerable<Action<Type>> actions) - { Type[] exportedTypes; try { foreach (Type type in assembly.GetExportedTypes()) { - foreach (Action<Type> action in actions) - { - action(type); - } + _scanners.ForEach(scanner => scanner.Process(type, graph)); } } catch (Exception ex) { - _log.RegisterError(170, ex, assembly.FullName); + graph.Log.RegisterError(170, ex, assembly.FullName); } } - public void Add(Assembly assembly) + public void Assembly(Assembly assembly) { if (!_assemblies.Contains(assembly)) { @@ -99,9 +54,9 @@ } } - public void Add(string assemblyName) + public void Assembly(string assemblyName) { - Add(AppDomain.CurrentDomain.Load(assemblyName)); + Assembly(AppDomain.CurrentDomain.Load(assemblyName)); } public bool Contains(string assemblyName) @@ -117,19 +72,19 @@ return false; } - public void AddScanner(ITypeScanner scanner) + public void With(ITypeScanner scanner) { if (_scanners.Contains(scanner)) return; _scanners.Add(scanner); } - public void AddScanner<T>() where T : ITypeScanner, new() + public void With<T>() where T : ITypeScanner, new() { - var previous = _scanners.FirstOrDefault(scanner => scanner is T); + ITypeScanner previous = _scanners.FirstOrDefault(scanner => scanner is T); if (previous == null) { - AddScanner(new T()); + With(new T()); } } @@ -137,5 +92,55 @@ { _scanners.RemoveAll(x => x is FindRegistriesScanner); } + + public void TheCallingAssembly() + { + Assembly callingAssembly = findTheCallingAssembly(); + + if (callingAssembly != null) + { + _assemblies.Add(callingAssembly); + } + } + + private static Assembly findTheCallingAssembly() + { + StackTrace trace = new StackTrace(Thread.CurrentThread, false); + + Assembly thisAssembly = System.Reflection.Assembly.GetExecutingAssembly(); + Assembly callingAssembly = null; + for (int i = 0; i < trace.FrameCount; i++) + { + StackFrame frame = trace.GetFrame(i); + Assembly assembly = frame.GetMethod().DeclaringType.Assembly; + if (assembly != thisAssembly) + { + callingAssembly = assembly; + break; + } + } + return callingAssembly; + } + + public void AssemblyContainingType<T>() + { + _assemblies.Add(typeof(T).Assembly); + } + + public void AssemblyContainingType(Type type) + { + _assemblies.Add(type.Assembly); + } + + public void AddAllTypesOf<PLUGINTYPE>() + { + AddAllTypesOf(typeof(PLUGINTYPE)); + } + + public void AddAllTypesOf(Type pluginType) + { + With(new FindAllTypesFilter(pluginType)); + } + } } \ No newline at end of file Modified: trunk/Source/StructureMap/Graph/PluginGraph.cs =================================================================== --- trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap/Graph/PluginGraph.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -16,41 +16,48 @@ [Serializable] public class PluginGraph { - private readonly AssemblyScanner _assemblies; private readonly InterceptorLibrary _interceptorLibrary = new InterceptorLibrary(); - private GraphLog _log = new GraphLog(); + private readonly List<Type> _pluggedTypes = new List<Type>(); private readonly PluginFamilyCollection _pluginFamilies; private readonly ProfileManager _profileManager = new ProfileManager(); - private bool _sealed = false; private readonly List<Registry> _registries = new List<Registry>(); - private readonly List<Type> _pluggedTypes = new List<Type>(); - + private readonly List<AssemblyScanner> _scanners = new List<AssemblyScanner>(); + private GraphLog _log = new GraphLog(); + private bool _sealed; + /// <summary> /// Default constructor /// </summary> - public PluginGraph() : base() + public PluginGraph() { - _assemblies = new AssemblyScanner(_log); _pluginFamilies = new PluginFamilyCollection(this); } public PluginGraph(AssemblyScanner assemblies) { - _assemblies = assemblies; _pluginFamilies = new PluginFamilyCollection(this); + _scanners.Add(assemblies); } - public List<Registry> Registries + public void Scan(Action<AssemblyScanner> action) { - get { return _registries; } + var scanner = new AssemblyScanner(); + action(scanner); + + AddScanner(scanner); } - public AssemblyScanner Assemblies + public void ScanThisAssembly() { - get { return _assemblies; } + Scan(x => x.TheCallingAssembly()); } + public List<Registry> Registries + { + get { return _registries; } + } + public PluginFamilyCollection PluginFamilies { get { return _pluginFamilies; } @@ -95,7 +102,7 @@ return; } - _assemblies.ScanForAll(this); + _scanners.ForEach(scanner => scanner.ScanForAll(this)); _pluginFamilies.Each(family => family.AddTypes(_pluggedTypes)); _pluginFamilies.Each(family => family.Seal()); @@ -107,14 +114,19 @@ #endregion + public void AddScanner(AssemblyScanner scanner) + { + _scanners.Add(scanner); + } + public static PluginGraph BuildGraphFromAssembly(Assembly assembly) { - PluginGraph pluginGraph = new PluginGraph(); - pluginGraph.Assemblies.Add(assembly); + var graph = new PluginGraph(); + graph.Scan(x => x.Assembly(assembly)); - pluginGraph.Seal(); + graph.Seal(); - return pluginGraph; + return graph; } public PluginFamily FindFamily(Type pluginType) Modified: trunk/Source/StructureMap/StructureMap.csproj =================================================================== --- trunk/Source/StructureMap/StructureMap.csproj 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap/StructureMap.csproj 2008-10-01 18:29:38 UTC (rev 160) @@ -218,7 +218,6 @@ <Compile Include="Pipeline\ExplicitArguments.cs" /> <Compile Include="Configuration\DSL\Expressions\ProfileExpression.cs" /> <Compile Include="Configuration\DSL\Registry.cs" /> - <Compile Include="Configuration\DSL\Expressions\ScanAssembliesExpression.cs" /> <Compile Include="Configuration\FamilyParser.cs"> <SubType>Code</SubType> </Compile> Modified: trunk/Source/StructureMap/StructureMapConfiguration.cs =================================================================== --- trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap/StructureMapConfiguration.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -167,9 +167,9 @@ /// Programmatically determine Assembly's to be scanned for attribute configuration /// </summary> /// <returns></returns> - public static ScanAssembliesExpression ScanAssemblies() + public static void Scan(Action<AssemblyScanner> action) { - return registry.ScanAssemblies(); + registry.Scan(action); } /// <summary> Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/AddInstanceTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -16,7 +16,7 @@ { container = new Container(registry => { - registry.ScanAssemblies().IncludeAssemblyContainingType<ColorWidget>(); + registry.Scan(x => x.AssemblyContainingType<ColorWidget>()); // Add an instance with properties registry.InstanceOf<IWidget>() @@ -64,8 +64,8 @@ { IContainer container = new Container( registry => registry.InstanceOf<Rule>().Is.OfConcreteType<WidgetRule>() - .WithName("AWidgetRule") - .CtorDependency<IWidget>().Is(i => i.OfConcreteType<AWidget>())); + .WithName("AWidgetRule") + .CtorDependency<IWidget>().Is(i => i.OfConcreteType<AWidget>())); container.GetInstance<Rule>("AWidgetRule") .IsType<WidgetRule>() @@ -124,9 +124,10 @@ IContainer manager = new Container( registry => registry.InstanceOf<Rule>().Is.OfConcreteType<WidgetRule>().WithName(instanceKey) - .CtorDependency<IWidget>().Is(i => i.OfConcreteType<ColorWidget>().WithCtorArg("color").EqualTo("Orange").WithName("Orange")) - - ); + .CtorDependency<IWidget>().Is( + i => + i.OfConcreteType<ColorWidget>().WithCtorArg("color").EqualTo("Orange").WithName("Orange")) + ); var rule = (WidgetRule) manager.GetInstance<Rule>(instanceKey); var widget = (ColorWidget) rule.Widget; @@ -178,7 +179,6 @@ } } - public class WidgetRule : Rule { Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/CreatePluginFamilyTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -38,7 +38,7 @@ [Test] public void Add_an_instance_by_lambda() { - Container manager = + var manager = new Container( r => r.InstanceOf<IWidget>().Is.ConstructedBy(() => new AWidget())); @@ -48,9 +48,9 @@ [Test] public void Add_an_instance_by_literal() { - AWidget aWidget = new AWidget(); + var aWidget = new AWidget(); - Container manager = + var manager = new Container(registry => registry.InstanceOf<IWidget>().Is.Object(aWidget)); Assert.IsInstanceOfType(typeof (AWidget), manager.GetAllInstances<IWidget>()[0]); @@ -60,7 +60,8 @@ public void AddInstanceByNameOnlyAddsOneInstanceToStructureMap() { IContainer manager = new Container(registry => registry.ForRequestedType<Something>().AddInstance( - RegistryExpressions.Instance<RedSomething>().WithName("Red") + RegistryExpressions.Instance<RedSomething>().WithName( + "Red") )); IList<Something> instances = manager.GetAllInstances<Something>(); Assert.AreEqual(1, instances.Count); @@ -70,7 +71,8 @@ public void AddInstanceWithNameOnlyAddsOneInstanceToStructureMap() { IContainer manager = - new Container(registry => registry.InstanceOf<Something>().Is.OfConcreteType<RedSomething>().WithName("Red")); + new Container( + registry => registry.InstanceOf<Something>().Is.OfConcreteType<RedSomething>().WithName("Red")); IList<Something> instances = manager.GetAllInstances<Something>(); Assert.AreEqual(1, instances.Count); } @@ -78,7 +80,7 @@ [Test] public void AsAnotherScope() { - Registry registry = new Registry(); + var registry = new Registry(); CreatePluginFamilyExpression<IGateway> expression = registry.BuildInstancesOf<IGateway>().CacheBy(InstanceScope.ThreadLocal); Assert.IsNotNull(expression); @@ -92,7 +94,7 @@ [Test] public void BuildInstancesOfType() { - Registry registry = new Registry(); + var registry = new Registry(); registry.BuildInstancesOf<IGateway>(); PluginGraph pluginGraph = registry.Build(); @@ -103,7 +105,7 @@ [Test] public void BuildPluginFamilyAsPerRequest() { - Registry registry = new Registry(); + var registry = new Registry(); CreatePluginFamilyExpression<IGateway> expression = registry.BuildInstancesOf<IGateway>(); Assert.IsNotNull(expression); @@ -117,7 +119,7 @@ [Test] public void BuildPluginFamilyAsSingleton() { - Registry registry = new Registry(); + var registry = new Registry(); CreatePluginFamilyExpression<IGateway> expression = registry.BuildInstancesOf<IGateway>().AsSingletons(); Assert.IsNotNull(expression); @@ -130,15 +132,15 @@ [Test] public void CanOverrideTheDefaultInstance1() { - Registry registry = new Registry(); + var registry = new Registry(); // Specify the default implementation for an interface registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<StubbedGateway>(); PluginGraph pluginGraph = registry.Build(); Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - Container manager = new Container(pluginGraph); - IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); + var manager = new Container(pluginGraph); + var gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (StubbedGateway), gateway); } @@ -146,14 +148,14 @@ [Test] public void CanOverrideTheDefaultInstanceAndCreateAnAllNewPluginOnTheFly() { - Registry registry = new Registry(); + var registry = new Registry(); registry.BuildInstancesOf<IGateway>().TheDefaultIsConcreteType<FakeGateway>(); PluginGraph pluginGraph = registry.Build(); Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - Container manager = new Container(pluginGraph); - IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); + var manager = new Container(pluginGraph); + var gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (FakeGateway), gateway); } @@ -162,21 +164,22 @@ public void CreatePluginFamilyWithADefault() { IContainer manager = new Container(registry => registry.BuildInstancesOf<IWidget>().TheDefaultIs( - RegistryExpressions.Instance<ColorWidget>().WithProperty("color"). + RegistryExpressions.Instance<ColorWidget>().WithProperty( + "color"). EqualTo( "Red") )); - ColorWidget widget = (ColorWidget) manager.GetInstance<IWidget>(); + var widget = (ColorWidget) manager.GetInstance<IWidget>(); Assert.AreEqual("Red", widget.Color); } [Test] public void PutAnInterceptorIntoTheInterceptionChainOfAPluginFamilyInTheDSL() { - StubbedInstanceFactoryInterceptor factoryInterceptor = new StubbedInstanceFactoryInterceptor(); + var factoryInterceptor = new StubbedInstanceFactoryInterceptor(); - Registry registry = new Registry(); + var registry = new Registry(); registry.BuildInstancesOf<IGateway>().InterceptConstructionWith(factoryInterceptor); PluginGraph pluginGraph = registry.Build(); @@ -187,7 +190,7 @@ [Test] public void Set_the_default_by_a_lambda() { - Container manager = + var manager = new Container( registry => registry.ForRequestedType<IWidget>().TheDefault.Is.ConstructedBy(() => new AWidget())); @@ -197,15 +200,28 @@ [Test] public void Set_the_default_to_a_built_object() { - AWidget aWidget = new AWidget(); + var aWidget = new AWidget(); - Container manager = + var manager = new Container( registry => registry.ForRequestedType<IWidget>().TheDefault.Is.Object(aWidget)); Assert.AreSame(aWidget, manager.GetInstance<IWidget>()); } + [Test( + Description = + "Guid test based on problems encountered by Paul Segaro. See http://groups.google.com/group/structuremap-users/browse_thread/thread/34ddaf549ebb14f7?hl=en" + )] + public void TheDefaultInstanceIsALambdaForGuidNewGuid() + { + var manager = + new Container( + registry => registry.ForRequestedType<Guid>().TheDefault.Is.ConstructedBy(() => Guid.NewGuid())); + + Assert.IsInstanceOfType(typeof (Guid), manager.GetInstance<Guid>()); + } + [Test] public void TheDefaultInstanceIsConcreteType() { @@ -218,29 +234,19 @@ [Test] public void TheDefaultInstanceIsPickedUpFromTheAttribute() { - Registry registry = new Registry(); + var registry = new Registry(); registry.BuildInstancesOf<IGateway>(); - registry.ScanAssemblies().IncludeAssemblyContainingType<IGateway>(); + registry.Scan(x => x.AssemblyContainingType<IGateway>()); PluginGraph pluginGraph = registry.Build(); Assert.IsTrue(pluginGraph.ContainsFamily(typeof (IGateway))); - Container manager = new Container(pluginGraph); - IGateway gateway = (IGateway) manager.GetInstance(typeof (IGateway)); + var manager = new Container(pluginGraph); + var gateway = (IGateway) manager.GetInstance(typeof (IGateway)); Assert.IsInstanceOfType(typeof (DefaultGateway), gateway); } - - [Test(Description = "Guid test based on problems encountered by Paul Segaro. See http://groups.google.com/group/structuremap-users/browse_thread/thread/34ddaf549ebb14f7?hl=en")] - public void TheDefaultInstanceIsALambdaForGuidNewGuid() - { - Container manager = - new Container( - registry => registry.ForRequestedType<Guid>().TheDefault.Is.ConstructedBy(()=>Guid.NewGuid())); - - Assert.IsInstanceOfType(typeof(Guid), manager.GetInstance<Guid>()); - } } public class StubbedInstanceFactoryInterceptor : IBuildInterceptor Modified: trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/RegistryIntegratedTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -1,7 +1,6 @@ using System.Collections.Generic; using NUnit.Framework; using StructureMap.Graph; -using StructureMap.Pipeline; using StructureMap.Testing.Widget; using StructureMap.Testing.Widget5; @@ -28,10 +27,9 @@ [Test] public void AutomaticallyFindRegistryFromAssembly() { - StructureMapConfiguration.ResetAll(); - StructureMapConfiguration.ScanAssemblies().IncludeAssemblyContainingType<RedGreenRegistry>(); + ObjectFactory.Initialize(x => { x.Scan(s => { s.AssemblyContainingType<RedGreenRegistry>(); }); }); - List<string> colors = new List<string>(); + var colors = new List<string>(); foreach (IWidget widget in ObjectFactory.GetAllInstances<IWidget>()) { if (!(widget is ColorWidget)) @@ -39,7 +37,7 @@ continue; } - ColorWidget color = (ColorWidget) widget; + var color = (ColorWidget) widget; colors.Add(color.Color); } @@ -55,11 +53,15 @@ [Test] public void FindRegistriesWithinPluginGraphSeal() { - PluginGraph graph = new PluginGraph(); - graph.Assemblies.Add(typeof (RedGreenRegistry).Assembly); + var graph = new PluginGraph(); + + var scanner = new AssemblyScanner(); + scanner.AssemblyContainingType(typeof (RedGreenRegistry)); + scanner.ScanForAll(graph); + graph.Seal(); - List<string> colors = new List<string>(); + var colors = new List<string>(); PluginFamily family = graph.FindFamily(typeof (IWidget)); family.EachInstance(instance => colors.Add(instance.Name)); Deleted: trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Configuration/DSL/ScanAssembliesTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -1,89 +0,0 @@ -using System.Reflection; -using NUnit.Framework; -using StructureMap.Configuration.DSL.Expressions; -using StructureMap.Graph; -using StructureMap.Testing.Widget3; - -namespace StructureMap.Testing.Configuration.DSL -{ - [TestFixture] - public class ScanAssembliesTester - { - #region Setup/Teardown - - [SetUp] - public void SetUp() - { - StructureMapConfiguration.ResetAll(); - } - - [TearDown] - public void TearDown() - { - StructureMapConfiguration.ResetAll(); - } - - #endregion - - [Test] - public void Combination1() - { - StructureMapConfiguration.ScanAssemblies() - .IncludeAssemblyContainingType<IGateway>() - .IncludeTheCallingAssembly(); - PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - Assembly assembly = typeof (IGateway).Assembly; - Assert.IsTrue(graph.Assemblies.Contains(assembly.GetName().Name)); - - Assert.IsTrue(graph.Assemblies.Contains(Assembly.GetExecutingAssembly().GetName().Name)); - } - - - [Test] - public void Combination2() - { - StructureMapConfiguration.ScanAssemblies() - .IncludeTheCallingAssembly() - .IncludeAssemblyContainingType<IGateway>(); - PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - Assembly assembly = typeof (IGateway).Assembly; - Assert.IsTrue(graph.Assemblies.Contains(assembly.GetName().Name)); - - Assert.IsTrue(graph.Assemblies.Contains(Assembly.GetExecutingAssembly().GetName().Name)); - } - - [Test] - public void ScanAssemblyByName() - { - ScanAssembliesExpression expression = StructureMapConfiguration.ScanAssemblies() - .IncludeAssembly(typeof (IGateway).Assembly.FullName); - Assert.IsNotNull(expression); - - PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - Assembly assembly = typeof (IGateway).Assembly; - Assert.IsTrue(graph.Assemblies.Contains(assembly.GetName().Name)); - } - - [Test] - public void ScanAssemblyContainingType() - { - StructureMapConfiguration.ScanAssemblies().IncludeAssemblyContainingType<IGateway>(); - PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - Assembly assembly = typeof (IGateway).Assembly; - Assert.IsTrue(graph.Assemblies.Contains(assembly.GetName().Name)); - } - - [Test] - public void ScanCallingAssembly() - { - StructureMapConfiguration.ScanAssemblies().IncludeTheCallingAssembly(); - PluginGraph graph = StructureMapConfiguration.GetPluginGraph(); - - Assert.IsTrue(graph.Assemblies.Contains(Assembly.GetExecutingAssembly().GetName().Name)); - } - } -} \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Configuration/IncludeTesting.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -32,19 +32,6 @@ } [Test] - public void GetAssembliesFromIncludes() - { - PluginGraph graph = buildGraph(); - - Assert.AreEqual(4, graph.Assemblies.Count); - - Assert.IsTrue(graph.Assemblies.Contains("StructureMap.Testing.Widget")); - Assert.IsTrue(graph.Assemblies.Contains("StructureMap.Testing.Widget2")); - Assert.IsTrue(graph.Assemblies.Contains("StructureMap.Testing.Widget3")); - Assert.IsTrue(graph.Assemblies.Contains("StructureMap.Testing.Widget4")); - } - - [Test] public void GetFamilyFromIncludeAndMaster() { PluginGraph graph = buildGraph(); Modified: trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Configuration/NormalGraphBuilderTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -1,4 +1,3 @@ -using System; using NUnit.Framework; using StructureMap.Configuration; using StructureMap.Configuration.DSL; @@ -21,20 +20,9 @@ #endregion [Test] - public void AddAssembly_HappyPath() - { - GraphBuilder builder = new GraphBuilder(new Registry[0]); - string assemblyName = GetType().Assembly.GetName().Name; - builder.AddAssembly(assemblyName); - - Assert.IsTrue(builder.PluginGraph.Assemblies.Contains(assemblyName)); - Assert.AreEqual(0, builder.PluginGraph.Log.ErrorCount); - } - - [Test] public void AddAssembly_SadPath() { - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var builder = new GraphBuilder(new Registry[0]); builder.AddAssembly("something"); builder.PluginGraph.Log.AssertHasError(101); @@ -43,10 +31,10 @@ [Test] public void Call_the_action_on_configure_family_if_the_pluginType_is_found() { - TypePath typePath = new TypePath(typeof (IGateway)); + var typePath = new TypePath(typeof (IGateway)); bool iWasCalled = false; - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var builder = new GraphBuilder(new Registry[0]); builder.ConfigureFamily(typePath, f => { Assert.AreEqual(typeof (IGateway), f.PluginType); @@ -60,7 +48,7 @@ [Test] public void Configure_a_family_that_does_not_exist_and_log_an_error_with_PluginGraph() { - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var builder = new GraphBuilder(new Registry[0]); builder.ConfigureFamily(new TypePath("a,a"), delegate { }); builder.PluginGraph.Log.AssertHasError(103); @@ -69,11 +57,11 @@ [Test] public void Create_system_object_successfully_and_call_the_requested_action() { - MemoryInstanceMemento memento = new MemoryInstanceMemento("Singleton", "anything"); + var memento = new MemoryInstanceMemento("Singleton", "anything"); bool iWasCalled = false; - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var builder = new GraphBuilder(new Registry[0]); builder.PrepareSystemObjects(); builder.WithSystemObject<IBuildInterceptor>(memento, "singleton", policy => { @@ -87,15 +75,15 @@ [Test] public void Do_not_call_the_action_on_ConfigureFamily_if_the_type_path_blows_up() { - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var builder = new GraphBuilder(new Registry[0]); builder.ConfigureFamily(new TypePath("a,a"), obj => Assert.Fail("Should not be called")); } [Test] public void Do_not_try_to_execute_the_action_when_requested_system_object_if_it_cannot_be_created() { - MemoryInstanceMemento memento = new MemoryInstanceMemento(); - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var memento = new MemoryInstanceMemento(); + var builder = new GraphBuilder(new Registry[0]); builder.WithSystemObject<MementoSource>(memento, "I am going to break here", delegate { Assert.Fail("Wasn't supposed to be called"); }); @@ -104,8 +92,8 @@ [Test] public void Log_an_error_for_a_requested_system_object_if_it_cannot_be_created() { - MemoryInstanceMemento memento = new MemoryInstanceMemento(); - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var memento = new MemoryInstanceMemento(); + var builder = new GraphBuilder(new Registry[0]); builder.WithSystemObject<MementoSource>(memento, "I am going to break here", delegate { }); @@ -115,7 +103,7 @@ [Test] public void WithType_calls_through_to_the_Action_if_the_type_can_be_found() { - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var builder = new GraphBuilder(new Registry[0]); bool iWasCalled = true; builder.WithType(new TypePath(GetType()), "creating a Plugin", t => @@ -130,7 +118,7 @@ [Test] public void WithType_fails_and_logs_error_with_the_context() { - GraphBuilder builder = new GraphBuilder(new Registry[0]); + var builder = new GraphBuilder(new Registry[0]); builder.WithType(new TypePath("a,a"), "creating a Plugin", obj => Assert.Fail("Should not be called")); builder.PluginGraph.Log.AssertHasError(131); Modified: trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs =================================================================== --- trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/DataAccess/Debugging.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -11,6 +11,7 @@ [TestFixture] public class Debugging { + [Test, Explicit] public void GiveJSONAWhirl() { Modified: trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/GenericsAcceptanceTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -1,7 +1,6 @@ using System; using System.Reflection; using NUnit.Framework; -using StructureMap.Configuration.DSL; using StructureMap.Graph; using StructureMap.Pipeline; using StructureMap.Testing.GenericWidgets; @@ -20,20 +19,20 @@ #endregion - - [Test] public void BuildFamilyAndPluginThenSealAndCreateInstanceManagerWithGenericTypeWithOpenGenericParameters() { - PluginGraph graph = new PluginGraph(); - graph.Assemblies.Add(Assembly.GetExecutingAssembly()); + var graph = new PluginGraph(); + graph.Scan(x => x.TheCallingAssembly()); + + PluginFamily family = graph.FindFamily(typeof (IGenericService<>)); family.DefaultInstanceKey = "Default"; family.AddPlugin(typeof (GenericService<>), "Default"); graph.Seal(); - Container manager = new Container(graph); + var manager = new Container(graph); } [Test] @@ -41,11 +40,11 @@ { Type serviceType = typeof (IService<double>); PluginGraph pluginGraph = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly); - Container manager = new Container(pluginGraph); + var manager = new Container(pluginGraph); Type doubleServiceType = typeof (IService<double>); - ServiceWithPlug<double> service = + var service = (ServiceWithPlug<double>) manager.GetInstance(doubleServiceType, "Plugged"); Assert.AreEqual(typeof (double), service.Plug.PlugType); } @@ -53,53 +52,53 @@ [Test] public void CanCreatePluginFamilyForGenericTypeWithGenericParameter() { - PluginFamily family = new PluginFamily(typeof (IGenericService<int>)); + var family = new PluginFamily(typeof (IGenericService<int>)); } [Test] public void CanCreatePluginFamilyForGenericTypeWithoutGenericParameter() { - PluginFamily family = new PluginFamily(typeof (IGenericService<>)); + var family = new PluginFamily(typeof (IGenericService<>)); } [Test] public void CanCreatePluginForGenericTypeWithGenericParameter() { - Plugin plugin = new Plugin(typeof (GenericService<int>)); + var plugin = new Plugin(typeof (GenericService<int>)); } [Test] public void CanCreatePluginForGenericTypeWithoutGenericParameter() { - Plugin plugin = new Plugin(typeof (GenericService<>)); + var plugin = new Plugin(typeof (GenericService<>)); } [Test] public void CanEmitForATemplateWithTwoTemplates() { - PluginFamily family = new PluginFamily(typeof (ITarget<int, string>)); + var family = new PluginFamily(typeof (ITarget<int, string>)); family.AddPlugin(typeof (SpecificTarget<int, string>), "specific"); - InstanceFactory factory = new InstanceFactory(family); + var factory = new InstanceFactory(family); } [Test] public void CanEmitInstanceBuilderForATypeWithConstructorArguments() { - PluginGraph graph = new PluginGraph(); + var graph = new PluginGraph(); PluginFamily family = graph.FindFamily(typeof (ComplexType<int>)); family.AddPlugin(typeof (ComplexType<int>), "complex"); - Container manager = new Container(graph); + var manager = new Container(graph); - ConfiguredInstance instance = new ConfiguredInstance(typeof(ComplexType<int>)) + ConfiguredInstance instance = new ConfiguredInstance(typeof (ComplexType<int>)) .WithProperty("name").EqualTo("Jeremy") .WithProperty("age").EqualTo(32); - ComplexType<int> com = manager.GetInstance<ComplexType<int>>(instance); + var com = manager.GetInstance<ComplexType<int>>(instance); Assert.AreEqual("Jeremy", com.Name); Assert.AreEqual(32, com.Age); } @@ -107,8 +106,9 @@ [Test] public void CanGetPluginFamilyFromPluginGraphWithNoParameters() { - PluginGraph graph = new PluginGraph(); - graph.Assemblies.Add(Assembly.GetExecutingAssembly()); + var graph = new PluginGraph(); + graph.Scan(x => x.TheCallingAssembly()); + PluginFamily family1 = graph.FindFamily(typeof (IGenericService<int>)); PluginFamily family2 = graph.FindFamily(typeof (IGenericService<string>)); PluginFamily family3 = graph.FindFamily(typeof (IGenericService<>)); @@ -121,8 +121,9 @@ [Test] public void CanGetPluginFamilyFromPluginGraphWithParameters() { - PluginGraph graph = new PluginGraph(); - graph.Assemblies.Add(Assembly.GetExecutingAssembly()); + var graph = new PluginGraph(); + graph.Scan(x => x.TheCallingAssembly()); + PluginFamily family1 = graph.FindFamily(typeof (IGenericService<int>)); PluginFamily family2 = graph.FindFamily(typeof (IGenericService<string>)); @@ -185,9 +186,9 @@ pluginGraph.SetDefault("2", typeof (IService<>), new ReferencedInstance("Plugged")); - Container manager = new Container(pluginGraph); + var manager = new Container(pluginGraph); - IPlug<string> plug = manager.GetInstance<IPlug<string>>(); + var plug = manager.GetInstance<IPlug<string>>(); manager.SetDefaultsToProfile("1"); Assert.IsInstanceOfType(typeof (Service<string>), manager.GetInstance(typeof (IService<string>))); Modified: trunk/Source/StructureMap.Testing/Graph/ArrayConstructorTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ArrayConstructorTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Graph/ArrayConstructorTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -8,16 +8,7 @@ [TestFixture] public class ArrayConstructorTester { - #region Setup/Teardown - [TearDown] - public void TearDown() - { - ObjectMother.Reset(); - } - - #endregion - [Test] public void BuildDecisionWithRules() { Modified: trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Graph/ContainerTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -20,7 +20,7 @@ { _manager = new Container(registry => { - registry.ScanAssemblies().IncludeAssembly("StructureMap.Testing.Widget"); + registry.Scan(x => x.Assembly("StructureMap.Testing.Widget")); registry.BuildInstancesOf<Rule>(); registry.BuildInstancesOf<IWidget>(); registry.BuildInstancesOf<WidgetMaker>(); @@ -36,8 +36,10 @@ _manager.Configure(r => { r.InstanceOf<Rule>().Is.OfConcreteType<ColorRule>().WithCtorArg("color").EqualTo(Color).WithName(Color); - r.InstanceOf<IWidget>().Is.OfConcreteType<ColorWidget>().WithCtorArg("color").EqualTo(Color).WithName(Color); - r.InstanceOf<WidgetMaker>().Is.OfConcreteType<ColorWidgetMaker>().WithCtorArg("color").EqualTo(Color).WithName(Color); + r.InstanceOf<IWidget>().Is.OfConcreteType<ColorWidget>().WithCtorArg("color").EqualTo(Color).WithName( + Color); + r.InstanceOf<WidgetMaker>().Is.OfConcreteType<ColorWidgetMaker>().WithCtorArg("color").EqualTo(Color). + WithName(Color); }); } @@ -71,7 +73,7 @@ private void assertColorIs(IContainer manager, string color) { - ColorService rule = (ColorService) manager.GetInstance<IService>(); + var rule = (ColorService) manager.GetInstance<IService>(); Assert.AreEqual(color, rule.Color); } @@ -111,7 +113,7 @@ // Now, have that same Container create a ClassThatUsesProvider. StructureMap will // see that ClassThatUsesProvider is concrete, determine its constructor args, and build one // for you with the default IProvider. No other configuration necessary. - ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(); + var classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(); Assert.IsInstanceOfType(typeof (Provider), classThatUsesProvider.Provider); } @@ -122,18 +124,18 @@ new Container( registry => registry.ForRequestedType<IProvider>().TheDefaultIsConcreteType<Provider>()); - DifferentProvider differentProvider = new DifferentProvider(); - ExplicitArguments args = new ExplicitArguments(); + var differentProvider = new DifferentProvider(); + var args = new ExplicitArguments(); args.Set<IProvider>(differentProvider); - ClassThatUsesProvider classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(args); + var classThatUsesProvider = manager.GetInstance<ClassThatUsesProvider>(args); Assert.AreSame(differentProvider, classThatUsesProvider.Provider); } [Test, ExpectedException(typeof (StructureMapConfigurationException))] public void CTOR_throws_StructureMapConfigurationException_if_there_is_an_error() { - PluginGraph graph = new PluginGraph(); + var graph = new PluginGraph(); graph.Log.RegisterError(400, new ApplicationException("Bad!")); new Container(graph); @@ -145,12 +147,12 @@ { Type serviceType = typeof (IService<string>); PluginGraph pluginGraph = PluginGraph.BuildGraphFromAssembly(serviceType.Assembly); - PipelineGraph pipelineGraph = new PipelineGraph(pluginGraph); + var pipelineGraph = new PipelineGraph(pluginGraph); Type stringService = typeof (IService<string>); IInstanceFactory factory = pipelineGraph.ForType(stringService); - Assert.AreEqual(stringService, factory.PluginType); + Assert.AreEqual((object) stringService, factory.PluginType); } [Test] @@ -161,7 +163,7 @@ addColorMemento("Blue"); _manager.SetDefault(typeof (Rule), "Blue"); - ColorRule rule = _manager.GetInstance(typeof (Rule)) as ColorRule; + var rule = _manager.GetInstance(typeof (Rule)) as ColorRule; Assert.IsNotNull(rule); Assert.AreEqual("Blue", rule.Color); @@ -174,15 +176,15 @@ addColorMemento("Orange"); addColorMemento("Blue"); - ColorRule rule = _manager.GetInstance(typeof (Rule), "Blue") as ColorRule; + var rule = _manager.GetInstance(typeof (Rule), "Blue") as ColorRule; Assert.IsNotNull(rule); Assert.AreEqual("Blue", rule.Color); - ColorWidget widget = _manager.GetInstance(typeof (IWidget), "Red") as ColorWidget; + var widget = _manager.GetInstance(typeof (IWidget), "Red") as ColorWidget; Assert.IsNotNull(widget); Assert.AreEqual("Red", widget.Color); - ColorWidgetMaker maker = _manager.GetInstance(typeof (WidgetMaker), "Orange") as ColorWidgetMaker; + var maker = _manager.GetInstance(typeof (WidgetMaker), "Orange") as ColorWidgetMaker; Assert.IsNotNull(maker); Assert.AreEqual("Orange", maker.Color); } @@ -198,8 +200,8 @@ { IContainer container = new Container(); - ColorRule red = new ColorRule("Red"); - ColorRule blue = new ColorRule("Blue"); + var red = new ColorRule("Red"); + var blue = new ColorRule("Blue"); container.Inject<Rule>("Red", red); container.Inject<Rule>("Blue", blue); @@ -236,12 +238,8 @@ [Test, ExpectedException(typeof (StructureMapException))] public void TryToGetDefaultInstanceWithNoInstance() { - Container manager = new Container(new PluginGraph()); + var manager = new Container(new PluginGraph()); manager.GetInstance<IService>(); } - - } - - } \ No newline at end of file Modified: trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs =================================================================== --- trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2008-10-01 15:53:44 UTC (rev 159) +++ trunk/Source/StructureMap.Testing/Graph/DefaultConventionScanningTester.cs 2008-10-01 18:29:38 UTC (rev 160) @@ -38,8 +38,14 @@ [Test] public void Process_to_Container() { - Container container = new Container(registry => registry.ScanAssemblies().IncludeTheCallingAssembly() - .With(new DefaultConventionScanner())); + Container container = new Container(registry => + { + registry.Scan(x => + { + x.TheCallingAssembly(); + x.With<DefaultConventionScanner>(); + }); + }); Debug.WriteLine(container.WhatDoIHave()); @@ -50,8 +56,14 @@ [Test] public void Process_to_Container_2() { - Container container = new Container(registry => registry.ScanAssemblies().IncludeTheCallingAssembly() - .With<DefaultConventionScanner>()); + Container container = new Container(registry => + { + registry.Scan(x => + { + x.TheCallingAssembly(); + x.With(new DefaultConventionScanner()); + }); + }); Assert.IsInstanceOfType... [truncated message content] |