Innovabit.DotNet.Interceptors.Abstractions 1.0.0.104

There is a newer version of this package available.
See the version list below for details.
dotnet add package Innovabit.DotNet.Interceptors.Abstractions --version 1.0.0.104
                    
NuGet\Install-Package Innovabit.DotNet.Interceptors.Abstractions -Version 1.0.0.104
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Innovabit.DotNet.Interceptors.Abstractions" Version="1.0.0.104" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Innovabit.DotNet.Interceptors.Abstractions" Version="1.0.0.104" />
                    
Directory.Packages.props
<PackageReference Include="Innovabit.DotNet.Interceptors.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Innovabit.DotNet.Interceptors.Abstractions --version 1.0.0.104
                    
#r "nuget: Innovabit.DotNet.Interceptors.Abstractions, 1.0.0.104"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Innovabit.DotNet.Interceptors.Abstractions@1.0.0.104
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Innovabit.DotNet.Interceptors.Abstractions&version=1.0.0.104
                    
Install as a Cake Addin
#tool nuget:?package=Innovabit.DotNet.Interceptors.Abstractions&version=1.0.0.104
                    
Install as a Cake Tool

Innovabit.DotNet.Interceptors.Abstractions

Core building blocks for aspect-oriented programming (AOP) in .NET using Castle DynamicProxy and Microsoft.Extensions.DependencyInjection. This is the base package every other Innovabit.DotNet.Interceptors.* package builds on (logging, validation, notifications, retry, ...).

What it provides

  • InterceptorBase — the abstract base for an interceptor (sync, Task/Task<T> and ValueTask/ValueTask<T> aware).
  • AddInterceptors() / InterceptorBuilder — register the proxy generator and your interceptors.
  • Add*WithInterception / TryAdd*WithInterception — register a service so its interface is proxied and intercepted. The concrete implementation is kept under a private key, so it can't be resolved — and its interception bypassed — by accident.
  • Add*ClassWithInterception / TryAdd*ClassWithInterception — proxy a service that has no interface (class proxy; only virtual members are intercepted).
  • An ordered, multi-interceptor pipeline: InterceptorBase.Order, InterceptorOrders (recommended scale) and InterceptorOrderOptions (per-registration overrides).
  • [Sensitive] / [Mask], RedactionRule and IValueRedactor — mark a parameter, return value, property or field once and every interceptor in the suite redacts it (see below).
  • A bundled Roslyn analyzer that flags interceptor attributes with no effect at compile time — INTX001 (attribute on a static method) and INTX002 (a parameter attribute such as [DoNotLog] on a method that isn't intercepted).

Install

dotnet add package Innovabit.DotNet.Interceptors.Abstractions

Usage

using Innovabit.DotNet.Interceptors;

public sealed class TracingInterceptor : InterceptorBase
{
    public override bool CanIntercept(IInvocation invocation) => true;
    public override void ProcessInterceptionSync(IInvocation invocation) => invocation.Proceed();
    public override Task ProcessInterceptionAsync(IInvocation invocation) { invocation.Proceed(); return (Task)invocation.ReturnValue!; }
    public override Task<TResult> ProcessInterceptionAsync<TResult>(IInvocation invocation) { invocation.Proceed(); return (Task<TResult>)invocation.ReturnValue!; }
}

services.AddInterceptors()
    .Register<TracingInterceptor>();          // or Register<T>(order) to place it in the pipeline

// Proxy IMyService so registered interceptors wrap MyService. Anything that depends on
// IMyService — even services registered without interception — receives the proxied instance.
services.AddScopedWithInterception<IMyService, MyService>();

// No interface? Use a class proxy (only virtual members are intercepted; the class must be non-sealed).
services.AddScopedClassWithInterception<MyService>();

The un-proxied MyService is registered under a private key, so consumers must depend on IMyService (or, for class proxies, MyService itself) and always get the intercepted instance — there is no publicly resolvable concrete to inject and silently skip the pipeline.

Sensitive data

[Sensitive] and [Mask] mark a parameter, a return value (with [return: ...]), a property or a field as something the interceptors may not write down verbatim. Mark it once and it stays redacted in logging, auditing, tracing and exception notifications alike, including in features you adopt later:

[Log]
[Audited]
[NotifyOnException]
public Task<Receipt> ChargeAsync(
    string orderId,
    [Sensitive] string cardHolder,           // recorded as ***
    [Mask(ShowLast = 4)] string cardNumber)  // recorded as ************1111
{ ... }
[Sensitive] [Mask]
Recorded as Placeholder (default ***) The value with only ShowFirst/ShowLast characters left visible
A null value Still replaced, so the record never reveals that the secret was missing Stays null — nothing to hide, no fragment to show
Use it for Passwords, tokens, whole payloads Values where a fragment is genuinely useful: a card, an e-mail, an IBAN

A parameter carrying both is treated as [Sensitive] — between "never record this" and "record a fragment", the stricter rule is the safe reading. [Mask] never reveals a value in full either: if the visible window would cover the whole value, it is masked entirely, so [Mask(ShowLast = 4)] on a four-digit PIN does not print it verbatim.

Inside objects

A parameter-level rule can only cover the argument itself. Put the attributes on the type's own members and the rule travels with the data, however deep inside an argument it turns up:

public class Customer
{
    public string Name { get; set; }

    [Sensitive] public string Email { get; set; }

    [Mask(ShowLast = 4)] public string Phone { get; set; }
}

[Audited]
public Task PlaceAsync(Order order) { ... }   // order.Customer.Email is recorded as ***

Walking the object graph is the serializer's job, not the interceptor's, so this applies wherever a serializer that honours the rules is used. The audit trail's default one (SystemTextJsonAuditSerializer) does, through nested objects and collections alike, and it keeps doing so when you hand it your own JsonSerializerOptions — options that quietly dropped the rules would turn a configuration tweak into a data leak. To honour them in a serializer of your own, add one modifier:

options.TypeInfoResolver = (options.TypeInfoResolver ?? new DefaultJsonTypeInfoResolver())
    .WithAddedModifier(RedactionJsonModifier.Apply);

A redacted value is always written as text, whatever the member's declared type: a masked decimal stops being a number. That is the point — the record keeps the shape of the data, not data you could compute with. Masking uses the invariant culture, so a masked number reads the same whatever machine wrote the record.

What redaction does not touch

  • The call itself. The method receives the real values; only what the interceptors record changes.
  • Cache keys. [Cache] hashes arguments rather than storing them, and redacting first would make two different cards share an entry. Use [CacheKeyIgnore] to shape a key.
  • Validation. [Validate] checks the real value, as it must.

These attributes are about what leaves the process in a record, not about hiding values from your own code.

Custom rules

services.AddInterceptors().UseValueRedactor<HashingRedactor>();

Implement IValueRedactor to hash instead of replacing, to keep a format-preserving mask, or to honour your own data-classification attributes. It is resolved once and must not throw — an interceptor recording a value is never a good reason to fail the call it is observing.

Pipeline order

When several interceptors are registered they run as a pipeline. InterceptorBase.Order controls position: lower runs first (outermost); higher runs closer to the intercepted method. Ties keep registration order. Override per registration with Register<T>(int order) or SetOrder<T>(int order). See InterceptorOrders for the recommended scale.

Part of

The Innovabit.DotNet.Interceptors suite — github.com/Innovabit/dotnet-interceptors.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (15)

Showing the top 5 NuGet packages that depend on Innovabit.DotNet.Interceptors.Abstractions:

Package Downloads
Innovabit.DotNet.Interceptors.Logging.Abstractions

Base package for logging using interceptor.

Innovabit.DotNet.Interceptors.Collections

Package for some useful interceptors like retry on exception.

Innovabit.DotNet.Interceptors.Notifications.Abstractions

Base package for sending notifications when an intercepted method throws an exception.

Innovabit.DotNet.Interceptors.Validation.Abstractions

Package for data validation using interceptor.

Innovabit.DotNet.Interceptors.Caching.Abstractions

Base package for method result caching using interceptors.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.119 118 11/14/2026
2.0.118 806 11/7/2026
2.0.117 818 10/31/2026
2.0.116 768 10/26/2026
2.0.115 749 10/17/2026
2.0.114 724 10/10/2026
2.0.113 762 10/3/2026
2.0.112 722 9/28/2026
2.0.111 688 9/28/2026
2.0.110 702 9/27/2026
2.0.109 719 9/26/2026
2.0.108 698 9/26/2026
2.0.107 763 9/26/2026
2.0.106 574 9/25/2026
2.0.105 705 9/25/2026
1.0.0.104 669 9/25/2026
1.0.0.103 542 9/25/2026
1.0.0.102 412 9/25/2026
1.0.0.101 401 9/25/2026
1.0.0.100 402 9/25/2026
Loading failed