Skip to content

Commit c3b2a0e

Browse files
committed
fix voter types not always resolving
1 parent f28a3c3 commit c3b2a0e

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

AuthorizationChecker/src/Extensions/ServiceCollectionExtensions.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@ public static IServiceCollection AddAuthorizationChecker(this IServiceCollection
1818

1919
foreach (var voterType in voterTypes)
2020
{
21-
foreach (var voterInterface in voterType.GetInterfaces().Where(type => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IVoter<>)))
21+
var voterTypeInterfaces = new HashSet<Type>();
22+
var currentType = voterType;
23+
24+
while (currentType != null && currentType != typeof(object))
25+
{
26+
foreach (var @interface in currentType.GetInterfaces())
27+
{
28+
voterTypeInterfaces.Add(@interface);
29+
}
30+
31+
currentType = currentType.BaseType;
32+
}
33+
34+
foreach (var voterInterface in voterTypeInterfaces.Where(type => type.IsGenericType))
2235
{
2336
services.AddTransient(voterInterface, voterType);
2437
}

0 commit comments

Comments
 (0)