Skip to content

Commit

Permalink
Remove Missing Constraints logic
Browse files Browse the repository at this point in the history
- remove logic
- reomove tests
  • Loading branch information
zachpainter77 committed Aug 3, 2024
1 parent 811ce54 commit 6abee0c
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
5 changes: 1 addition & 4 deletions src/MediatR/Registration/ServiceRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions test/MediatR.Tests/GenericRequestHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArgumentException>(() =>
{
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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6abee0c

Please sign in to comment.