protected internal DocumentRepository(CloudStorageAccount storageAccount, string tableName, Func <T, string> partitionKey, Func <T, string> rowKey, IDocumentSerializer serializer)
        {
            this.storageAccount = storageAccount;
            TableName           = tableName ?? TableRepository.GetDefaultTableName <T>();

            this.partitionKey = partitionKey ?? PartitionKeyAttribute.CreateCompiledAccessor <T>();
            this.rowKey       = rowKey ?? RowKeyAttribute.CreateCompiledAccessor <T>();

            stringSerializer = serializer as IStringDocumentSerializer;
            binarySerializer = serializer as IBinaryDocumentSerializer;

            if (stringSerializer == null && binarySerializer == null)
            {
                throw new ArgumentException($"A valid serializer implementing either {nameof(IBinaryDocumentSerializer)} or {nameof(IStringDocumentSerializer)} is required.", nameof(serializer));
            }

            // Use the right strategy depending on the provided serializer.
            if (stringSerializer != null)
            {
                enumerate = EnumerateStringAsync;
                get       = GetStringAsync;
                put       = PutStringAsync;
            }
            else
            {
                enumerate = EnumerateBinaryAsync;
                get       = GetBinaryAsync;
                put       = PutBinaryAsync;
            }

            table = GetTableAsync(TableName);
        }
예제 #2
0
        public static IDocumentRepository <T> Create <T>(
            CloudStorageAccount storageAccount,
            string?tableName = default,
            Func <T, string>?partitionKey  = default,
            Func <T, string>?rowKey        = default,
            IDocumentSerializer?serializer = default) where T : class
        {
            tableName ??= TableRepository.GetDefaultTableName <T>();
            partitionKey ??= PartitionKeyAttribute.CreateCompiledAccessor <T>();
            rowKey ??= RowKeyAttribute.CreateCompiledAccessor <T>();
            serializer ??= DocumentSerializer.Default;

            return(new DocumentRepository <T>(storageAccount, tableName, partitionKey, rowKey, serializer));
        }