Skip to content

Commit cf1f9cf

Browse files
author
ChristianHaase
committed
feat: add readme and prepare for initial release
1 parent 4f65e09 commit cf1f9cf

File tree

3 files changed

+82
-2
lines changed

3 files changed

+82
-2
lines changed

ByteGuard.FileValidator.Extensions.DependencyInjection.slnx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<File Path="Directory.Build.props" />
55
<File Path="Directory.Version.props" />
66
<File Path="LICENSE" />
7-
<File Path="README.md" />
87
</Folder>
98
<Folder Name="/tests/">
109
<Project Path="tests/FileValidator.Extensions.DependencyInjection.Tests.Unit/FileValidator.Extensions.DependencyInjection.Tests.Unit.csproj" />

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
11
# ByteGuard.FileValidator.Extensions.DependencyInjection ![NuGet Version](https://img.shields.io/nuget/v/ByteGuard.FileValidator.Extensions.DependencyInjection)
22

3+
`ByteGuard.FileValidator.Extensions.DependencyInjection` provides first-class integration of `ByteGuard.FileValidator` with `Microsoft.Extensions.DependencyInjection`.
4+
5+
It gives you:
6+
- Extension methods to register the file validator in the DI container
7+
- Easy configuration via appsettings.json or fluent configuration in code
8+
9+
> This package is the `Microsoft.Extensions.DependencyInjection` integration layer.
10+
> The core validation logic lives in [`ByteGuard.FileValidator`](https://github.com/ByteGuard-HQ/byteguard-file-validator-net).
11+
12+
## Getting Started
13+
14+
### Installation
15+
This package is published and installed via NuGet.
16+
17+
Reference the package in your project:
18+
```bash
19+
dotnet add package ByteGuard.FileValidator.Extensions.DependencyInjection
20+
```
21+
22+
## Usage
23+
24+
### Add to DI container
25+
In your `Program.cs` (or `Startup.cs` in older projects), register the validator:
26+
27+
```csharp
28+
using ByteGuard.FileValidator;
29+
using ByteGuard.FileValidator.Extensions.DependencyInjection;
30+
31+
// Using inline configuration
32+
builder.Services.AddFileValidator(options =>
33+
{
34+
options.AllowFileTypes(FileExtensions.Pdf, FileExtensions.Jpg, FileExtensions.Png);
35+
options.FileSizeLimit = ByteSize.MegaBytes(25);
36+
options.ThrowOnInvalidFiles(false);
37+
});
38+
39+
// Using configuration from appsettings.json
40+
builder.Services.AddFileValidator(options => configuration.GetSection("FileValidatorConfiguration").Bind(options));
41+
```
42+
43+
### Injection & Usage
44+
You can then inject `FileValidator` into your services and other classes.
45+
46+
```csharp
47+
public class MyService
48+
{
49+
private readonly FileValidator _fileValidator;
50+
51+
public MyService(FileValidator fileValidator)
52+
{
53+
_fileValidator = fileValidator;
54+
}
55+
56+
public bool SaveFile(Stream fileStream, string fileName)
57+
{
58+
var isValid = _fileValidator.IsValidFile(fileName, fileStream);
59+
60+
// ...
61+
}
62+
}
63+
```
64+
65+
### Configuration via appsettings
66+
It's possible to configure the `FileValidator` through `appsettings.json`.
67+
68+
> _ℹ️ As you'll notice below, you can either define the `FileSizeLimit` in raw byte size, or use the `UnitFileSizeLimit` to define
69+
> the file size in a more human readable format. When both are defined, `FileSizeLimit` always wins over `UnitFileSizeLimit`._
70+
71+
```json
72+
{
73+
"FileValidatorConfiguration": {
74+
"SupportedFileTypes": [ ".pdf", ".jpg", ".png" ],
75+
"FileSizeLimit": 26214400,
76+
"UnitFileSizeLimit": "25MB",
77+
"ThrowExceptionOnInvalidFile": true
78+
}
79+
}
80+
```
81+
82+
## License
83+
_ByteGuard.FileValidator.Extensions.DpendencyInjection is Copyright © ByteGuard Contributors - Provided under the MIT license._

src/ByteGuard.FileValidator.Extensions.DependencyInjection/ByteGuard.FileValidator.Extensions.DependencyInjection.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
5-
<Authors>ByteGuard Contributors, detilium</Authors>
5+
<Authors>ByteGuard Contributors</Authors>
66
<Description>ByteGuard File Validator support for Microsoft.Extensions.DependencyInjection.</Description>
77
<PackageProjectUrl>https://github.com/ByteGuard-HQ/byteguard-file-validator-extensions-dependency-injection</PackageProjectUrl>
88
<RepositoryUrl>https://github.com/ByteGuard-HQ/byteguard-file-validator-extensions-dependency-injection</RepositoryUrl>

0 commit comments

Comments
 (0)