liveBook · Manning

EndpointFilterFactoryContext

As explained in ASP.NET Core in Action, 3e

EndpointFilterFactoryContext is the ASP.NET Core context object that provides endpoint details to an endpoint filter factory while the application is being built.

EndpointFilterFactoryContext supplies endpoint-definition details while the application is being built. A filter factory uses it to inspect the handler and decide whether to create a filter for that endpoint. section 5.4.3

The context provides information that ordinary filter invocation context does not:

  • MethodInfo exposes the endpoint handler’s method signature, including its parameters. section 5.4.3
  • EndpointMetadata supplies additional endpoint details for factory decisions. section 5.4.3
  • A factory can inspect parameters such as a string id, return the next delegate when no match exists, and create a tailored filter when it does. section 5.4.3

One factory for different handlers

A validation factory can attach to both GET /fruit/{id} with parameters (string id) and POST /fruit/{id} with parameters (Fruit fruit, string id). It examines each handler through EndpointFilterFactoryContext and creates a filter that locates the id argument regardless of its position.

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains build-time inspection through MethodInfo and EndpointMetadata, but does not detail endpoint metadata itself or implement every delegate signature.
Examples
Uses GET and POST fruit routes whose id parameter appears in different handler positions.
What it assumes
Assumes familiarity with endpoint filters and handler parameters while distinguishing factory context from invocation context.
What you can do after
Build generalized endpoint filters via AddEndpointFilterFactory for handlers with different method signatures.
How it connects
Connects endpoint filters with filter factories, endpoint handlers, MethodInfo, EndpointMetadata, and route groups.

Related concepts

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