[refactor] Apply mediator DP on TrustFunction#185
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the trust functionality from a traditional service pattern to the CQRS/Mediator pattern, removing ITrustService and TrustService in favor of MediatR command handlers.
- Replaces
ITrustService/TrustServicewith three new MediatR request/handler pairs for trust operations - Updates
TrustFunctionto dispatch commands viaIMediatorinstead of direct service calls - Adds comprehensive unit tests for all three new command handlers covering both success and failure scenarios
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
TrustFunction.cs |
Updated to inject only IMediator and dispatch trust commands through it |
SetAuthChecked* |
New MediatR request and handler for setting authentication checked status |
RequestTrustPublicKey* |
New MediatR request and handler for requesting trust public keys |
InformPublicKeyValidationIsFinished* |
New MediatR request and handler for informing validation completion |
TrustService.cs |
Removed obsolete service implementation |
ITrustService.cs |
Removed obsolete service interface |
| Test files | Added comprehensive unit tests for all three command handlers |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/ByteSync.ServerCommon/Commands/Trusts/RequestTrustPublicKeyCommandHandler.cs
Outdated
Show resolved
Hide resolved
src/ByteSync.ServerCommon/Commands/Trusts/InformPublicKeyValidationIsFinishedCommandHandler.cs
Outdated
Show resolved
Hide resolved
src/ByteSync.ServerCommon/Commands/Trusts/RequestTrustPublicKeyCommandHandler.cs
Outdated
Show resolved
Hide resolved
|
paul-fresquet
approved these changes
Aug 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



PR Title
Refactor Trust HTTP endpoints to Mediator (remove TrustService) + add command handlers and tests
Summary
ITrustService/TrustServicewith MediatR requests/handlers; updatesTrustFunctionto dispatch viaIMediator; adds targeted unit tests for trust flows.Changes
src/ByteSync.Functions/Http/TrustFunction.csIMediator.SetAuthCheckedRequestRequestTrustPublicKeyRequestInformPublicKeyValidationIsFinishedRequestsrc/ByteSync.ServerCommon/Commands/Trusts/SetAuthCheckedRequest.cssrc/ByteSync.ServerCommon/Commands/Trusts/SetAuthCheckedCommandHandler.cssrc/ByteSync.ServerCommon/Commands/Trusts/RequestTrustPublicKeyRequest.cssrc/ByteSync.ServerCommon/Commands/Trusts/RequestTrustPublicKeyCommandHandler.cssrc/ByteSync.ServerCommon/Commands/Trusts/InformPublicKeyValidationIsFinishedRequest.cssrc/ByteSync.ServerCommon/Commands/Trusts/InformPublicKeyValidationIsFinishedCommandHandler.csITrustServiceandTrustService(obsolete after mediator migration)tests/ByteSync.ServerCommon.Tests/Commands/Trusts/RequestTrustPublicKeyCommandHandlerTests.cstests/ByteSync.ServerCommon.Tests/Commands/Trusts/InformPublicKeyValidationIsFinishedCommandHandlerTests.csBehavior
ICloudSessionsRepositoryandIInvokeClientsServicein the same way the old service did.Dependency Injection
ITrustServiceregistrations are removed.Validation
dotnet build ByteSync.sln --verbosity quietdotnet test tests/ByteSync.ServerCommon.Tests/ByteSync.ServerCommon.Tests.csproj --nologoNotes / Follow-ups
RequestTrustPublicKeyCommandHandler, the logger is typed asILogger<SetAuthCheckedCommandHandler>; it should likely beILogger<RequestTrustPublicKeyCommandHandler>.RequestTrustPublicKeyCommandHandlerreferences “InformPublicKeyValidationIsFinished” instead of the current action.InformPublicKeyValidationIsFinishedCommandHandlersays “AskCloudSessionMembersPublicKeys” (copy/paste artifact).Risks
Low. Internal refactor; handlers mirror prior service logic; covered by unit tests.
Moved trust logic behind MediatR requests and handlers; removed
ITrustService/TrustService.Updated
TrustFunctionto send mediator requests; added unit tests for happy/negative paths.Called out minor logger category and message nits for follow-up.