The Media module provides a standardized way to track and persist metadata for media files (e.g., photos, documents) used across TaskHub.
Enable media tracking in your appsettings.json within the Persistence section.
"Persistence": {
"Media": {
"IsEnabled": true,
"TableName": "MediaMetadata"
}
}
When using AddAppDbContext, the media configuration is automatically applied if IsEnabled is true.
builder.Services.AddAppDbContext<MyDbContext>(builder.Configuration.GetSection("Persistence").Bind);
MediaMetadata entity to store details like FileName, Size, ContentType, and StoragePath.MediaConfiguration (applied by ContextBase) defines the table structure.IMediaReader and IMediaWriter (from TaskHub.Shared.Persistence.Media) to interact with the media records.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.