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..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); @@ -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); + } + } } } }