TaskHub.Shared

Media Persistence Usage

The Media module provides a standardized way to track and persist metadata for media files (e.g., photos, documents) used across TaskHub.

Configuration

Enable media tracking in your appsettings.json within the Persistence section.

"Persistence": {
  "Media": {
    "IsEnabled": true,
    "TableName": "MediaMetadata"
  }
}

Registration

When using AddAppDbContext, the media configuration is automatically applied if IsEnabled is true.

builder.Services.AddAppDbContext<MyDbContext>(builder.Configuration.GetSection("Persistence").Bind);

Internal Workflow

  1. Metadata Entity: The system uses a MediaMetadata entity to store details like FileName, Size, ContentType, and StoragePath.
  2. Configuration: MediaConfiguration (applied by ContextBase) defines the table structure.
  3. Reading/Writing: Use IMediaReader and IMediaWriter (from TaskHub.Shared.Persistence.Media) to interact with the media records.

Usage Example

Typically, you would associate a media record with a domain entity.

public class UserProfile : AggregateBase<Guid>
{
    // Store the ID of the media record
    public Guid? ProfilePhotoId { get; private set; }

    public void UpdatePhoto(Guid mediaId)
    {
        ProfilePhotoId = mediaId;
        AddEvent(new ProfilePhotoUpdatedDomainEvent(Id, mediaId));
    }
}

This allows you to decouple the actual file storage (handled by IStorageService) from the database-level tracking of those files.