Skip to content

Commit f272e43

Browse files
committed
renamed the request handler to use case and added some xml documentation.
1 parent 42ea54e commit f272e43

22 files changed

+544
-177
lines changed

sources/RequestR.Demo/PresentProductsRequestHandler.cs renamed to sources/RequestR.Demo/PresentProductsUseCase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919
namespace DustInTheWind.RequestR.Demo
2020
{
21-
internal class PresentProductsRequestHandler : IRequestHandler<PresentProductsRequest, List<Product>>
21+
internal class PresentProductsUseCase : IUseCase<PresentProductsRequest, List<Product>>
2222
{
23-
public List<Product> Handle(PresentProductsRequest request)
23+
public List<Product> Execute(PresentProductsRequest request)
2424
{
2525
return new List<Product>
2626
{

sources/RequestR.Demo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ private static void Main(string[] args)
2525
{
2626
// Setup request bus
2727
RequestBus requestBus = new RequestBus();
28-
requestBus.RegisterHandler<PresentProductsRequestHandler>();
28+
requestBus.RegisterUseCase<PresentProductsUseCase>();
2929

3030
// Send request
3131
PresentProductsRequest request = new PresentProductsRequest();

sources/RequestR/AssemblyExtensions.cs

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,83 @@
2121

2222
namespace DustInTheWind.RequestR
2323
{
24+
/// <summary>
25+
/// Contains extension methods for the <see cref="Assembly"/> type.
26+
/// </summary>
2427
public static class AssemblyExtensions
2528
{
26-
public static IEnumerable<Type> GetAllRequestHandlersOrValidators(this Assembly assembly)
29+
/// <summary>
30+
/// Enumerates all the types that implement the one of the interfaces: <see cref="IUseCase{TRequest}"/>,
31+
/// <see cref="IUseCase{TRequest, TResponse}"/>, <see cref="IUseCaseAsync{TRequest}"/>,
32+
/// <see cref="IUseCaseAsync{TRequest, TResponse}"/> or <see cref="IRequestValidator{TRequest}"/>.
33+
/// </summary>
34+
/// <param name="assembly">The assembly to be searched.</param>
35+
/// <returns>An enumeration of <see cref="Type"/> objects representing the use case and request validator classes.</returns>
36+
public static IEnumerable<Type> GetAllUseCasesAndRequestValidators(this Assembly assembly)
2737
{
2838
if (assembly == null) throw new ArgumentNullException(nameof(assembly));
2939

3040
Type[] handlerOrValidatorTypes = assembly.GetTypes()
3141
.Where(x => x.IsClass && !x.IsAbstract)
32-
.Where(x => x.GetInterfaces().Any(IsRequestHandlerOrValidatorInterface))
42+
.Where(x => x.GetInterfaces().Any(IsUseCaseOrValidatorInterface))
3343
.ToArray();
3444

3545
foreach (Type handlerOrValidatorType in handlerOrValidatorTypes)
3646
yield return handlerOrValidatorType;
3747
}
3848

39-
private static bool IsRequestHandlerOrValidatorInterface(Type type)
49+
private static bool IsUseCaseOrValidatorInterface(Type type)
4050
{
4151
if (!type.IsGenericType)
4252
return false;
4353

4454
Type genericTypeDefinition = type.GetGenericTypeDefinition();
4555

46-
return genericTypeDefinition == typeof(IRequestHandler<,>) ||
47-
genericTypeDefinition == typeof(IRequestHandler<>) ||
56+
return genericTypeDefinition == typeof(IUseCase<,>) ||
57+
genericTypeDefinition == typeof(IUseCase<>) ||
58+
genericTypeDefinition == typeof(IUseCaseAsync<,>) ||
59+
genericTypeDefinition == typeof(IUseCaseAsync<>) ||
4860
genericTypeDefinition == typeof(IRequestValidator<>);
4961
}
5062

51-
public static IEnumerable<Type> GetAllRequestHandlers(this Assembly assembly)
63+
/// <summary>
64+
/// Enumerates all the types that implement the one of the interfaces: <see cref="IUseCase{TRequest}"/>,
65+
/// <see cref="IUseCase{TRequest, TResponse}"/>, <see cref="IUseCaseAsync{TRequest}"/> or
66+
/// <see cref="IUseCaseAsync{TRequest, TResponse}"/>.
67+
/// </summary>
68+
/// <param name="assembly">The assembly to be searched.</param>
69+
/// <returns>An enumeration of <see cref="Type"/> objects representing the use case classes.</returns>
70+
public static IEnumerable<Type> GetAllUseCases(this Assembly assembly)
5271
{
5372
if (assembly == null) throw new ArgumentNullException(nameof(assembly));
5473

5574
Type[] handlerOrValidatorTypes = assembly.GetTypes()
5675
.Where(x => x.IsClass && !x.IsAbstract)
57-
.Where(x => x.GetInterfaces().Any(IsRequestHandlerInterface))
76+
.Where(x => x.GetInterfaces().Any(IsUseCaseInterface))
5877
.ToArray();
5978

6079
foreach (Type handlerOrValidatorType in handlerOrValidatorTypes)
6180
yield return handlerOrValidatorType;
6281
}
6382

64-
private static bool IsRequestHandlerInterface(Type type)
83+
private static bool IsUseCaseInterface(Type type)
6584
{
6685
if (!type.IsGenericType)
6786
return false;
6887

6988
Type genericTypeDefinition = type.GetGenericTypeDefinition();
7089

71-
return genericTypeDefinition == typeof(IRequestHandler<,>) ||
72-
genericTypeDefinition == typeof(IRequestHandler<>);
90+
return genericTypeDefinition == typeof(IUseCase<,>) ||
91+
genericTypeDefinition == typeof(IUseCase<>) ||
92+
genericTypeDefinition == typeof(IUseCaseAsync<,>) ||
93+
genericTypeDefinition == typeof(IUseCaseAsync<>);
7394
}
7495

96+
/// <summary>
97+
/// Enumerates all the types that implement the <see cref="IRequestValidator{TRequest}"/> interface.
98+
/// </summary>
99+
/// <param name="assembly">The assembly to be searched.</param>
100+
/// <returns>An enumeration of <see cref="Type"/> objects representing the request validator classes.</returns>
75101
public static IEnumerable<Type> GetAllRequestValidators(this Assembly assembly)
76102
{
77103
if (assembly == null) throw new ArgumentNullException(nameof(assembly));

sources/RequestR/ValidationException.cs renamed to sources/RequestR/DefaultUseCaseFactory.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818

1919
namespace DustInTheWind.RequestR
2020
{
21-
public class ValidationException : Exception
21+
/// <summary>
22+
/// This default implementation uses the <see cref="Activator"/> class to create use case instances.
23+
/// As a result it can create only use cases that provide a parameterless constructor.
24+
/// </summary>
25+
public class DefaultUseCaseFactory : UseCaseFactoryBase
2226
{
23-
public ValidationException(string message)
24-
: base(message)
27+
protected override object CreateInternal(Type type)
2528
{
29+
return Activator.CreateInstance(type);
2630
}
2731
}
2832
}

sources/RequestR/DustInTheWind.RequestR.xml

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sources/RequestR/IRequestHandler2.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

sources/RequestR/IRequestHandlerAsync2.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)