.NET 5 virtual file system

Features

  • In a single application, it can divide the front end and back end (management system) into separate project projects.
  • In development it allows developers to develop different businesses or modules at the same time.
  • It allows us to split the system function modules and assemble them together.

Quick Start

Install-Package TinyVFS
<ItemGroup>
<EmbeddedResource Include="MyResources\**\*.*" />
<Content Remove="MyResources\**\*.*" />
</ItemGroup>
services.AddVirtualFilesService();
services.Configure<VirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<WebApplication1.Pages.IndexModel>("WebResources");
});
public class MyService
{
private readonly IVirtualFileProvider _virtualFileProvider;
public MyService(IVirtualFileProvider virtualFileProvider)
{
_virtualFileProvider = virtualFileProvider;
}
public void Foo()
{
//Getting a single file
var file = _virtualFileProvider.GetFileInfo("/MyResources/js/test.js");
var fileContent = file.ReadAsString(); //ReadAsString is an extension method of ABP
//Getting all files/directories under a directory
var directoryContents = _virtualFileProvider.GetDirectoryContents("/MyResources/js");
}
}
services.AddVirtualFilesService();
services.Configure<VirtualFileSystemOptions>(options =>
{
options.FileSets.ReplaceEmbeddedByPhysical<WebApplication1.Pages.IndexModel>(
Path.Combine(WebHostEnvironment.ContentRootPath, "..\\WebResources")
);
});
app.UseVirtualFiles();
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".less"] = "text/css";
app.UseVirtualFiles(provider);
  • Virtual files can be used like physical static files in web applications.
  • Razor Views, Razor Pages, js, css, image files and all other web content can be embedded in the assembly and used like physical files.
  • The application can overwrite the virtual file of the module (web resource), just like putting a file with the same name and extension into the same folder of the virtual file.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Consistent Hashing with Clojure

Proxying requests to google cloud storage using Hadoop GCS connector through Envoy proxy.

Keeping Domain Model and Database Schema Sync in EF Core

TribeOne’s Christmas Discord party

Kotlin Delegates

Deploy Apps on Android using Meraki MDM (Mobile Device Management)

Deploy Apps on Android using Meraki MDM (Mobile Device Management)

How to restrict user access with to Grafana with Generic OAuth

Flutter vs React Native

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
冯辉

冯辉

More from Medium

Why and How to Migrate Old ASP.NET Applications to .NET Core?

Publishing an artifact on Github Actions of a .Net 6 applications

Creating an ASP.NET Core API Docker Container

Application Insights: How to set the cloud role name in .NET Core & .NET 5