...

/

Creating the ICartService Interface and CartService Class

Creating the ICartService Interface and CartService Class

Learn how to create and register a service in Blazor WebAssemblly using DI.

Creating the ICartService interface

We need to create an ICartService interface. We do this as follows:

  1. Return to Visual Studio.
  2. Right-click the ShoppingCart project and select the “Add, New Folder” option from the menu.
  3. Name the new folder Services.
  4. Right-click the Services folder and select the “Add, New Item” option from the menu.
  5. Enter “interface” in the “Search” box.
  6. Select “Interface.”
  7. Name the file ICartService.
  8. Click the “Add” button.
  9. Enter the following code:
Press + to interact
IList<Product> Cart{ get; }
int Total { get; set; }
event Action OnChange;
void AddProduct(Product product);
void DeleteProduct(Product product);
  1. Add the following using statement:
Press + to interact
using ShoppingCart.Models;

We have created the ICartService interface. Now we need to create a class ...