FileCompositions.Hosting 2.0.0

dotnet add package FileCompositions.Hosting --version 2.0.0
                    
NuGet\Install-Package FileCompositions.Hosting -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FileCompositions.Hosting" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FileCompositions.Hosting" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FileCompositions.Hosting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FileCompositions.Hosting --version 2.0.0
                    
#r "nuget: FileCompositions.Hosting, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FileCompositions.Hosting@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FileCompositions.Hosting&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FileCompositions.Hosting&version=2.0.0
                    
Install as a Cake Tool

<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>

Demo

🔍 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

  1. 📁 Treat files and directories as injectable services.
  2. 🔧 Automatically create and initialize required storage on startup.
  3. 📄 Support common file types such as JSON, databases, and assemblies.
  4. 🏗️ Seamless integration with .NET dependency injection and IHost.

🚀 Roadmap

  1. 🌐 Cloud file systems (Azure Blob Storage, S3, GCS, etc.).
  2. 🧩 Custom file type composition and extensible architecture for custom and private file systems.
  3. 🔗 Support for dependency graphs between file definitions.
  4. ✅ File-type-specific validation and integrity checks.
  5. 🏗️ Integration beyond IHost and the default Microsoft DI container.
  6. 📚 Unified abstractions for common file formats.
  7. 📝 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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