ByteGuard.FileValidator.Extensions.DependencyInjection 10.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package ByteGuard.FileValidator.Extensions.DependencyInjection --version 10.0.0
                    
NuGet\Install-Package ByteGuard.FileValidator.Extensions.DependencyInjection -Version 10.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="ByteGuard.FileValidator.Extensions.DependencyInjection" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ByteGuard.FileValidator.Extensions.DependencyInjection" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ByteGuard.FileValidator.Extensions.DependencyInjection" />
                    
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 ByteGuard.FileValidator.Extensions.DependencyInjection --version 10.0.0
                    
#r "nuget: ByteGuard.FileValidator.Extensions.DependencyInjection, 10.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 ByteGuard.FileValidator.Extensions.DependencyInjection@10.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=ByteGuard.FileValidator.Extensions.DependencyInjection&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ByteGuard.FileValidator.Extensions.DependencyInjection&version=10.0.0
                    
Install as a Cake Tool

ByteGuard.FileValidator.Extensions.DependencyInjection NuGet Version

ByteGuard.FileValidator.Extensions.DependencyInjection provides first-class integration of ByteGuard.FileValidator with Microsoft.Extensions.DependencyInjection.

It gives you:

  • Extension methods to register the file validator in the DI container
  • Easy configuration via appsettings.json or fluent configuration in code

This package is the Microsoft.Extensions.DependencyInjection integration layer. The core validation logic lives in ByteGuard.FileValidator.

Getting Started

Installation

This package is published and installed via NuGet.

Reference the package in your project:

dotnet add package ByteGuard.FileValidator.Extensions.DependencyInjection

Usage

Add to DI container

In your Program.cs (or Startup.cs in older projects), register the validator:

using ByteGuard.FileValidator;
using ByteGuard.FileValidator.Extensions.DependencyInjection;

// Using inline configuration
builder.Services.AddFileValidator(options => 
{
    options.AllowFileTypes(FileExtensions.Pdf, FileExtensions.Jpg, FileExtensions.Png);
    options.FileSizeLimit = ByteSize.MegaBytes(25);
    options.ThrowOnInvalidFiles(false);
});

// Using configuration from appsettings.json
builder.Services.AddFileValidator(options => configuration.GetSection("FileValidatorConfiguration").Bind(options));

Injection & Usage

You can then inject FileValidator into your services and other classes.

public class MyService
{
    private readonly FileValidator _fileValidator;

    public MyService(FileValidator fileValidator)
    {
        _fileValidator = fileValidator;
    }

    public bool SaveFile(Stream fileStream, string fileName)
    {
        var isValid = _fileValidator.IsValidFile(fileName, fileStream);
        
        // ...
    }
}

Configuration via appsettings

It's possible to configure the FileValidator through appsettings.json.

ℹ️ As you'll notice below, you can either define the FileSizeLimit in raw byte size, or use the UnitFileSizeLimit to define the file size in a more human readable format. When both are defined, FileSizeLimit always wins over UnitFileSizeLimit.

{
  "FileValidatorConfiguration": {
    "SupportedFileTypes": [ ".pdf", ".jpg", ".png" ],
    "FileSizeLimit": 26214400,
    "UnitFileSizeLimit": "25MB",
    "ThrowExceptionOnInvalidFile": true
  }
}

License

ByteGuard.FileValidator.Extensions.DpendencyInjection is Copyright © ByteGuard Contributors - Provided under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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

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
10.1.0 564 12/1/2025
10.0.0 108 11/29/2025
10.0.0-dev-01003 103 11/29/2025
10.0.0-dev-01002 104 11/29/2025