Common.API.Extensions.Lib 2.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Common.API.Extensions.Lib --version 2.2.1
                    
NuGet\Install-Package Common.API.Extensions.Lib -Version 2.2.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Common.API.Extensions.Lib" Version="2.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Common.API.Extensions.Lib" Version="2.2.1" />
                    
Directory.Packages.props
<PackageReference Include="Common.API.Extensions.Lib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Common.API.Extensions.Lib --version 2.2.1
                    
#r "nuget: Common.API.Extensions.Lib, 2.2.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Common.API.Extensions.Lib@2.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Common.API.Extensions.Lib&version=2.2.1
                    
Install as a Cake Addin
#tool nuget:?package=Common.API.Extensions.Lib&version=2.2.1
                    
Install as a Cake Tool

Common.API.Extensions for .NET 8

This project provides a set of extensions for .NET 8 applications, covering authentication, logging, security, and validation.

Features

  • Custom Authorization: Implements role-based access control with custom attributes.
  • Logging: Provides Serilog-based logging extensions.
  • Security: Includes middleware for XSS protection.
  • Utilities: Provides reusable token management services.
  • Validation: Implements custom DTO validation attributes.

Project Structure

Common.API.Extensions
├── CustomAuthorization
│   ├── Model
│   │   ├── Menu.cs
│   │   ├── Permission.cs
│   │   ├── SubMenu.cs
│   │   ├── UserAccessDetails.cs
│   ├── CustomAuthorizeAttribute.cs
├── Logging
│   ├── ConfigurationExtensions.cs
│   ├── Constants.cs
│   ├── RequestLoggingMiddleware.cs
├── Sanitation
│   ├── AntiXssMiddleware.cs
│   ├── ErrorResponse.cs
│   ├── XssSettings.cs
├── Utils
│   ├── TokenService.cs
├── Validation
│   ├── CustomDtoValidations
│   │   ├── AccomodationKind
│   │   ├── ContactKind
│   │   ├── EventKind
│   │   ├── RoomType
│   │   ├── DateGreaterThanAttribute.cs
│   ├── AccessTokenValidationMiddleware.cs
│   ├── OpenIdConnectConfiguration.cs
│   ├── TokenValidationService.cs
├── LICENSE.txt
├── README.md

Installation

  1. Install required NuGet packages:

    dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer
    dotnet add package Serilog.AspNetCore
    dotnet add package Serilog.Settings.Configuration
    dotnet add package Serilog.Sinks.Console
    

Usage

Logging Configuration

using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using Serilog.Formatting.Json;

public static class LoggingExtensions
{
    public static IHostBuilder UseUniversalLogging(this IHostBuilder hostBuilder)
    {
        hostBuilder.UseSerilog((context, services, loggerConfiguration) =>
        {
            loggerConfiguration
                .ReadFrom.Configuration(context.Configuration)
                .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                .Enrich.FromLogContext()
                .WriteTo.Console(new JsonFormatter()) // Writes logs to console
                .WriteTo.Console(new JsonFormatter(), standardErrorFromLevel: LogEventLevel.Verbose); // Writes logs to stdout
        });

        return hostBuilder;
    }
}

Authorization

[CustomAuthorize("Admin")]
public class AdminController : ControllerBase
{
    // Controller logic here
}

XSS Protection Middleware

app.UseMiddleware<AntiXssMiddleware>();

Token Validation

services.AddSingleton<ITokenService, TokenService>();

Deployment Notes

  • Ensure your authentication and logging configurations are properly set in appsettings.json.
  • Supports Kubernetes logging with JSON formatting for compatibility with log aggregators like Fluentd and Loki.

Contributing

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature-branch
  3. Commit changes: git commit -m "Added new feature"
  4. Push and create a PR.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.3 88 1/2/2026
2.2.2 288 12/24/2025
2.2.1 168 12/24/2025
2.2.0 757 11/11/2025
1.0.19 251 6/9/2025
1.0.18 144 6/3/2025
1.0.17 1,777 3/25/2025
1.0.16 251 3/10/2025
1.0.15 160 3/10/2025
1.0.14 168 3/10/2025
1.0.13 431 12/8/2024
1.0.12 97 12/7/2024
1.0.11 680 11/26/2024
1.0.10 98 11/26/2024
1.0.9 175 11/8/2024
1.0.8 307 10/29/2024
1.0.7 121 10/28/2024
1.0.6 112 10/28/2024
1.0.5 145 10/25/2024
1.0.3 280 10/23/2024
1.0.2 341 10/21/2024
1.0.1 158 10/21/2024
1.0.0 158 10/15/2024