Auto property definition alongside [DynamoDbIgnore]
#1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As I mentioned on AllocZero#238, under
Attribute Annotation Requirements in EfficientDynamoDb
, this PR should allow basically a more seamless experience. It will automatically map properties that are derivates of the class that has the attribute.This PR introduces two new attribute classes as part of our push for improving DynamoDb utilization:
DynamoDbAutoPropertyAttribute
andDynamoDbIgnoreAttribute
.Key Changes
Introduction of
DynamoDbAutoPropertyAttribute
This attribute allows automatic mapping of the properties from a class or interface to DynamoDb attributes. It includes:
The properties are marked to be automatically mapped to DynamoDb attributes unless they are explicitly ignored.
Is equivalent to
With
DynamoDbAutoPropertyAttribute
, the properties are automatically treated as DynamoDb attributesIntroduction of
DynamoDbIgnoreAttribute
This attribute can be used to mark unwanted properties, preventing them from being automatically mapped to DynamoDb attributes, even in classes carrying the
DynamoDbAutoPropertyAttribute
.Is equivalent to
In the example above,
AutoProp1
is automatically mapped to a DynamoDb attribute, whileAutoProp2
is ignored.The Precedence of DynamoDbPropertyAttribute over DynamoDbIgnoreAttribute
In the event that a property is marked using both the
DynamoDbIgnoreAttribute
andDynamoDbPropertyAttribute
, the explicit nature ofDynamoDbPropertyAttribute
takes precedence. This allows an overriding feature, whereby a specific property, despite being explicitly ignored (e.g., at the interface), can still be stored if it's explicitly required usingDynamoDbPropertyAttribute
at the derived class level.This feature allows more flexibility in dealing with attributes on both parent and child classes or interfaces. By specifying
DynamoDbPropertyAttribute
on a property, that property will be included in the mapping process to DynamoDb attributes, bypassing theDynamoDbIgnoreAttribute
.InterfaceProp1
is MAPPED and this is why:SampleInterface
interface usingDynamoDbIgnoreAttribute
, it is explicitly marked for mapping to DynamoDb in theSampleEntity
usingDynamoDbPropertyAttribute
, which takes presedence.InterfaceProp2
is MAPPED and this is why:DynamoDbAutoProperty
and no explicit ignore is defined, it is naturally mapped to DynamoDb.InterfaceProp3
is NOT MAPPED and this is why:SampleEntity
usingDynamoDbIgnoreAttribute
, theDynamoDbAutoProperty
from the interface (parent) doesn't have any effect.