0

I have a domain model for a project that can be used with multiple data storage endpoints.

I want to use it with DynamoDB. Dynamo provides object-persistence approach that allows you to annotate properties of a class with structure elements of a DynamoDB collection (i.e. [DynamoDBTable], [DynamoDBHashKey], [DynamoDBLocalSecondaryIndexRangeKey], etc). I would like to keep my Domain model clean so I do not want to decorate it with these endpoint specific annotations.

I know I could use Dynamo Document Model approach but I like the organization of attaching the attributes to properties.

To satisfy both wants, is there a way to inherit my domain model and apply those dynamo annotations in the sub class? Or alternatively, is there a way to apply the data annotations programatically?

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
JakeHova
  • 1,189
  • 2
  • 15
  • 36
  • Is it a viable option for you to define two separate classes? One domain class without annotation and another dto class with annotations. You can use AutoMapper (or any similar) to reduce the overhead of defining mapping back and forth between the two classes. – Peter Csala Nov 08 '21 at 15:10
  • @PeterCsala - I could do that but I worry about the maintenance of it. Someone would have to know to update both models whenever a change comes through. It also seems like a waste because most properties wouldnt have any annotation. I'd really only need to define the table, hashkey, sortkey, and secondary indexes. Most other fields would be kept as is. – JakeHova Nov 08 '21 at 15:42
  • 1
    I'm unaware of this kind of programmatic option of the AWS DynamoDb C# SDK. You can [annotate the properties at runtime](https://stackoverflow.com/questions/14663763/how-to-add-an-attribute-to-a-property-at-runtime) via reflection but that should be plan C. – Peter Csala Nov 08 '21 at 15:52

0 Answers0