Creating the shopping cart project
The ShoppingCart
project will be created by using the Empty Blazor WebAssembly App project template. First, we will add logic to add and remove products from the shopping cart. Then, we will demonstrate that the cart's state is lost when we navigate between pages. To maintain the cart's state, we will register a service in the DI container that uses the AppState pattern. Finally, we will demonstrate that by injecting the new service into the relevant components, the cart's state is not lost.
Getting started with the project
We need to create a new Blazor WebAssembly app. We do this as follows:
- Open Visual Studio 2019.
- Click the Create a new project button.
- In the Search for templates (Alt + S) textbox, enter
blazor
and then hit the Enter key.The following screenshot shows the Empty Blazor WebAssembly App project template that we created in Chapter 2, Building Your First Blazor WebAssembly Application: