diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/BaseOperationConfig.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BaseOperationConfig.cs new file mode 100644 index 000000000000..5f52b622ba09 --- /dev/null +++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/BaseOperationConfig.cs @@ -0,0 +1,101 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +namespace Amazon.DynamoDBv2.DataModel +{ + /// + /// Base class for operation-specific configurations for DynamoDB object persistence operations. + /// + /// + /// This should only contain members that are relevant to all object persistence operations, + /// anything operation-specific should be added to derived classes. + /// +#if NET8_0_OR_GREATER + // The DataModel namespace doesn't support trimming yet, so annotate public classes/methods as incompatible + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode(Custom.Internal.InternalConstants.RequiresUnreferencedCodeMessage)] +#endif + public abstract class BaseOperationConfig + { + /// + /// Indicates which DynamoDB table to use. This overrides the table specified + /// by the on the .NET objects that you're saving or loading. + /// + public string OverrideTableName { get; set; } + + /// + /// Directs to prefix all table names + /// with a specific string. If this is null or empty, no prefix is used + /// and default table names are used. + /// + public string TableNamePrefix { get; set; } + + /// + /// The object persistence model API relies on an internal cache of the DynamoDB table's metadata to + /// construct and validate requests. This controls how the cache key is derived, which influences + /// when the SDK will call DescribeTable internally to populate the cache. + /// + /// + /// For the cache key will be a combination of the table name, credentials, region and service URL. + /// For the cache key will only consist of the table name. This reduces cache misses in contexts + /// where you are accessing tables with identical structure but using different credentials or endpoints (such as a multi-tenant application). + /// + public MetadataCachingMode? MetadataCachingMode { get; set; } + + /// + /// If true disables fetching table metadata automatically from DynamoDB. Table metadata must be + /// defined by attributes and/or in . + /// + /// + /// Setting this to true can avoid latency and thread starvation due to blocking asynchronous + /// DescribeTable calls that are used to populate the SDK's cache of table metadata. + /// It requires that the table's index schema be accurately described via the above methods, + /// otherwise exceptions may be thrown and/or the results of certain DynamoDB operations may change. + /// + public bool? DisableFetchingTableMetadata { get; set; } + + /// + /// Specification which controls the conversion between .NET and DynamoDB types. + /// + public DynamoDBEntryConversion Conversion { get; set; } + + /// + /// Contorls how interprets emptry string values. + /// If the property is false (or not set), empty string values will be + /// interpreted as null values. + /// + public bool? IsEmptyStringValueEnabled { get; set; } + + /// + /// Converts this to the shared + /// + /// + /// Users should interact with the new, operation-specific configs, but we + /// convert to the internal shared config for the internal code paths. + /// + /// A new with settings copied from the operation-specific config + internal virtual DynamoDBOperationConfig ToDynamoDBOperationConfig() + { + return new DynamoDBOperationConfig() + { + OverrideTableName = OverrideTableName, + TableNamePrefix = TableNamePrefix, + MetadataCachingMode = MetadataCachingMode, + DisableFetchingTableMetadata = DisableFetchingTableMetadata, + Conversion = Conversion, + IsEmptyStringValueEnabled = IsEmptyStringValueEnabled + }; + } + } +} diff --git a/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DataModelOperationSpecificConfigTests.cs b/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DataModelOperationSpecificConfigTests.cs new file mode 100644 index 000000000000..0ecf3bc18180 --- /dev/null +++ b/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DataModelOperationSpecificConfigTests.cs @@ -0,0 +1,22 @@ +using Amazon.DynamoDBv2.DataModel; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AWSSDK_DotNet.UnitTests +{ + /// + /// These tests serve as a reminder to developers and reviewers to + /// ensure that new DynamoDB operation-specific properties are plumbed + /// into the internal code paths correctly + /// + [TestClass] + public class DataModelOperationSpecificConfigTests + { + [TestMethod] + public void BaseOperationConfig() + { + // If this fails because you've added a property, be sure to add it to + // `ToDynamoDBOperationConfig` before updating this unit test + Assert.AreEqual(6, typeof(BaseOperationConfig).GetProperties().Length); + } + } +}