Skip to content

Commit

Permalink
Check for DefaultHandler(false) before selection
Browse files Browse the repository at this point in the history
  • Loading branch information
volkanceylan committed Jan 5, 2025
1 parent 72ee725 commit d68b2c6
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ private Type GetHandlerType((Type rowType, Type handlerInterface) args)
var requestHandler = typeof(IRequestHandler<>).MakeGenericType(args.rowType);

var handlers = registry.GetTypes(args.handlerInterface)
.Where(requestHandler.IsAssignableFrom)
.Where(x =>
requestHandler.IsAssignableFrom(x) &&
x.GetAttribute<DefaultHandlerAttribute>()?.Value != false)
.ToArray();

if (handlers.Length == 1)
Expand All @@ -36,13 +38,6 @@ private Type GetHandlerType((Type rowType, Type handlerInterface) args)
if (defaults.Count() == 1)
return defaults.First();

if (!defaults.Any())
{
var withoutDefaultsFalse = handlers.Where(x => x.GetAttribute<DefaultHandlerAttribute>()?.Value != false);
if (withoutDefaultsFalse.Count() == 1)
return withoutDefaultsFalse.First();
}

throw new InvalidProgramException($"There are multiple {args.handlerInterface.FullName} types " +
$"for row type {args.rowType.FullName}. Please add [DefaultHandler] to one of them.");
}
Expand Down

0 comments on commit d68b2c6

Please sign in to comment.