Extract CommandHandlerFactory to centralize handler creation#91
Merged
josecelano merged 4 commits intomainfrom Oct 29, 2025
Merged
Extract CommandHandlerFactory to centralize handler creation#91josecelano merged 4 commits intomainfrom
josecelano merged 4 commits intomainfrom
Conversation
Co-authored-by: josecelano <[email protected]>
Co-authored-by: josecelano <[email protected]>
Co-authored-by: josecelano <[email protected]>
Copilot
AI
changed the title
[WIP] Extract command handler factory to reduce code duplication
Extract CommandHandlerFactory to centralize handler creation
Oct 29, 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.
Each presentation command handler was manually constructing application command handlers with duplicate initialization code, making it difficult to modify handler creation logic or add new commands consistently.
Changes
Created
CommandHandlerFactoryCreateCommandHandlerandDestroyCommandHandlerRepositoryFactoryto manage lock timeout configurationcreate_context()to buildCommandContextwith shared dependenciesnew_for_testing()for custom test configurationsUpdated command handlers
destroy/handler.rs: Use factory instead of manualDestroyCommandHandler::new()create/subcommands/environment.rs: Use factory instead of manualCreateCommandHandler::new()Added
CommandContext::new_with_factory()RepositoryFactoryinstanceExample
Before:
After:
Original prompt
This section details on the original issue you should resolve
<issue_title>Extract Command Handler Factory</issue_title>
<issue_description>Parent Issue: #63
Type: 🚀 Advanced Pattern
Impact: 🟢🟢🟢 High
Effort: 🔵🔵🔵🔵 Very High
Priority: P2
Problem
Each command handler manually constructs all its dependencies and output handling, leading to:
Current pattern (repeated in every command):
Proposed Solution
Create a
CommandHandlerFactorythat centralizes command handler creation:Then simplify command handlers:
Benefits
Implementation Checklist
Phase 1: Create factory
src/presentation/commands/factory.rsCommandHandlerFactorystructnew()constructorcreate_context()methodcreate_create_handler()methodcreate_destroy_handler()methodnew_for_testing()for test supportPhase 2: Update command handlers
Phase 3: Update tests
Phase 4: Documentation
Phase 5: Validation
Acceptance Criteria
CommandHandlerFactoryexists and is documentedcargo test presentation::commands./scripts/pre-commit.shRelated Documentation
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.