/dknet-skills:dknet-blob-storagefrom dknet-skills
Covers DKNet.Svc.BlobStorage.Abstractions and its three providers (Local, AWS S3, Azure Storage) for uploading, downloading, listing, and deleting blobs with DI wiring, URL generation, and debugging common exceptions.
Ships in dknet-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
This skill teaches the IBlobService contract and its three provider packages: how to register one, save/read/
list/delete blobs, generate public URLs, and avoid the traps that differ across Local, S3, and Azure. Open
references/<PackageId>.md for full member tables, runtime behaviour, and testing notes per package.
| Package | Install | What it gives you | Depends on | Reference |
|---|---|---|---|---|
DKNet.Svc.BlobStorage.Abstractions | dotnet add package DKNet.Svc.BlobStorage.Abstractions | IBlobService, BlobService base class, BlobRequest/BlobDetails.* records, BlobServiceOptions | none | reference |
DKNet.Svc.BlobStorage.Local | dotnet add package DKNet.Svc.BlobStorage.Local | AddLocalDirectoryBlobService — filesystem-backed IBlobService with path-traversal protection | Abstractions | reference |
DKNet.Svc.BlobStorage.AwsS3 | dotnet add package DKNet.Svc.BlobStorage.AwsS3 | AddS3BlobService — IBlobService over AWS S3, MinIO, or Cloudflare R2 | Abstractions | reference |
DKNet.Svc.BlobStorage.AzureStorage | dotnet add package DKNet.Svc.BlobStorage.AzureStorage | AddAzureStorageAdapter — IBlobService over Azure Blob Storage, managed identity + SAS URLs | Abstractions | reference |
using DKNet.Svc.BlobStorage.Abstractions;
using System.Threading;
var builder = WebApplication.CreateBuilder(args);
// appsettings.json: { "BlobStorage": { "LocalFolder": { "RootFolder": "/var/app/storage" } } }
builder.Services.AddLocalDirectoryBlobService(builder.Configuration);
var app = builder.Build();
app.MapPost("/files/{name}", async (string name, IBlobService blobService, HttpRequest request, CancellationToken ct) =>
{
var data = await BinaryData.FromStreamAsync(request.Body, ct);
var location = await blobService.SaveAsync(new BlobDetails.BlobData(name, data) { Overwrite = true }, ct);
return Results.Ok(location);
});
app.Run();
Swap AddLocalDirectoryBlobService for AddS3BlobService or AddAzureStorageAdapter to target S3-compatible
storage or Azure Blob Storage — application code above the DI registration line never changes.
IBlobService (from DKNet.Svc.BlobStorage.Abstractions) everywhere in application code. Never
reference LocalBlobService, S3BlobService, or AzureStorageBlobService directly — each provider registers
only the interface, so GetRequiredService<S3BlobService>()-style resolution throws.AddLocalDirectoryBlobService,
AddS3BlobService, or AddAzureStorageAdapter. Registering more than one does not error — the last
registration wins whenever IBlobService is resolved as a single instance.using DKNet.Svc.BlobStorage.AwsS3; is required to call AddS3BlobService — its S3Setup class sits in a
normal namespace, unlike AddLocalDirectoryBlobService and AddAzureStorageAdapter, which are declared ambient
under Microsoft.Extensions.DependencyInjection and need no extra using to call (their option types still
do: LocalDirectoryOptions, AzureStorageOptions).GetAsync's "missing blob" signal differs per provider: Local throws FileNotFoundException; S3 and Azure
both return null. CheckExistsAsync returns false on every provider — prefer it when only presence
matters.Overwrite on BlobData/BlobStreamData defaults to false. Local and S3 throw InvalidOperationException
on a duplicate save without it; Azure instead lets the SDK's RequestFailedException (409, "BlobAlreadyExists")
surface unwrapped.MaxFileSizeInMb, MaxFileNameLength, and IncludedExtensions all default to disabled (0/0/[]) — there
is no built-in cap unless you set one, and the size math is decimal MB (* 1_000_000), not binary MiB.BlobRequest.Type default to BlobTypes.Directory — a bare name
like "reports" needs no extra flag to be treated as a folder, but a genuinely extension-less file needs
Type = BlobTypes.File set explicitly, or a delete against it becomes a recursive folder delete...-string path-traversal check around the Local provider — its GetFinalPath guard already
resolves and normalizes every request and throws UnauthorizedAccessException outside RootFolder.BlobServiceClientFactory via services.Configure<AzureStorageOptions>(...) in code, never
through the Action<AzureStorageOptions> overload of AddAzureStorageAdapter — that overload's values never
reach the resolved IOptions<AzureStorageOptions> (see Gotchas).When: writing or replacing a file by name.
using DKNet.Svc.BlobStorage.Abstractions;
using System.Threading;
var services = new ServiceCollection();
services.AddLocalDirectoryBlobService(new ConfigurationBuilder().Build());
var blobService = services.BuildServiceProvider().GetRequiredService<IBlobService>();
var draft = new BlobDetails.BlobData("reports/2026/q1.pdf", BinaryData.FromString("first draft"));
await blobService.SaveAsync(draft, CancellationToken.None);
var final = new BlobDetails.BlobData("reports/2026/q1.pdf", BinaryData.FromString("final")) { Overwrite = true };
await blobService.SaveAsync(final, CancellationToken.None);
Notes: a second save without Overwrite = true throws on Local/S3 (InvalidOperationException); Azure surfaces
the SDK's 409 instead.
When: code must run against any of the three providers without crashing on a miss.
using DKNet.Svc.BlobStorage.Abstractions;
using System.IO;
using System.Threading;
var services = new ServiceCollection();
services.AddLocalDirectoryBlobService(new ConfigurationBuilder().Build());
var blobService = services.BuildServiceProvider().GetRequiredService<IBlobService>();
async Task<BinaryData?> TryReadAsync(IBlobService service, string name, CancellationToken ct)
{
try
{
var result = await service.GetAsync(new BlobRequest(name), ct);
return result?.Data; // S3 and Azure both return null here instead of throwing
}
catch (FileNotFoundException)
{
return null; // Local-only signal for a missing blob
}
}
var content = await TryReadAsync(blobService, "reports/2026/q1.pdf", CancellationToken.None);
Notes: CheckExistsAsync returns false on every provider for a miss — prefer it when you only need presence,
not content.
When: enumerating a "folder" recursively.
using DKNet.Svc.BlobStorage.Abstractions;
using System.Threading;
var services = new ServiceCollection();
services.AddLocalDirectoryBlobService(new ConfigurationBuilder().Build());
var blobService = services.BuildServiceProvider().GetRequiredService<IBlobService>();
var fileNames = new List<string>();
await foreach (var item in blobService.ListItemsAsync(new BlobRequest("reports") { Type = BlobTypes.Directory }, CancellationToken.None))
if (item.Type == BlobTypes.File)
fileNames.Add(item.Name);
Notes: S3 pages internally via ContinuationToken until every object is returned; Local performs one interleaved
filesystem walk. Do not assume "files, then directories" ordering on any provider.
When: the payload is big enough that materializing it as BinaryData first is wasteful.
using DKNet.Svc.BlobStorage.Abstractions;
using System.IO;
using System.Threading;
var services = new ServiceCollection();
services.AddLocalDirectoryBlobService(new ConfigurationBuilder().Build());
var blobService = services.BuildServiceProvider().GetRequiredService<IBlobService>();
await using var fileStream = File.OpenRead("large-export.csv");
var savedName = await blobService.SaveAsync(
new BlobDetails.BlobStreamData("exports/large-export.csv", fileStream) { Overwrite = true },
CancellationToken.None);
Notes: all three shipped providers override SaveAsync(BlobStreamData, ...) to write straight from the stream;
only a hand-rolled IBlobService/BlobService subclass that skips that override falls back to the buffering
default.
When: sharing a private blob without handing out credentials. Not supported on Local.
using DKNet.Svc.BlobStorage.Abstractions;
using DKNet.Svc.BlobStorage.AzureStorage;
using System.Threading;
var services = new ServiceCollection();
services.AddAzureStorageAdapter(new ConfigurationBuilder().Build());
services.Configure<AzureStorageOptions>(o =>
{
o.ConnectionString = "UseDevelopmentStorage=true";
o.ContainerName = "documents";
});
var blobService = services.BuildServiceProvider().GetRequiredService<IBlobService>();
var url = await blobService.GetPublicAccessUrl(
new BlobRequest("reports/monthly.pdf"),
TimeSpan.FromMinutes(15),
CancellationToken.None);
Notes: S3's GetPublicAccessUrl returns a pre-signed URL the same way. Azure throws NotSupportedException for
a managed-identity (token-credential) client — SAS needs an account-key/connection-string client. Local always
throws NotSupportedException.
When: an S3-compatible endpoint instead of real AWS.
using DKNet.Svc.BlobStorage.Abstractions;
using DKNet.Svc.BlobStorage.AwsS3;
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
["BlobService:S3:ConnectionString"] = "http://localhost:9000",
["BlobService:S3:BucketName"] = "app-documents",
["BlobService:S3:AccessKey"] = "minioadmin",
["BlobService:S3:Secret"] = "minioadmin",
["BlobService:S3:ForcePathStyle"] = "true"
})
.Build();
var services = new ServiceCollection();
services.AddS3BlobService(configuration);
var blobService = services.BuildServiceProvider().GetRequiredService<IBlobService>();
Notes: ForcePathStyle = true is required for MinIO and most S3-compatible services. For Cloudflare R2 also set
DisablePayloadSigning = true. RegionEndpointName has no effect either way — encode a region, if any, into
ConnectionString.
When: no account key/connection string is allowed.
using Azure.Core;
using Azure.Storage.Blobs;
using DKNet.Svc.BlobStorage.Abstractions;
using DKNet.Svc.BlobStorage.AzureStorage;
// credential: pass in `new Azure.Identity.DefaultAzureCredential()` from the composition root.
public sealed class ManagedIdentityBlobSetup(TokenCredential credential)
{
public IBlobService Build()
{
var services = new ServiceCollection();
services.AddAzureStorageAdapter(new ConfigurationBuilder().Build()); // binds ContainerName, etc.
services.Configure<AzureStorageOptions>(o =>
{
o.ContainerName = "documents";
o.BlobServiceClientFactory = _ => Task.FromResult(
new BlobServiceClient(new Uri("https://myaccount.blob.core.windows.net"), credential));
});
return services.BuildServiceProvider().GetRequiredService<IBlobService>();
}
}
Notes: use the IConfiguration overload of AddAzureStorageAdapter plus Configure<AzureStorageOptions>, not
the Action<AzureStorageOptions> overload — that overload's values never reach the resolved options. A
managed-identity client generally cannot sign SAS URLs. DKNet.Svc.BlobStorage.AzureStorage's own .csproj does
not reference Azure.Identity — but don't add it yourself either: Azure.Storage.Blobs already pulls in an
Azure.Core version that re-exports the whole Azure.Identity credential surface (DefaultAzureCredential
included) under that same namespace, so using Azure.Identity; plus new DefaultAzureCredential() at the call
site (the TokenCredential credential passed into ManagedIdentityBlobSetup above) already resolves it, no
extra package needed. Explicitly adding the standalone Azure.Identity package on top gives you two same-named
DefaultAzureCredential types and fails the build with error CS0433: The type 'DefaultAzureCredential' exists in both 'Azure.Core...' and 'Azure.Identity...'.
When: unit/integration-testing application code that only needs some IBlobService, not S3/Azure-specific
behavior.
using DKNet.Svc.BlobStorage.Abstractions;
using System.IO;
public sealed class BlobFixture : IDisposable
{
public BlobFixture()
{
TestRoot = Path.Combine(Path.GetTempPath(), "test-blobs-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(TestRoot);
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string?>
{
["BlobStorage:LocalFolder:RootFolder"] = TestRoot
})
.Build();
Service = new ServiceCollection()
.AddLogging()
.AddLocalDirectoryBlobService(config)
.BuildServiceProvider()
.GetRequiredService<IBlobService>();
}
public IBlobService Service { get; }
public string TestRoot { get; }
public void Dispose()
{
if (Directory.Exists(TestRoot)) Directory.Delete(TestRoot, true);
}
}
Notes: reach for Azurite/MinIO containers (see the provider reference pages' Testing notes) only when the test needs to verify S3- or Azure-specific behavior; Local's filesystem backing is faster and needs no Docker for everything else.
Every save funnels through the same shape regardless of provider: ValidateFile (name/extension/size, shared
from Abstractions) → GetBlobLocation (path/key normalization) → the provider's own SDK write. The native client
each cloud provider needs (AmazonS3Client, BlobContainerClient) is built lazily on the first call after
registration and cached for the life of the resolved IBlobService instance — so the first call after startup
pays a real network/bucket-or-container-ensure round trip on S3 and Azure; Local pays nothing extra since it has
no client to build.
S3Options.RegionEndpointName is inert — building the S3 client never reads it. Encode the region into
ConnectionString instead.BucketName typo silently creates a new empty bucket rather than
failing — double-check BucketName before deploying.DeleteObjectAsync per key, not a batch call (this SDK version's batch API needs a
Content-MD5 header that MinIO rejects). Expect O(n) round trips deleting a very large prefix against real AWS
S3.RootFolder defaults to {CurrentDirectory}/LocalStore when unset — that directory differs
between dotnet run, a published binary, and a container. Always set RootFolder explicitly outside a quick
local run.ListItemsAsync's Details.ContentType on S3 is always "". Call GetAsync for the real content type;
don't trust the listing for it.SizeLimitedStream (the non-seekable-stream size guard used internally) is read-only and forward-only —
Seek/SetLength/Write/Length/Position all throw NotSupportedException. Only sequential
Read/ReadAsync works on a stream handed back from ValidateFile(BlobStreamData).IBlobService's own default interface members for OpenReadAsync/SaveAsync(BlobStreamData, ...) still
fully buffer the payload. Only a provider that overrides them (all three shipped providers do) avoids that —
a hand-rolled provider that skips the override gets no memory benefit from calling them.IBlobService.SaveAsync(byte[] data, ...) — no such overload exists. Wrap arrays with BinaryData.FromBytes(...).IBlobServiceFactory, or any provider registry/selector type — does not exist. DI registration order ("the
last registration wins") is the only selection mechanism.S3Options.Region / S3Options.RegionEndpoint — the real (inert) property is RegionEndpointName.AddLocalBlobService, AddLocalBlobStorage, UseLocalBlobStorage — the real method is
AddLocalDirectoryBlobService.LocalBlobServiceOptions / LocalStorageOptions — the real type is LocalDirectoryOptions.AzureStorageOptions.UseManagedIdentity — no such flag. Managed identity is expressed only by setting
BlobServiceClientFactory and leaving ConnectionString unset.GetRequiredService<S3BlobService>() / <AzureStorageBlobService>() / <LocalBlobService>() — only
IBlobService is registered; resolving a concrete provider type throws InvalidOperationException unless you
registered it yourself.new AmazonS3Client(...) handed into S3BlobService — there is no constructor overload that accepts a
pre-built client.S3Options.MaxKeys or any page-size option — pagination is automatic and internal, not caller-tunable.dknet-packages — start there to confirm blob storage is the right package family before wiring DI.dknet-efcore-domain-model — for the aggregate/entity that stores a blob's returned location string as a plain
property.dknet-efcore-specifications — for querying/persisting entities that reference a blob location; IBlobService
itself never appears in a specification.dknet-efcore-save-pipeline — to raise a domain event after SaveAsync returns a location, rather than
calling IBlobService from inside a SaveChanges interceptor.dknet-efcore-data-security — for encrypting/row-securing the entity that references a blob, not the blob
bytes themselves (that's dknet-services).dknet-codegen — unrelated to blob storage; route here only for [CrudAction]/[GenerateDto] questions.dknet-slimbus-cqrs — for the command/handler that calls IBlobService as part of a CQRS vertical slice.dknet-aspcore-api — for minimal-API endpoint conventions around the upload/download endpoint itself, not the
storage call.dknet-idempotency — for making a repeated upload request safe to retry; blob storage's own Overwrite flag
is not idempotency.dknet-services — for encrypting blob bytes before SaveAsync, or generating a PDF to then store via
IBlobService.dknet-core-utilities — for a random file-name/key generator to hand to SaveAsync; not blob-storage-specific
itself.dknet-testing — for TestContainers fixture conventions (Azurite/MinIO) beyond what this skill's reference
pages already cover, and for testing inside the DKNet repo itself.IBlobService contract, BlobService base class, request/result records, shared validation options, and how
to write your own provider.S3BlobService/
S3Options, MinIO/R2 endpoint configuration, pagination, and folder-delete mechanics.AzureStorageBlobService/AzureStorageOptions, managed identity, SAS URLs, and the folder-marker heuristic.LocalBlobService/
LocalDirectoryOptions, the path-traversal guard, and the no-Docker testing fixture pattern.AwsS3,
AzureStorage, or Local)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub baoduy/dknet --plugin dknet-skills13 skills in this plugin
/dknet-aspcore-apiCovers DKNet.AspCore.Extensions and DKNet.AspCore.Tasks. Use when writing an IEndpointConfig group, calling UseEndpointConfigs for minimal-API endpoint discovery and DKNet API versioning, mapping verbs with MapGet/MapPost/MapPut/MapPatch/MapDelete/MapPutById/MapActionById/MapParameterlessActionById, building a generic list endpoint with MapGetList/MapGetById/MapDeleteById plus PagedResponse and ListFilter, converting a FluentResults Result to ProblemDetails via .Response()/.Response<T>() or AddErrorResponses, scoping authorization per verb with [EndpointGroupScope], populating [FromClaim]/[FromRequestHeader] members via AddContextualRequestPopulation, or registering IBackgroundTask with AddBackgroundJob/AddBackgroundJobFrom to run work once at host start-up./dknet-codegenCovers DKNet.EfCore.DtoGenerator's [GenerateDto(typeof(Entity))] generator (Include/Exclude/IgnoreComplexType, DtoGeneratorExclusions, DtoGeneratorIgnoreComplexType, DKDTOGEN001-005) plus its RaisesEventValidator for [RaisesEvent] (DKRAISEVT001-011); and DKNet.SlimBus.Generators' CrudGenerator, turning [CrudCreate]/[CrudUpdate]/[CrudAction] (DKNet.EfCore.Abstractions.Attributes) into request records, IHandler<,> implementations and Map{Entity}Crud endpoints (DKCRUDGEN001-010). Use when a source generator is not generating, a build reports a duplicate type generated, a generated request/handler/endpoint is missing, EmitCompilerGeneratedFiles is needed for .g.cs output, or before hand-writing what an attribute already emits. Also clarifies [FromClaim] is not a generator — it's runtime model binding in DKNet.AspCore.Extensions.ModelBinding (see dknet-aspcore-api)./dknet-core-utilitiesCovers DKNet.Fw.Extensions and DKNet.RandomCreator, the two dependency-light Core packages DKNet builds on. Fw.Extensions gives GetPropertyValue/SetPropertyValue/TrySetPropertyValue by dotted property path, IsImplementOf for open-generic type checks, TryConvertToEnum, enum [Display] attribute name lookup via GetEnumInfos<T>(), IsRegistered<T>()/IsRegisteredWithImplementation<T>() DI guards on IServiceCollection, and the lazy TypeExtractors assembly scanner to scan assemblies for types, e.g. Extract().Abstract().Publics() or Extract().Classes().NotAbstract().IsInstanceOf<T>(). RandomCreator gives RandomCreators.NewString/NewChars, a CSPRNG-only generator with StringCreatorOptions MinNumbers/MinSpecials exact quotas, to generate a secure password, token, or one-time code. Use when reading or writing object fields by name, checking an open-generic implementation, guarding a duplicate DI registration, converting a loose value to an enum, or generating a secure random string./dknet-efcore-data-securityCovers DKNet.EfCore.DataAuthorization and DKNet.EfCore.Encryption. DataAuthorization gives a multi-tenant row filter over IOwnedBy entities via IDataOwnerProvider and IDataOwnerDbContext.AccessibleKeys, wired with AddDataOwnerProvider<TDbContext,TProvider>; the global query filter fails closed (empty AccessibleKeys denies, not allows) and a SaveChanges hook stamps OwnedBy. Encryption encrypts a column transparently by marking a string property [Encrypted], registering AddEfCoreEncryption<TKeyProvider> plus an IEncryptionKeyProvider, then calling modelBuilder.UseColumnEncryption — a ValueConverter encryption pipeline producing an AES-GCM column with a random IV per write. Use this for tenant isolation EF Core wiring, rows leaking across tenants, an InvalidOperationException from UseColumnEncryption or DataOwnerAuthQuery, or key-rotation and IColumnEncryptionProvider questions./dknet-efcore-domain-modelCovers DKNet.EfCore.Abstractions, DKNet.EfCore.Extensions and DKNet.EfCore.Relational.Helpers: Entity<TKey>/Entity/AuditedEntity base classes, IConcurrencyEntity/ISoftDeletableEntity, GUID v7 keys, and the [RaisesEvent] declaration, [Sequence]/[SqlSequence], [AuditLog]/[SensitiveData] attributes; UseAutoConfigModel, IEntityTypeConfiguration discovery via DefaultEntityTypeConfiguration, global query filter (GlobalQueryFilter), data seeding, SQL sequences (NextSeqValue), SnapshotContext, SaveChangesWithConcurrencyHandlingAsync, role-aware [SensitiveData] JSON, and CreateTableAsync/TableExistsAsync for schema work outside migrations. Use when modeling an entity or aggregate, wiring DbContext model discovery, adding a concurrency token or soft delete, seeding reference data, generating sequence-backed codes, or provisioning a table without a migration./dknet-efcore-save-pipelineCovers DKNet.EfCore.Hooks, DKNet.EfCore.Events, and DKNet.EfCore.AuditLogs: the three SaveChangesAsync interceptors that stamp, dispatch, and audit around one EF Core write. APIs: AddDbContextWithHook, IBeforeSaveHookAsync/IAfterSaveHookAsync/IHookAsync/HookAsync, AddHook, DisableHooks, SnapshotContext (before/after SaveChanges hook, IHook wiring); AddEventPublisher, IEventPublisher, DefaultEventPublisher, AddEvent/AddEvent<TEvent>(), [RaisesEvent], EventOperations, EventException (domain events not firing); AddEfCoreAuditLogs, AddEfCoreAuditHook, AddCurrentUserProvider, ICurrentUserProvider, AuditLogEntry, AuditFieldChange, [SensitiveData], [IgnoreAuditLog], [AuditLog] (audit trail, redact sensitive fields). Use when wiring a SaveChanges hook, when events or the audit trail silently never fire, or EventException throws.Other plugins' skills for the same job