Ramstack.FileProviders.Composition
2.2.1
dotnet add package Ramstack.FileProviders.Composition --version 2.2.1
NuGet\Install-Package Ramstack.FileProviders.Composition -Version 2.2.1
<PackageReference Include="Ramstack.FileProviders.Composition" Version="2.2.1" />
paket add Ramstack.FileProviders.Composition --version 2.2.1
#r "nuget: Ramstack.FileProviders.Composition, 2.2.1"
// Install Ramstack.FileProviders.Composition as a Cake Addin #addin nuget:?package=Ramstack.FileProviders.Composition&version=2.2.1 // Install Ramstack.FileProviders.Composition as a Cake Tool #tool nuget:?package=Ramstack.FileProviders.Composition&version=2.2.1
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.Extensions — Useful and convenient extensions for
IFileProvider
, bringing its capabilities and experience closer to what's provided by theDirectoryInfo
andFileInfo
classes. - Ramstack.FileProviders — Additional file providers, including
ZipFileProvider
,PrefixedFileProvider
, andSubFileProvider
. - Ramstack.FileProviders.Globbing — A file provider that filters files using include and/or exclude glob patterns. Include patterns make only matching files visible, while exclude patterns hide specific files. Both include and exclude patterns can be combined for flexible file visibility control.
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 | 127 | 9/14/2024 |
2.2.0 | 92 | 9/14/2024 |
2.1.0 | 105 | 8/28/2024 |
2.1.0-preview.3 | 49 | 8/27/2024 |