Description
I think the Table
class misrepresents it's dependency on IAmazonDynamoDB
when it really depends on an AmazonDynamoDBClient
. The constructor takes an IAmazonDynamoDB
but then attempts to cast it to a AmazonDynamoDBClient
just a few lines later.
aws-sdk-net/sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Table.cs
Lines 369 to 383 in 41ca576
This hinders the ability to unit test code that relies on the Table
class by passing in a mocked version of IAmazonDynamoDB
and also makes it very difficult to do something like use a decorator instead of an AmazonDynamoDBClient
specifically.
At very least I think the constructor should be clear that it depends on a AmazonDynamoDBClient
, but ideally the Table
class would really only depended on an IAmazonDynamoDB
.
Steps to Reproduce
Use the Table
class with an object that implements IAmazonDynamoDB
but is not a AmazonDynamoDBClient
.
Table.LoadTable((IAmazonDynamoDB)notAnAmazonDynamoDBClient, "tablename")
This will cause the cast to an AmazonDynamoDBClient
to fail and set DDBClient
to null and eventually result in a NullReferenceException
.