| | | 1 | | using ArturRios.Heimdall.Query.Handlers; |
| | | 2 | | using ArturRios.Heimdall.Query.Input; |
| | | 3 | | using ArturRios.Heimdall.Query.Input.Validation; |
| | | 4 | | using ArturRios.Heimdall.Query.Output; |
| | | 5 | | using ArturRios.Mediator.Query; |
| | | 6 | | using ArturRios.Mediator.Query.Interfaces; |
| | | 7 | | using FluentValidation; |
| | | 8 | | using Microsoft.Extensions.DependencyInjection; |
| | | 9 | | |
| | | 10 | | namespace ArturRios.Heimdall.Query.Registration; |
| | | 11 | | |
| | | 12 | | public static class QueryServiceCollectionExtensions |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Registers the query mediator, the query handlers and the validators of the paginated list queries. |
| | | 16 | | /// </summary> |
| | | 17 | | public static IServiceCollection AddQueryHandlers(this IServiceCollection services) |
| | | 18 | | { |
| | | 19 | | // #219: the controllers pass HttpContext.RequestAborted to every query, and the mediator forwards it |
| | | 20 | | // to the handler, so an abandoned read stops its query. Commands are the opposite (see CommandMediator). |
| | 973 | 21 | | services.AddScoped<QueryMediator>(); |
| | 973 | 22 | | services |
| | 973 | 23 | | .AddScoped<IQueryHandlerAsync<GetScopeByIdQuery, ScopeOutput>, GetScopeByIdQueryHandler>(); |
| | 973 | 24 | | services |
| | 973 | 25 | | .AddScoped<IPaginatedQueryHandlerAsync<ListScopesQuery, ScopeOutput>, ListScopesQueryHandler>(); |
| | 973 | 26 | | services |
| | 973 | 27 | | .AddScoped<IQueryHandlerAsync<GetPersonByIdQuery, PersonOutput>, GetPersonByIdQueryHandler>(); |
| | 973 | 28 | | services |
| | 973 | 29 | | .AddScoped<IPaginatedQueryHandlerAsync<ListScopePersonsQuery, PersonOutput>, ListScopePersonsQueryHandler>() |
| | 973 | 30 | | services |
| | 973 | 31 | | .AddScoped<IPaginatedQueryHandlerAsync<ListScopeOwnersQuery, PersonOutput>, ListScopeOwnersQueryHandler>(); |
| | 973 | 32 | | services |
| | 973 | 33 | | .AddScoped<IPaginatedQueryHandlerAsync<ListScopeOwnerInvitationsQuery, ScopeOwnerInvitationOutput>, |
| | 973 | 34 | | ListScopeOwnerInvitationsQueryHandler>(); |
| | 973 | 35 | | services |
| | 973 | 36 | | .AddScoped<IPaginatedQueryHandlerAsync<ListMyScopeInvitationsQuery, MyScopeInvitationOutput>, |
| | 973 | 37 | | ListMyScopeInvitationsQueryHandler>(); |
| | 973 | 38 | | services |
| | 973 | 39 | | .AddScoped<IPaginatedQueryHandlerAsync<ListScopeAdminsQuery, PersonSummaryOutput>, |
| | 973 | 40 | | ListScopeAdminsQueryHandler>(); |
| | 973 | 41 | | services |
| | 973 | 42 | | .AddScoped<IPaginatedQueryHandlerAsync<ListPendingRegistrationsQuery, PendingRegistrationOutput>, |
| | 973 | 43 | | ListPendingRegistrationsQueryHandler>(); |
| | 973 | 44 | | services |
| | 973 | 45 | | .AddScoped<IPaginatedQueryHandlerAsync<ListSystemAdminsQuery, PersonSummaryOutput>, |
| | 973 | 46 | | ListSystemAdminsQueryHandler>(); |
| | 973 | 47 | | services |
| | 973 | 48 | | .AddScoped<IQueryHandlerAsync<GetApplicationByIdQuery, ApplicationOutput>, |
| | 973 | 49 | | GetApplicationByIdQueryHandler>(); |
| | 973 | 50 | | services |
| | 973 | 51 | | .AddScoped<IQueryHandlerAsync<CheckApplicationTokenQuery, ApplicationTokenCheckOutput>, |
| | 973 | 52 | | CheckApplicationTokenQueryHandler>(); |
| | 973 | 53 | | services |
| | 973 | 54 | | .AddScoped<IPaginatedQueryHandlerAsync<ListScopeApplicationsQuery, ApplicationOutput>, |
| | 973 | 55 | | ListScopeApplicationsQueryHandler>(); |
| | 973 | 56 | | services |
| | 973 | 57 | | .AddScoped<IQueryHandlerAsync<ListApplicationCredentialsQuery, ApplicationCredentialListOutput>, |
| | 973 | 58 | | ListApplicationCredentialsQueryHandler>(); |
| | 973 | 59 | | services |
| | 973 | 60 | | .AddScoped<IQueryHandlerAsync<GetScopePermissionByIdQuery, ScopePermissionOutput>, |
| | 973 | 61 | | GetScopePermissionByIdQueryHandler>(); |
| | 973 | 62 | | services |
| | 973 | 63 | | .AddScoped<IPaginatedQueryHandlerAsync<ListScopePermissionsQuery, ScopePermissionOutput>, |
| | 973 | 64 | | ListScopePermissionsQueryHandler>(); |
| | 973 | 65 | | services |
| | 973 | 66 | | .AddScoped<IQueryHandlerAsync<GetGoogleUserByIdQuery, GoogleUserOutput>, |
| | 973 | 67 | | GetGoogleUserByIdQueryHandler>(); |
| | 973 | 68 | | services |
| | 973 | 69 | | .AddScoped<IPaginatedQueryHandlerAsync<ListScopeGoogleUsersQuery, GoogleUserOutput>, |
| | 973 | 70 | | ListScopeGoogleUsersQueryHandler>(); |
| | 973 | 71 | | services |
| | 973 | 72 | | .AddScoped<IPaginatedQueryHandlerAsync<ListErasureRequestsQuery, ErasureRequestOutput>, |
| | 973 | 73 | | ListErasureRequestsQueryHandler>(); |
| | 973 | 74 | | services |
| | 973 | 75 | | .AddScoped<IQueryHandlerAsync<DetectSecuritySignalsQuery, SecuritySignalsOutput>, |
| | 973 | 76 | | DetectSecuritySignalsQueryHandler>(); |
| | 973 | 77 | | services |
| | 973 | 78 | | .AddScoped<IValidator<ListErasureRequestsQuery>, ListErasureRequestsQueryValidator>(); |
| | | 79 | | |
| | | 80 | | // UC-48 (FR-AT-01/02): the audit trail, System Admins only. |
| | 973 | 81 | | services |
| | 973 | 82 | | .AddScoped<IPaginatedQueryHandlerAsync<ListAuditLogQuery, AuditLogEntryOutput>, |
| | 973 | 83 | | ListAuditLogQueryHandler>(); |
| | 973 | 84 | | services.AddScoped<IValidator<ListAuditLogQuery>, ListAuditLogQueryValidator>(); |
| | 973 | 85 | | services |
| | 973 | 86 | | .AddScoped<IQueryHandlerAsync<GetTwoFactorStatusQuery, TwoFactorStatusOutput>, |
| | 973 | 87 | | GetTwoFactorStatusQueryHandler>(); |
| | | 88 | | |
| | | 89 | | // NFR-10: pagination/filter validation for every paginated list query. |
| | 973 | 90 | | services.AddScoped<IValidator<ListScopesQuery>, ListScopesQueryValidator>(); |
| | 973 | 91 | | services.AddScoped<IValidator<ListScopePersonsQuery>, ListScopePersonsQueryValidator>(); |
| | 973 | 92 | | services.AddScoped<IValidator<ListScopeOwnersQuery>, ListScopeOwnersQueryValidator>(); |
| | 973 | 93 | | services.AddScoped<IValidator<ListScopeOwnerInvitationsQuery>, ListScopeOwnerInvitationsQueryValidator>(); |
| | 973 | 94 | | services.AddScoped<IValidator<ListMyScopeInvitationsQuery>, ListMyScopeInvitationsQueryValidator>(); |
| | 973 | 95 | | services.AddScoped<IValidator<ListScopeAdminsQuery>, ListScopeAdminsQueryValidator>(); |
| | 973 | 96 | | services |
| | 973 | 97 | | .AddScoped<IValidator<ListPendingRegistrationsQuery>, ListPendingRegistrationsQueryValidator>(); |
| | 973 | 98 | | services.AddScoped<IValidator<ListSystemAdminsQuery>, ListSystemAdminsQueryValidator>(); |
| | 973 | 99 | | services |
| | 973 | 100 | | .AddScoped<IValidator<ListScopeApplicationsQuery>, ListScopeApplicationsQueryValidator>(); |
| | 973 | 101 | | services |
| | 973 | 102 | | .AddScoped<IValidator<ListScopePermissionsQuery>, ListScopePermissionsQueryValidator>(); |
| | 973 | 103 | | services |
| | 973 | 104 | | .AddScoped<IValidator<ListScopeGoogleUsersQuery>, ListScopeGoogleUsersQueryValidator>(); |
| | | 105 | | |
| | 973 | 106 | | return services; |
| | | 107 | | } |
| | | 108 | | } |