> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.nimbleapps.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# DualHttpContextAccessor

> [IHttpContextAccessor](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.ihttpcontextaccessor) that keeps an outer request and an inner in-pro...

## Definition

**Assembly:** CloudNimble.EasyAF.Http.dll

**Namespace:** CloudNimble.EasyAF.Http

**Inheritance:** System.Object

## Syntax

```csharp theme={"dark"}
CloudNimble.EasyAF.Http.DualHttpContextAccessor
```

## Summary

[IHttpContextAccessor](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.ihttpcontextaccessor) that keeps an outer request and an inner in-process
request as two contexts. [DualHttpContextAccessor.HttpContext](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#httpcontext) always returns [DualHttpContextAccessor.Active](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#active).
`HttpContext)` / [DualHttpContextAccessor.End](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#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](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.ihttpcontextaccessor). Do not call `AddHttpContextAccessor`;
that registers a different implementation. Existing code keeps working because it takes
[IHttpContextAccessor](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.ihttpcontextaccessor).

Host `Initialize` assigns [DualHttpContextAccessor.HttpContext](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#httpcontext) (sets [DualHttpContextAccessor.Outer](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#outer) and
[DualHttpContextAccessor.Active](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#active)). Inner execute calls `HttpContext)`, then [DualHttpContextAccessor.End](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#end) in
`finally`. Host `Dispose` assigns [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null), which poisons the
holder so every execution context sees request-end.

## Examples

```csharp theme={"dark"}
accessor.HttpContext = incomingRequest;
InnerHttpContext.CopyFromOuter(innerRequest, incomingRequest);
accessor.Start(innerRequest);
try
{
    await pipeline(innerRequest);
}
finally
{
    accessor.End();
}
```

## Constructors

### &#x20;.ctor

#### Syntax

```csharp theme={"dark"}
public DualHttpContextAccessor()
```

### &#x20;.ctor Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public Object()
```

## Properties

### &#x20;Active

Gets the context [DualHttpContextAccessor.HttpContext](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#httpcontext) returns. `HttpContext)` and
[DualHttpContextAccessor.End](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#end) change this without using the setter.

#### Syntax

```csharp theme={"dark"}
public Microsoft.AspNetCore.Http.HttpContext Active { get; }
```

#### Property Value

Type: `Microsoft.AspNetCore.Http.HttpContext`

### &#x20;HttpContext

#### Syntax

```csharp theme={"dark"}
public Microsoft.AspNetCore.Http.HttpContext HttpContext { get; set; }
```

#### Property Value

Type: `Microsoft.AspNetCore.Http.HttpContext`

### &#x20;Inner

Gets the inner in-process context, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if `HttpContext)` has not run
or [DualHttpContextAccessor.End](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#end) / request-end has already cleared it.

#### Syntax

```csharp theme={"dark"}
public Microsoft.AspNetCore.Http.HttpContext Inner { get; }
```

#### Property Value

Type: `Microsoft.AspNetCore.Http.HttpContext`

### &#x20;Outer

Gets the incoming (outer) context, or [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if the host has not assigned
[DualHttpContextAccessor.HttpContext](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#httpcontext) yet.

#### Syntax

```csharp theme={"dark"}
public Microsoft.AspNetCore.Http.HttpContext Outer { get; }
```

#### Property Value

Type: `Microsoft.AspNetCore.Http.HttpContext`

## Methods

### &#x20;End

Makes [DualHttpContextAccessor.HttpContext](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#httpcontext) return [DualHttpContextAccessor.Outer](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#outer) again and clears
[DualHttpContextAccessor.Inner](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#inner). Does not write to [DualHttpContextAccessor.Outer](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#outer)'s response.

#### Syntax

```csharp theme={"dark"}
public void End()
```

### &#x20;Equals Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual bool Equals(object obj)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `obj` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;Equals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool Equals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;GetHashCode Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### &#x20;GetType Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public System.Type GetType()
```

#### Returns

Type: `System.Type`

### &#x20;MemberwiseClone Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
protected internal object MemberwiseClone()
```

#### Returns

Type: `object`

### &#x20;ReferenceEquals Inherited

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public static bool ReferenceEquals(object objA, object objB)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `objA` | `object?` | - |
| `objB` | `object?` | - |

#### Returns

Type: `bool`

### &#x20;Start

Makes [DualHttpContextAccessor.HttpContext](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#httpcontext) return *inner* without dropping
[DualHttpContextAccessor.Outer](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#outer). Do not use the [DualHttpContextAccessor.HttpContext](https://easyaf.nimbleapps.cloud/api-reference/CloudNimble/EasyAF/Http/DualHttpContextAccessor#httpcontext) setter for this.

#### Syntax

```csharp theme={"dark"}
public void Start(Microsoft.AspNetCore.Http.HttpContext inner)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `inner` | `Microsoft.AspNetCore.Http.HttpContext` | The inner in-process request. |

#### Exceptions

| Exception | Description |
| - | - |
| `ArgumentNullException` | Thrown when *inner* is [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null). |

### &#x20;ToString Inherited Virtual

> [!NOTE]
>
> Inherited from `object`

#### Syntax

```csharp theme={"dark"}
public virtual string ToString()
```

#### Returns

Type: `string?`

## Related APIs

* Microsoft.AspNetCore.Http.IHttpContextAccessor


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.