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
- 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).
- 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)
AspectWeaver.Abstractions is configured for C# 8.0.
IAspectHandler<T> includes the ShouldExecute method with a default implementation.
- The generated pipeline wrapping logic (Step 4) includes the conditional check and bypass logic.
- Integration tests validate that aspects implementing
ShouldExecute can be conditionally skipped at runtime.
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
IAspectHandler<T>: Add a new methodbool ShouldExecute(TAttribute attribute, InvocationContext context)using C# 8 Default Interface Methods (DIM) to maintain backward compatibility. The default implementation returnstrue.AspectWeaver.Abstractionsto C# 8.0 (compatible withnetstandard2.0).PipelineEmitter(Step 4 - Aspect Wrapping): Modify the generated code for the aspect wrapper delegate. The wrapper logic will first callhandler.ShouldExecute(context). If it returnsfalse, the wrapper will bypasshandler.InterceptAsyncand immediately call thenextdelegate.This strategy ensures the condition is evaluated dynamically at runtime during the invocation flow.
Acceptance Criteria (AC)
AspectWeaver.Abstractionsis configured for C# 8.0.IAspectHandler<T>includes theShouldExecutemethod with a default implementation.ShouldExecutecan be conditionally skipped at runtime.