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

Commit

Permalink
Added registration of bindings from external assemblies (#69)
Browse files Browse the repository at this point in the history
Contributor: @VakarisL
  • Loading branch information
VakarisL authored Sep 3, 2021
1 parent 8677491 commit 9891f2d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions SpecFlow.DependencyInjection/ServiceCollectionFinder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -46,7 +47,7 @@ protected virtual Func<IServiceCollection> FindCreateScenarioServiceCollection()
var serviceCollection = GetServiceCollection(methodInfo);
if (scenarioDependenciesAttribute.AutoRegisterBindings)
{
AddBindingAttributes(assembly, serviceCollection);
AddBindingAttributes(assemblies, serviceCollection);
}
return serviceCollection;
};
Expand All @@ -62,11 +63,14 @@ private static IServiceCollection GetServiceCollection(MethodBase methodInfo)
return (IServiceCollection)methodInfo.Invoke(null, null);
}

private static void AddBindingAttributes(Assembly assembly, IServiceCollection serviceCollection)
private static void AddBindingAttributes(IEnumerable<Assembly> bindingAssemblies, IServiceCollection serviceCollection)
{
foreach (var type in assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
foreach(var assembly in bindingAssemblies)
{
serviceCollection.AddSingleton(type);
foreach (var type in assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))))
{
serviceCollection.AddSingleton(type);
}
}
}
}
Expand Down

0 comments on commit 9891f2d

Please sign in to comment.