Common.API.Extensions.Lib 1.0.17

There is a newer version of this package available.
See the version list below for details.
dotnet add package Common.API.Extensions.Lib --version 1.0.17
                    
NuGet\Install-Package Common.API.Extensions.Lib -Version 1.0.17
                    
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="1.0.17" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Common.API.Extensions.Lib" Version="1.0.17" />
                    
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 1.0.17
                    
#r "nuget: Common.API.Extensions.Lib, 1.0.17"
                    
#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@1.0.17
                    
#: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=1.0.17
                    
Install as a Cake Addin
#tool nuget:?package=Common.API.Extensions.Lib&version=1.0.17
                    
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 net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Common.API.Extensions.Lib:

Package Downloads
Common.Infrastructure.Lib

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.5.0 160 4/1/2026
2.4.4 315 3/11/2026
2.4.3 235 3/3/2026
2.4.2 338 2/20/2026
2.4.1 93 2/20/2026
2.4.0 94 2/20/2026
2.3.0 359 2/11/2026
2.2.6 105 2/9/2026
2.2.5 177 2/4/2026
2.2.4 103 1/28/2026
2.2.3 127 1/2/2026
2.2.2 498 12/24/2025
2.2.1 185 12/24/2025
2.2.0 781 11/11/2025
1.0.19 269 6/9/2025
1.0.18 152 6/3/2025
1.0.17 1,791 3/25/2025
1.0.16 276 3/10/2025
1.0.15 180 3/10/2025
1.0.14 182 3/10/2025
Loading failed