Skip to content

[PBI 1.1.4] [Feature] Implement Dynamic Conditional Aspect Execution (ShouldExecute) #31

@Aymen83

Description

@Aymen83

User Story

As a Developer using AspectWeaver,
I want to conditionally enable or disable an aspect at runtime based on dynamic context (e.g., feature flags, user permissions, environment).

Strategy

  1. Update IAspectHandler<T>: Add a new method bool ShouldExecute(TAttribute attribute, InvocationContext context) using C# 8 Default Interface Methods (DIM) to maintain backward compatibility. The default implementation returns true.
    • Note: This requires updating AspectWeaver.Abstractions to C# 8.0 (compatible with netstandard2.0).
  2. Update PipelineEmitter (Step 4 - Aspect Wrapping): Modify the generated code for the aspect wrapper delegate. The wrapper logic will first call handler.ShouldExecute(context). If it returns false, the wrapper will bypass handler.InterceptAsync and immediately call the next delegate.

This strategy ensures the condition is evaluated dynamically at runtime during the invocation flow.

Acceptance Criteria (AC)

  1. AspectWeaver.Abstractions is configured for C# 8.0.
  2. IAspectHandler<T> includes the ShouldExecute method with a default implementation.
  3. The generated pipeline wrapping logic (Step 4) includes the conditional check and bypass logic.
  4. Integration tests validate that aspects implementing ShouldExecute can be conditionally skipped at runtime.

Metadata

Metadata

Assignees

Labels

Area: API/RuntimeThe public API and runtime (AspectWeaver.Abstractions).Area: GeneratorThe heart of the Source Generator (AspectWeaver.Generator).Priority: MediumType: FeatureNew feature or PBI.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions