...
/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:
- Return to Visual Studio.
- Right-click the
ShoppingCart
project and select the “Add, New Folder” option from the menu. - Name the new folder
Services
. - Right-click the
Services
folder and select the “Add, New Item” option from the menu. - Enter “interface” in the “Search” box.
- Select “Interface.”
- Name the file
ICartService
. - Click the “Add” button.
- 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);
- Add the following
using
statement:
Press + to interact
using ShoppingCart.Models;
We have created the ICartService
interface. Now we need to create a class ...