FileCompositions.Hosting
2.0.0
dotnet add package FileCompositions.Hosting --version 2.0.0
NuGet\Install-Package FileCompositions.Hosting -Version 2.0.0
<PackageReference Include="FileCompositions.Hosting" Version="2.0.0" />
<PackageVersion Include="FileCompositions.Hosting" Version="2.0.0" />
<PackageReference Include="FileCompositions.Hosting" />
paket add FileCompositions.Hosting --version 2.0.0
#r "nuget: FileCompositions.Hosting, 2.0.0"
#:package FileCompositions.Hosting@2.0.0
#addin nuget:?package=FileCompositions.Hosting&version=2.0.0
#tool nuget:?package=FileCompositions.Hosting&version=2.0.0
<h1 align="center"> FileCompositions </h1>
<div align="center"> <a href="https://github.com/SzymonFrac/FileCompositions/releases/latest"><img src="https://img.shields.io/github/v/release/SzymonFrac/FileCompositions?color=f25d3a"></a> <a href="https://www.nuget.org/packages/FileCompositions.Core/"><img src="https://img.shields.io/nuget/v/FileCompositions.Core" alt='NuGet'></a> <a href="LICENSE.txt"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
<br>
<a href="https://github.com/SzymonFrac/FileCompositions/tree/master/docs">Documentation</a> </div>
<p align="center"> FileCompositions is a C# library that allows a program to define files and directories as resources in DI from many file systems. </p>
🔍 Who is this library for?
This library is primarily designed for desktop applications that manage files, directories, databases, and other storage resources on the client machine.
Its goal is to centralize storage management through dependency injection, reducing boilerplate code and making storage requirements easier to evolve as an application grows.
Future versions may expand beyond local desktop storage, including support for mobile platforms and cloud-backed storage providers, but is primarily for clients.
✨ Features
- 📁 Treat files and directories as injectable services.
- 🔧 Automatically create and initialize required storage on startup.
- 📄 Support common file types such as JSON, databases, and assemblies.
- 🏗️ Seamless integration with .NET dependency injection and IHost.
🚀 Roadmap
- 🌐 Cloud file systems (Azure Blob Storage, S3, GCS, etc.).
- 🧩 Custom file type composition and extensible architecture for custom and private file systems.
- 🔗 Support for dependency graphs between file definitions.
- ✅ File-type-specific validation and integrity checks.
- 🏗️ Integration beyond IHost and the default Microsoft DI container.
- 📚 Unified abstractions for common file formats.
- 📝 Log your files and directories to clean any obsolete definitions.
Requirements
Targets
.NET 10.0
Installation
Via NuGet
dotnet add package FileCompositions.Core
Currently FileCompositions.Hosting is the only way of defining file resources using IHost
dotnet add package FileCompositions.Hosting
Getting Started
To get started, use the IHost extension to configure file resources.
private static IHost CreateHost() => Host.CreateDefaultBuilder()
.ConfigureFileComposition(schema =>
{
...
})
...
.Build()
Add Definitions
To add any files, you first must define a directory.
Be aware that any definition can be created in your file system. When testing, make sure that your file system is cleared afterward if you are not using a definition anymore.
// Todo:
// Define a Requied and Strict json file of type MyApplicationData, with name "myConfiguration"
// in 'Roaming/MyFunApp' directory.
static IHost CreateHost() => Host.CreateDefaultBuilder()
.ConfigureFileComposition(schema =>
{
schema.ConfigureDefinitions(registrar => registrar
.Store(directory =>
{
directory.Define(def => def
.CreateLocal(Environment.SpecialFolder.ApplicationData,
"MyFunApp")
.WithKey(new DirectoryDefinitionKey(0)));
directory.WithFiles(files => files
.DefineJson(json => json
.Create<MyApplicationData>()
.WithName("myConfiguration")
.WithKey(new FileDefinitionKey(0))));
return directory;
}));
})
.Build();
Initially, every definition is Required and Strict unless configured otherwise.
Find out more about Qualities
Use your Definitions
Finally, use your definitions like any other DI service.
public class MyConsumerClass
{
private readonly IJsonDefinition<StrictDefinition, RequiredInRequired, MyApplicationData> _jsonFile;
public MyConsumerClass([FromKeyedServices(0)] IJsonDefinition<StrictDefinition, RequiredInRequired, MyApplicationData> jsonFile) =>
_jsonFile = jsonFile;
public Task<MyApplicationData> ReadSampleFile(CancellationToken cancellationToken = default) =>
_jsonFile.ReadAsync(cancellationToken);
}
Contributions
Please write any bugs with the library under issues.
In the future, main contributions could be new file types and file system implementations.
There will be a proper CONTRIBUTING.md soon. Thanks for being interested in the project and don't hesitate to ask questions.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FileCompositions.Core (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.9)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.9)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.9)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FileCompositions.Hosting:
| Package | Downloads |
|---|---|
|
FileCompositions.Hosting.EntityFrameworkCore
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 128 | 6/22/2026 |