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. CD into the solution folder (LazyStackTutorial\PetStore).
  2. Create PetStoreRepo project from "C# Class Library (.NET Core)" template.
    dotnet new classlib -o PetStoreRepo
    Windows:
    dotnet sln add PetStoreRepo\PetStoreRepo.csproj
    MacOS/Linux:
    dotnet sln add PetStoreRepo/PetStoreRepo.csproj
    You now have a PetStoreRepo C# Class Lib project in your solution.
  3. Replaced the contents of the PetStoreRepo.csproj with this content
    <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
            <TargetFramework>net6.0</TargetFramework>
            <ImplicitUsings>enable</ImplicitUsings>
            <Nullable>enable</Nullable>
        </PropertyGroup>
    
        <ItemGroup>
            <ProjectReference Include="..\..\LazyStack\LazyStackDynamoDBRepo\LazyStackDynamoDBRepo.csproj" />
            <ProjectReference Include="..\PetStoreSchema\PetStoreSchema.csproj" />
        </ItemGroup>
    
    </Project>
    Note the TargetFramework is "net6.0".
  4. Delete the Class1.cs file from the PetStoreRepo project.
  5. Create a PetStoreRepo\Models folder.
  6. Click on the following class files to download them and then move them into the Models folder.
  7. CD into the solution folder (LazyStackTutorial\PetStore) and Build the solution.
    dotnet build
    The solution compiles 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 implemented the PetStoreRepo project by:

  • Creating a PetStoreRepo project using the C# Class(.NET Core) Library template.
  • Referencing the LazyStackDynamoDBRepo NuGet package generated controller projects.
  • Implementing the PetStoreRepo repository logic with the CategoryRepo.cs, OrderRepo.cs, PetRepo.cs and TagRepo.cs files.