Allow AspNetCoreServer.Hosting to use a custom serializer
Describe the feature
Currently the AspNetCoreServer.Hosting package initializes a DefaultLambdaJsonSerializer when creating the HandlerWrapper for the specific RuntimeSupportServer. Update this to use DefaultLamddaJsonSerializer as a default but allow a custom JsonSerializer to be used if required.
A link to the line in question can be seen here: https://github.com/aws/aws-lambda-dotnet/blob/0e8e42a0fe818f1adc1f97bb035f2535934c16b4/Libraries/src/Amazon.Lambda.AspNetCoreServer.Hosting/Internal/LambdaRuntimeSupportServer.cs#L73
Use Case
Allow source generated serialization to be used when running an API on Lambda. If compiling an API with NativeAOT enabled to run on Lambda the DefaultLambdaJsonSerializer will not work and a custom serialization context is required.
Proposed Solution
Add an optional parameter to the AddAWSLambdaHosting method to allow a custom serializer to be passed in. Store the option in a static variable.
Update the CreateHandlerWrapper method to use this static variable instead of being hardcoded to initialize a new DefaultLambdaJsonSerializer.
Other Information
No response
Acknowledgements
- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
AWS .NET SDK and/or Package version used
Amazon.Lambda.AspNetCoreServer.Hosting 1.0.0
Targeted .NET Platform
.NET6 / .NET 7
Operating System and version
ASL2
This needs review with the team. @jeastham1993 Feel free to contribute PR so that it could be reviewed by the team.
@ashishdhingra happy to. I've got a version I've been using for testing locally. I'll create a PR today or tomorrow for review.
@ashishdhingra PR raised.
PR has been released as part of version 1.5.0 of Amazon.Lambda.AspNetCoreServer.Hosting
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.