Ramstack.FileProviders.Composition
2.1.0-preview.3
See the version list below for details.
dotnet add package Ramstack.FileProviders.Composition --version 2.1.0-preview.3
NuGet\Install-Package Ramstack.FileProviders.Composition -Version 2.1.0-preview.3
<PackageReference Include="Ramstack.FileProviders.Composition" Version="2.1.0-preview.3" />
paket add Ramstack.FileProviders.Composition --version 2.1.0-preview.3
#r "nuget: Ramstack.FileProviders.Composition, 2.1.0-preview.3"
// Install Ramstack.FileProviders.Composition as a Cake Addin #addin nuget:?package=Ramstack.FileProviders.Composition&version=2.1.0-preview.3&prerelease // Install Ramstack.FileProviders.Composition as a Cake Tool #tool nuget:?package=Ramstack.FileProviders.Composition&version=2.1.0-preview.3&prerelease
Ramstack.FileProviders.Composition
Represents a .NET library that provides a helper class for flattening and composing IFileProvider
instances.
Getting Started
To install the Ramstack.FileProviders.Composition
NuGet package
in your project, run the following command:
dotnet add package Ramstack.FileProviders.Composition
Flattening Providers
The FlattenProvider
method attempts to flatten a given IFileProvider
into a single list of file providers.
This is especially useful when dealing with nested CompositeFileProvider
instances, which might have been created during
different stages of a pipeline or configuration. Flattening helps in removing unnecessary indirectness and improving efficiency
by consolidating all file providers into a single level.
var builder = WebApplication.CreateBuilder(args);
// Application pipeline configuration
...
builder.Environment.ContentRootFileProvider = FileProviderComposer.FlattenProvider(
builder.Environment.ContentRootFileProvider);
Composing Providers
The ComposeProviders
method combines a list of IFileProvider
instances into a single IFileProvider
.
During this process, all encountered CompositeFileProvider
instances recursively flattened and merged into a single level.
This eliminates unnecessary indirectness and streamline the file provider hierarchy.
string packagesPath = Path.Combine(environment.ContentRootPath, "../Packages");
string themesPath = Path.Combine(environment.ContentRootPath, "../Themes");
environment.ContentRootFileProvider = FileProviderComposer.ComposeProviders(
// Inject external Modules directory
new PrefixedFileProvider("/Packages", new PhysicalFileProvider(packagesPath)),
// Inject external Themes directory
new PrefixedFileProvider("/Themes", new PhysicalFileProvider(themesPath)),
// Current provider
environment.ContentRootFileProvider);
In this example, the ComposeProviders
method handles any unnecessary nesting that might occur, including when the current
environment.ContentRootFileProvider
is a CompositeFileProvider
. This ensures that all file providers merged into a single
flat structure, avoiding unnecessary indirectness.
Related Packages
- Ramstack.FileProviders — Additional file providers.
- Ramstack.FileProviders.Globbing — Wraps the file provider, filtering files using glob patterns.
- Ramstack.FileProviders.Extensions — Useful and convenient extensions for
IFileProvider
.
Supported versions
Version | |
---|---|
.NET | 6, 7, 8 |
Contributions
Bug reports and contributions are welcome.
License
This package is released as open source under the MIT License. See the LICENSE file for more details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.FileProviders.Abstractions (>= 6.0.0)
- Microsoft.Extensions.FileProviders.Composite (>= 6.0.0)
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 |
---|---|---|
2.2.1 | 130 | 9/14/2024 |
2.2.0 | 95 | 9/14/2024 |
2.1.0 | 108 | 8/28/2024 |
2.1.0-preview.3 | 52 | 8/27/2024 |