Skip to content

Clean up prompt optimization flow: remove double init, fix DI, deduplicate DTO#489

Draft
Copilot wants to merge 2 commits intoDeveloper-KnowledgeBasefrom
copilot/optimize-business-process-flow
Draft

Clean up prompt optimization flow: remove double init, fix DI, deduplicate DTO#489
Copilot wants to merge 2 commits intoDeveloper-KnowledgeBasefrom
copilot/optimize-business-process-flow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

The prompt optimization flow had three structural issues: redundant initialization on every request, Service Locator anti-pattern in plugins, and a duplicated DTO class across two files.

Changes

  • Double EnsureInitializedAsync() removed from PromptOptimizationController
    OptimizePromptAsync() already calls it internally — the controller was triggering it twice per request.

  • PromptOptimizationPlugin constructor injection
    PromptItemService, PromptRangeService, PromptResultService were resolved via SenparcDI.GetServiceProvider().GetRequiredService<T>(). Now injected through constructor parameters.

  • PromptCatalyzerPlugin constructor injection
    Same fix — PromptOptimizationService now injected instead of resolved via Service Locator.

  • Duplicate PromptOptimizationRequestDto removed from controller
    Identical class was defined in both PromptOptimizationController.cs and PromptOptimizationAppService.cs. Controller now imports the shared definition from OHS.Local.AppService.

// Before: controller resolved deps in constructor body
public PromptOptimizationPlugin(PromptOptimizationAgentBridge bridge)
{
    _bridge = bridge;
    var serviceProvider = SenparcDI.GetServiceProvider();
    _promptItemService = serviceProvider.GetRequiredService<PromptItemService>();
    ...
}

// After: standard constructor injection
public PromptOptimizationPlugin(
    PromptOptimizationAgentBridge bridge,
    PromptItemService promptItemService,
    PromptRangeService promptRangeService,
    PromptResultService promptResultService)
{
    _bridge = bridge;
    _promptItemService = promptItemService;
    ...
}
Original prompt

检查并整理目前提示词“优化”的业务流程、逻辑是怎么样的


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Remove redundant EnsureInitializedAsync() call in PromptOptimizationController
  (OptimizePromptAsync already calls it internally)
- Refactor PromptOptimizationPlugin to use constructor DI injection instead of
  Service Locator anti-pattern for PromptItemService, PromptRangeService, PromptResultService
- Refactor PromptCatalyzerPlugin to use constructor DI injection instead of
  Service Locator for PromptOptimizationService
- Remove duplicate PromptOptimizationRequestDto from controller; use shared
  definition from OHS.Local.AppService namespace

Co-authored-by: JeffreySu <2281927+JeffreySu@users.noreply.github.com>
Agent-Logs-Url: https://github.com/NeuCharFramework/NcfPackageSources/sessions/753ef2d6-0af5-40fb-82e6-98bf4896bf73
Copilot AI changed the title [WIP] Review and organize the current optimization workflow Clean up prompt optimization flow: remove double init, fix DI, deduplicate DTO Mar 26, 2026
Copilot AI requested a review from JeffreySu March 26, 2026 06:41
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.

2 participants