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