eBuildingBlocks.API 2.0.0

dotnet add package eBuildingBlocks.API --version 2.0.0
                    
NuGet\Install-Package eBuildingBlocks.API -Version 2.0.0
                    
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="eBuildingBlocks.API" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="eBuildingBlocks.API" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="eBuildingBlocks.API" />
                    
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 eBuildingBlocks.API --version 2.0.0
                    
#r "nuget: eBuildingBlocks.API, 2.0.0"
                    
#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 eBuildingBlocks.API@2.0.0
                    
#: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=eBuildingBlocks.API&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=eBuildingBlocks.API&version=2.0.0
                    
Install as a Cake Tool

eBuildingBlocks.API

A comprehensive API building block library for .NET applications that provides essential cross-cutting concerns, infrastructure components, and utilities for building robust web APIs.

Overview

eBuildingBlocks.API is a foundational library that encapsulates common API patterns, middleware, and configuration utilities. It provides a standardized approach to building ASP.NET Core APIs with built-in support for versioning, documentation, monitoring, and cross-cutting concerns.

Key Features

🔧 Core Infrastructure

  • API Versioning: Built-in support for URL segment and header-based API versioning
  • Swagger/OpenAPI Integration: Automatic API documentation with JWT authentication support
  • CORS Configuration: Pre-configured CORS policies for cross-origin requests
  • Health Checks: Built-in health monitoring endpoints
  • Metrics & Monitoring: Prometheus metrics integration and OpenTelemetry tracing

🛡️ Security & Authentication

  • JWT Bearer Authentication: Ready-to-use JWT authentication configuration
  • Authorization Headers: Automatic Accept-Language header parameter injection
  • Current User Context: User context management with tenant support

📊 Monitoring & Observability

  • OpenTelemetry Integration: Distributed tracing and metrics collection
  • Prometheus Metrics: HTTP metrics and custom application metrics
  • Health Checks: Database and application health monitoring
  • Hangfire Dashboard: Background job monitoring and management

🔄 Background Processing

  • Hangfire Integration: Background job processing with memory storage
  • Redis Support: Distributed caching and session management
  • Memory Cache: In-memory caching capabilities

Installation

dotnet add package eBuildingBlocks.API

Quick Start

1. Register Services

using eBuildingBlocks.API.Startup;

var builder = WebApplication.CreateBuilder(args);

// Register all base services
builder.Services.BaseRegister(builder.Configuration, builder.Host);

2. Configure Application

var app = builder.Build();

// Configure all base middleware
app.BaseAppUse(builder.Configuration);

3. Create Controllers

using eBuildingBlocks.API.Controllers;

[ApiController]
[Route("[controller]/[action]")]
public class SampleController : BaseController
{
    [HttpGet]
    public IActionResult Get()
    {
        return Ok("Hello from eBuildingBlocks!");
    }
}

Configuration

appsettings.json

{
  "ConnectionStrings": {
    "RedisConnection": "localhost:6379"
  },
  "OpenTelemetry": {
    "name": "YourApiService",
    "url": "http://localhost:4317"
  },
  "PathBase": "/api"
}

API Versioning

The library supports multiple API versioning strategies:

// URL-based versioning: /api/v1/controller/action
// Header-based versioning: X-API-Version: 1.0

Swagger Configuration

Automatic Swagger documentation with JWT authentication:

// Available at: /swagger
// JWT Bearer token support included

Features in Detail

API Versioning

// Configure versioning in DependencyInjection.cs
services.RegisterAPIVersioning();

Health Checks

// Health check endpoint: /healthz
// Includes database and application health

Metrics

// Prometheus metrics endpoint: /metrics
// HTTP metrics automatically collected

Background Jobs

// Hangfire dashboard: /hangfire
// Default credentials: admin/admin

Dependencies

  • ASP.NET Core 9.0
  • Swashbuckle.AspNetCore - API documentation
  • Asp.Versioning - API versioning
  • Hangfire.AspNetCore - Background job processing
  • prometheus-net.AspNetCore - Metrics collection
  • OpenTelemetry - Distributed tracing
  • StackExchange.Redis - Redis client

Project Structure

eBuildingBlocks.API/
├── Configs/
│   ├── AddAcceptLanguageHeaderParameter.cs
│   ├── AppUseExtensions.cs
│   ├── CaptchaSettings.cs
│   ├── CurrentUser.cs
│   └── DependencyInjection.cs
├── Controllers/
│   └── BaseController.cs
└── eBuildingBlocks.API.csproj

Usage Examples

Custom Controller

public class UserController : BaseController
{
    private readonly IUserService _userService;
    
    public UserController(IUserService userService)
    {
        _userService = userService;
    }
    
    [HttpGet]
    public async Task<IActionResult> GetUsers()
    {
        var users = await _userService.GetAllAsync();
        return Ok(users);
    }
}

Adding Custom Middleware

public static IApplicationBuilder UsingCustomMiddleware(this IApplicationBuilder app)
{
    app.UseMiddleware<CustomMiddleware>();
    return app;
}

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

Copyright © Inam Ul Haq. All rights reserved.

Support

Product 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. 
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.0.0 213 8/5/2025
1.0.6 212 8/5/2025
1.0.5 194 7/20/2025
1.0.4 26 7/19/2025
1.0.1 25 7/19/2025