LazyStack

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 NuGet package that implements generic Create, Read, Update, Delete and List (CRUDL) operations on the Amazon DynamoDB.

3.1 Create the PetStoreRepo project

  1. Create PetStoreRepo project from "Class Library (C#)" 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 "Add a new project" dialog appears.
    3. Find the "C# Class Library" project template.
    4. Double click on the "C# Class Library template. The Configure your new project window is presented. Note: You have to look at the icon to see which template is for C#.
    5. Enter "PetStoreRepo" as the project name.
    6. Click on the Next button. The 'Additional Information' page is presented.
    7. For the 'Target Framework', select '.NET6' option.
    8. 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.
      
          <ItemGroup>
              <ProjectReference Include="..\..\LazyStack\LazyStackDynamoDBRepo\LazyStackDynamoDBRepo.csproj" />
              <ProjectReference Include="..\PetStoreSchema\PetStoreSchema.csproj" />
          </ItemGroup>
                          
    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 C# Class(.NET Core) Library template.
  • Adding classes for Categories, Orders, Pets and Tags.
  • Referencing the LazyStackDynamoDBRepo project.