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

# ODataMcpSessionFactory

> Builds one MCP session per enabled OData route prefix discovered from endpoint routing.

## Definition

**Assembly:** Microsoft.OData.Mcp.AspNetCore.dll

**Namespace:** Microsoft.OData.Mcp.AspNetCore.Hosting

**Inheritance:** System.Object

## Syntax

```csharp theme={null}
Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpSessionFactory
```

## Summary

Builds one MCP session per enabled OData route prefix discovered from endpoint routing.

## Constructors

### &#x20;.ctor

Initializes a new instance of the [ODataMcpSessionFactory](https://ai.easyaf.dev/odata-mcp/api-reference/Microsoft/OData/Mcp/AspNetCore/Hosting/ODataMcpSessionFactory.md) class.

#### Syntax

```csharp theme={null}
public ODataMcpSessionFactory(System.IServiceProvider services, Microsoft.Extensions.Options.IOptions<Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpHostOptions> hostOptions, Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpPipeline pipeline, Microsoft.OData.Mcp.AspNetCore.Hosting.McpHttpContextAccessor httpContextAccessor)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `services` | `System.IServiceProvider` | The application service provider used to read `EndpointDataSource`. |
| `hostOptions` | `Microsoft.Extensions.Options.IOptions<Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpHostOptions>` | Host catalog, include/exclude, and explicit routes. |
| `pipeline` | `Microsoft.OData.Mcp.AspNetCore.Hosting.ODataMcpPipeline` | The captured application pipeline. |
| `httpContextAccessor` | `Microsoft.OData.Mcp.AspNetCore.Hosting.McpHttpContextAccessor` | The wrapping accessor that can Start/End the inner context. |

### &#x20;.ctor Inherited

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

#### Syntax

```csharp theme={null}
public Object()
```

## Properties

### &#x20;Sessions

Gets sessions keyed by OData route prefix. Discovery runs on first access when
`UseODataMcp` has not already rebuilt after endpoints exist.

#### Syntax

```csharp theme={null}
public System.Collections.Generic.IReadOnlyDictionary<string, Microsoft.OData.Mcp.Core.Catalog.ODataMcpSession> Sessions { get; }
```

#### Property Value

Type: `System.Collections.Generic.IReadOnlyDictionary<string, Microsoft.OData.Mcp.Core.Catalog.ODataMcpSession>`

## Methods

### &#x20;Equals Inherited Virtual

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

#### Syntax

```csharp theme={null}
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={null}
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={null}
public virtual int GetHashCode()
```

#### Returns

Type: `int`

### &#x20;GetType Inherited

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

#### Syntax

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

#### Returns

Type: `System.Type`

### &#x20;MemberwiseClone Inherited

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

#### Syntax

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

#### Returns

Type: `object`

### &#x20;Rebuild

Discovers routes from DI and optional application data sources, then rebuilds sessions.

#### Syntax

```csharp theme={null}
public void Rebuild(System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Routing.EndpointDataSource> additionalSources = null)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `additionalSources` | `System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Routing.EndpointDataSource>?` | `WebApplication` data sources that may not be exported to DI yet. Pass [`null`](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) |
| to use DI only. | | |

### &#x20;ReferenceEquals Inherited

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

#### Syntax

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

#### Parameters

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

#### Returns

Type: `bool`

### &#x20;Resolve

Resolves the session for the current HTTP path.

#### Syntax

```csharp theme={null}
public Microsoft.OData.Mcp.Core.Catalog.ODataMcpSession Resolve(Microsoft.AspNetCore.Http.HttpContext http)
```

#### Parameters

| Name | Type | Description |
| - | - | - |
| `http` | `Microsoft.AspNetCore.Http.HttpContext?` | The current HTTP context. |

#### Returns

Type: `Microsoft.OData.Mcp.Core.Catalog.ODataMcpSession`
The matching session.

### &#x20;ToString Inherited Virtual

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

#### Syntax

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

#### Returns

Type: `string?`


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