![]() |
VOOZH | about |
dotnet add package Omnia.Utility --version 10.0.1
NuGet\Install-Package Omnia.Utility -Version 10.0.1
<PackageReference Include="Omnia.Utility" Version="10.0.1" />
<PackageVersion Include="Omnia.Utility" Version="10.0.1" />Directory.Packages.props
<PackageReference Include="Omnia.Utility" />Project file
paket add Omnia.Utility --version 10.0.1
#r "nuget: Omnia.Utility, 10.0.1"
#:package Omnia.Utility@10.0.1
#addin nuget:?package=Omnia.Utility&version=10.0.1Install as a Cake Addin
#tool nuget:?package=Omnia.Utility&version=10.0.1Install as a Cake Tool
Libreria di utility comuni per il framework Omnia, che fornisce classi e helper per sviluppare applicazioni ASP.NET Core con funzionalità avanzate.
dotnet add package Omnia.Utility
using Omnia.Utility;
var builder = WebApplication.CreateBuilder(args);
// Aggiungi servizi Omnia
builder.Services.AddOmniaUtilities();
var app = builder.Build();
Il middleware centralizzato gestisce automaticamente tutte le eccezioni non gestite e le converte in risposte HTTP strutturate.
using Omnia.Utility.Extensions;
var app = builder.Build();
// Aggiungi il middleware per la gestione centralizzata delle eccezioni
// DEVE essere uno dei primi middleware nella pipeline
app.UseExceptionHandling();
// Altri middleware...
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
Il middleware mapba automaticamente le eccezioni ai seguenti codici HTTP:
| Eccezione | Codice HTTP | Descrizione |
|---|---|---|
KeyNotFoundException |
404 | Risorsa non trovata |
ArgumentNullException |
400 | Parametro obbligatorio mancante |
ArgumentException |
400 | Parametro non valido |
InvalidOperationException |
409 | Operazione non valida nello stato attuale |
UnauthorizedAccessException |
401 | Accesso non autorizzato |
TimeoutException |
408 | Timeout della richiesta |
OperationCanceledException |
400 | Operazione annullata |
| Tutte le altre | 500 | Errore interno del server |
Tutte le risposte di errore seguono questo formato:
{
"statusCode": 404,
"error": "Not Found",
"message": "Order PAYID-12345678 not found",
"timestamp": "2026-01-09T10:30:45.123Z",
"traceId": null
}
using PaymentPaypal.Interfaces;
[ApiController]
[Route("api/[controller]")]
public class OrdersController : ControllerBase
{
private readonly IPayPalOrderRepository _repository;
public OrdersController(IPayPalOrderRepository repository)
{
_repository = repository;
}
[HttpGet("{orderId}")]
public async Task<IActionResult> GetOrder(string orderId)
{
// Se orderId non esiste, il middleware catturerà KeyNotFoundException
// e ritornerà 404 automaticamente
var order = await _repository.GetOrderAsync(orderId);
return Ok(order);
}
[HttpPost("capture/{orderId}")]
public async Task<IActionResult> CaptureOrder(string orderId)
{
// Se lo stato non è APPROVED, sarà lanciata InvalidOperationException
// che il middleware converte in 409 Conflict
var result = await _repository.CaptureOrderAsync(orderId);
return Ok(result);
}
}
Il middleware registra automaticamente tutte le eccezioni non gestite usando ILogger<ExceptionHandlingMiddleware>. Puoi configurare il livello di logging nel appsettings.json:
{
"Logging": {
"LogLevel": {
"Omnia.Utility.ExceptionHandling": "Error"
}
}
}
public class MyController : ControllerBase
{
[HttpPost("upload")]
public async Task<IActionResult> Upload(IFormFile file)
{
var result = await FormFileUtility.ProcessFileAsync(file);
return Ok(result);
}
}
public async Task<PagedResult<Product>> GetProducts(PaginationRequest request)
{
return await _repository.GetPagedAsync(request);
}
// Configura JWT
builder.Services.AddJwtAuthentication(builder.Configuration);
// Nel controller
[Authorize]
public class SecureController : ControllerBase
{
// Endpoint sicuri
}
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Omnia.Utility;
[ApiController]
[Route("api/[controller]")]
public class ProductsController : StandardController<Product>
{
private readonly IProductService _service;
public ProductsController(IProductService service) : base(service)
{
_service = service;
}
[HttpGet("paged")]
public async Task<IActionResult> GetPaged([FromQuery] PaginationRequest request)
{
var result = await _service.GetPagedAsync(request);
return Ok(result);
}
[HttpPost("upload")]
[Authorize]
public async Task<IActionResult> UploadFile(IFormFile file)
{
var result = await FormFileUtility.ProcessFileAsync(file);
return Ok(result);
}
}
Questo progetto è distribuito sotto licenza LGPL-3.0-or-later.
Luca Gualandi - Sviluppatore del framework Omnia
Per supporto e domande, contatta il team di sviluppo o apri una issue nel repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 4 NuGet packages that depend on Omnia.Utility:
| Package | Downloads |
|---|---|
|
Omnia.PaymentStripe
ASP.NET Core library for Stripe integration: abstract base controllers for payments and customers requiring inheritance, webhook handling, customizable Before/After hooks, payment intents, subscriptions, and event processing. Includes StripeBase for consistent API key configuration. v1.3.3: Customer parameter now optional - supports anonymous payments. v1.3.2: Additional ServiceCollectionExtensions fixes. v1.3.1: Fixed namespace. v1.3.0: Fixed customer auto-creation, added AllowRedirects=never, 29/29 integration tests passing. |
|
|
Omnia.FileAzure
File storage helpers and Azure Blob repository used by Omnia components. |
|
|
Omnia.GenericImplementationEF
Implementazioni generiche per Entity Framework Core nel framework Omnia - Repository, AutoMapper, PredicateUtility e pattern avanzati |
|
|
Omnia.GenericImplementationEF.Core
Core provider-agnostico per Omnia GenericImplementationEF - Repository, AutoMapper, IPredicateBuilder, AuthInterceptor e pattern avanzati |
This package is not used by any popular GitHub repositories.