Skip to content

Commit 25646ff

Browse files
authored
Merge pull request #28 from markjbrown/main
Refresh all
2 parents f749672 + ba7f29d commit 25646ff

File tree

108 files changed

+1319
-3125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1319
-3125
lines changed

.devcontainer/data-binning/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
44
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
55
"workspaceFolder": "/workspace/data-binning/source/",
6-
"postAttachCommand": "dotnet build Cosmos_Patterns_Bucketing.csproj",
6+
"postAttachCommand": "dotnet build DataBinning.csproj",
77
"customizations": {
88
"codespaces": {
99
"openFiles": [

.devcontainer/distributed-counter/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
44
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
55
"workspaceFolder": "/workspace/distributed-counter/source/",
6-
"postAttachCommand": "dotnet build Cosmos_Patterns_DistributedCounter.sln",
6+
"postAttachCommand": "dotnet build DistributedCounter.sln",
77
"customizations": {
88
"codespaces": {
99
"openFiles": [

.devcontainer/distributed-lock/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
44
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
55
"workspaceFolder": "/workspace/distributed-lock/source/",
6-
"postAttachCommand": "dotnet build consoleapp/Cosmos_Patterns_GlobalLock.sln",
6+
"postAttachCommand": "dotnet build GlobalLock.csproj",
77
"customizations": {
88
"codespaces": {
99
"openFiles": [

.devcontainer/event-sourcing/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
44
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
55
"workspaceFolder": "/workspace/event-sourcing/source/",
6-
"postAttachCommand": "dotnet build Cosmos_Patterns_EventSourcing.csproj",
6+
"postAttachCommand": "dotnet build EventSourcing.csproj",
77
"customizations": {
88
"codespaces": {
99
"openFiles": [

.devcontainer/preallocation/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"image": "ghcr.io/azure-samples/cosmos-db-design-patterns/devcontainer-base:latest",
44
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
55
"workspaceFolder": "/workspace/preallocation/source/",
6-
"postAttachCommand": "dotnet build Cosmos_Patterns_Preallocation.csproj",
6+
"postAttachCommand": "dotnet build Preallocation.csproj",
77
"customizations": {
88
"codespaces": {
99
"openFiles": [

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
appsettings.development.json
1111
appsettings.production.json
1212
appsettings.*.json
13+
local.settings.json
1314

1415
# User-specific files
1516
*.rsuser
@@ -356,7 +357,6 @@ MigrationBackup/
356357

357358
# Ionide (cross platform F# VS Code tools) working folder
358359
.ionide/
359-
/distributed-lock/source/consoleapp/appsettings.development.json
360-
/distributed-counter/source/Visualizer/appsettings.Development.json
361-
/distributed-counter/source/ConsumerApp/appsettings.Development.json
362-
/data-binning/source/appsettings.development.json
360+
361+
/document-versioning/source/website/appsettings.Development.json
362+
/schema-versioning/source/website/appsettings.Development.json

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,14 @@ Design patterns play a crucial role in building robust applications and modeling
1111
### Key Benefits of Using Design Patterns
1212

1313
- **Efficiency and Best Practices**: Design patterns encapsulate proven solutions, saving you time and effort by leveraging established best practices.
14-
1514
- **Scalability and Performance**: Many patterns are optimized for scalability, ensuring your application can handle growth without compromising performance.
16-
1715
- **Consistency and Maintainability**: Patterns promote consistent architecture, making codebases easier to understand, maintain, and extend.
18-
1916
- **Reliability and Resilience**: Patterns address fault tolerance and error handling, resulting in applications that gracefully recover from failures.
20-
2117
- **Flexibility and Adaptability**: Patterns facilitate changes, enabling your application to evolve and adapt to new requirements seamlessly.
22-
2318
- **Reusability and Accelerated Development**: Patterns encourage reusable components, speeding up development and reducing the risk of bugs.
24-
2519
- **Effective Data Modeling**: In NoSQL databases like Azure Cosmos DB, choosing the right pattern ensures efficient data modeling for enhanced performance.
26-
2720
- **Documentation and Communication**: Patterns provide a shared vocabulary, aiding communication and collaboration among team members.
28-
2921
- **Adherence to Best Practices**: Design patterns ensure applications adhere to security, data integrity, and maintainability best practices.
30-
3122
- **Reduced Learning Curve**: Developers familiar with patterns quickly understand and contribute to projects, reducing onboarding time.
3223

3324

@@ -74,15 +65,31 @@ Dive into the `schema-versioning` folder to learn how to manage changes to your
7465

7566
## Getting Started
7667

77-
Navigate to the individual folders of each design pattern for a dedicated `README.md` file that provides step-by-step instructions on how to implement and work with the pattern in your applications.
68+
### Using the Terminal:
69+
- Open the terminal on your computer.
70+
- Navigate to the directory where you want to clone the repository.
71+
- Type `git clone https://github.com/Azure-Samples/cosmos-db-design-patterns.git` and press enter.
72+
- The repository will be cloned to your local machine.
73+
74+
### Using Visual Studio Code:
75+
- Open Visual Studio Code.
76+
- Click on the **Source Control** icon in the left sidebar.
77+
- Click on the **Clone Repository** button at the top of the Source Control panel.
78+
- Paste `https://github.com/Azure-Samples/cosmos-db-design-patterns.git` into the text field and press enter.
79+
- Select a directory where you want to clone the repository.
80+
- The repository will be cloned to your local machine.
81+
82+
### Using GitHub Codespaces
83+
84+
Nearly all of these samples are configured to run from [GitHub Codespaces](https://docs.github.com/codespaces/overview).
7885

79-
### Trying Out the Design Patterns with Azure Cosmos DB for Free
86+
Navigate to the individual folders of each design pattern for a dedicated `README.md` file and look for the GitHub Codespaced badge.
8087

81-
You can try out these design patterns using a **free Azure Cosmos DB account**, making it easy to experiment with Azure Cosmos DB before making a commitment. No credit card is required to get started, and your account is free for 30 days. After the initial 30-day period, you can create a new sandbox account. Additionally, you have the option to extend the trial beyond 30 days for an additional 24 hours. If you decide to upgrade, you can do so at any time during the 30-day trial period.
88+
### Setting up Azure Cosmos DB
8289

83-
**Sign up for your free Azure Cosmos DB account at [aka.ms/trycosmosdb](https://aka.ms/trycosmosdb).**
90+
All of these design patterns are built to run from a single Serverless Azure Cosmos DB account. Before running any of the samples, click the Deploy to Azure button below to create a Serverless Azure Cosmos DB account. You will need the URI Primary Key and Connection String for these. Keep those handy as you prepare each sample to run.
8491

85-
This opportunity provides a risk-free environment to explore these design patterns and see how Azure Cosmos DB can enhance your application development and data modeling efforts. Whether you're an experienced developer or just getting started, the free trial allows you to discover the benefits firsthand.
92+
[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fgithub.com%2FAzureCosmosDB%2Fdesign-patterns%2Ftree%2Fmain%2Fazuredeploy.json)
8693

8794
Happy coding with Azure Cosmos DB and these powerful design patterns!
8895

attribute-array/README.md

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,38 +176,19 @@ You can try out this implementation by running the code in [GitHub Codespaces](h
176176

177177
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/azure-samples/cosmos-db-design-patterns?quickstart=1&devcontainer_path=.devcontainer%2Fattribute-array%2Fdevcontainer.json)
178178

179-
## Create an Azure Cosmos DB for NoSQL account
179+
## Set up application configuration files
180180

181-
1. Create a free Azure Cosmos DB for NoSQL account: (<https://cosmos.azure.com/try>)
181+
You need to configure **two** application configuration files to run these demos.
182182

183-
1. In the Data Explorer, create a new database named **CosmosPatterns** with shared autoscale throughput:
183+
1. Go to your resource group.
184184

185-
| | Value |
186-
| --- | --- |
187-
| **Database name** | `CosmosPatterns` |
188-
| **Throughput** | `1000` (*Autoscale*) |
185+
1. Select the Serverless Azure Cosmos DB for NoSQL account that you created for this repository.
189186

190-
**Note:** We are using shared database throughput because it can scale down to 100 RU/s when not running. This is the most cost efficient if running in a paid subscription and not using Free Tier.
187+
1. From the navigation, under **Settings**, select **Keys**. The values you need for the application settings for the demo are here.
191188

192-
1. Create a container **AttributeArrays** with the following values:
189+
While on the Keys blade, make note of the `URI` and `PRIMARY KEY`. You will need these for the sections below.
193190

194-
| | Value |
195-
| --- | --- |
196-
| **Database name** | `CosmosPatterns` |
197-
| **Container name** | `AttributeArrays` |
198-
| **Partition key path** | `/productId` |
199-
200-
## Get Azure Cosmos DB connection information
201-
202-
You will need connection details for the Azure Cosmos DB account.
203-
204-
1. Select the new Azure Cosmos DB for NoSQL account.
205-
206-
1. Open the Keys blade, click the Eye icon to view the `PRIMARY KEY`. Keep this and the `URI` handy. You will need these for the next step.
207-
208-
## Prepare the app configuration
209-
210-
1. Open the application code, create an **appsettings.Development.json** file in the **/source** folder. In the file, create a JSON object with **CosmosUri** and **CosmosKey** properties. Copy and paste the values for `URI` and `PRIMARY KEY` from the previous step:
191+
1. Open the attribute-array project and add a new **appsettings.development.json** file with the following contents:
211192

212193
```json
213194
{
@@ -216,6 +197,20 @@ You will need connection details for the Azure Cosmos DB account.
216197
}
217198
```
218199

200+
1. Replace the `CosmosURI` and `CosmosKey` with the values from the Keys blade in the Azure Portal.
201+
1. Modify the **Copy to Output Directory** to **Copy Always** (For VS Code add the XML below to the csproj file)
202+
1. Save the file.
203+
204+
```xml
205+
<ItemGroup>
206+
<Content Update="appsettings.development.json">
207+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208+
</Content>
209+
</ItemGroup>
210+
```
211+
212+
## Run the app
213+
219214
1. Open a terminal and run the application:
220215

221216
```bash

attribute-array/source/Program.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
IConfigurationBuilder configuration = new ConfigurationBuilder()
1111
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
12-
.AddJsonFile($"appsettings.Development.json", optional: true);
12+
.AddJsonFile($"appsettings.development.json", optional: true);
1313

1414
Cosmos? config = configuration
1515
.Build()
@@ -37,8 +37,7 @@
3737
);
3838

3939
Database database = await client.CreateDatabaseIfNotExistsAsync(
40-
id: "CosmosPatterns",
41-
throughputProperties: ThroughputProperties.CreateAutoscaleThroughput(1000)
40+
id: "AttributeArrayDB"
4241
);
4342

4443
Console.Write(

azuredeploy.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"location": {
6+
"type": "string",
7+
"defaultValue": "[resourceGroup().location]",
8+
"metadata": {
9+
"description": "Location for all resources."
10+
}
11+
},
12+
"accountName": {
13+
"type": "string",
14+
"metadata": {
15+
"description": "Azure Cosmos DB account name, max length 44 characters"
16+
}
17+
}
18+
},
19+
"resources": [
20+
{
21+
"type": "Microsoft.DocumentDB/databaseAccounts",
22+
"apiVersion": "2022-05-15",
23+
"name": "[toLower(parameters('accountName'))]",
24+
"kind": "GlobalDocumentDB",
25+
"location": "[parameters('location')]",
26+
"properties": {
27+
"databaseAccountOfferType": "Standard",
28+
"locations": [
29+
{
30+
"locationName": "[parameters('location')]",
31+
"failoverPriority": 0
32+
}
33+
],
34+
"capabilities": [
35+
{
36+
"name": "EnableServerless"
37+
}
38+
]
39+
}
40+
}
41+
]
42+
}

0 commit comments

Comments
 (0)