Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

Commit 9891f2d

Browse files
authored
Added registration of bindings from external assemblies (#69)
Contributor: @VakarisL
1 parent 8677491 commit 9891f2d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

SpecFlow.DependencyInjection/ServiceCollectionFinder.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Reflection;
45
using Microsoft.Extensions.DependencyInjection;
@@ -46,7 +47,7 @@ protected virtual Func<IServiceCollection> FindCreateScenarioServiceCollection()
4647
var serviceCollection = GetServiceCollection(methodInfo);
4748
if (scenarioDependenciesAttribute.AutoRegisterBindings)
4849
{
49-
AddBindingAttributes(assembly, serviceCollection);
50+
AddBindingAttributes(assemblies, serviceCollection);
5051
}
5152
return serviceCollection;
5253
};
@@ -62,11 +63,14 @@ private static IServiceCollection GetServiceCollection(MethodBase methodInfo)
6263
return (IServiceCollection)methodInfo.Invoke(null, null);
6364
}
6465

65-
private static void AddBindingAttributes(Assembly assembly, IServiceCollection serviceCollection)
66+
private static void AddBindingAttributes(IEnumerable<Assembly> bindingAssemblies, IServiceCollection serviceCollection)
6667
{
67-
foreach (var type in assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
68+
foreach(var assembly in bindingAssemblies)
6869
{
69-
serviceCollection.AddSingleton(type);
70+
foreach (var type in assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
71+
{
72+
serviceCollection.AddSingleton(type);
73+
}
7074
}
7175
}
7276
}

0 commit comments

Comments
 (0)