aws / aws/aws-lambda-dotnet

Add support for specifying '[LambdaSerializer]' at the class level

Open
#840 3 comments 2 reactions 0 assignees View on GitHub
feature-request module/lambda-client-lib p2 queued
Dominant language
C#
Stars
1.7k
Forks
503
Avg merge
1d 5h
Merged PRs (30d)
18

Description

Allow specifying a lambda serializer for a whole class.

## Describe the Feature
The `[LambdaSerializer]` attribute can currently only be specified either at the assembly level (applying to all lambda functions in the whole dll) or at the method level (which only applies the serializer for that specific method).

When both the assembly and method attributes are applied, the method-level one takes precedence, which is a sensible design.

However, it would be very useful to also allow the attribute at the class level, so that it applies the serializer to all lambda functions inside the class.

### Is your Feature Request related to a problem?
We have a base class defined for all lambda functions as part of a shared library project. Several consuming projects rely on this package to expose their lambda functions by inheriting from this base class.

We had a situation where we needed to have different serializers configured in the same assembly for different functions, but .Net does not expose a way to add attributes to the methods of a base class from the inheriting class. In our scenario, we had to create a new method in the parent class, add the method-level attribute to it, and then redirect the call to the base class' method.

This design is less than ideal, and could be completely avoided on our end if it was possible to just specify the attribute on the class instead: no redirection would be needed.

## Proposed Solution
1. Add the `Class` attribute target to the `[LambdaSerializer]` and use it to indicate which serializer should be used for all functions in a class.
2. Change the place where the serializer is fetched to consider the class-level attribute as well
3. The order of precedence for the attributes should be method->class->assembly.

### Describe alternatives you've considered
Only alternative we found in our scenario was creating a redirection method in the class with the serializer attribute, and then pointing AWS to that method instead of the original one.

## Additional Context
We want to have a strong interface for lambda functions on our side, so this was created as a shared library that other projects implement. We don't want to force a specific serializer in that base class, since the decision depends on the actual implementors.

### Environment
Not environment specific

* [ ] :wave: I may be able to implement this feature request
* [ ] :warning: This feature might incur a breaking change

---

This is a :rocket: Feature Request

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.