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
- Create OrderControllerImpl project from "Class Library " template.
- Right Click on the Controllers folder in the solution explorer. The context menu appears.
- Select the Add → New Project context menu item. The "Choose a template for
your new project" dialog appears.
- Select the "Web and Console → Library → Class Library" project template.
- Click the Next button. The next page in the "Configure your new Class Library" page is
presented.
- Set the Target Framework to ".NET6" and press the Next button. The second page of the
"Configure your new Class Library" dialog appears.
- Enter "OrderControllerImpl" int the Project Name field.
- Click the Create button.
- Click the Create button. The project is created with a default class Class1.cs.
- Add Project Dependencies
- Open the OrderControllerImpl.csproj file.
- Copy the following ItemGroup into the .csproj file.
<ItemGroup>
<ProjectReference Include="..\..\PetStoreRepo\PetStoreRepo.csproj" />
<ProjectReference Include="..\OrderController\OrderController.csproj" />
</ItemGroup>
- Save the file.
- Add Class File
- Delete the Class1.cs file from the project.
- Click on the following class file to download it and then move it into the
project folder.
- Build the project. The project builds successfully.
4.2 Create the PetControllerImpl project
- Create PetControllerImpl project from "Class Library " template.
- Right Click on the Controllers folder in the solution explorer. The context menu appears.
- Select the Add → New Project context menu item. The "Choose a template for
your new project" dialog appears.
- Select the "Web and Console → Library → Class Library" project template.
- Click the Next button. The next page in the "Configure your new Class Library" page is
presented.
- Set the Target Framework to ".NET6" and press the Next button. The second page of the
"Configure your new Class Library" dialog appears.
- Enter "PetControllerImpl" int the Project Name field.
- Click the Create button.
- Click the Create button. The project is created with a default class Class1.cs.
- Add Project Dependencies
- Open the PetControllerImpl.csproj file.
- Copy the following ItemGroup into the .csproj file.
<ItemGroup>
<ProjectReference Include="..\..\PetStoreRepo\PetStoreRepo.csproj" />
<ProjectReference Include="..\PetController\PetController.csproj" />
</ItemGroup>
- Save the file.
- Add Class File
- Delete the Class1.cs file from the project.
- Click on the following class file to download it and then move it into the
project folder.
- 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.