Momentum.ServiceDefaults.Api
0.0.9
dotnet add package Momentum.ServiceDefaults.Api --version 0.0.9
NuGet\Install-Package Momentum.ServiceDefaults.Api -Version 0.0.9
<PackageReference Include="Momentum.ServiceDefaults.Api" Version="0.0.9" />
<PackageVersion Include="Momentum.ServiceDefaults.Api" Version="0.0.9" />
<PackageReference Include="Momentum.ServiceDefaults.Api" />
paket add Momentum.ServiceDefaults.Api --version 0.0.9
#r "nuget: Momentum.ServiceDefaults.Api, 0.0.9"
#:package Momentum.ServiceDefaults.Api@0.0.9
#addin nuget:?package=Momentum.ServiceDefaults.Api&version=0.0.9
#tool nuget:?package=Momentum.ServiceDefaults.Api&version=0.0.9
Momentum.ServiceDefaults.Api
API-specific service defaults for Momentum platform extending the base ServiceDefaults with gRPC, OpenAPI documentation (Scalar), and API-focused configurations. Essential for Momentum API projects.
Overview
The Momentum.ServiceDefaults.Api package extends Momentum.ServiceDefaults with additional configurations specifically designed for API projects. It provides comprehensive support for both REST and gRPC APIs, along with modern documentation tools.
Installation
Add the package to your project using the .NET CLI:
dotnet add package Momentum.ServiceDefaults.Api
Or using the Package Manager Console:
Install-Package Momentum.ServiceDefaults.Api
Key Features
- All ServiceDefaults Features: Inherits complete observability, messaging, and database capabilities
- gRPC Support: Full gRPC server configuration with reflection and web support
- OpenAPI Integration: Automatic OpenAPI 3.0 specification generation
- Scalar Documentation: Modern, interactive API documentation interface
- Enhanced Telemetry: API-specific metrics, tracing, and monitoring
Getting Started
Prerequisites
- .NET 10.0 or later
- ASP.NET Core 9.0 or later
- All prerequisites from Momentum.ServiceDefaults
Basic Usage
REST API Example
// Program.cs
using Momentum.ServiceDefaults.Api;
using Momentum.ServiceDefaults.Api.OpenApi.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add API service defaults - includes all base features plus API-specific configurations
builder.AddApiServiceDefaults();
// Configure OpenAPI with .NET 10 native support and XML documentation
// NOTE: AddOpenApi must be called directly in the API project (not in a library)
// for the .NET 10 source generator to intercept it and generate XML documentation
builder.Services.AddOpenApi(options => options.ConfigureOpenApiDefaults());
var app = builder.Build();
// Configure API defaults (routing, auth, OpenAPI endpoints, etc.)
app.ConfigureApiUsingDefaults();
app.Run();
gRPC Service Example
// Program.cs
using Momentum.ServiceDefaults.Api;
using Momentum.ServiceDefaults.Api.OpenApi.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.AddApiServiceDefaults();
builder.Services.AddOpenApi(options => options.ConfigureOpenApiDefaults());
var app = builder.Build();
app.ConfigureApiUsingDefaults();
// Map gRPC services
app.MapGrpcService<UserService>();
app.MapGrpcService<OrderService>();
app.Run();
Hybrid API (REST + gRPC)
// Program.cs
using Momentum.ServiceDefaults.Api;
using Momentum.ServiceDefaults.Api.OpenApi.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.AddApiServiceDefaults();
builder.Services.AddOpenApi(options => options.ConfigureOpenApiDefaults());
var app = builder.Build();
app.ConfigureApiUsingDefaults();
// Map additional gRPC services
app.MapGrpcService<UserService>();
app.Run();
What Gets Configured
In addition to all Momentum.ServiceDefaults features, this package automatically configures:
1. gRPC Services
- gRPC Server: Full ASP.NET Core gRPC support
- Server Reflection: gRPC reflection for tool support
- gRPC-Web: Browser-compatible gRPC over HTTP
2. OpenAPI Documentation
- Specification Generation: Automatic OpenAPI 3.0 spec generation
- Endpoint Discovery: Automatic API endpoint documentation
- Schema Generation: Request/response model documentation
3. Scalar API Documentation
- Interactive UI: Modern API documentation interface
- Try It Out: Built-in API testing capabilities
- Automatic Discovery: Works with your OpenAPI specification
4. Enhanced Observability
- gRPC Telemetry: Metrics and tracing for gRPC calls
- API Metrics: Request rates, latencies, and error rates
- Documentation Metrics: API documentation usage tracking
Available Endpoints
When you call app.ConfigureApiUsingDefaults(), in development you get:
| Endpoint | Purpose |
|---|---|
/openapi/v1.json |
OpenAPI specification (cached) |
/scalar/v1 |
Interactive API documentation |
/grpc-reflection |
gRPC reflection service |
Configuration
OpenAPI Settings
// appsettings.json
{
"OpenApi": {
"Document": {
"Title": "My API",
"Version": "v1",
"Description": "API for my application"
}
}
}
gRPC Configuration
// appsettings.json
{
"Grpc": {
"EnableDetailedErrors": true,
"MaxReceiveMessageSize": 4194304,
"MaxSendMessageSize": 4194304
}
}
Advanced Usage
Custom OpenAPI Configuration
using Momentum.ServiceDefaults.Api;
using Momentum.ServiceDefaults.Api.OpenApi.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.AddApiServiceDefaults();
// Configure OpenAPI with custom transformers
builder.Services.AddOpenApi(options =>
{
// Apply Momentum defaults (server URL normalization, etc.)
options.ConfigureOpenApiDefaults();
// Add custom document transformers
options.AddDocumentTransformer((document, context, cancellationToken) =>
{
document.Info.Contact = new() { Name = "Support", Email = "support@company.com" };
return Task.CompletedTask;
});
});
Custom gRPC Configuration
using Momentum.ServiceDefaults.Api;
var builder = WebApplication.CreateBuilder(args);
builder.AddApiServiceDefaults();
// Customize gRPC services (overrides defaults)
builder.Services.AddGrpc(options =>
{
options.EnableDetailedErrors = true;
options.MaxReceiveMessageSize = 8 * 1024 * 1024; // 8MB
});
Integrated Dependencies
This package includes:
| Package | Purpose |
|---|---|
| Grpc.AspNetCore | gRPC server framework |
| Grpc.AspNetCore.Server.Reflection | gRPC reflection support |
| Grpc.AspNetCore.Web | gRPC-Web support for browsers |
| Microsoft.AspNetCore.OpenApi | OpenAPI 3.1 specification generation with .NET 10 source generator |
| Scalar.AspNetCore | Modern API documentation UI |
| OpenTelemetry.Extensions.Hosting | Enhanced telemetry |
| Momentum.Extensions.Abstractions | Core abstractions |
Note: For XML documentation in OpenAPI, ensure your project has
<GenerateDocumentationFile>true</GenerateDocumentationFile>and enable the OpenAPI source generator interceptors with:<InterceptorsNamespaces>$(InterceptorsNamespaces);Microsoft.AspNetCore.OpenApi.Generated</InterceptorsNamespaces>
Target Frameworks
- .NET 10.0: Primary target framework
- ASP.NET Core 9.0: Includes framework reference
Use Cases
This package is ideal for:
- REST APIs: Traditional HTTP APIs with OpenAPI documentation
- gRPC Services: High-performance RPC services
- Hybrid APIs: Services supporting both REST and gRPC protocols
- API Gateways: Services that aggregate other APIs
- Microservice APIs: Services in event-driven architectures
Related Packages
- Momentum.ServiceDefaults - Base service configuration
- Momentum.Extensions.Messaging.Kafka - Kafka messaging
- Momentum.Extensions.Abstractions - Core abstractions
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
For contribution guidelines and more information about the Momentum platform, visit the main repository.
| 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
- Asp.Versioning.Http (>= 8.1.1)
- Grpc.AspNetCore (>= 2.67.0)
- Grpc.AspNetCore.Server.Reflection (>= 2.67.0)
- Grpc.AspNetCore.Web (>= 2.67.0)
- Microsoft.AspNetCore.OpenApi (>= 10.0.3)
- Momentum.Extensions.Abstractions (>= 0.0.9)
- Momentum.ServiceDefaults (>= 0.0.9)
- OpenTelemetry.Extensions.Hosting (>= 1.15.0)
- OpenTelemetry.Instrumentation.GrpcCore (>= 1.0.0-beta.10)
- Scalar.AspNetCore (>= 2.12.52)
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 |
|---|---|---|
| 0.0.9 | 43 | 3/5/2026 |
| 0.0.9-preview.3 | 31 | 3/4/2026 |
| 0.0.9-preview.2 | 43 | 2/25/2026 |
| 0.0.9-preview.1 | 44 | 2/25/2026 |
| 0.0.8 | 74 | 2/23/2026 |
| 0.0.8-preview.12 | 45 | 2/22/2026 |
| 0.0.8-preview.11 | 39 | 2/22/2026 |
| 0.0.8-preview.10 | 45 | 2/22/2026 |
| 0.0.8-preview.9 | 43 | 2/22/2026 |
| 0.0.8-preview.8 | 44 | 2/22/2026 |
| 0.0.8-preview.7 | 49 | 2/22/2026 |
| 0.0.8-preview.6 | 40 | 2/22/2026 |
| 0.0.8-preview.5 | 48 | 2/22/2026 |
| 0.0.8-preview.4 | 48 | 2/21/2026 |
| 0.0.8-preview.3 | 48 | 2/20/2026 |
| 0.0.8-preview.2 | 44 | 2/20/2026 |
| 0.0.8-preview.1 | 42 | 2/20/2026 |
| 0.0.7 | 71 | 2/16/2026 |
| 0.0.7-preview.3 | 50 | 2/16/2026 |
| 0.0.7-preview.2 | 48 | 2/16/2026 |