Skip to content
Tracon

IAttachmentStore

Namespace Tracon · Assembly Tracon.Abstractions.dll

The contract for attachment metadata and for the default (database) content storage.

public interface IAttachmentStore

When IAttachmentStorage is registered the content lives there and this store keeps the metadata only; when it is not registered the content is stored directly in the database (bytea).

DI lifetime — singleton. Registered as a singleton with TryAdd; a consumer’s own registration wins.

DeleteAsync(string, Guid, CancellationToken)

Section titled “ DeleteAsync(string, Guid, CancellationToken)”

Deletes an attachment.

ValueTask<bool> DeleteAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)

tenantId string

The tenant id.

id Guid

The attachment id.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true when a record was deleted.

DeleteBySessionAsync(string, string, CancellationToken)

Section titled “ DeleteBySessionAsync(string, string, CancellationToken)”

Deletes every attachment of a session.

ValueTask<int> DeleteBySessionAsync(string tenantId, string sessionId, CancellationToken cancellationToken = default)

tenantId string

The tenant id.

sessionId string

The session id.

cancellationToken CancellationToken

The cancellation token.

ValueTask<int>

The number of records deleted.

It is called when a session is deleted; it keeps orphaned attachments from piling up.

GetAsync(string, Guid, CancellationToken)

Section titled “ GetAsync(string, Guid, CancellationToken)”

Reads the metadata of a single attachment.

ValueTask<AttachmentDescriptor?> GetAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)

tenantId string

The tenant id.

id Guid

The attachment id.

cancellationToken CancellationToken

The cancellation token.

ValueTask<AttachmentDescriptor?>

The record, or null when it does not exist or belongs to another tenant.

ListAsync(AttachmentQuery, CancellationToken)

Section titled “ ListAsync(AttachmentQuery, CancellationToken)”

Lists the attachments through a filter.

ValueTask<IReadOnlyList<AttachmentDescriptor>> ListAsync(AttachmentQuery query, CancellationToken cancellationToken = default)

query AttachmentQuery

The filter.

cancellationToken CancellationToken

The cancellation token.

ValueTask<IReadOnlyList<AttachmentDescriptor>>

The records ordered from newest to oldest.

OpenReadAsync(string, Guid, CancellationToken)

Section titled “ OpenReadAsync(string, Guid, CancellationToken)”

Opens the raw content of an attachment as a stream.

ValueTask<Stream?> OpenReadAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)

tenantId string

The tenant id.

id Guid

The attachment id.

cancellationToken CancellationToken

The cancellation token.

ValueTask<Stream?>

A readable stream, or null when the record does not exist or belongs to another tenant.

Stream ownership. The CALLER owns the returned stream and must dispose it; this store does not dispose it and does not keep a reference to it after returning.

SaveAsync(AttachmentContent, CancellationToken)

Section titled “ SaveAsync(AttachmentContent, CancellationToken)”

Saves a new attachment.

ValueTask<AttachmentDescriptor> SaveAsync(AttachmentContent content, CancellationToken cancellationToken = default)

content AttachmentContent

The content and metadata to save.

cancellationToken CancellationToken

The cancellation token.

ValueTask<AttachmentDescriptor>

The attachment record with its id and digest assigned.