Implement PetStore application repository

In most applications we have a persistence layer, often called the repository layer. In this tutorial we create a PetStoreRepo project to use DynamoDB to store our data. Since our PetStoreRepo will use AWS DynamoDB, we use the LazyStackDynamoDBRepo library that implements generic Create, Read, Update, Delete and List (CRUDL) operations on the Amazon DynamoDB. This library is also available as a NuGet package.

3.1 Create the PetStoreRepo project

  1. Create PetStoreRepo project from "Web and Console → Library → Class Library" template.
    1. Right Click on Solution PetStore item in the solution explorer. The context menu appears.
    2. Select the Add → New Project context menu item. The "Choose a template for your new project" dialog appears.
    3. Select the "Web and Console → Library → Class Library" project template.
    4. Click the Next button. The next page in the "Configure your new project" dialog appears.
    5. Set the Target Framework to ".NET6" and press the Next button. The next page appears.
    6. Enter "PetStoreRepo" as the project name.
    7. Click the Create button. The project is created with a default class Class1.cs.
  2. Add Project Dependencies
    1. Open the PetStoreRepo.csproj file.
    2. Copy the following ItemGroup into the .csproj file.
              <ProjectReference Include="..\..\LazyStack\LazyStackDynamoDBRepo\LazyStackDynamoDBRepo.csproj" />
              <ProjectReference Include="..\PetStoreSchema\PetStoreSchema.csproj" />
    3. Save the file.
  3. Delete the Class1.cs file from the PetStoreRepo project.
  4. Right Click on the PetStoreRepo project. The context menu appears.
  5. Select Add → New Folder. A "New Folder" is created in the project.
  6. Enter "Models" as the folder name.
  7. Click on the following class files to download them and then move them into the Models folder.
  8. Build the project. The project builds successfully.

Note the reference to the LazyStackDynamoDBRepo.csproj residing in the LazyStack repository we cloned in the first step of this tutorial. In a production app you might choose to reference the corresponding NuGet package instead.

Step Summary

In this step we created the PetStoreRepo project by:

  • Creating a PetStoreRepo project using the Class Library template.
  • Adding classes for Categories, Orders, Pets and Tags.
  • Referencing the LazyStackDynamoDBRepo project.