Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions LightInject.Tests/AssemblyScannerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void Register_AssemblyWithFuncAndLifeCycle_CallsAssemblyScanner()
mockContext.Assert(a => a.Scan(typeof(IFoo).Assembly, The<IServiceRegistry>.IsAnyValue, The<Func<ILifetime>>.IsAnyValue, The<Func<Type, Type, bool>>.IsAnyValue), Invoked.Once);
}
#if NET || NET45

[TestMethod]
public void Register_SearchPattern_CallsAssemblyScanner()
{
Expand All @@ -234,6 +235,17 @@ public void Register_SearchPattern_CallsAssemblyScanner()
serviceContainer.RegisterAssembly("LightInject.SampleLibrary.dll");
mockContext.Assert(a => a.Scan(typeof(IFoo).Assembly, The<IServiceRegistry>.IsAnyValue, The<Func<ILifetime>>.IsAnyValue, The<Func<Type, Type, bool>>.IsAnyValue), Invoked.Once);
}

[TestMethod]
public void Register_SearchPattern_CallsAssemblyScanner_FromFullPath()
{
var mockContext = new MockContext<IAssemblyScanner>();
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<IServiceRegistry>.IsAnyValue, The<Func<ILifetime>>.IsAnyValue, The<Func<Type, Type, bool>>.IsAnyValue), Invoked.Once);
}
#endif

[TestMethod]
Expand Down
16 changes: 13 additions & 3 deletions LightInject/LightInject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -6958,9 +6958,19 @@ public IEnumerable<Assembly> 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);
}
}
}
}
}
Expand Down