Namotion.Interceptor.GraphQL 0.11.0

dotnet add package Namotion.Interceptor.GraphQL --version 0.11.0
                    
NuGet\Install-Package Namotion.Interceptor.GraphQL -Version 0.11.0
                    
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="Namotion.Interceptor.GraphQL" Version="0.11.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Namotion.Interceptor.GraphQL" Version="0.11.0" />
                    
Directory.Packages.props
<PackageReference Include="Namotion.Interceptor.GraphQL" />
                    
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 Namotion.Interceptor.GraphQL --version 0.11.0
                    
#r "nuget: Namotion.Interceptor.GraphQL, 0.11.0"
                    
#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 Namotion.Interceptor.GraphQL@0.11.0
                    
#: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=Namotion.Interceptor.GraphQL&version=0.11.0
                    
Install as a Cake Addin
#tool nuget:?package=Namotion.Interceptor.GraphQL&version=0.11.0
                    
Install as a Cake Tool

NuGet

Note: This library is in active development. APIs may change between versions.

Namotion.Interceptor for .NET

Namotion.Interceptor is a .NET library for building reactive applications with automatic property tracking and change propagation. It uses C# 13 partial properties and source generation to transform your classes into observable object graphs, without reflection on property access or proxy objects.

Mark your classes with [InterceptorSubject] and declare properties as partial. The source generator handles the rest: creating interception logic, change detection, derived property updates, and lifecycle management. Your domain models remain clean POCOs while gaining reactive capabilities.

The library supports bidirectional synchronization with external systems. When a property changes locally, connectors propagate the change outward. When external data arrives, your object model updates and triggers change notifications. Built-in integrations include MQTT, OPC UA, WebSocket, ASP.NET Core, Blazor, GraphQL, and MCP. Typical use cases are IoT dashboards, industrial HMIs, real-time web apps, and data synchronization services.

alternate text is missing from this package README image

Why Namotion.Interceptor?

  • Reactive object graphs - Property changes automatically propagate to derived properties and external systems
  • No reflection on property access - All interception logic is generated at compile-time for maximum performance
  • Bidirectional synchronization - Connect your object model to MQTT brokers, OPC UA servers, or databases with minimal code
  • Clean domain models - Your classes stay as POCOs with simple attributes
  • INotifyPropertyChanged built-in - Generated classes implement it automatically for UI data binding, including derived properties when derived property change detection is enabled

Packages

Namotion.Interceptor is structured as Core, Tracking, Validation, Registry, Connectors, and Integrations. Each builds on the previous, so you can adopt only what you need.

  1. Core: [InterceptorSubject], the source generator, and the read/write interceptor pipeline. Everything else plugs into this.
  2. Tracking: observable, queue-based, and per-property change subscriptions, derived property recalculation, lifecycle attach/detach, transactions.
  3. Validation: data-annotation and custom property validators that reject invalid writes before they reach your model.
  4. Registry: runtime subject and property discovery, property metadata via attributes, dynamic properties, stable subject IDs.
  5. Connectors: bidirectional synchronization with external systems (MQTT, OPC UA, WebSocket).
  6. Integrations: host frameworks (ASP.NET Core, Blazor, GraphQL, MCP) that surface subjects through familiar APIs.

Several extension points let you plug in your own behavior:

Extension Point What it enables Documentation
Read/Write Interceptors Add cross-cutting concerns like logging, caching, or transformation to property access Interceptors
Lifecycle Handlers React to objects entering or leaving the object graph (cleanup, initialization) Tracking
Custom Property Validation Implement custom validation logic beyond data annotations Validation
Custom Connectors Synchronize with any external system (databases, message queues, APIs) Connectors

The rest of this README walks through each, then lists every package with a documentation link.

Requirements

  • .NET 10.0 or later
  • C# 14 (the .NET 10 default; partial properties need C# 13 or later)
  • IDE with source generator support (Visual Studio 2022, Rider, VS Code with C# extension)

Installation

Add the core library and the source generator. Most projects also want the Tracking package for change events and derived properties.

dotnet add package Namotion.Interceptor
dotnet add package Namotion.Interceptor.Generator
dotnet add package Namotion.Interceptor.Tracking

Additional packages are listed in the Package Reference at the bottom.

Core

The core library defines the central abstractions: the interceptor subject (a class whose property accesses route through a pipeline) and the subject context (the registry of services and interceptors that drives that pipeline). Everything else registers services into the context to do its work.

Interceptor Subjects

An interceptor subject is any class implementing IInterceptorSubject, the core contract that routes property access through the interception pipeline. The typical way to produce one is to mark a class with [InterceptorSubject] and declare stored properties as partial; the source generator then emits the interface implementation at compile time, so your class stays a clean POCO:

[InterceptorSubject]
public partial class Person
{
    public partial string FirstName { get; set; }
    public partial string LastName { get; set; }
    public partial Person[] Children { get; set; }

    [Derived]
    public string FullName => $"{FirstName} {LastName}";

    public Person()
    {
        FirstName = string.Empty;
        LastName = string.Empty;
        Children = [];
    }
}

To create instances, build a context and pass it in. The context is typically created once at startup and shared across the object graph:

var context = InterceptorSubjectContext
    .Create()
    .WithFullPropertyTracking();

var person = new Person(context);

Only the root subject needs the context explicitly. Child subjects assigned to the parent's properties automatically inherit the same context, so the entire object graph participates in the same interception pipeline. Child subjects can be constructed without passing the context:

var person = new Person(context);
person.Children = [new Person { FirstName = "Alice" }];  // Alice inherits the context automatically

Inheritance requires WithContextInheritance() on the context, which is bundled into WithFullPropertyTracking().

For the patterns that work, the patterns that don't (collection mutation, explicit interface implementation, abstract properties), and the rules around constructors and initialization, see the Subject Design Guidelines.

Generator

The source generator (Namotion.Interceptor.Generator) is the bridge between your partial declarations and the interception pipeline. It runs at compile-time.

For each partial property, the generator expands the declaration into a real getter and setter that route through the subject's context. A read passes through the chain of IReadInterceptors. A write first runs your optional OnXxxChanging hook (which can cancel or coerce the value), then the chain of IWriteInterceptors (where validation, change tracking, and source synchronization plug in), whose innermost step writes the backing field. Only if that field write happened does the setter call OnXxxChanged and raise INotifyPropertyChanged.

Concretely, for each [InterceptorSubject] class the generator emits:

  • A backing field paired with the expanded getter and setter for every partial property.
  • A constructor accepting IInterceptorSubjectContext, chained to the parameterless constructor, which the generator also adds when the class declares no constructor (see Constructors for when each is generated).
  • IInterceptorSubject, INotifyPropertyChanged, and IRaisePropertyChanged implementations.
  • Static metadata describing the class's properties.

For example, this hook trims whitespace and rejects empty names:

partial void OnFirstNameChanging(ref string newValue, ref bool cancel)
{
    if (string.IsNullOrWhiteSpace(newValue)) cancel = true;
    else newValue = newValue.Trim();
}

Because the interception code is generated at compile-time, property access involves no reflection and no proxy creation. See Generator for supported features (inheritance, init-only, virtual/override, partial-class spanning) and limitations.

If partial properties aren't an option (for example, you need to add interfaces to a subject at runtime), the Dynamic package builds equivalent subjects from interfaces using Castle DynamicProxy. For advanced scenarios where neither path fits, IInterceptorSubject can also be implemented by hand.

Interception Pipeline

Property reads and writes flow through a configurable chain of interceptors. Each interceptor receives a context and a next delegate, so it can run code before and after the actual field access. A write interceptor finds the new value in the context; a read interceptor gets the value back from next. This is how tracking, validation, sources, transactions, and everything else plug in.

using Namotion.Interceptor.Interceptors;

public class LoggingInterceptor : IWriteInterceptor
{
    public void WriteProperty<T>(ref PropertyWriteContext<T> context, WriteInterceptionDelegate<T> next)
    {
        Console.WriteLine($"Writing {context.Property.Name} = {context.NewValue}");
        next(ref context);
    }
}

var context = InterceptorSubjectContext
    .Create()
    .WithService(() => new LoggingInterceptor());

Methods can be intercepted similarly: implement IMethodInterceptor and suffix your method name with WithoutInterceptor. The generator emits a wrapper (with the suffix dropped) that routes through the chain.

Interceptor ordering, fallback contexts, and the read/write pipeline diagrams are documented in Interceptors and Contexts.

Tracking

The Tracking package adds change observation, derived-property recalculation, and lifecycle events to the core pipeline. Most applications enable everything in one call:

var context = InterceptorSubjectContext
    .Create()
    .WithFullPropertyTracking();

WithFullPropertyTracking() registers equality checking, derived-property change detection, the property-change subscriptions (observable, queue, and per-property), lifecycle tracking, and context inheritance for child subjects.

The samples below use the Person class from the Core section above.

Change Tracking

Subscribe to property changes anywhere in the graph through the observable:

context
    .GetPropertyChangeObservable()
    .Subscribe(change =>
    {
        Console.WriteLine(
            $"Property '{change.Property.Name}' changed " +
            $"from '{change.GetOldValue<object?>()}' to '{change.GetNewValue<object?>()}'.");
    });

person.FirstName = "John";
// Property 'FirstName' changed from '' to 'John'.
// Property 'FullName' changed from ' ' to 'John '.

person.LastName = "Doe";
// Property 'LastName' changed from '' to 'Doe'.
// Property 'FullName' changed from 'John ' to 'John Doe'.

By default the callbacks run on the thread pool, so the lines above appear shortly after each assignment, in order. Pass ImmediateScheduler.Instance to GetPropertyChangeObservable to run them synchronously inside the setter.

For high-throughput scenarios (>1000 changes/second, source synchronization, IoT pipelines), use the lock-free queue instead of the observable. It avoids per-event allocations and is the mechanism the connectors use internally. To follow a single property, subscribe to it directly instead of filtering the whole stream. All three mechanisms are described in Tracking.

Derived Properties

When [Derived] properties read other properties during evaluation, the tracking system records those reads as dependencies. When any dependency changes, the derived property is recalculated and fires its own change event. The example above shows FullName updating automatically whenever FirstName or LastName changes. Derived properties also work across the object graph (a derived property can depend on a child subject's property).

Lifecycle Tracking

The tracking package also reports when subjects enter or leave the object graph:

var lifecycle = context.TryGetLifecycleInterceptor()!;
lifecycle.SubjectAttached += change => Console.WriteLine($"Attached: {((Person)change.Subject).FirstName}");
lifecycle.SubjectDetaching += change => Console.WriteLine($"Detaching: {((Person)change.Subject).FirstName}");

person.Children = [new Person { FirstName = "Alice" }, new Person { FirstName = "Bob" }];
// Attached: Alice
// Attached: Bob

person.Children = [];
// Detaching: Bob
// Detaching: Alice

Collection items detach in reverse order. Handlers registered at startup implement ILifecycleHandler instead, see Tracking.

Higher-level features rely on this to start and stop work as the graph grows and shrinks: the registry inserts and removes entries, the hosting package starts and stops services, and connectors subscribe and unsubscribe from external sources.

Note: Property interceptors only fire when you assign to a property. Mutating a collection in-place (person.Children[0] = ...) does not trigger interception. Replace the whole collection instead. See Subject Design Guidelines for details.

Transactions

WithTransactions() enables atomic batching: writes inside a transaction are captured and applied together on commit, with notifications firing only after the commit succeeds. Reading a property inside the transaction returns its pending value (read-your-writes), and an uncommitted transaction discards its changes when disposed.

var context = InterceptorSubjectContext
    .Create()
    .WithFullPropertyTracking()
    .WithTransactions();

using var tx = await context.BeginTransactionAsync(TransactionFailureHandling.BestEffort);
person.FirstName = "John";
person.LastName = "Doe";
await tx.CommitAsync(cancellationToken);

For source-bound properties, WithSourceTransactions() writes to the external system before the local apply, providing confirmed delivery (used in the Connectors section below). See Transactions for locking modes (exclusive vs optimistic), conflict detection, and the multi-stage commit flow.

Validation

The Validation package rejects invalid writes before they reach the backing field. Standard .NET data-annotation attributes like [Required], [MaxLength], and [Range] work out of the box once you add WithDataAnnotationValidation() to the context. Invalid writes throw ValidationException and the property keeps its previous value.

[InterceptorSubject]
public partial class Person
{
    [Required, MaxLength(50)]
    public partial string FirstName { get; set; }
    // ... other properties unchanged
}

var context = InterceptorSubjectContext
    .Create()
    .WithFullPropertyTracking()
    .WithDataAnnotationValidation();

var person = new Person(context);
person.FirstName = "This name is way too long and exceeds the maximum length";
// Throws ValidationException; person.FirstName is unchanged.

For custom rules, cross-property validation, or external checks, implement IPropertyValidator and register it on the context. See Validation.

Registry

The Registry package keeps track of every subject in the graph and the metadata attached to it. Once enabled, subjects can be enumerated, looked up by ID, and extended with dynamic properties at runtime.

var context = InterceptorSubjectContext
    .Create()
    .WithFullPropertyTracking()
    .WithRegistry();

var person = new Person(context);
var registered = person.TryGetRegisteredSubject()!;

foreach (var property in registered.Properties)
{
    Console.WriteLine($"{property.Name} ({property.Type.Name})");
}

Two patterns built on the registry are used heavily by other packages:

  • Property attributes: strongly typed metadata stored as actual properties (e.g., a Pressure_Minimum companion to a Pressure property), discoverable at runtime, trackable like any other property, and bindable through connectors.
  • Stable subject IDs: short string identifiers used by connectors (notably WebSocket) to reference subjects across the wire, with optional client-supplied IDs and a context-wide reverse index.

Both, plus dynamic property and attribute creation at runtime, are covered in Registry.

Connectors

A connector synchronizes a subject graph with an external system. It comes in two flavors:

  • Sources (ISubjectSource): the external system is the source of truth. The connector loads initial state, subscribes to inbound updates, and writes local changes back. Each property has at most one source.
  • Servers: the C# graph is the source of truth. The connector exposes properties to external clients and applies their incoming writes.

Both directions use the same path-mapping infrastructure ([Path] attributes, customizable path providers) and route outbound changes through the property-change queue, which batches and merges them before they are written. The shared connector infrastructure also handles loop prevention (echoed values are deduplicated by source filtering), write retry queues during disconnection, and reconnection with state replay.

Writes are local-first by default: the in-process model updates immediately and the change is sent to the external system asynchronously. This keeps the local model responsive but means it can be temporarily ahead of the source. For scenarios that need the source to confirm before the local model updates (industrial control, financial data), wrap the writes in a source transaction: the local model only changes if the source accepts the write.

The MQTT connector illustrates a typical setup. Define your subject with topic mappings:

using Namotion.Interceptor.Registry.Attributes;

[InterceptorSubject]
public partial class Sensor
{
    [Path("mqtt", "Temperature")]
    public partial decimal Temperature { get; set; }

    [Path("mqtt", "Humidity")]
    public partial decimal Humidity { get; set; }

    public Sensor()
    {
        Temperature = 0;
        Humidity = 0;
    }
}

Then wire up the host, register the subject, and configure the MQTT client:

var builder = Host.CreateApplicationBuilder(args);

var context = InterceptorSubjectContext
    .Create()
    .WithFullPropertyTracking()
    .WithRegistry()
    .WithHostedServices(builder.Services);

builder.Services.AddSingleton(new Sensor(context));
builder.Services.AddMqttSubjectClientSource<Sensor>(
    brokerHost: "mqtt.example.com",
    connectorName: "mqtt",
    topicPrefix: "sensors/room1");

var host = builder.Build();
await host.StartAsync();

Property changes now flow in both directions automatically:

var sensor = host.Services.GetRequiredService<Sensor>();

// Local change is published to the broker
sensor.Temperature = 25.5m;

// Inbound MQTT messages update the property and trigger change notifications

The same pattern applies to OPC UA (industrial automation, dynamic property discovery, companion specifications), Modbus (read-only polling of Modbus TCP devices) and WebSocket (digital twin synchronization with sequence numbers and heartbeats). Implementation details for sources, servers, ownership, and write retry are in Connectors. The wire format used for partial state synchronization is documented in Subject Updates.

Integrations

Integrations expose subjects through .NET host frameworks. They reuse the tracking and registry packages (no protocol of their own) and are designed to drop into existing applications.

  • ASP.NET Core - MapSubjectWebApis<T> adds REST endpoints for reading the subject graph as JSON, updating properties via JSON paths, and exposing structure metadata. Integrates with data-annotation validation and OpenAPI/Swagger.
  • Blazor - <TrackingScope> automatically re-renders content when any property accessed inside it (or anywhere in its descendant graph) changes. Works with both server and WebAssembly hosting models.
  • GraphQL - adds a root query and a root subscription via HotChocolate, streaming property changes to subscribed clients.
  • MCP (experimental) - exposes the subject registry as Model Context Protocol tools (browse, search, get_property, set_property, list_types) so AI agents can navigate and interact with the object graph.
  • Hosting - WithHostedServices() integrates with the .NET Generic Host so subjects extending BackgroundService (or services dynamically attached to subjects) start and stop with attach/detach.

Package Reference

Core

Package Description Documentation
Namotion.Interceptor Core interfaces and the read/write interceptor pipeline Interceptors
Namotion.Interceptor.Generator Source generator for [InterceptorSubject] classes Generator
Namotion.Interceptor.Dynamic Create subjects from interfaces at runtime Dynamic

Tracking

Package Description Documentation
Namotion.Interceptor.Tracking Change tracking, derived properties, lifecycle events, transactions Tracking

Validation

Package Description Documentation
Namotion.Interceptor.Validation Property validation with data annotation support Validation

Registry

Package Description Documentation
Namotion.Interceptor.Registry Runtime property discovery, metadata, and dynamic properties Registry
Namotion.Interceptor.Expressions Expressions over property values: comparisons, conditions and templates Expressions

Connectors

Package Description Documentation
Namotion.Interceptor.Connectors Base infrastructure for external system integration Connectors
Namotion.Interceptor.Mqtt Bidirectional MQTT synchronization MQTT
Namotion.Interceptor.OpcUa OPC UA client and server integration OPC UA
Namotion.Interceptor.Modbus Read-only Modbus TCP polling Modbus
Namotion.Interceptor.WebSocket Real-time WebSocket synchronization WebSocket
Connector Tester Chaos and load testing for connector verification Connector Tester

Integrations

Package Description Documentation
Namotion.Interceptor.AspNetCore ASP.NET Core integration for web APIs ASP.NET Core
Namotion.Interceptor.Blazor Automatic re-rendering on property changes Blazor
Namotion.Interceptor.GraphQL GraphQL subscriptions for real-time updates GraphQL
Namotion.Interceptor.Mcp MCP server for AI agent access to the subject registry MCP
Namotion.Interceptor.Hosting Hosted service lifecycle management Hosting

For more examples, see the Samples directory in the solution.

Product Compatible and additional computed target framework versions.
.NET 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.11.0 92 11/18/2026
0.10.1 112 11/3/2026
0.10.0 107 10/30/2026
0.9.4 122 10/6/2026
0.9.3 124 9/18/2026
0.9.2 130 8/31/2026
0.9.1 129 8/13/2026
0.9.0 123 8/10/2026
0.8.0 133 7/17/2026
0.7.0 145 6/2/2026
0.6.1 129 5/13/2026
0.6.0 133 5/11/2026
0.5.2 157 4/13/2026
0.5.1 138 4/8/2026
0.5.0 145 3/31/2026
0.4.1 155 3/16/2026
0.4.0 138 3/6/2026
0.3.1 169 2/5/2026
0.3.0 151 2/2/2026
0.2.4 152 1/19/2026
Loading failed