# MutableTenantContext

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.testing.contracts.storage.mutabletenantcontext/
> Summary: MutableTenantContext: An ITenantContext whose tenant can be swapped at run time.

<div class="api-provenance">Namespace Tracon.Testing.Contracts.Storage · Assembly <code>Tracon.Testing.Contracts.Xunit.dll</code></div>

An [ITenantContext](/api/tracon.itenantcontext/) whose tenant can be swapped at run time.

```csharp
public sealed class MutableTenantContext : ITenantContext
```

<dl class="api-relations"><dt>Inheritance</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object">object</a> ← <a href="/api/tracon.testing.contracts.storage.mutabletenantcontext/">MutableTenantContext</a></dd><dt>Implements</dt><dd><a href="/api/tracon.itenantcontext/">ITenantContext</a></dd><dt>Inherited Members</dt><dd><a href="https://learn.microsoft.com/dotnet/api/system.object.gettype">object.GetType()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.tostring">object.ToString()</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)">object.Equals(object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)">object.Equals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.referenceequals">object.ReferenceEquals(object?, object?)</a>, <a href="https://learn.microsoft.com/dotnet/api/system.object.gethashcode">object.GetHashCode()</a></dd></dl>

## Remarks

Some stores take the tenant as a method parameter, others read it from
[ITenantContext](/api/tracon.itenantcontext/) (for example `IRunStore`,
`ISessionStore`, `IAgentDefinitionStore`). To write a two-tenant
scenario for the second group, we need either two separate store
instances or a single context whose tenant can be swapped. The latter was
chosen: the same store instance points at the same backend, and the
question "does B see what A wrote" can be asked against a single store.

## Constructors

### <a id="Tracon_Testing_Contracts_Storage_MutableTenantContext__ctor_System_String_"></a> MutableTenantContext\(string\)

An [ITenantContext](/api/tracon.itenantcontext/) whose tenant can be swapped at run time.

```csharp
public MutableTenantContext(string tenantId)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The initial tenant.

#### Remarks

Some stores take the tenant as a method parameter, others read it from
[ITenantContext](/api/tracon.itenantcontext/) (for example `IRunStore`,
`ISessionStore`, `IAgentDefinitionStore`). To write a two-tenant
scenario for the second group, we need either two separate store
instances or a single context whose tenant can be swapped. The latter was
chosen: the same store instance points at the same backend, and the
question "does B see what A wrote" can be asked against a single store.

## Properties

### <a id="Tracon_Testing_Contracts_Storage_MutableTenantContext_TenantId"></a> TenantId

The current tenant's identifier. Never returns empty.

```csharp
public string TenantId { get; set; }
```

#### Property Value

 [string](https://learn.microsoft.com/dotnet/api/system.string)

#### Remarks

**The value must be canonical** — the form
[AmbientTenantScope.Normalize](/api/tracon.ambienttenantscope/#Tracon_AmbientTenantScope_Normalize_System_String_) returns. The tenant
identifier is matched case-insensitively across the product, and every
layer achieves that by normalizing the value rather than by comparing
case-insensitively. An implementation that returns `Acme` where
another path resolves `acme` splits one tenant into two on
PostgreSQL and SQLite, and merges them on SQL Server's default
collation — the authorization layer and the storage layer then disagree.
