Skip to content

refactor(plugins/api): make module constructors injectable#122

Merged
intel352 merged 1 commit intomainfrom
refactor/issue-64-injectable-api-plugin-factories
Feb 23, 2026
Merged

refactor(plugins/api): make module constructors injectable#122
intel352 merged 1 commit intomainfrom
refactor/issue-64-injectable-api-plugin-factories

Conversation

@intel352
Copy link
Contributor

Summary

  • Add seven typed constructor function types (QueryHandlerCtor, CommandHandlerCtor, RESTAPIHandlerCtor, APIGatewayCtor, WorkflowRegistryCtor, DataTransformerCtor, ProcessingStepCtor) to plugins/api/plugin.go
  • Add a private constructor field per type on Plugin, with a corresponding With* setter that returns *Plugin for method chaining
  • New() initialises each field to a thin wrapper around the existing concrete constructor, so all callers remain fully backward-compatible without any changes
  • ModuleFactories() 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 support

Test plan

  • All 12 pre-existing tests in plugins/api/plugin_test.go continue to pass
  • 9 new tests added: one per injectable constructor (TestInjectable*Ctor), TestDefaultCtorsUnchanged, and TestWithCtorChainingReturnsSelf
  • go build ./... passes
  • go test ./... passes (all packages)
  • golangci-lint run ./plugins/api/... reports 0 issues
  • Pre-push hooks (build + lint) pass

closes #64

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings February 23, 2026 08:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go with 7 typed constructor function types and corresponding With* 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

@intel352 intel352 merged commit 23d7164 into main Feb 23, 2026
18 checks passed
@intel352 intel352 deleted the refactor/issue-64-injectable-api-plugin-factories branch February 23, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API plugin factory creates concrete module types directly (plugins/api/plugin.go)

2 participants