diff --git a/src/MediatR/Registration/ServiceRegistrar.cs b/src/MediatR/Registration/ServiceRegistrar.cs index c4cdd008..5d22cc8f 100644 --- a/src/MediatR/Registration/ServiceRegistrar.cs +++ b/src/MediatR/Registration/ServiceRegistrar.cs @@ -228,10 +228,7 @@ private static (Type Service, Type Implementation) GetConcreteRegistrationTypes( var constraintsForEachParameter = openRequestHandlerImplementation .GetGenericArguments() .Select(x => x.GetGenericParameterConstraints()) - .ToList(); - - if (constraintsForEachParameter.Count > 2 && constraintsForEachParameter.Any(constraints => !constraints.Where(x => x.IsInterface || x.IsClass).Any())) - throw new ArgumentException($"Error registering the generic handler type: {openRequestHandlerImplementation.FullName}. When registering generic requests with more than two type parameters, each type parameter must have at least one constraint of type interface or class."); + .ToList(); var typesThatCanCloseForEachParameter = constraintsForEachParameter .Select(constraints => assembliesToScan diff --git a/test/MediatR.Tests/GenericRequestHandlerTests.cs b/test/MediatR.Tests/GenericRequestHandlerTests.cs index 3daa17e6..5c05b535 100644 --- a/test/MediatR.Tests/GenericRequestHandlerTests.cs +++ b/test/MediatR.Tests/GenericRequestHandlerTests.cs @@ -93,24 +93,6 @@ public void ShouldNotRegisterDuplicateHandlers(int numberOfClasses, int numberOf hasDuplicates.ShouldBeFalse(); } - [Fact] - public void ShouldThrowExceptionWhenRegisterningHandlersWithNoConstraints() - { - IServiceCollection services = new ServiceCollection(); - services.AddSingleton(new Logger()); - - var assembly = GenerateMissingConstraintsAssembly(); - - Should.Throw(() => - { - services.AddMediatR(cfg => - { - cfg.RegisterServicesFromAssembly(assembly); - }); - }) - .Message.ShouldContain("When registering generic requests with more than two type parameters, each type parameter must have at least one constraint of type interface or class."); - } - [Fact] public void ShouldThrowExceptionWhenTypesClosingExceedsMaximum() { diff --git a/test/MediatR.Tests/MicrosoftExtensionsDI/BaseGenericRequestHandlerTests.cs b/test/MediatR.Tests/MicrosoftExtensionsDI/BaseGenericRequestHandlerTests.cs index b87fc02b..72853099 100644 --- a/test/MediatR.Tests/MicrosoftExtensionsDI/BaseGenericRequestHandlerTests.cs +++ b/test/MediatR.Tests/MicrosoftExtensionsDI/BaseGenericRequestHandlerTests.cs @@ -9,11 +9,7 @@ namespace MediatR.Tests.MicrosoftExtensionsDI { public abstract class BaseGenericRequestHandlerTests - { - - protected static Assembly GenerateMissingConstraintsAssembly() => - CreateAssemblyModuleBuilder("MissingConstraintsAssembly", 3, 3, CreateHandlerForMissingConstraintsTest); - + { protected static Assembly GenerateTypesClosingExceedsMaximumAssembly() => CreateAssemblyModuleBuilder("ExceedsMaximumTypesClosingAssembly", 201, 1, CreateHandlerForExceedsMaximumClassesTest);