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. CD into the solution folder (LazyStackTutorial\PetStore).
  2. Create PetStoreRepo project from "C# Class Library (.NET Core)" template. Windows:
    dotnet new classlib -o Controllers\OrderControllerImpl
    MacOS/Linus:
    dotnet new classlib -o Controllers/OrderControllerImpl
    Windows:
    dotnet sln add Controllers\OrderControllerImpl\OrderControllerImpl.csproj
    MacOS/Linux:
    dotnet sln add Controllers/OrderControllerImpl/OrderControllerImpl.csproj
    You now have a OrderControllerImpl C# Class Lib project in your solution.
  3. Replaced the contents of the OrderControllerImpl.csproj with this content
    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
      <ProjectReference Include="..\..\PetStoreRepo\PetStoreRepo.csproj" />
      <ProjectReference Include="..\OrderController\OrderController.csproj" />
    </ItemGroup>
    
    </Project>
    Note the TargetFramework is "netcoreapp3.1".
  4. 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.
  5. CD into the solution folder (LazyStackTutorial\PetStore) and Build the solution.
    dotnet build
    The solution compiles successfully.

4.2 Create the PetControllerImpl project

  1. CD into the solution folder (LazyStackTutorial\PetStore).
  2. Create PetStoreRepo project from "C# Class Library (.NET Core)" template. Windows:
    dotnet new classlib -o Controllers\PetControllerImpl
    MacOS/Linus:
    dotnet new classlib -o Controllers/PetControllerImpl
    Windows:
    dotnet sln add Controllers\PetControllerImpl\PetControllerImpl.csproj
    MacOS/Linux:
    dotnet sln add Controllers/PetControllerImpl/PetControllerImpl.csproj
    You now have a PetControllerImpl C# Class Lib project in your solution.
  3. Replaced the contents of the PetControllerImpl.csproj with this content
    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
      <ProjectReference Include="..\..\PetStoreRepo\PetStoreRepo.csproj" />
      <ProjectReference Include="..\PetController\PetController.csproj" />
    </ItemGroup>
    
    </Project>
    Note the TargetFramework is "netcoreapp3.1".
  4. 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.
  5. CD into the solution folder (LazyStackTutorial\PetStore) and Build the solution.
    dotnet build
    The solution compiles successfully.

Step Summary

In this step we implemented the PetStoreRepo project by:

  • Creating a PetStoreRepo project using the C# Class(.NET Core) Library template.
  • Modifying the project to target netcoreapp3.1 instead of net5
  • 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.