Skip to content

InterceptAttribute TInterceptor

NexusLabs.Needlr

NexusLabs.Needlr

InterceptAttribute<TInterceptor> Class

Applies an interceptor to a class or method. Generic version that provides compile-time type safety for the interceptor type.

public sealed class InterceptAttribute<TInterceptor> : System.Attribute
    where TInterceptor : class, NexusLabs.Needlr.IMethodInterceptor

Type parameters

TInterceptor

The type of the interceptor. Must implement IMethodInterceptor.

Inheritance System.Object 🡒 System.Attribute 🡒 InterceptAttribute\<TInterceptor>

Example

[Intercept<LoggingInterceptor>(Order = 1)]
[Intercept<CachingInterceptor>(Order = 2)]
[Scoped]
public class OrderService : IOrderService
{
    public Task<Order> GetOrderAsync(int id) => ...;
}

Remarks

This is the preferred form when the interceptor type is known at compile time. For dynamic scenarios, use the non-generic InterceptAttribute.

See InterceptAttribute for full documentation and examples.

Properties

InterceptAttribute<TInterceptor>.InterceptorType Property

Gets the type of the interceptor to apply.

public System.Type InterceptorType { get; }

Property Value

System.Type

InterceptAttribute<TInterceptor>.Order Property

Gets or sets the order in which this interceptor executes relative to other interceptors on the same target. Lower values execute first (outermost in the interceptor chain). Default is 0.

public int Order { get; set; }

Property Value

System.Int32