Feature: Virtual File System (ManagedCode.Storage.VirtualFileSystem)

Purpose

Expose a higher-level “virtual file system” API on top of IStorage:

This is not a separate cloud provider. It is an abstraction layer that sits above any configured IStorage.

Main Flows

File operations

flowchart TD
  A[Caller] --> VFS[IVirtualFileSystem]
  VFS --> VF[IVirtualFile]
  VF --> S[IStorage]
  S --> P[Concrete provider]

Directory operations

Components

Key files:

DI Wiring

dotnet add package ManagedCode.Storage.VirtualFileSystem

VFS requires an IStorage to be registered first (any provider works). Then you add the overlay:

using ManagedCode.Storage.FileSystem.Extensions;
using ManagedCode.Storage.VirtualFileSystem.Core;
using ManagedCode.Storage.VirtualFileSystem.Extensions;

builder.Services.AddFileSystemStorageAsDefault(options =>
{
    options.BaseFolder = Path.Combine(builder.Environment.ContentRootPath, "storage");
});

builder.Services.AddVirtualFileSystem(options =>
{
    options.DefaultContainer = "vfs";
    options.EnableCache = true;
});

public sealed class MyService(IVirtualFileSystem vfs)
{
    public async Task DemoAsync(CancellationToken ct)
    {
        var file = await vfs.GetFileAsync("docs/readme.txt", ct);
        await file.WriteAllTextAsync("hello", cancellationToken: ct);

        var text = await file.ReadAllTextAsync(cancellationToken: ct);
    }
}

Current Behavior

Tests

References