From d68b2c6ac57acf939b8e6d82b04c93fdae2f5aa7 Mon Sep 17 00:00:00 2001 From: volkanceylan Date: Sun, 5 Jan 2025 14:08:46 +0300 Subject: [PATCH] Check for DefaultHandler(false) before selection --- .../RequestHandlers/Handler/DefaultHandlerFactory.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Serenity.Net.Services/RequestHandlers/Handler/DefaultHandlerFactory.cs b/src/Serenity.Net.Services/RequestHandlers/Handler/DefaultHandlerFactory.cs index 131d2ce909..b559580a8a 100644 --- a/src/Serenity.Net.Services/RequestHandlers/Handler/DefaultHandlerFactory.cs +++ b/src/Serenity.Net.Services/RequestHandlers/Handler/DefaultHandlerFactory.cs @@ -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()?.Value != false) .ToArray(); if (handlers.Length == 1) @@ -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()?.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."); }