refactor(plugins/api): make module constructors injectable#122
Merged
Conversation
Add typed constructor fields (QueryHandlerCtor, CommandHandlerCtor, RESTAPIHandlerCtor, APIGatewayCtor, WorkflowRegistryCtor, DataTransformerCtor, ProcessingStepCtor) to the Plugin struct, along with corresponding With* setter methods that return *Plugin for chaining. New() continues to default to the existing concrete constructors so all existing callers are fully backward-compatible. ModuleFactories() now delegates construction to the stored constructor fields and uses local interface assertions for post-construction config wiring, so custom implementations only need to satisfy the methods they actually support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the API plugin to make module constructors injectable, addressing issue #64. The change enables users to substitute custom module implementations without modifying plugin source code, following the Open/Closed Principle. The refactoring introduces typed constructor function types, adds setter methods with method chaining support, and maintains full backward compatibility through default constructors that wrap existing concrete module constructors.
Changes:
- Adds constructor injection capability to
plugins/api/plugin.gowith 7 typed constructor function types and correspondingWith*setter methods - Refactors
ModuleFactories()to delegate construction to injectable fields and use interface assertions for optional configuration - Adds comprehensive test coverage with 9 new tests validating constructor injection, backward compatibility, and method chaining
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| plugins/api/plugin.go | Adds 7 constructor types, injectable fields, With* setters, default constructors in New(), and refactors ModuleFactories() to use delegation with interface assertions |
| plugins/api/plugin_test.go | Adds stubModule implementation and 9 new tests covering all injectable constructors, backward compatibility, and method chaining |
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.
Summary
QueryHandlerCtor,CommandHandlerCtor,RESTAPIHandlerCtor,APIGatewayCtor,WorkflowRegistryCtor,DataTransformerCtor,ProcessingStepCtor) toplugins/api/plugin.goPlugin, with a correspondingWith*setter that returns*Pluginfor method chainingNew()initialises each field to a thin wrapper around the existing concrete constructor, so all callers remain fully backward-compatible without any changesModuleFactories()now delegates construction to the injectable fields; post-construction config wiring uses local interface assertions so custom implementations only need to satisfy the methods they actually supportTest plan
plugins/api/plugin_test.gocontinue to passTestInjectable*Ctor),TestDefaultCtorsUnchanged, andTestWithCtorChainingReturnsSelfgo build ./...passesgo test ./...passes (all packages)golangci-lint run ./plugins/api/...reports 0 issuescloses #64
🤖 Generated with Claude Code