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 "C# Class Library (.NET Core)" 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 "Add a new project" dialog appears.
    3. Find the "Class Library (.NET Core)" project template.
    4. Double click on the "Class Library (.NET Core)" template. The Configure your new project window is presented.
    5. Enter "OrderControllerImpl" as the project name.
    6. Modify the location to point to the "LazyStackTutorial\PetStore\Controllers" folder.
    7. Click the Next button. The 'Additional Information' page appears.
    8. For the 'Target Framework' select '.NET Core 3.1 (Long-term support).
    9. 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 (.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 "Class Library (.NET Core)" project template.
    4. Double click on the "Class Library (.NET Core)" template. The Configure your new project window is presented.
    5. Enter "PetControllerImpl" as the project name.
    6. Modify the location to point to the "LazyStackTutorial\PetStore\Controllers" folder.
    7. Click the Next button. The 'Additional Information' page appears.
    8. For the 'Target Framework' select '.NET Core 3.1 (Long-term support).
    9. 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 C# Class(.NET Core) Library template.
  • Referencing the Controller and PetStoreRepo projects.