liveBook · Manning

Interceptor

As explained in .NET in Action, Second Edition

An interceptor is a component that observes or modifies an operation before it is sent to an external system.

An interceptor observes or modifies an operation before it reaches an external system. In EF Core, a DbCommandInterceptor can capture generated SQL before it is sent to the data store. section 9.4.1

A practical SQL interceptor:

  • Writes trimmed command text through ITestOutputHelper, keeping parallel test output associated with its test. section 9.4.1
  • Returns a ValueTask because interception commonly performs synchronous SQL manipulation. section 9.4.1

Auditing generated SQL

A query for a book by ID produces parameterized SQL such as WHERE "b"."Id" = @__id_0. Logging this output provides an auditable record of what EF Core will execute. section 9.4.1

How .NET in Action, Second Edition covers it

How deep it goes
Implements DbCommandInterceptor, ReaderExecutingAsync, test registration, output handling, and ValueTask rationale.
Examples
Logs generated book-lookup SQL and uses an in-memory SQLite test context with xUnit output.
What it assumes
Assumes EF Core and C# testing familiarity; teaches interceptor registration and command logging directly.
What you can do after
Diagnose and audit EF Core database commands by capturing generated SQL in tests.
How it connects
Connects EF Core, DbContext, SQL injection, LINQ, xUnit, ITestOutputHelper, and ValueTask.

Also explained in

Compare how 2 books explain interceptor →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET in Action, Second Edition. The section links point to the parts of the book it draws on.