eBuildingBlocks.Application 2.0.5

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

eBuildingBlocks.Application

A comprehensive application layer building block for .NET applications that provides essential cross-cutting concerns, exception handling, response models, and application utilities.

Overview

eBuildingBlocks.Application is a foundational library that encapsulates common application patterns, exception handling, response models, and middleware components. It provides a standardized approach to building application layers with built-in support for validation, exception handling, and response formatting.

Key Features

🛡️ Exception Handling

  • Global Exception Handler: Centralized exception handling middleware
  • Custom Exceptions: Predefined exception types for common scenarios
  • HTTP Response Middleware: Standardized HTTP response formatting
  • Error Response Models: Consistent error response structures

📋 Response Models

  • Standardized Response Format: Consistent API response structure
  • Paged List Support: Built-in pagination support
  • View Models: Common view model patterns
  • Enum View Models: Enumeration display models

🔧 Middleware Components

  • HTTP Response Middleware: Response formatting and logging
  • Global Exception Handler: Centralized error handling
  • Request/Response Logging: Built-in request/response logging

✅ Validation & Business Logic

  • FluentValidation Integration: Built-in validation support
  • AutoMapper Integration: Object mapping utilities
  • Feature Management: Feature flag support

Installation

dotnet add package eBuildingBlocks.Application

Quick Start

1. Register Services

using eBuildingBlocks.Application;

var builder = WebApplication.CreateBuilder(args);

// Register application services
builder.Services.AddApplication();

2. Configure Middleware

var app = builder.Build();

// Add global exception handler
app.UseMiddleware<GlobalExceptionHandler>();

// Add HTTP response middleware
app.UseMiddleware<HttpResponseMiddleware>();

3. Use Response Models

using eBuildingBlocks.Application.Models;

public class UserController : ControllerBase
{
    [HttpGet]
    public async Task<ResponseModel<List<UserDto>>> GetUsers()
    {
        var users = await _userService.GetAllAsync();
        return ResponseModel<List<UserDto>>.Success(users);
    }
}

Features in Detail

Exception Handling

The library provides a comprehensive exception handling system:

// Global exception handler automatically catches and formats exceptions
app.UseMiddleware<GlobalExceptionHandler>();
Available Exception Types
// HTTP 400 - Bad Request
throw new BadRequestException("Invalid input");

// HTTP 401 - Unauthorized
throw new UnauthorizedException("Authentication required");

// HTTP 403 - Forbidden
throw new ForbiddenException("Access denied");

// HTTP 404 - Not Found
throw new NotFoundException("Resource not found");

// HTTP 405 - Method Not Allowed
throw new MethodNotAllowedException("Method not supported");

// HTTP 409 - Conflict
throw new ConflictException("Resource conflict");

// HTTP 429 - Too Many Requests
throw new TooManyRequestException("Rate limit exceeded");

// HTTP 501 - Not Implemented
throw new NotImplementedException("Feature not implemented");

Response Models

Standard Response Format
public class ResponseModel<T>
{
    public bool IsSuccess { get; set; }
    public string Message { get; set; }
    public T Data { get; set; }
    public List<string> Errors { get; set; }
    public int StatusCode { get; set; }
}

// Usage
return ResponseModel<UserDto>.Success(user);
return ResponseModel<UserDto>.Failure("User not found", 404);
Paged List Support
public class PagedList<T>
{
    public List<T> Items { get; set; }
    public int PageNumber { get; set; }
    public int PageSize { get; set; }
    public int TotalCount { get; set; }
    public int TotalPages { get; set; }
    public bool HasPreviousPage { get; set; }
    public bool HasNextPage { get; set; }
}

View Models

Entity View Model
public class EntityViewModel
{
    public Guid Id { get; set; }
    public string Name { get; set; }
}
Enum View Model
public class EnumViewModel
{
    public int Value { get; set; }
    public string Name { get; set; }
    public string DisplayName { get; set; }
}
Redirect View Model
public class RedirectViewModel
{
    public string Url { get; set; }
    public bool IsPermanent { get; set; }
}

Project Structure

eBuildingBlocks.Application/
├── Exceptions/
│   ├── BadRequestException.cs
│   ├── ConflictException.cs
│   ├── ForbiddenException.cs
│   ├── MethodNotAllowedException.cs
│   ├── NotFoundException.cs
│   ├── NotImplementedException.cs
│   ├── TooManyRequestException.cs
│   └── UnauthorizedException.cs
├── Models/
│   ├── PagedList.cs
│   └── ResponseModel.cs
├── ViewModels/
│   ├── EntityViewModel.cs
│   ├── EnumViewModel.cs
│   └── RedirectViewModel.cs
├── Middlewares/
│   └── HttpResponseMiddleware.cs
├── GlobalExceptionHandler.cs
└── eBuildingBlocks.Application.csproj

Usage Examples

Custom Exception Handler

public class CustomExceptionHandler : GlobalExceptionHandler
{
    protected override async Task HandleExceptionAsync(HttpContext context, Exception exception)
    {
        // Custom exception handling logic
        await base.HandleExceptionAsync(context, exception);
    }
}

Custom Response Middleware

public class CustomResponseMiddleware : HttpResponseMiddleware
{
    protected override async Task ProcessResponseAsync(HttpContext context)
    {
        // Custom response processing
        await base.ProcessResponseAsync(context);
    }
}

Using Response Models

[HttpGet]
public async Task<ResponseModel<PagedList<UserDto>>> GetUsers(int page = 1, int pageSize = 10)
{
    try
    {
        var users = await _userService.GetPagedAsync(page, pageSize);
        return ResponseModel<PagedList<UserDto>>.Success(users);
    }
    catch (Exception ex)
    {
        return ResponseModel<PagedList<UserDto>>.Failure(ex.Message, 500);
    }
}

Custom Exception

public class CustomBusinessException : Exception
{
    public CustomBusinessException(string message) : base(message)
    {
    }
}

// Usage
throw new CustomBusinessException("Business rule violation");

Dependencies

  • ASP.NET Core 9.0
  • FluentValidation - Input validation
  • AutoMapper - Object mapping
  • Microsoft.FeatureManagement - Feature flags
  • Polly - Resilience and transient-fault-handling
  • Swashbuckle.AspNetCore.Annotations - API documentation
  • System.IdentityModel.Tokens.Jwt - JWT token handling

Configuration

Exception Handling Configuration

// Configure global exception handler
app.UseMiddleware<GlobalExceptionHandler>();

// Configure response middleware
app.UseMiddleware<HttpResponseMiddleware>();

Validation Configuration

// Register FluentValidation
services.AddFluentValidationAutoValidation();
services.AddValidatorsFromAssemblyContaining<Startup>();

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 (1)

Showing the top 1 NuGet packages that depend on eBuildingBlocks.Application:

Package Downloads
eBuildingBlocks.API

Reusable building block for the ecosystem. Implements core cross-cutting concerns, infrastructure, or domain utilities for .NET applications.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.5 298 10/6/2025
2.0.4 243 9/29/2025
2.0.3 201 9/29/2025
2.0.2 241 9/25/2025
2.0.1 201 9/25/2025
2.0.0 261 8/5/2025
1.0.6 274 8/5/2025
1.0.5 268 7/20/2025
1.0.4 89 7/19/2025
1.0.1 103 7/19/2025