Skip to content

refactor(abstractions): replace Lazy implementation with property for JSON options#199

Merged
j-d-ha merged 4 commits into
mainfrom
refactor/update-envelope-options-default-lambda-json-options
Nov 29, 2025
Merged

refactor(abstractions): replace Lazy implementation with property for JSON options#199
j-d-ha merged 4 commits into
mainfrom
refactor/update-envelope-options-default-lambda-json-options

Conversation

@j-d-ha

@j-d-ha j-d-ha commented Nov 29, 2025

Copy link
Copy Markdown
Collaborator

🚀 Pull Request

📋 Summary

This PR refactors the EnvelopeOptions.LambdaDefaultJsonOptions field from a Lazy<JsonSerializerOptions> to a regular property with lazy initialization using C# 14's field keyword. This simplifies the API surface by removing the need to access .Value throughout the codebase while maintaining the lazy initialization behavior.

Changes:

  • Abstractions: Converted LambdaDefaultJsonOptions from Lazy<JsonSerializerOptions> to a property with lazy initialization
  • Core: Updated EnvelopeOptionsPostConfiguration to use null-coalescing assignment, only setting TypeInfoResolver when not explicitly configured
  • Envelopes: Removed .Value access throughout CloudWatchLogs and SQS envelope implementations
  • Tests: Updated test code to use the simplified property access

✅ 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

Part of ongoing refactoring efforts to improve API ergonomics and leverage modern C# features.


💬 Notes for Reviewers

Key improvements:

  1. Simpler API: Consumers no longer need to use .Value to access JSON options
  2. Safer post-configuration: TypeInfoResolver is only set when not explicitly configured (using ??= instead of direct assignment)
  3. Modern C#: Leverages C# 14's field keyword for clean lazy initialization pattern

Breaking change consideration: While this changes the field type from Lazy<T> to T, it's unlikely to be a breaking change since:

  • The field was always accessed via .Value in the codebase
  • External consumers would typically only read the property, not depend on the Lazy<> wrapper type
  • The lazy initialization behavior is preserved

…or JSON options

- Refactored `LambdaDefaultJsonOptions` from lazy initialization to a property with caching.
- Improved clarity and maintainability of the code by simplifying access patterns.
…nfigured

- Updated `PostConfigure` logic to conditionally assign `TypeInfoResolver` if not already set.
- Clarified XML documentation regarding the behavior of `TypeInfoResolver` assignment.
…ccess

- Updated `SqsSnsEnvelope` to use `LambdaDefaultJsonOptions` directly instead of `.Value`.
- Updated `CloudWatchLogsEnvelopeBase` for consistent use of `LambdaDefaultJsonOptions`.
- Updated `CloudWatchLogsEnvelopeTests` to access `LambdaDefaultJsonOptions` directly.
- Simplified `JsonSerializer.Serialize` calls for improved readability and maintainability.
@github-actions github-actions Bot added breaking-change Introduces a breaking change type: refactor Code refactoring labels Nov 29, 2025
@j-d-ha j-d-ha removed the breaking-change Introduces a breaking change label Nov 29, 2025
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 29, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ambda.Host.Abstractions/Options/EnvelopeOptions.cs 92.30% 1 Missing ⚠️
...t/Core/Options/EnvelopeOptionsPostConfiguration.cs 0.00% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #199      +/-   ##
==========================================
+ Coverage   90.65%   90.68%   +0.02%     
==========================================
  Files         102      102              
  Lines        2237     2233       -4     
  Branches      252      254       +2     
==========================================
- Hits         2028     2025       -3     
+ Misses        116      115       -1     
  Partials       93       93              
Files with missing lines Coverage Δ
...lopes.CloudWatchLogs/CloudWatchLogsEnvelopeBase.cs 89.47% <100.00%> (ø)
...pes/AwsLambda.Host.Envelopes.Sqs/SqsSnsEnvelope.cs 100.00% <100.00%> (ø)
...ambda.Host.Abstractions/Options/EnvelopeOptions.cs 94.11% <92.30%> (-5.89%) ⬇️
...t/Core/Options/EnvelopeOptionsPostConfiguration.cs 0.00% <0.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 90d4fa1...f1c631d. 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 e6b9b28 into main Nov 29, 2025
8 checks passed
@j-d-ha
j-d-ha deleted the refactor/update-envelope-options-default-lambda-json-options branch November 29, 2025 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant