BlackDigital.AspNet 26.10.20.21

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

BlackDigital.AspNet

πŸ‡§πŸ‡· PortuguΓͺs | πŸ‡ΊπŸ‡Έ English

<div align="center"> <img src="https://raw.githubusercontent.com/blackdigital-br/blackdigital-mvc/main/doc/images/Logo128.png" alt="BlackDigital.AspNet Logo" width="128" height="128">

Modern framework for REST API development in .NET

License .NET </div>

πŸ“‹ About the Project

BlackDigital.AspNet is an innovative framework that dramatically simplifies REST API development in .NET, eliminating the need for traditional controllers and offering an advanced transformation system for API evolution with full compatibility.

πŸš€ Key Features

  • πŸ”§ REST System: Create APIs without controllers using service interfaces and attributes
  • πŸ”„ Transformation System: API evolution maintaining backward compatibility
  • πŸ“– OpenAPI + Scalar: Automatic API documentation generation (no Swashbuckle)
  • ⚑ High Performance: Optimized middleware for maximum efficiency
  • πŸ§ͺ Testability: Architecture that facilitates unit and integration testing
  • πŸ“¦ Modular: Independent and reusable components

πŸ’‘ Why use BlackDigital.AspNet?

  • Productivity: Reduce up to 70% of boilerplate code
  • Maintainability: Cleaner and more organized code
  • Safe Evolution: Update APIs without breaking existing clients
  • Flexibility: Coexists perfectly with traditional controllers
  • Simplicity: Focus on business logic, not infrastructure

πŸ“¦ Installation

Via NuGet Package Manager

Install-Package BlackDigital.AspNet

Via .NET CLI

dotnet add package BlackDigital.AspNet

Via PackageReference

<PackageReference Include="BlackDigital.AspNet" Version="25.10.7.16" />

βš™οΈ Basic Configuration

1. Configure in Program.cs

using BlackDigital.AspNet.OpenApi;
using BlackDigital.AspNet.Rest;
using BlackDigital.AspNet.Rest.Transforms;

var builder = WebApplication.CreateBuilder(args);

// Register REST services (interface + implementation)
builder.Services.AddRestServices(rest =>
{
    rest.AddService<IUserService, UserService>();
});

// Configure MVC options (model binders, route constraints, validation filter)
builder.Services.AddRestMvcOptions();

// Configure the transformation system (optional)
builder.Services.AddTransform(transform =>
{
    transform.AddInputRule<OldUserToUserRule>("POST:api/users/", "2020-01-01");
});

// Configure OpenAPI + Scalar documentation (optional)
builder.Services.AddOpenApi(options =>
{
    options.Title = "My API";
    options.Version = "v1";
    options.Enabled = builder.Environment.IsDevelopment() || builder.Environment.IsStaging();
});

var app = builder.Build();

app.UseRouting();
app.UseRestMiddleware();   // REST middleware (before UseAuthorization)
app.UseAuthorization();
app.MapControllers();      // Traditional controllers keep working
app.MapOpenApi();          // OpenAPI JSON + Scalar UI

app.Run();

2. Create your first service

Services are defined as interfaces decorated with [Service], with methods decorated with [Action]:

using BlackDigital.Rest;

[Service("api/users")]
public interface IUserService
{
    [Action("{id}", method: RestMethod.Get)]
    Task<User> GetUserAsync([Path] int id);

    [Action(method: RestMethod.Post)]
    Task<User> CreateUserAsync([Body] CreateUserRequest request);
}

Implement the interface as a regular class (no controller base class required). Access requirements are declared on the implementation with [Authorize] (from BlackDigital.Domain.Security), never on the interface:

using BlackDigital.Domain.Security;

public class UserService : IUserService
{
    public async Task<User> GetUserAsync(int id)
    {
        // Your logic here
        return await GetUserByIdAsync(id);
    }

    [Authorize]   // any authenticated user; narrow with [Authorize(Roles = ...)] or [Authorize(Policy = ...)]
    public async Task<User> CreateUserAsync(CreateUserRequest request)
    {
        // Your logic here
        return await CreateUserAsync(request);
    }
}

🎯 Main Features

πŸ”§ REST System

Create complete REST APIs without traditional controllers:

  • Interface-based: [Service] and [Action] attributes define routes automatically
  • Automatic Binding: [Path], [Body], [Query], [Header] parameters bound automatically
  • Built-in Id support: Custom model binder and route constraint for BlackDigital.Model.Id
  • CancellationToken: Request abortion token is bound automatically
  • Authorization: [Authorize] (roles/policy) declared on the service implementation
  • Business exceptions: BusinessException maps directly to HTTP status codes
  • Full Support: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
  • Async/Await: Native support for Task, Task<T>, ValueTask, ValueTask<T>

πŸ”„ Transformation System

Evolve your APIs maintaining compatibility:

  • Input and Output rules: Transform request body and response independently
  • Date-based versioning: Version selected via api-version query string or x-api-version header
  • Automatic chaining: Rules are applied sequentially by version order
  • DI integration: Rule types are instantiated through the DI container

πŸ“– OpenAPI + Scalar

Automatic, Swashbuckle-free documentation:

  • Pure Microsoft.OpenApi: Built directly with Microsoft.OpenApi 3.x
  • Automatic discovery: Scans assemblies for [Service] interfaces
  • Scalar UI: Interactive API documentation via Scalar.AspNetCore
  • Bearer JWT: Pre-configured security scheme (overridable)
  • Customizable: Title, version, contact, license, server URL, assembly filters

Note: Security (JWT, password hashing) and Email infrastructure are now part of the BlackDigital.Domain package.

πŸ“š Detailed Documentation

πŸ“– Complete Guides

🎯 Quick Navigation

πŸš€ Quick Examples

Simple REST Service

[Service("api/products")]
public interface IProductService
{
    [Action(method: RestMethod.Get)]
    Task<IEnumerable<Product>> GetProductsAsync();

    [Action("{id}", method: RestMethod.Get)]
    Task<Product> GetProductAsync([Path] int id);

    [Action(method: RestMethod.Post)]
    Task<Product> CreateProductAsync([Body] Product product);
}

Basic Transformation

public class OldUserToUserRule : TransformRule<OldUser, User>
{
    public override User? Transform(OldUser? source)
    {
        if (source == null) return null;
        return new User
        {
            Id = source.Id,
            FullName = $"{source.FirstName} {source.LastName}",
            Email = source.Email
        };
    }
}

πŸ“ Complete Example Project

Explore the example project that demonstrates:

  • Complete configuration
  • REST services (interface-based)
  • Input and output transformations
  • OpenAPI + Scalar setup

πŸ“ Project Structure

BlackDigital.AspNet/
β”œβ”€β”€ πŸ“ src/                    # Main source code
β”‚   β”œβ”€β”€ πŸ“ Rest/              # REST system (middleware, routing, binding)
β”‚   β”‚   └── πŸ“ Transforms/    # Transformation engine
β”‚   β”œβ”€β”€ πŸ“ OpenApi/           # OpenAPI document builder + Scalar integration
β”‚   β”œβ”€β”€ πŸ“ Binder/            # Custom model binders (Id)
β”‚   β”œβ”€β”€ πŸ“ Constraint/        # Route constraints (id)
β”‚   β”œβ”€β”€ πŸ“ Filters/           # MVC filters (ModelState validation)
β”‚   └── πŸ“ Services/          # DI helpers and HTTP context utilities
β”œβ”€β”€ πŸ“ example/               # Example project
β”œβ”€β”€ πŸ“ test/                  # Unit tests
β”œβ”€β”€ πŸ“ doc/                   # Documentation
β”‚   β”œβ”€β”€ πŸ“„ rest-system.md     # REST system documentation
β”‚   β”œβ”€β”€ πŸ“„ transform-system.md # Transformation documentation
β”‚   β”œβ”€β”€ πŸ“„ openapi.md         # OpenAPI + Scalar documentation
β”‚   └── πŸ“ images/            # Documentation images
└── πŸ“„ README.md              # This file

πŸ” Where to Find

  • Examples: example/ folder contains complete implementation
  • Tests: test/ folder with usage examples and tests
  • Documentation: doc/ folder with detailed guides
  • Source Code: src/ folder with implementation

🀝 Contributing

Contributions are welcome! To contribute:

  1. Fork the project
  2. Create a branch for your feature (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“‹ Guidelines

  • Follow existing code standards
  • Add tests for new features
  • Update documentation when necessary
  • Use English for code and comments

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

πŸ“ž Support Channels

πŸ“š Additional Resources


<div align="center"> <p>Made with ❀️ by the <strong>BlackDigital</strong> team</p> <p> <a href="https://blackdigital.com.br">Website</a> β€’ <a href="doc/">Documentation</a> β€’ <a href="example/">Examples</a> β€’ <a href="https://github.com/blackdigital-br/blackdigital-mvc/issues">Support</a> </p> </div>

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
26.10.20.21 89 10/20/2026
26.10.15.4 97 10/15/2026
26.10.11.19 95 10/11/2026
26.10.11.2 94 10/11/2026
25.10.7.16 253 10/9/2025