Omnia.FileAzure
9.0.3
dotnet add package Omnia.FileAzure --version 9.0.3
NuGet\Install-Package Omnia.FileAzure -Version 9.0.3
<PackageReference Include="Omnia.FileAzure" Version="9.0.3" />
<PackageVersion Include="Omnia.FileAzure" Version="9.0.3" />
<PackageReference Include="Omnia.FileAzure" />
paket add Omnia.FileAzure --version 9.0.3
#r "nuget: Omnia.FileAzure, 9.0.3"
#:package Omnia.FileAzure@9.0.3
#addin nuget:?package=Omnia.FileAzure&version=9.0.3
#tool nuget:?package=Omnia.FileAzure&version=9.0.3
Omnia.FileAzure — API Reference
Questo file documenta le API pubbliche esposte dal progetto Omnia.FileAzure. Contiene i namespace, le interfacce e le classi principali, con la descrizione dei metodi pubblici e esempi d'uso.
Namespaces
Omnia.FileAzure.Interfaces— interfacce pubbliche per i servizi di file/Blob.Omnia.FileAzure.Implementations— implementazioni concrete fornite dal package.
Interfacce (namespace Omnia.FileAzure.Interfaces)
IBlobConfig- Proprietà:
string ConnectionString { get; }— connection string per Azure Storage.string ContainerName { get; }— nome del container blob da usare.
- Proprietà:
IPrivateFile<IdFile>- Metodi:
Task<string> UploadFileAsync(IFormFile file)- Carica
filesu blob storage e restituisce l'id/nome del blob caricato.
- Carica
Task<Stream> GetFileAsync(IdFile id)- Scarica il blob identificato da
ide restituisce unoStreamcon i dati.
- Scarica il blob identificato da
Task DeleteFileAsync(IdFile id)- Elimina il blob identificato da
id.
- Elimina il blob identificato da
- Metodi:
IFileRepository<IdFile>:IPrivateFile<IdFile>— repository che implementa l'accesso diretto allo storage.IFileService<IdFile>:IPrivateFile<IdFile>— servizio che incapsula la logica attorno al repository.IFileUpperService<IdFile>:IFileService<IdFile>— upper service che aggiunge hook before/after.IFileBeforeService<in IdFile>- Metodi (default no-op):
Task UploadFileAsync(IFormFile file)— chiamato prima dell'upload principale.Task GetFileAsync(IdFile id)— chiamato prima del get.Task DeleteFileAsync(IdFile id)— chiamato prima della delete.
- Metodi (default no-op):
IFileAfterService<in IdFile>- Metodi (default no-op):
Task UploadFileAsync(IFormFile file, IdFile idFile)— chiamato dopo l'upload principale e riceve l'id risultato.Task AfterGetFileAsync(IdFile id, Stream file)— chiamato dopo il get con lo stream restituito.Task AfterDeleteFileAsync(IdFile id)— chiamato dopo la delete.
- Metodi (default no-op):
Implementazioni (namespace Omnia.FileAzure.Implementations)
BlobConfig : IBlobConfig- Costruttore:
BlobConfig(IConfiguration configuration)- Legge
Blob:ConnectionStringeBlob:ContainerNamedaIConfiguration.
- Legge
- Proprietà:
ConnectionString— ritorna la connection string ostring.Emptyse non presente.ContainerName— ritorna il container name ostring.Emptyse non presente.
- Costruttore:
BlobRepository : IFileRepository<string>- Costruttore:
BlobRepository(IBlobConfig blobConfig)- Crea
BlobServiceClientconblobConfig.ConnectionStringeBlobContainerClientperblobConfig.ContainerName.
- Crea
- Metodi pubblici:
Task<string> UploadFileAsync(IFormFile file)- Genera un nome univoco per il blob (
FormFileID.CreateUniqueBlobNameAsync(file)), effettuaUploadAsynce restituisce il blob name.
- Genera un nome univoco per il blob (
Task<Stream> GetFileAsync(string blobName)- Recupera
BlobClient, chiamaDownloadAsync()e ritornadownloadInfo.Value.Content.
- Recupera
Task DeleteFileAsync(string blobName)- Recupera
BlobCliente chiamaDeleteIfExistsAsync().
- Recupera
- Costruttore:
BlobService : IFileService<string>- Costruttore:
BlobService(IFileRepository<string> repository) - Metodi:
Task<string> UploadFileAsync(IFormFile file)— delega arepository.UploadFileAsync.Task<Stream> GetFileAsync(string blobName)— delega arepository.GetFileAsync.Task DeleteFileAsync(string blobName)— delega arepository.DeleteFileAsync.
- Costruttore:
BlobUpperService : IFileUpperService<string>- Costruttore:
BlobUpperService(IFileService<string> service, IFileBeforeService<string> beforeService, IFileAfterService<string> afterService) - Comportamento:
UploadFileAsync(IFormFile file)- chiama
_beforeService.UploadFileAsync(file), poi_service.UploadFileAsync(file)e_afterService.UploadFileAsync(file, idFile).
- chiama
GetFileAsync(string blobName)- chiama
_beforeService.GetFileAsync(blobName),_service.GetFileAsync(blobName)e_afterService.AfterGetFileAsync(blobName, file).
- chiama
DeleteFileAsync(string blobName)- chiama
_beforeService.DeleteFileAsync(blobName),_service.DeleteFileAsync(blobName)e_afterService.AfterDeleteFileAsync(blobName).
- chiama
- Costruttore:
ServiceCollectionExtensions(static class)- Metodi di estensione:
IServiceCollection AddFileAzure(this IServiceCollection services, IConfiguration configuration, bool addDummies = true)- Registra
IBlobConfigcomenew BlobConfig(configuration)e i servizi/repository (BlobRepository,BlobService,BlobUpperService). SeaddDummiesè true, registra le implementazioni dummy perIFileBeforeServiceeIFileAfterService.
- Registra
IServiceCollection AddFileAzure(this IServiceCollection services, string connectionString, string containerName, bool addDummies = true)- Overload (non consigliato se hai già
IConfiguration): registraIBlobConfig(con valori passati) e gli altri servizi.
- Overload (non consigliato se hai già
- Metodi di estensione:
Esempi d'uso
- Registrazione preferita (legge da
IConfiguration):
using Omnia.FileAzure.Implementations;
var builder = WebApplication.CreateBuilder(args);
// Registra tutto leggendo da appsettings / environment
builder.Services.AddFileAzure(builder.Configuration);
var app = builder.Build();
- Registrazione esplicita (valori forniti):
builder.Services.AddFileAzure("UseDevelopmentStorage=true", "my-container");
Note operative
BlobConfiglegge i valori daBlob:ConnectionStringeBlob:ContainerNameinIConfiguration.- Le eccezioni del client Azure (
Azure.RequestFailedException) vengono propagate: gestiscile nel tuo codice chiamante. - Le implementazioni
Before/Aftersono opzionali: il pacchetto fornisce no-op dummy se non registri implementazioni custom.
Se vuoi, posso generare una sezione aggiuntiva che mostra esempi completi di appsettings.json, test di integrazione e un piccolo snippet per utilizzare il package in un'app console.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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. |
-
net9.0
- Azure.Storage.Blobs (>= 12.25.0)
- Microsoft.AspNetCore.Http (>= 2.3.0)
- Omnia.Utility (>= 9.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.