LazyStack

Implement PetStore application Controllers

In this lesson step we will add controller logic to the Controller projects in the PetStoreMac 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. 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.

2.1 Create the PetStoreRepo project

  1. Create PetStoreRepo project from "C# Class Library (.NET Core)" 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 Class Library" page is presented.
    5. Set the Target Framework to ".NET Core 3.1" and press the Next button. The second page of the "Configure your new Class Library" dialog appears.
    6. Enter "PetStoreRepo" int the Project Name field.
    7. Click the Create button.
    8. Click the Create button. The project is created with a default class Class1.cs.
  2. Add Package References
    1. Right click on Dependencies. The context menu appears.
    2. Select Manage NuGet Packages. the NuGet: PetStoreRepo tab appears.
    3. Select Browse.
    4. Type "LazyStack" into the search field. The LazyStackDynamoDBRepo package is listed.
    5. Select the LazyStackDynamoDBRepo package and then click on the Add Package button. The package is installed.
  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. The "New Folder" dialog appears,.
  6. Enter "Models" as the folder name and press the Add button.
  7. Click on the following class files to download them and then move them into the Models folder.
  8. Add PetStoreRepo Project References
    1. Right click on Dependencies. The context menu appears.
    2. Select Add Project Reference. The Reference Manager dialog appears.
    3. Select these projects:
      • OrderController
      • OrderSecureController
      • PetController
      • PetSecureController
    4. Click the OK button.
  9. Build the project. The project builds successfully.

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.