Skip to content

Commit 6abee0c

Browse files
committed
Remove Missing Constraints logic
- remove logic - reomove tests
1 parent 811ce54 commit 6abee0c

File tree

3 files changed

+2
-27
lines changed

3 files changed

+2
-27
lines changed

src/MediatR/Registration/ServiceRegistrar.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ private static (Type Service, Type Implementation) GetConcreteRegistrationTypes(
228228
var constraintsForEachParameter = openRequestHandlerImplementation
229229
.GetGenericArguments()
230230
.Select(x => x.GetGenericParameterConstraints())
231-
.ToList();
232-
233-
if (constraintsForEachParameter.Count > 2 && constraintsForEachParameter.Any(constraints => !constraints.Where(x => x.IsInterface || x.IsClass).Any()))
234-
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.");
231+
.ToList();
235232

236233
var typesThatCanCloseForEachParameter = constraintsForEachParameter
237234
.Select(constraints => assembliesToScan

test/MediatR.Tests/GenericRequestHandlerTests.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,6 @@ public void ShouldNotRegisterDuplicateHandlers(int numberOfClasses, int numberOf
9393
hasDuplicates.ShouldBeFalse();
9494
}
9595

96-
[Fact]
97-
public void ShouldThrowExceptionWhenRegisterningHandlersWithNoConstraints()
98-
{
99-
IServiceCollection services = new ServiceCollection();
100-
services.AddSingleton(new Logger());
101-
102-
var assembly = GenerateMissingConstraintsAssembly();
103-
104-
Should.Throw<ArgumentException>(() =>
105-
{
106-
services.AddMediatR(cfg =>
107-
{
108-
cfg.RegisterServicesFromAssembly(assembly);
109-
});
110-
})
111-
.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.");
112-
}
113-
11496
[Fact]
11597
public void ShouldThrowExceptionWhenTypesClosingExceedsMaximum()
11698
{

test/MediatR.Tests/MicrosoftExtensionsDI/BaseGenericRequestHandlerTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
namespace MediatR.Tests.MicrosoftExtensionsDI
1010
{
1111
public abstract class BaseGenericRequestHandlerTests
12-
{
13-
14-
protected static Assembly GenerateMissingConstraintsAssembly() =>
15-
CreateAssemblyModuleBuilder("MissingConstraintsAssembly", 3, 3, CreateHandlerForMissingConstraintsTest);
16-
12+
{
1713
protected static Assembly GenerateTypesClosingExceedsMaximumAssembly() =>
1814
CreateAssemblyModuleBuilder("ExceedsMaximumTypesClosingAssembly", 201, 1, CreateHandlerForExceedsMaximumClassesTest);
1915

0 commit comments

Comments
 (0)