Skip to content

DynamoDB Table misrepresents dependency on IAmazonDynamoDB #1589

Closed
@rlyczynski

Description

@rlyczynski

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.

private Table(IAmazonDynamoDB ddbClient, TableConfig config)
{
if (config == null)
throw new ArgumentNullException("config");
if (ddbClient == null)
throw new ArgumentNullException("ddbClient");
#if PCL || UNITY || NETSTANDARD
DDBClient = ddbClient as AmazonDynamoDBClient;
#else
DDBClient = ddbClient;
#endif
Config = config;
}

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.

Metadata

Metadata

Assignees

Labels

dynamodbfeature-requestA feature should be added or improved.needs-major-versionCan only be considered for the next major releasep1This is a high priority issuequeuedv4

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions