LazyStack

Implement PetStore application Controllers

In this lesson step we will add controller logic to the Controller projects in the PetStore solution. Controller Implementation projects implement an interface generated by LazyStack to service Lambda events. Controller Implementation methods implement business logic, usually calling the repository project to perform CRUDL operations on persistent data. It is not unusual for Controller Implementation methods to call other libraries required by your application.

4.1 Create the OrderControllerImpl project

  1. Create OrderControllerImpl project from "Class Library " template.
    1. Right Click on the Controllers folder 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 ".NET6" and press the Next button. The second page of the "Configure your new Class Library" dialog appears.
    6. Enter "OrderControllerImpl" 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 Project Dependencies
    1. Open the OrderControllerImpl.csproj file.
    2. Copy the following ItemGroup into the .csproj file.
      
          <ItemGroup>
              <ProjectReference Include="..\..\PetStoreRepo\PetStoreRepo.csproj" />
              <ProjectReference Include="..\OrderController\OrderController.csproj" />
          </ItemGroup>
                          
    3. Save the file.
  3. Add Class File
    1. Delete the Class1.cs file from the project.
    2. Click on the following class file to download it and then move it into the project folder.
  4. Build the project. The project builds successfully.

4.2 Create the PetControllerImpl project

  1. Create PetControllerImpl project from "Class Library " template.
    1. Right Click on the Controllers folder 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 ".NET6" and press the Next button. The second page of the "Configure your new Class Library" dialog appears.
    6. Enter "PetControllerImpl" 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 Project Dependencies
    1. Open the PetControllerImpl.csproj file.
    2. Copy the following ItemGroup into the .csproj file.
      
          <ItemGroup>
              <ProjectReference Include="..\..\PetStoreRepo\PetStoreRepo.csproj" />
              <ProjectReference Include="..\PetController\PetController.csproj" />
          </ItemGroup>
                          
    3. Save the file.
  3. Add Class File
    1. Delete the Class1.cs file from the project.
    2. Click on the following class file to download it and then move it into the project folder.
  4. Build the project. The project builds successfully.

Step Summary

In this step we created to Controller Implementation projects by:

  • Creating new projects using the Class Library template.
  • Referencing the Controller and PetStoreRepo projects.