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
<PackageReference Include="BlackDigital.AspNet" Version="26.10.20.21" />
<PackageVersion Include="BlackDigital.AspNet" Version="26.10.20.21" />
<PackageReference Include="BlackDigital.AspNet" />
paket add BlackDigital.AspNet --version 26.10.20.21
#r "nuget: BlackDigital.AspNet, 26.10.20.21"
#:package BlackDigital.AspNet@26.10.20.21
#addin nuget:?package=BlackDigital.AspNet&version=26.10.20.21
#tool nuget:?package=BlackDigital.AspNet&version=26.10.20.21
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
π 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
Idsupport: Custom model binder and route constraint forBlackDigital.Model.Id - CancellationToken: Request abortion token is bound automatically
- Authorization:
[Authorize](roles/policy) declared on the service implementation - Business exceptions:
BusinessExceptionmaps 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-versionquery string orx-api-versionheader - 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.OpenApi3.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
- REST System - Complete REST system guide
- Transformation System - Complete transformation system guide
- OpenAPI + Scalar - API documentation generation guide
π― 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:
- Fork the project
- Create a branch for your feature (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - 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
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@blackdigital.com.br
π 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 | Versions 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. |
-
net10.0
- BlackDigital (>= 26.10.20.19)
- BlackDigital.Domain (>= 26.10.20.2)
- Konscious.Security.Cryptography.Argon2 (>= 1.3.1)
- Microsoft.OpenApi (>= 3.11.0)
- Scalar.AspNetCore (>= 2.18.2)
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 |