Skip to content

[feat] Add FileProvider to abstract file system visit to support oss provided by cloud service #76

@ikesnowy

Description

@ikesnowy

Is your feature request related to a problem? Please describe.

Need common abstractions for file operations like CreateDirectory, SaveFileToPath.

Describe the solution you'd like

// Program.cs

services.AddCqrs(typeof(SaveFileCommandHandler).Assembly).AddFileProvider<AliyunOssFileProvider>();

// handler

private readonly IFileProvider _fileProvider;

public SaveFileCommandHandler(IFileProvider fileProvider)
{
    _fileProvider = fileProvider;
}

public async Task Handle(SaveFileCommand request, CancellationToken cancellationToken) 
{
    var exists = _fileProvider.ExistsAsync(request.FilePath);
    if (exists)
    {
        return CommandResponse<byte[], FileError>.Fail(FileError.FileAlreadyExists);
    }
    
    var fileBytes = _fileProvider.ReadBytesAsync(request.FilePath);
    return CommandResponse<byte[], FileError>(fileBytes);
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions