LazyStack

Create a .NET Console App

In this step we will create a simple PetStoreConsoleApp. This console app will support all the features of AuthProcess running against AWS Cognito, initialize the PetStore library and make a simple call against the stack.

9.1 Create PetStoreConsoleApp Project

  1. Right Click on "Solution PetStore" in the Solution Explorer. The context menu appears.
  2. Select "Add → New Project" from the context menu. The "Add new project" dialog appears.
  3. Type "C# Console Application" in the search field. The project template is listed.
  4. Double Click on the template list item. The "Configure your project" dialog appears.
  5. Edit the project name to read "PetStoreConsoleApp".
  6. Click the Next button. The 'Additional Information' page appears.
  7. For 'Target Framework', select '.NET6' option.
  8. Click on the Create button. The project is added to your solution.

9.2 Add Project Dependencies

  1. Open the PetStoreConsoleApp.csproj file.
  2. Copy the following ItemGroup into the .csproj file.
    
        <ItemGroup>
            <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
            <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
            <ProjectReference Include="..\PetStoreClientSDK\PetStoreClientSDK.csproj" />
            <EmbeddedResource Include="..\Stacks\Dev\AwsSettings.json" />
            <EmbeddedResource Include="..\LocalApis.json" />
        </ItemGroup>
  3. Save the file.

Note the inclusion of the "..\Stacks\Dev\AwsSettings.json" file as an embedded resource. This file contains the information necessary for a client app to connect to and use the AWS Stack. We generated this file earlier with using Tools → LazyStack - Generate Stacks\Dev\AwsSettings.json.

The "..\LocalApis.json" embedded resource contains the information necessary for the a client app to connect to the local WebApi service. The local WebApi service (our PetStore project) is useful for testing controller implementation and repository code.

9.3 Implement Program

  1. Download Program.cs and move it into your project, replacing the existing Program.cs.
  2. Build project.

Run Project

9.4 Run Against AWS Stack
  1. Right Click "PetStoreConsoleApp" project in solution explorer. The context menu appears.
  2. Select Set as Startup Project.
  3. Debug program. A command window opens.

    Here is a sample command window session:

    You can use any login, password and email you want in this tutorial step. The email must be valid so you can receive the authentication code sent to that email in the sign up step. You can sign up only once with the same email address.

    Welcome to the PetStoreConsoleApp program
    Use LocalApi? y/n:n
    1. Sign Up
    2. Sign In
    3. Reset Password
    4. Quit
    >1
    Enter your Login: MyLoginName
    Enter your Password: MyPassword!
    Enter your Email address: myemail@gmail.com
    Enter authentication code: 984185
    You are Signed Up! You can now SignIn.
    1. Sign Up
    2. Sign In
    3. Reset Password
    4. Quit
    >2
    Enter your Login: MyLoginName
    Enter your current Password: MyPassword!
    1. Sign Out
    2. Update Password
    3. Update Phone
    4. Update Login
    5. Seed Pets data
    6. Get Pet 1
    7. See Available Pets
    8. GetUserId
    9. Quit
    >5
    Pets added to database
    1. Sign Out
    2. Update Password
    3. Update Phone
    4. Update Login
    5. Seed Pets data
    6. Get Pet 1
    7. See Available Pets
    8. GetUserId
    9. Quit
    >6
    pet: 1 Alf Available
    1. Sign Out
    2. Update Password
    3. Update Phone
    4. Update Login
    5. Seed Pets data
    7. See Available Pets
    8. GetUserId
    9. Quit
    >8
    UserId=b184b386-22c9-41a3-8a33-15d2bf1ff4ed
    1. Sign Out
    2. Update Password
    3. Update Phone
    4. Update Login
    5. Seed Pets data
    7. See Available Pets
    8. GetUserId
    9. Quit
    >9
    
9.5 Run Against Local WebApi
  1. Right Click "PetStoreConsoleApp" project in solution explorer. The context menu appears.
  2. Select Set as Startup Project.
  3. Debug program. A command window opens.
  4. Right click on the PetStore project in the solution explorer. The context menu appears.
  5. Select Debug → Start New Instance. The PetStore WebApi project launches.
    • Note that this assumes you previously ran the WebApi project and have changed the server type from IISExpress to PetStore.
  6. In the PetStoreConsoleApp command window. Answer 'y' to the "Use LocalApi?" prompt.

    Your authentication process still runs against the AWS stack but your calls to the PetStore library will call the Local WebApi (PetStore) project. You can set debug breakpoints in both the PetStoreConsoleApp and PetStore projects!

Step Summary

In this step we created a Console App project and used it to run against both the AWS Application Stack and the local WebApi. When running locally, we simultaneously debugged the client and WebApi projects.