#### [Abblix\.Oidc\.Server](https://www.abblix.com/docs/api/abblix-oidc-server 'index')
### [Abblix\.Oidc\.Server\.Features\.MultiTenancy](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy 'Abblix\.Oidc\.Server\.Features\.MultiTenancy')

## ITenantStoreWriter Interface

Writes to a store of tenants, for a host that changes its tenants through [ITenantManager](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.ITenantManager 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.ITenantManager')\.

```csharp
public interface ITenantStoreWriter
```

### Remarks
Registered beside an [ITenantStore](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.ITenantStore 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.ITenantStore') of the host's own that reads what it writes: beside the tenants of
the settings, which nothing writes to, the server does not start\. A store the host writes to by other means
needs none\. Each change of a stored tenant names the version it was read at and is applied only while the store
still holds that version, as one conditional write, so a change made meanwhile by another instance is never
overwritten unseen\.

Registered as a singleton, as the store is: the manager that takes it lives for the life of the process, so a
writer registered for a request would be held for every request after the first, and a container validating
its scopes refuses it at startup.
### Methods

## ITenantStoreWriter\.AddAsync\(TenantDefinition, CancellationToken\) Method {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.AddAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,System.Threading.CancellationToken)}

Adds [tenant](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.AddAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,System.Threading.CancellationToken).tenant 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.ITenantStoreWriter\.AddAsync\(Abblix\.Oidc\.Server\.Features\.MultiTenancy\.TenantDefinition, System\.Threading\.CancellationToken\)\.tenant'), unless the store holds a tenant under its id already\.

```csharp
System.Threading.Tasks.Task<string?> AddAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition tenant, System.Threading.CancellationToken cancellationToken);
```
#### Parameters

###### `tenant` [TenantDefinition](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.TenantDefinition') {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.AddAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,System.Threading.CancellationToken).tenant}

The tenant to add, its generation assigned\.

###### `cancellationToken` [System\.Threading\.CancellationToken](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken 'System\.Threading\.CancellationToken') {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.AddAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,System.Threading.CancellationToken).cancellationToken}

Cancels the write\.

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
The version the tenant is stored at; null when the store holds a tenant under its id\.

## ITenantStoreWriter\.RemoveAsync\(string, string, CancellationToken\) Method {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.RemoveAsync(string,string,System.Threading.CancellationToken)}

Removes the tenant stored under [tenantId](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.RemoveAsync(string,string,System.Threading.CancellationToken).tenantId 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.ITenantStoreWriter\.RemoveAsync\(string, string, System\.Threading\.CancellationToken\)\.tenantId'), while it is stored at
[expectedVersion](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.RemoveAsync(string,string,System.Threading.CancellationToken).expectedVersion 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.ITenantStoreWriter\.RemoveAsync\(string, string, System\.Threading\.CancellationToken\)\.expectedVersion')\.

```csharp
System.Threading.Tasks.Task<bool> RemoveAsync(string tenantId, string expectedVersion, System.Threading.CancellationToken cancellationToken);
```
#### Parameters

###### `tenantId` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.RemoveAsync(string,string,System.Threading.CancellationToken).tenantId}

The id of the tenant to remove\.

###### `expectedVersion` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.RemoveAsync(string,string,System.Threading.CancellationToken).expectedVersion}

The version the tenant was read at\.

###### `cancellationToken` [System\.Threading\.CancellationToken](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken 'System\.Threading\.CancellationToken') {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.RemoveAsync(string,string,System.Threading.CancellationToken).cancellationToken}

Cancels the write\.

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[System\.Boolean](https://learn.microsoft.com/en-us/dotnet/api/system.boolean 'System\.Boolean')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
Whether the tenant was removed; false when it is stored at another version or not at all\.

## ITenantStoreWriter\.UpdateAsync\(TenantDefinition, string, CancellationToken\) Method {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.UpdateAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,string,System.Threading.CancellationToken)}

Replaces the tenant stored under the id of [tenant](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.UpdateAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,string,System.Threading.CancellationToken).tenant 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.ITenantStoreWriter\.UpdateAsync\(Abblix\.Oidc\.Server\.Features\.MultiTenancy\.TenantDefinition, string, System\.Threading\.CancellationToken\)\.tenant'), while it is stored at
[expectedVersion](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.UpdateAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,string,System.Threading.CancellationToken).expectedVersion 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.ITenantStoreWriter\.UpdateAsync\(Abblix\.Oidc\.Server\.Features\.MultiTenancy\.TenantDefinition, string, System\.Threading\.CancellationToken\)\.expectedVersion')\.

```csharp
System.Threading.Tasks.Task<string?> UpdateAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition tenant, string expectedVersion, System.Threading.CancellationToken cancellationToken);
```
#### Parameters

###### `tenant` [TenantDefinition](https://www.abblix.com/docs/api/abblix-oidc-server/Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition 'Abblix\.Oidc\.Server\.Features\.MultiTenancy\.TenantDefinition') {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.UpdateAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,string,System.Threading.CancellationToken).tenant}

The tenant as it is to be stored\.

###### `expectedVersion` [System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String') {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.UpdateAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,string,System.Threading.CancellationToken).expectedVersion}

The version the tenant was read at\.

###### `cancellationToken` [System\.Threading\.CancellationToken](https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken 'System\.Threading\.CancellationToken') {#Abblix.Oidc.Server.Features.MultiTenancy.ITenantStoreWriter.UpdateAsync(Abblix.Oidc.Server.Features.MultiTenancy.TenantDefinition,string,System.Threading.CancellationToken).cancellationToken}

Cancels the write\.

#### Returns
[System\.Threading\.Tasks\.Task&lt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')[System\.String](https://learn.microsoft.com/en-us/dotnet/api/system.string 'System\.String')[&gt;](https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1 'System\.Threading\.Tasks\.Task\`1')  
The version the tenant is stored at now; null when it is stored at another version or not at all\.
