FileCompositions.Core
1.0.0
dotnet add package FileCompositions.Core --version 1.0.0
NuGet\Install-Package FileCompositions.Core -Version 1.0.0
<PackageReference Include="FileCompositions.Core" Version="1.0.0" />
<PackageVersion Include="FileCompositions.Core" Version="1.0.0" />
<PackageReference Include="FileCompositions.Core" />
paket add FileCompositions.Core --version 1.0.0
#r "nuget: FileCompositions.Core, 1.0.0"
#:package FileCompositions.Core@1.0.0
#addin nuget:?package=FileCompositions.Core&version=1.0.0
#tool nuget:?package=FileCompositions.Core&version=1.0.0
FileCompositions
Installation
Via NuGet
dotnet add package FileCompositions.Core
Currently FileCompositions.Extensions is the only way of defining file resources using IHost
dotnet add package FileCompositions.Extensions
Sample Usage
To get started, use the IHost extension to configure file resources.
private static IHost CreateHost() => Host.CreateDefaultBuilder()
.ConfigureFileResources(schema =>
{
...
})
...
.Build()
Compose Resources
Defining file resources does not implicitly create any resource. Each file must be Ensured. Storage addresses (directories) will be implicitly created unless marked as Optional
.ConfigureFileResources(schema =>
{
// Resources includes Directories and Files
schema.ConfigureResources((resources, ctx) =>
{
resources.Directories(dirs => dirs
.Store(register => register
.UseKey(new DirectoryLocationKey(0))
.Register(config => config
.WithAddress(StorageAddress.Create("C:\\My\\Storage\\Directory"))))
.Store(register => register
.UseKey(new DirectoryLocationKey(1))
.Register(config => config
.WithAddress(StorageAddress.Create("C:\\My\\Other\\Storage\\Directory")))));
resources.Files(files => files
.Store(register => register
.To(new DirectoryLocationKey(0))
.UseKey(new("mySampleJsonFile"))
.File(config => config
.WithName("sampleJsonFile"))
.Register(mux => mux
.AsJson<MyJsonSettings>(json => json
.UseSerializerOptions(new() { WriteIndented = true }))))
.Store(register => register
.To(new DirectoryLocationKey(1))
.UseKey(new("mySampleDbFile"))
.File(config => config
.WithName("sampleDbFile"))
.Register(mux => mux.AsDb())));
});
}
Composition Options
File resources and directories have configurable options, which are shown in the docs
Consume Resources
A database file is not intended to be consumed as a service. Instead, it defines a .db file to use when migrating in EFCore using Sqlite.
You should inject your AppDbContext instead.
public class MyConsumerClass
{
private readonly IJsonFileResource<MyJsonSettings> _jsonFile;
private readonly IDbFileResource _dbFileResource;
public MyConsumerClass([FromKeyedServices("mySampleJsonFile")] IJsonFileResource<MyJsonSettings> jsonFile,
[FromKeyedServices("mySampleDbFile")] IDbFileResource dbFileResource)
{
_jsonFile = jsonFile;
_dbFileResource = dbFileResource;
}
public async Task<MyJsonSettings?> ReadSampleFile(CancellationToken cancellationToken = default) =>
await _jsonFile.Read(cancellationToken);
}
Currently supported file types
Roadmap & Features for future versions
- Unify all or as many standard file types under one library. Allow custom user-defined file types compatibility with composition.
- Create native storage backend implementations for major cloud providers.
- Allow composition beyond IHost.
- Allow resource schema to automatically assign ids for directories.
- Simplify and expand settings capabilities during composition time, to remove bloat syntax and allow for any setting type to be available.
- Native validations for all files with custom handlers.
- Extensions for functional programming, possibly using C# Language Extensions. Eg. allow
Option<T>rather thanT?for .json, .txt, .config etc.
If there are any features that should exist in the library to make it easier to integrate with real production code, please raise the issue.
License MIT
| 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
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 104 | 2/22/2026 |