VOOZH about

URL: https://www.nuget.org/packages/MinimalLambda

⇱ NuGet Gallery | MinimalLambda 2.6.0


ο»Ώ

MinimalLambda 2.6.0

dotnet add package MinimalLambda --version 2.6.0
 
 
NuGet\Install-Package MinimalLambda -Version 2.6.0
 
 
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="MinimalLambda" Version="2.6.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MinimalLambda" Version="2.6.0" />
 
Directory.Packages.props
<PackageReference Include="MinimalLambda" />
 
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 MinimalLambda --version 2.6.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MinimalLambda, 2.6.0"
 
 
#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 MinimalLambda@2.6.0
 
 
#: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=MinimalLambda&version=2.6.0
 
Install as a Cake Addin
#tool nuget:?package=MinimalLambda&version=2.6.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

MinimalLambda

Minimal API-style ergonomics, Lambda-first runtime – Build Lambda functions for any trigger using familiar .NET patterns without sacrificing Lambda-specific capabilities.

πŸ“š View Full Documentation

Overview

Write Lambda functions with the familiar minimal API pattern from ASP.NET Core, adapted for Lambda's execution model:

var builder = LambdaApplication.CreateBuilder();
builder.Services.AddScoped<IMyService, MyService>();

var lambda = builder.Build();
lambda.MapHandler(([FromEvent] string input, IMyService service) =>
 service.Process(input));

await lambda.RunAsync();

The framework provides:

  • Minimal API Pattern: lambda.MapHandler(...) in the same declarative style as app.MapGet()
  • Dependency Injection: The ASP.NET Core container with scoped lifetimes tailored to Lambda invocations
  • Middleware Pipeline: Familiar Use() pattern for cross-cutting concerns
  • Source Generated: Compile-time code generation for zero reflection overhead
  • Native AOT Ready: Full AOT support for sub-100ms cold starts
  • Lambda-Optimized: Envelopes, lifecycle hooks, automatic cancellation tokens, and timeout handling

Installation

Install the NuGet package:

dotnet add package MinimalLambda

Ensure your project uses C# 11 or later:


<PropertyGroup>
 <LangVersion>11</LangVersion>
 
</PropertyGroup>

Quick Start

Create a simple Lambda handler:

using MinimalLambda.Builder;
using Microsoft.Extensions.Hosting;

var builder = LambdaApplication.CreateBuilder();
var lambda = builder.Build();

// The [FromEvent] attribute marks the parameter that receives the deserialized Lambda event
lambda.MapHandler(([FromEvent] string input) => $"Hello {input}!");

await lambda.RunAsync();

The [FromEvent] attribute tells the framework which parameter receives the deserialized event. You can also inject dependencies:

lambda.MapHandler(([FromEvent] Order order, IOrderService service) =>
 service.Process(order)
);

Add middleware for cross-cutting concerns:

lambda.UseMiddleware(async (context, next) =>
{
 Console.WriteLine("Before handler");
 await next(context);
 Console.WriteLine("After handler");
});

Use OnInit() for setup and OnShutdown() for cleanup:

// Service can be injected into the Init handler
lambda.OnInit(ICache cache =>
{
 // Runs once at startup - perfect for setting up resources
 cache.Warm();
});

// Handlers can also control if the Init phase should be continued or not
lambda.OnInit(async (services, token) =>
{
 // Returns false to abort startup
 return true;
});

// Runs once at shutdown - cleanup resources
lambda.OnShutdown(async (services, token) =>
{
 // ...
});

// Service can be injected into the shutdown handler too handler
lambda.OnShutdown(ITelemetryService telemetryService =>
{
 // Runs once at shutdown - great for cleaning up resources
 telemetryService.ForceFlush();
});

Key Features

  • Source Generators – Compile-time code generation eliminates reflection; zero runtime overhead
  • Interceptors – Handler parameters resolved at compile time, not runtime
  • Dependency Injection – Built-in scoped lifetime management per invocation
  • Middleware Pipeline – Familiar ASP.NET Core-style middleware for cross-cutting concerns
  • AOT Ready – Full support for .NET Native AOT compilation
  • Lambda Lifecycle – Explicit control over Init, Invocation, and Shutdown phases
  • Automatic Cancellation – Cancellation tokens respect Lambda timeout with configurable buffer

Core Concepts

Handlers & Middleware

Register your Lambda handler with the builder. The framework uses source generation to analyze your handler signature:

  • The [FromEvent] attribute marks the input parameter type
  • The return type determines the response type
  • Source generation handles serialization/deserialization automatically

Handlers can inject dependencies alongside the event:

lambda.MapHandler(([FromEvent] Order order, IOrderService service) =>
 service.Process(order) // Return type automatically serialized to JSON
);

Middleware wraps the handler for cross-cutting concerns. Add as many middlewares as neededβ€”they compose into a pipeline:

lambda.UseMiddleware(async (context, next) =>
{
 // Pre-handler logic
 await next(context);
 // Post-handler logic
});

lambda.UseMiddleware(async (context, next) =>
{
 // Another middleware layer
 await next(context);
});

Lambda Lifecycle

The framework manages initialization and shutdown phases automatically. Add as many callbacks as neededβ€”they execute in order and then all awaited:

  • OnInit – Runs once when the function initializes; ideal for setting up resources like database connections
  • OnShutdown – Runs once before Lambda terminates; cleanup and resource release

Both run asynchronously and should be kept as short as possible to minimize startup/shutdown time.

lambda.OnInit(async (services, token) =>
{
 // One-time setup (runs once, reused across invocations)
 return true; // or false to abort startup
});

lambda.OnShutdown(async (services, token) =>
{
 // Cleanup before shutdown
});

Dependency Injection

Register services in the builder; they're available in handlers, middleware, and lifecycle methods:

builder.Services.AddSingleton<ICache, MemoryCache>(); // Reused across invocations
builder.Services.AddScoped<IRepository, Repository>(); // New per invocation

Each invocation receives its own scopeβ€”scoped services are isolated per request. OnInit() and OnShutdown() handlers receive their own scopes as well. You can also request the ILambdaInvocationContext or CancellationToken in any handler, and they're automatically injected.

Source Generation & Interceptors

The framework uses C# source generators and compile-time interceptors to:

  • Analyze handler signatures at compile time
  • Generate optimized dependency injection code
  • Resolve handler parameters without reflection

Result: Zero runtime reflection, zero performance cost.

AOT Support

To use .NET Native AOT, define a JSON serializer context and annotate with types to serialize:

using System.Text.Json.Serialization;

[JsonSerializable(typeof(string))]
public partial class SerializerContext : JsonSerializerContext;

Register the serializer context with the application:

using MinimalLambda;

var builder = LambdaApplication.CreateBuilder();

builder.Services.AddLambdaSerializerWithContext<SerializerContext>();

var lambda = builder.Build();

The AddLambdaSerializerWithContext<TContext>() method registers a source-generated JSON serializer that uses your context for all Lambda event and response serialization, providing compile-time serialization metadata and eliminating runtime reflection.

Enable AOT in your project file:

<PublishAot>true</PublishAot>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>full</TrimMode>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>

See AOT documentation for details.

Configuration

The framework supports configuration through LambdaHostOptions:

builder.Services.ConfigureLambdaHostOptions(options =>
{
 options.InitTimeout = TimeSpan.FromSeconds(10);
 options.InvocationCancellationBuffer = TimeSpan.FromSeconds(5);
 options.ShutdownDuration = ShutdownDuration.ExternalExtensions;
 options.ShutdownDurationBuffer = TimeSpan.FromMilliseconds(100);
 options.ClearLambdaOutputFormatting = true;
});

Available options include timeout control, shutdown duration, output formatting, and JSON serialization customization. The framework automatically registers DefaultLambdaHostJsonSerializer which uses JsonSerializerOptions and JsonWriterOptions for all Lambda serialization. See the configuration guide for details.

Other Packages

Additional packages in the minimal-lambda framework for abstractions, observability, and event source handling.

Package NuGet Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads
πŸ‘ NuGet
πŸ‘ Downloads

License

This project is licensed under the MIT License. See for details.

Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed.  net11.0 net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on MinimalLambda:

Package Downloads
AlexaVoxCraft.MinimalLambda

Minimal API-style Lambda hosting for AlexaVoxCraft skills powered by MinimalLambda.

MinimalLambda.OpenTelemetry

OpenTelemetry integration for MinimalLambda

MinimalLambda.Testing

In-memory testing harness for MinimalLambda

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.6.0 125 6/12/2026
2.5.0 457 5/9/2026
2.4.0 453 4/17/2026
2.3.1 616 3/23/2026
2.3.0 138 3/21/2026
2.2.0 1,001 1/12/2026
2.2.0-beta.1 85 1/9/2026
2.1.1 364 12/22/2025
2.1.0-beta.6 133 12/20/2025
2.1.0-beta.5 161 12/19/2025
2.1.0-beta.4 177 12/19/2025
2.1.0-beta.3 179 12/19/2025
2.1.0-beta.2 181 12/19/2025
2.1.0-beta.1 258 12/19/2025
2.0.0 342 12/18/2025
2.0.0-beta.11 283 12/17/2025
2.0.0-beta.10 281 12/17/2025
2.0.0-beta.9 279 12/15/2025
2.0.0-beta.8 242 12/15/2025
2.0.0-beta.7 211 12/15/2025
Loading failed