Skip to content

feat(host): add factory-based middleware creation support#266

Merged
j-d-ha merged 4 commits into
mainfrom
feature/#259-add-ILambdaMiddlewareFactory-interface
Dec 21, 2025
Merged

feat(host): add factory-based middleware creation support#266
j-d-ha merged 4 commits into
mainfrom
feature/#259-add-ILambdaMiddlewareFactory-interface

Conversation

@j-d-ha

@j-d-ha j-d-ha commented Dec 21, 2025

Copy link
Copy Markdown
Collaborator

🚀 Pull Request

📋 Summary

Adds support for factory-based middleware creation through a new ILambdaMiddlewareFactory interface and corresponding UseMiddleware<TFactory>() extension method. This enables scenarios where middleware construction needs to be customized or deferred, with automatic disposal support for middleware that implements IDisposable or IAsyncDisposable.

Key Changes:

  • New ILambdaMiddlewareFactory interface in MinimalLambda.Abstractions
  • UseMiddleware<TFactory>() extension method that resolves factories from the invocation service provider
  • Automatic disposal of middleware instances after invocation completes
  • Comprehensive unit tests covering factory resolution, middleware invocation, and disposal patterns
  • Documentation and examples in the middleware guide

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (if applicable)

🧪 Related Issues or PRs

Closes #259


💬 Notes for Reviewers

The factory pattern enables:

  • Custom middleware construction logic
  • Deferred middleware instantiation per invocation
  • Per-invocation middleware instances with proper disposal
  • Integration with DI patterns while maintaining middleware lifecycle control

The implementation automatically detects and handles both IAsyncDisposable and IDisposable middleware, prioritizing async disposal when both interfaces are implemented.

- Introduced `ILambdaMiddlewareFactory` for custom middleware construction.
- Added `UseMiddleware<TFactory>()` extension method in `MiddlewareLambdaApplicationExtensions`.
- Enhanced DI container integration for resolving middleware factories.
- Included proper handling and disposal for `IAsyncDisposable` and `IDisposable` middlewares.
- Added tests for `UseMiddlewareFactory` with null application argument.
- Verified middleware registration and execution using `TestMiddlewareFactory`.
- Implemented tests for proper handling of disposable and async disposable middlewares.
- Included scenarios tracking middleware creation, invocation, and disposal.
- Documented `ILambdaMiddlewareFactory` for custom middleware creation.
- Included example for middleware registration using `UseMiddleware<TFactory>()`.
- Demonstrated integration of DI and proper handling of disposal features.
- Replaced hardcoded scope list with a reference to `./.claude/commands/pr.md` for valid scopes.
- Clarified where to find the complete list of allowed scope values.
@github-actions github-actions Bot added the type: feat New feature label Dec 21, 2025
@sonarqubecloud

sonarqubecloud Bot commented Dec 21, 2025

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@codecov

codecov Bot commented Dec 21, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #266      +/-   ##
==========================================
+ Coverage   88.76%   88.87%   +0.11%     
==========================================
  Files         132      132              
  Lines        3231     3263      +32     
  Branches      321      322       +1     
==========================================
+ Hits         2868     2900      +32     
  Misses        247      247              
  Partials      116      116              
Files with missing lines Coverage Δ
...xtensions/MiddlewareLambdaApplicationExtensions.cs 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9951080...49da19e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@j-d-ha
j-d-ha merged commit 9c82817 into main Dec 21, 2025
10 checks passed
@j-d-ha
j-d-ha deleted the feature/#259-add-ILambdaMiddlewareFactory-interface branch December 21, 2025 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(abstractions): add ILambdaMiddlewareFactory interface

1 participant