Skip to content

Comments

Add optional parameters to the ServiceCollection extensions#27

Merged
ncipollina merged 2 commits intoLayeredCraft:mainfrom
TylerReid:configExtensionOptions
Aug 14, 2025
Merged

Add optional parameters to the ServiceCollection extensions#27
ncipollina merged 2 commits intoLayeredCraft:mainfrom
TylerReid:configExtensionOptions

Conversation

@TylerReid
Copy link
Collaborator

  • Add optional parameters to the ServiceCollection extensions to configure dynamodb client. Fix warnings in unit tests by passing test cancellation token
  • add tests

🚀 Pull Request

📋 Summary

This allows users to configure the DynamoDB client in more ways. This can be helpful in scenarios such as needing to set a custom ServiceURL for private link inside aws, or to use localstack for testing.


✅ Checklist

  • My changes build cleanly
  • I’ve added/updated relevant tests
  • I’ve added/updated documentation or README
  • I’ve followed the coding style for this project
  • I’ve tested the changes locally (if applicable)

🧪 Related Issues or PRs

Closes #25


💬 Notes for Reviewers

This contains a binary breaking change due to the optional parameters.

I went ahead and fixed some xunit analyzer warnings about cancellation tokens in the tests. It was so close to no warnings in the build I couldn't resist 🙂

* Add optional parameters to the ServiceCollection extensions to configure dynamodb client. Fix warnings in unit tests by passing test cancellation token
* add tests
public static IServiceCollection AddDynamoDbDistributedLock(this IServiceCollection services,
IConfiguration configuration,
string sectionName = DynamoDbLockOptions.DynamoDbLockSettings)
string sectionName = DynamoDbLockOptions.DynamoDbLockSettings, string? awsOptionsSectionName = null)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding these optional parameters breaks binary compatibility, but because this has an existing optional param of the same type, I couldn't think of a way to do the trick of manually making another set of methods, because they are ambiguous and one gets hidden.

I think this is probably OK, since in my experience binary breaks are not as big of a deal in modern dotnet + nuget, and if you did hit this by copying some old dll, you would see it immediately in startup.

return Task.FromResult(expectedResult);
},
_ => true);
}, _ => true, TestContext.Current.CancellationToken);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xunit analyzer was warning about not using a cancellation token here, and recommended this one, so that if you cancel tests that hang they will have a better chance of failing fast and gracefully. This does slightly change the code paths being hit, but seems worth it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥Good catch!

{
// Arrange
var services = new ServiceCollection();
var awsOptions = new AWSOptions
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit tests only cover the overload that passes in the object, not the config section, because in the other tests you override the dynamodb service in order to bypass credential resolution. I couldn't figure out a good way to make all that work outside of setting fake aws env vars, and if I did the same thing of registering a substitute, it wouldn't actually test anything.

So to increase coverage you could set aws access keys and secret env vars, but that makes me feel gross in tests so I didn't.

@ncipollina ncipollina requested a review from Copilot August 14, 2025 16:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds optional parameters to ServiceCollection extensions for configuring the DynamoDB client with custom AWS options, enabling scenarios like using custom service URLs for private links or LocalStack testing. Additionally, it fixes xUnit analyzer warnings by passing cancellation tokens to test methods.

  • Add optional AWSOptions parameter to service registration methods
  • Add optional awsOptionsSectionName parameter for configuration-based setup
  • Fix xUnit analyzer warnings by adding cancellation token parameters to test method calls

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/DynamoDb.DistributedLock/Extensions/ServiceCollectionExtensions.cs Add optional AWSOptions parameters to both extension methods for DynamoDB client configuration
src/DynamoDb.DistributedLock/DynamoDbLockOptions.cs Add XML documentation comment for the DynamoDbLockSettings constant
test/DynamoDb.DistributedLock.Tests/Extensions/ServiceCollectionExtensionsTests.cs Add test case for new AWSOptions functionality
test/DynamoDb.DistributedLock.Tests/Retry/RetryIntegrationTests.cs Add cancellation token parameters to test method calls
test/DynamoDb.DistributedLock.Tests/Retry/ExponentialBackoffRetryPolicyTests.cs Add cancellation token parameters and clean up lambda formatting
README.md Add documentation examples for the new AWSOptions configuration capabilities

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

@ncipollina ncipollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀The change looks good. The only ask I have is that you update the VersionPrefix in Directory.Build.props to 1.1.2.

@TylerReid
Copy link
Collaborator Author

TylerReid commented Aug 14, 2025

@ncipollina ah, I looked in the project file and didn't see that. Didn't know if your actions did magic.

What prefix do you think makes sense? 1.2.0? helps if I read the comment...

@ncipollina
Copy link
Collaborator

@all-contributors add @TylerReid for code

@allcontributors
Copy link
Contributor

@ncipollina

I've put up a pull request to add @TylerReid! 🎉

Copy link
Collaborator

@ncipollina ncipollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Nice work!!!

@ncipollina ncipollina merged commit b1e021f into LayeredCraft:main Aug 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: AddDynamoDbDistributedLock should take in an optional AWSOptions

2 participants