|
21 | 21 |
|
22 | 22 | namespace DustInTheWind.RequestR
|
23 | 23 | {
|
| 24 | + /// <summary> |
| 25 | + /// Contains extension methods for the <see cref="Assembly"/> type. |
| 26 | + /// </summary> |
24 | 27 | public static class AssemblyExtensions
|
25 | 28 | {
|
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) |
27 | 37 | {
|
28 | 38 | if (assembly == null) throw new ArgumentNullException(nameof(assembly));
|
29 | 39 |
|
30 | 40 | Type[] handlerOrValidatorTypes = assembly.GetTypes()
|
31 | 41 | .Where(x => x.IsClass && !x.IsAbstract)
|
32 |
| - .Where(x => x.GetInterfaces().Any(IsRequestHandlerOrValidatorInterface)) |
| 42 | + .Where(x => x.GetInterfaces().Any(IsUseCaseOrValidatorInterface)) |
33 | 43 | .ToArray();
|
34 | 44 |
|
35 | 45 | foreach (Type handlerOrValidatorType in handlerOrValidatorTypes)
|
36 | 46 | yield return handlerOrValidatorType;
|
37 | 47 | }
|
38 | 48 |
|
39 |
| - private static bool IsRequestHandlerOrValidatorInterface(Type type) |
| 49 | + private static bool IsUseCaseOrValidatorInterface(Type type) |
40 | 50 | {
|
41 | 51 | if (!type.IsGenericType)
|
42 | 52 | return false;
|
43 | 53 |
|
44 | 54 | Type genericTypeDefinition = type.GetGenericTypeDefinition();
|
45 | 55 |
|
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<>) || |
48 | 60 | genericTypeDefinition == typeof(IRequestValidator<>);
|
49 | 61 | }
|
50 | 62 |
|
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) |
52 | 71 | {
|
53 | 72 | if (assembly == null) throw new ArgumentNullException(nameof(assembly));
|
54 | 73 |
|
55 | 74 | Type[] handlerOrValidatorTypes = assembly.GetTypes()
|
56 | 75 | .Where(x => x.IsClass && !x.IsAbstract)
|
57 |
| - .Where(x => x.GetInterfaces().Any(IsRequestHandlerInterface)) |
| 76 | + .Where(x => x.GetInterfaces().Any(IsUseCaseInterface)) |
58 | 77 | .ToArray();
|
59 | 78 |
|
60 | 79 | foreach (Type handlerOrValidatorType in handlerOrValidatorTypes)
|
61 | 80 | yield return handlerOrValidatorType;
|
62 | 81 | }
|
63 | 82 |
|
64 |
| - private static bool IsRequestHandlerInterface(Type type) |
| 83 | + private static bool IsUseCaseInterface(Type type) |
65 | 84 | {
|
66 | 85 | if (!type.IsGenericType)
|
67 | 86 | return false;
|
68 | 87 |
|
69 | 88 | Type genericTypeDefinition = type.GetGenericTypeDefinition();
|
70 | 89 |
|
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<>); |
73 | 94 | }
|
74 | 95 |
|
| 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> |
75 | 101 | public static IEnumerable<Type> GetAllRequestValidators(this Assembly assembly)
|
76 | 102 | {
|
77 | 103 | if (assembly == null) throw new ArgumentNullException(nameof(assembly));
|
|
0 commit comments