Skip to content

HTTP Writing Streamlining#18

Merged
feO2x merged 3 commits intomainfrom
17-http-writing-streamlining
Feb 24, 2026
Merged

HTTP Writing Streamlining#18
feO2x merged 3 commits intomainfrom
17-http-writing-streamlining

Conversation

@feO2x
Copy link
Copy Markdown
Owner

@feO2x feO2x commented Feb 23, 2026

Closes #17

This pull request streamlines the HTTP write integration for ASP.NET Core Minimal APIs and MVC by adopting a new wrapper-based serialization pattern. The changes replace the previous custom converter and out-of-band options passing with stateless, pipeline-friendly JSON converters, improving extensibility and simplifying the codebase. The most important changes are:

Serialization Pipeline Refactor

JSON Converter Improvements

  • Implemented new stateless, write-only JSON converters (HttpResultForWritingJsonConverter, generic variant, and factory) that serialize the wrapper types through the standard System.Text.Json pipeline, removing the need for custom Serialize methods or converter downcasts. (ai-plans/0017-HTTP-write-integration-streamlining.md, ai-plans/0017-HTTP-write-integration-streamlining.mdR1-R209)

ASP.NET Core Integration Updates

  • Refactored BaseLightResult and LightResult to resolve and freeze options once per request, passing ResolvedHttpWriteOptions to header and body writing methods. Updated method signatures and removed legacy converter downcast logic. (src/Light.Results.AspNetCore.MinimalApis/BaseLightResult.cs, [1] [2]; src/Light.Results.AspNetCore.MinimalApis/LightResult.cs, [3]
  • Updated body serialization in LightResult to use the new wrapper and pipeline, removing custom converter logic and fallback paths. (src/Light.Results.AspNetCore.MinimalApis/LightResult.cs, src/Light.Results.AspNetCore.MinimalApis/LightResult.csR38-R55)

Benchmark and Registration Adjustments

@feO2x feO2x self-assigned this Feb 23, 2026
@feO2x feO2x added the enhancement New feature or request label Feb 23, 2026
@feO2x feO2x linked an issue Feb 23, 2026 that may be closed by this pull request
23 tasks
@feO2x feO2x requested a review from Copilot February 23, 2026 20:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the HTTP write integration for ASP.NET Core Minimal APIs and MVC by introducing a wrapper-based serialization pattern. The changes replace the previous custom converter architecture with stateless, pipeline-friendly JSON converters that bundle result data with resolved serialization options. This approach follows the existing CloudEvents pattern and addresses two key issues: (1) custom converters can now properly extend the serialization behavior, and (2) serialization options are passed through the standard System.Text.Json pipeline rather than out-of-band.

Changes:

  • Introduced intermediary wrapper structs (HttpResultForWriting and HttpResultForWriting<T>) that bundle results with frozen ResolvedHttpWriteOptions
  • Implemented stateless JSON converters that serialize wrapper types through the standard System.Text.Json pipeline
  • Updated ASP.NET Core integration layers to construct wrappers and resolve options once per request
  • Simplified module registration by removing the need to inject options into converter constructors
  • Updated metadata serialization helpers to accept annotation parameters directly instead of JsonSerializerOptions

Reviewed changes

Copilot reviewed 40 out of 40 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Light.Results/Http/Writing/ResolvedHttpWriteOptions.cs New frozen struct capturing per-request HTTP write options
src/Light.Results/Http/Writing/HttpResultForWriting.cs New wrapper structs bundling results with resolved options
src/Light.Results/Http/Writing/HttpResultForWritingExtensions.cs Extension methods for creating wrapper structs
src/Light.Results/Http/Writing/ResolvedHttpWriteOptionsExtensions.cs Extension method for freezing mutable options
src/Light.Results/Http/Writing/Json/HttpResultForWritingJsonConverter.cs New stateless converters for wrapper types
src/Light.Results/Http/Writing/Json/HttpResultForWritingJsonConverterFactory.cs Factory for creating generic wrapper converters
src/Light.Results/Http/Writing/Json/SerializerExtensions.cs Updated to accept ResolvedHttpWriteOptions parameter
src/Light.Results/Http/Writing/Module.cs Simplified to register stateless converters without options parameter
src/Light.Results/SharedJsonSerialization/Writing/MetadataExtensions.cs Refactored to accept annotation parameter instead of JsonSerializerOptions
src/Light.Results/SharedJsonSerialization/Writing/ErrorsExtensions.cs Updated to use JsonSerializer.Serialize with JsonTypeInfo
src/Light.Results/SharedJsonSerialization/Writing/SystemTextJsonWritingExtensions.cs Updated to use JsonSerializer.Serialize with JsonTypeInfo
src/Light.Results/CloudEvents/Writing/Json/JsonCloudEventsExtensions.cs Updated metadata writing to use annotation parameter
src/Light.Results.AspNetCore.Shared/HttpExtensions.cs Removed options parameter from SetMetadataValuesAsHeadersIfNecessary
src/Light.Results.AspNetCore.MinimalApis/BaseLightResult.cs Resolve options once and pass to SetHeaders and WriteBodyAsync
src/Light.Results.AspNetCore.MinimalApis/LightResult.cs Construct wrapper and serialize through standard pipeline
src/Light.Results.AspNetCore.MinimalApis/Module.cs Simplified JSON options configuration
src/Light.Results.AspNetCore.MinimalApis/Serialization/LightResultsMinimalApiJsonContext.cs Updated to include HttpResultForWriting in source generation
src/Light.Results.AspNetCore.Mvc/BaseLightActionResult.cs Resolve options once and pass to SetHeaders and WriteBodyAsync
src/Light.Results.AspNetCore.Mvc/LightActionResult.cs Construct wrapper and serialize through standard pipeline
src/Light.Results.AspNetCore.Mvc/Module.cs Simplified JSON options configuration
tests/Light.Results.Tests/Http/Writing/HttpResultForWritingSerializationTests.cs New comprehensive tests for wrapper serialization
tests/Light.Results.Tests/Http/Writing/ModuleTests.cs Updated to remove options parameter from converter registration tests
tests/Light.Results.Tests/Http/JsonConverterDirectionTests.cs Updated to test new wrapper converters
tests/Light.Results.Tests/SharedJsonSerialization/Writing/SharedWritingExtensionsTests.cs Updated to test annotation-based metadata writing
tests/Light.Results.AspNetCore.Shared.Tests/Serialization/ResultJsonConverterReadTests.cs Updated to test wrapper type deserialization (which throws)
tests/Light.Results.AspNetCore.MinimalApis.Tests/LightResultSerializationTests.cs Updated to test custom serializer options with new architecture
tests/Light.Results.AspNetCore.MinimalApis.Tests/IntegrationTests/ExtendedMinimalApiApp.cs Updated test endpoints and removed custom converters
tests/Light.Results.AspNetCore.MinimalApis.Tests/ExtendedMinimalApiJsonContext.cs Updated to include HttpResultForWriting types in source generation
tests/Light.Results.AspNetCore.Mvc.Tests/IntegrationTests/ExtendedMvcController.cs Updated test endpoints and removed custom converters
benchmarks/Benchmarks/HttpWriteSerializationBenchmarks.cs New benchmarks for wrapper-based serialization
ai-plans/0017-HTTP-write-integration-streamlining.md Detailed plan documenting the refactoring approach

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Light.Results.AspNetCore.Mvc/LightActionResult.cs Outdated
Comment thread src/Light.Results/SharedJsonSerialization/Writing/ErrorsExtensions.cs Outdated
Comment thread src/Light.Results.AspNetCore.MinimalApis/LightResult.cs Outdated
Comment thread src/Light.Results.AspNetCore.MinimalApis/LightResult.cs Outdated
Comment thread src/Light.Results.AspNetCore.Mvc/LightActionResult.cs Outdated
@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Complexity Health
Light.Results 96% 94% 2300
Light.Results.AspNetCore.MinimalApis 93% 80% 25
Light.Results.AspNetCore.Mvc 93% 80% 26
Light.Results.AspNetCore.Shared 94% 92% 28
Summary 96% (3565 / 3703) 94% (1839 / 1962) 2379

Minimum allowed line rate is 60%

@feO2x feO2x merged commit 2f0970d into main Feb 24, 2026
2 checks passed
@feO2x feO2x deleted the 17-http-writing-streamlining branch February 24, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamlining of HTTP Writing Integrations

2 participants