.NET API
IAttachmentStore
Tracon.Abstractions.dllThe contract for attachment metadata and for the default (database) content storage.
public interface IAttachmentStoreRemarks
Section titled “Remarks”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.
Methods
Section titled “Methods”DeleteAsync(string, Guid, CancellationToken)
Section titled “ DeleteAsync(string, Guid, CancellationToken)”Deletes an attachment.
ValueTask<bool> DeleteAsync(string tenantId, Guid id, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”tenantId string
The tenant id.
id Guid
The attachment id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”true when a record was deleted.
Remarks
Section titled “Remarks”When the content lives in IAttachmentStorage, the content is deleted first and the record second. If the content delete throws, the record stays and the exception propagates: the record is the only place that says where the content is, so a retry can still find it.
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)Parameters
Section titled “Parameters”tenantId string
The tenant id.
sessionId string
The session id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”The number of records deleted.
Remarks
Section titled “Remarks”It is called when a session is deleted; it keeps orphaned attachments from piling up.
Each attachment follows the order of IAttachmentStore.DeleteAsync: content first, record second. The first content delete that throws stops the call; that record and every record not yet reached stay, so a retry deletes the rest.
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)Parameters
Section titled “Parameters”tenantId string
The tenant id.
id Guid
The attachment id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”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)Parameters
Section titled “Parameters”query AttachmentQuery
The filter.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”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)Parameters
Section titled “Parameters”tenantId string
The tenant id.
id Guid
The attachment id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”A readable stream, or null when the record does not exist or belongs to another tenant.
Remarks
Section titled “Remarks”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)Parameters
Section titled “Parameters”content AttachmentContent
The content and metadata to save.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<AttachmentDescriptor>
The attachment record with its id and digest assigned.