From 46c9afdbc43b1b6603d20812d03be90a480d91e7 Mon Sep 17 00:00:00 2001 From: Jeffrey Knight Date: Mon, 2 Feb 2015 22:29:59 -0500 Subject: [PATCH 1/2] allow full file paths in assembly scanner --- LightInject.Tests/AssemblyScannerTests.cs | 12 ++++++++++++ LightInject/LightInject.cs | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/LightInject.Tests/AssemblyScannerTests.cs b/LightInject.Tests/AssemblyScannerTests.cs index acd32f1d..a11311a7 100644 --- a/LightInject.Tests/AssemblyScannerTests.cs +++ b/LightInject.Tests/AssemblyScannerTests.cs @@ -224,6 +224,7 @@ public void Register_AssemblyWithFuncAndLifeCycle_CallsAssemblyScanner() mockContext.Assert(a => a.Scan(typeof(IFoo).Assembly, The.IsAnyValue, The>.IsAnyValue, The>.IsAnyValue), Invoked.Once); } #if NET || NET45 + [TestMethod] public void Register_SearchPattern_CallsAssemblyScanner() { @@ -234,6 +235,17 @@ public void Register_SearchPattern_CallsAssemblyScanner() serviceContainer.RegisterAssembly("LightInject.SampleLibrary.dll"); mockContext.Assert(a => a.Scan(typeof(IFoo).Assembly, The.IsAnyValue, The>.IsAnyValue, The>.IsAnyValue), Invoked.Once); } + + [TestMethod] + public void Register_SearchPattern_CallsAssemblyScanner_FromFullPath() + { + var mockContext = new MockContext(); + var scannerMock = new AssemblyScannerMock(mockContext); + var serviceContainer = new ServiceContainer(); + serviceContainer.AssemblyScanner = scannerMock; + serviceContainer.RegisterAssembly(Environment.CurrentDirectory + "\\LightInject.SampleLibrary.dll"); + mockContext.Assert(a => a.Scan(typeof(IFoo).Assembly, The.IsAnyValue, The>.IsAnyValue, The>.IsAnyValue), Invoked.Once); + } #endif [TestMethod] diff --git a/LightInject/LightInject.cs b/LightInject/LightInject.cs index 47613c9e..3f8ba033 100644 --- a/LightInject/LightInject.cs +++ b/LightInject/LightInject.cs @@ -6958,9 +6958,19 @@ public IEnumerable Load(string searchPattern) if (directory != null) { string[] searchPatterns = searchPattern.Split('|'); - foreach (string file in searchPatterns.SelectMany(sp => Directory.GetFiles(directory, sp)).Where(CanLoad)) + foreach (string pattern in searchPatterns) { - yield return Assembly.LoadFrom(file); + if(File.Exists(pattern)) + { + yield return Assembly.LoadFrom(pattern); + } + else + { + foreach(string file in searchPattern.SelectMany(sp => Directory.GetFiles(directory, pattern)).Where(CanLoad)) + { + yield return Assembly.LoadFrom(file); + } + } } } } From 03f44d088368e2609e1edfb6a0d7ed499b6c4f00 Mon Sep 17 00:00:00 2001 From: jknight Date: Tue, 3 Feb 2015 07:43:35 -0500 Subject: [PATCH 2/2] friendlier help message for end user --- LightInject/LightInject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LightInject/LightInject.cs b/LightInject/LightInject.cs index 3f8ba033..ab69c655 100644 --- a/LightInject/LightInject.cs +++ b/LightInject/LightInject.cs @@ -6371,7 +6371,7 @@ private static void TrackInstance(Scope scope, IDisposable disposable) { if (scope == null) { - throw new InvalidOperationException("Attempt to create a disposable instance without a current scope."); + throw new InvalidOperationException("Attempt to create a disposable instance without a current scope. Put your GetInstance call in a 'using (var scope = container.BeginScope())' { ... } block."); } scope.TrackInstance(disposable);