| Name | Message | Date |
|---|---|---|
| 📄 BlobStorageOptions.cs | 13 days ago | |
| 📄 BlobStorageService.cs | 13 days ago |
📄
MatDenDagen/Infrastructure/Storage/BlobStorage/BlobStorageOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System.IO; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace MatDenDagen.Infrastructure.Storage.BlobStorage; public sealed class BlobStorageOptions { public required string BlobDirectory { get; set; } } file sealed class BlobStorageOptionsValidator : IValidateOptions<BlobStorageOptions> { public ValidateOptionsResult Validate(string? name, BlobStorageOptions options) { var builder = new ValidateOptionsResultBuilder(); ValidateUploadsPath(name, options.BlobDirectory, builder); return builder.Build(); } private static void ValidateUploadsPath(string? name, string uploadsPath, ValidateOptionsResultBuilder builder) { string propertyName = string.IsNullOrEmpty(name) ? nameof(BlobStorageOptions.BlobDirectory) : $"{name}.{nameof(BlobStorageOptions.BlobDirectory)}"; if (string.IsNullOrWhiteSpace(uploadsPath)) { builder.AddError("Cannot be null or empty.", propertyName); return; } if (!Directory.Exists(uploadsPath)) { builder.AddError("Directory must exist.", propertyName); return; } } } public static class BlobStorageOptionsServiceExtensions { public static IServiceCollection AddBlobStorageOptions(this IServiceCollection services) { services.AddOptions<BlobStorageOptions>().BindConfiguration("Storage").ValidateOnStart(); services.AddTransient<IValidateOptions<BlobStorageOptions>, BlobStorageOptionsValidator>(); return services; } }