Update to latest packages and show examples

This commit is contained in:
2026-07-05 22:05:53 +02:00
parent 3a36978997
commit c7ddc282ed
52 changed files with 2156 additions and 21 deletions
@@ -0,0 +1,27 @@
using GerstITS.Authentication.ApiKey;
using GerstITS.System.Configurations;
namespace GerstITS.Examples.Api.Configurations;
internal class ApiKeyConfiguration : IApiKeyConfiguration
{
#region Constructors
public ApiKeyConfiguration(string parentPrefix,
Microsoft.Extensions.Configuration.IConfiguration configuration)
{
var prefix = $"{parentPrefix}:{this.ToConfigurationPrefix()}";
Header = configuration.GetValue<string>($"{prefix}:{nameof(Header)}");
Key = configuration.GetValue<string>($"{prefix}:{nameof(Key)}");
}
#endregion
#region IApiKeyConfiguration
public string Header { get; }
public string Key { get; }
#endregion
}
@@ -0,0 +1,46 @@
using System.Net;
using GerstITS.Web.Api.ExceptionHandling;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http.Features;
namespace GerstITS.Examples.Api.ExceptionHandling;
internal static class WebApplicationExtensions
{
internal static WebApplication UseGlobalExceptionHandling(this WebApplication app)
{
app.UseExceptionHandler(exceptionHandlerApp =>
{
exceptionHandlerApp.Run(async context =>
{
var exceptionFeature = context.Features.Get<IExceptionHandlerFeature>();
if (exceptionFeature is null) return;
var exception = exceptionFeature.Error;
var ticketId = Guid.NewGuid().ToString();
context.RequestServices
.GetRequiredService<ILoggerFactory>()
.CreateLogger("GlobalExceptionHandler")
.LogError($"Global exception occurs (TicketId {ticketId}).{Environment.NewLine}{exception}");
var transformation = context.RequestServices
.GetServices<IExceptionTransformation>()
.FirstOrDefault(x => x.CanTransform(exception));
var info = transformation?.Transform(exception, ticketId) ?? new ExceptionTransformationInfo
{
StatusCode = HttpStatusCode.InternalServerError,
ReasonPhrase = "Internal Server Error.",
Details = $"An internal error occurs. Please contact support with ticket id '{ticketId}'."
};
context.Response.StatusCode = (int)info.StatusCode;
context.Features.Get<IHttpResponseFeature>().ReasonPhrase = info.ReasonPhrase;
await context.Response.WriteAsync(info.Details ?? string.Empty);
});
});
return app;
}
}