Definition
Assembly: Microsoft.OData.Mcp.AspNetCore.dll Namespace: Microsoft.OData.Mcp.AspNetCore.Hosting Inheritance: System.ObjectSyntax
Summary
IHttpContextAccessor that keeps the MCP request and the in-process OData request as two contexts. McpHttpContextAccessor.HttpContext always returns McpHttpContextAccessor.Active. HttpContext) / McpHttpContextAccessor.End change which context is active without using Microsoft’sHttpContextAccessor setter (that setter nulls a shared holder and ends
the outer request).
Remarks
Register this as IHttpContextAccessor afterAddHttpContextAccessor so
last-wins DI gives Restier and DefaultHttpContextFactory this instance.
Host Initialize assigns McpHttpContextAccessor.HttpContext (sets McpHttpContextAccessor.Outer and
McpHttpContextAccessor.Active). Inner execute calls HttpContext), then McpHttpContextAccessor.End in
finally. Host Dispose assigns null, which poisons the
holder so every execution context sees request-end.
Examples
Constructors
.ctor
Syntax
.ctor Inherited
Inherited from
objectSyntax
Properties
Active
Gets the context McpHttpContextAccessor.HttpContext returns. HttpContext) and McpHttpContextAccessor.End change this without using the setter.Syntax
Property Value
Type:Microsoft.AspNetCore.Http.HttpContext?
HttpContext
Syntax
Property Value
Type:Microsoft.AspNetCore.Http.HttpContext?
Inner
Gets the in-process OData context, ornull if HttpContext) has not run
or McpHttpContextAccessor.End / request-end has already cleared it.
Syntax
Property Value
Type:Microsoft.AspNetCore.Http.HttpContext?
Outer
Gets the MCP (incoming) context, ornull if the host has not assigned
McpHttpContextAccessor.HttpContext yet.
Syntax
Property Value
Type:Microsoft.AspNetCore.Http.HttpContext?
Methods
End
Makes McpHttpContextAccessor.HttpContext return McpHttpContextAccessor.Outer again and clears McpHttpContextAccessor.Inner. Does not write to McpHttpContextAccessor.Outer’s response.Syntax
Equals Inherited Virtual
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Equals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
GetHashCode Inherited Virtual
Inherited from
objectSyntax
Returns
Type:int
GetType Inherited
Inherited from
objectSyntax
Returns
Type:System.Type
MemberwiseClone Inherited
Inherited from
objectSyntax
Returns
Type:object
ReferenceEquals Inherited
Inherited from
objectSyntax
Parameters
Returns
Type:bool
Start
Makes McpHttpContextAccessor.HttpContext return inner without dropping McpHttpContextAccessor.Outer. Do not use the McpHttpContextAccessor.HttpContext setter for this.Syntax
Parameters
Exceptions
ToString Inherited Virtual
Inherited from
objectSyntax
Returns
Type:string?
Related APIs
- Microsoft.AspNetCore.Http.IHttpContextAccessor