Skip to main content

Definition

Assembly: Microsoft.OData.Mcp.AspNetCore.dll Namespace: Microsoft.OData.Mcp.AspNetCore.Hosting Inheritance: System.Object

Syntax

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’s HttpContextAccessor setter (that setter nulls a shared holder and ends the outer request).

Remarks

Register this as IHttpContextAccessor after AddHttpContextAccessor 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 object

Syntax

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, or null 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, or null 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 object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

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 object

Syntax

Returns

Type: string?
  • Microsoft.AspNetCore.Http.IHttpContextAccessor