eBuildingBlocks.API
2.0.0
dotnet add package eBuildingBlocks.API --version 2.0.0
NuGet\Install-Package eBuildingBlocks.API -Version 2.0.0
<PackageReference Include="eBuildingBlocks.API" Version="2.0.0" />
<PackageVersion Include="eBuildingBlocks.API" Version="2.0.0" />
<PackageReference Include="eBuildingBlocks.API" />
paket add eBuildingBlocks.API --version 2.0.0
#r "nuget: eBuildingBlocks.API, 2.0.0"
#:package eBuildingBlocks.API@2.0.0
#addin nuget:?package=eBuildingBlocks.API&version=2.0.0
#tool nuget:?package=eBuildingBlocks.API&version=2.0.0
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
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
Copyright © Inam Ul Haq. All rights reserved.
Support
- Author: Inam Ul Haq
- Email: inam.sys@gmail.com
- LinkedIn: https://www.linkedin.com/in/inam1567/
- Repository: https://github.com/ghazi1567/eBuildingBlocks
Product | Versions 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. |
-
net9.0
- Asp.Versioning.Http (>= 8.1.0)
- Asp.Versioning.Mvc.ApiExplorer (>= 8.1.0)
- AspNetCore.HealthChecks.UI.Client (>= 9.0.0)
- CaptchaGen.NetCore (>= 1.1.2)
- Consul (>= 1.7.14.7)
- eBuildingBlocks.Application (>= 2.0.0)
- eBuildingBlocks.Infrastructure (>= 2.0.0)
- Hangfire.AspNetCore (>= 1.8.20)
- Hangfire.MemoryStorage (>= 1.8.1.2)
- Microsoft.AspNet.WebApi.Client (>= 6.0.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.7)
- Microsoft.Extensions.DependencyInjection (>= 9.0.7)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.7)
- Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore (>= 9.0.7)
- Microsoft.Extensions.Localization (>= 9.0.7)
- Microsoft.Extensions.Localization.Abstractions (>= 9.0.7)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.12.0)
- OpenTelemetry.Extensions.Hosting (>= 1.12.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.12.0)
- OpenTelemetry.Instrumentation.Http (>= 1.12.0)
- prometheus-net.AspNetCore (>= 8.2.1)
- StackExchange.Redis (>= 2.8.41)
- Swashbuckle.AspNetCore (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.