Skip to content

Fragmented Hook Types: Unify inconsistent hook integration points #1871

@thomhurst

Description

@thomhurst

Problem

Pipeline hooks use inconsistent context types across different integration points:

  • Module Hooks (IPipelineModuleHooks): Receive IPipelineHookContext + IModule
  • Global Hooks (IPipelineGlobalHooks): Receive IPipelineHookContext + IPipelineSummary
  • Attribute Events: Receive different context per event receiver class
  • Context Extensions: Tool-specific extensions don't support hooks

This causes:

  • Inconsistency: Same concept (before/after) has different signatures
  • Confusion: Unclear which context object to use when
  • Fragmentation: Hooks scattered across multiple interfaces
  • Integration Difficulty: Hard to add hooks to custom tool integrations

Current Design

// Module hooks with one signature
public interface IPipelineModuleHooks
{
    Task OnBeforeModuleStartAsync(IPipelineHookContext context, IModule module);
    Task OnAfterModuleEndAsync(IPipelineHookContext context, IModule module);
}

// Global hooks with different signature
public interface IPipelineGlobalHooks
{
    Task OnStartAsync(IPipelineHookContext context);
    Task OnEndAsync(IPipelineHookContext context, PipelineSummary summary);
}

Proposed Solution

Unified hook interface with clear stages:

public interface IPipelineHooks
{
    Task OnPipelineStartingAsync(IPipelineContext context);
    Task OnModuleStartingAsync(IPipelineContext context, IModule module);
    Task OnModuleCompletedAsync(IPipelineContext context, IModule module, ModuleResult result);
    Task OnPipelineCompletedAsync(IPipelineContext context, PipelineSummary summary);
}

public class PipelineConfiguration
{
    public void AddHooks<THooks>() where THooks : IPipelineHooks;
}

Benefits

  • Consistent hook interface across all stages
  • Clear naming convention for lifecycle stages
  • Single place to understand all hooks
  • Easier to implement custom hooks
  • Better composition

Priority: MEDIUM - Breaking change, improves consistency

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codeenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions