Implement PetStoreCLI application Controllers

In this lesson step we will add controller logic to the Controller projects in the PetStoreCLI solution. 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 and then configure our Controller classes to use that PetStoreRepo. Our PetStoreRepo will use AWS DynamoDB, so we use the LazyStackDynamoDBRepo NuGet package to make implementing generic Create, Read, Update, Delete and List (CRUDL) operations on the Amazon DynamoDB easy.

2.1 Create the PetStoreRepo project

  1. CD into the solution folder (LazyStackTutorial\PetStoreCLI).
  2. Create PetStoreRepo project from "C# Class Library (.NET Core)" template.
    dotnet new classlib -o PetStoreRepo
    dotnet sln add PetStoreRepo\PetStoreRepo.csproj
    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">
        <PackageReference Include="LazyStackDynamoDBRepo" Version="1.0.0" />
        <ProjectReference Include="..\Controllers\OrderController\OrderController.csproj" />
        <ProjectReference Include="..\Controllers\OrderSecureController\OrderSecureController.csproj" />
        <ProjectReference Include="..\Controllers\PetController\PetController.csproj" />
        <ProjectReference Include="..\Controllers\PetSecureController\PetSecureController.csproj" />
    Note the TargetFramework is "netcoreapp3.1".
  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\PetStoreCLI) and Build the solution.
    dotnet build
    The solution compiles successfully.

Step Summary

In this step we implemented the PetStoreRepo project by:

  • Creating a PetStoreRepo project using the C# Class(.NET Core) Library template.
  • Modifying the project to target netcoreapp3.1 instead of net5
  • 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.