Implement PetStore application Controllers

In this lesson step we will add controller logic to the Controller projects in the PetStore 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 "Add a new project" dialog appears.
    3. Find the "C# Class Library (.NET Core)" project template.
    4. Double click on the "C# Class Library (.NET Core)" template. The Configure your new project window is presented.
    5. Enter PetStoreRepo" as the project name.
    6. 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 Install 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. 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. 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.