This example factors our previous API functionality into a service, linked through an interface. It also extends CRUD to Products, Categories, and Customers, with relationships explored between them.
- Tools > NuGet Package Manager > Package Manager Console
- update-database
- Tools > SQL Server Object Explorer > Database
- Add Customer, Order records
- Interact with Ordered Items, Products, Categories through API requests
- Related methods: ListOrderItemsForOrder, ListOrderItemsForProduct, ListCategoriesForProduct, ListProductsForCategory, LinkCategoryToProduct, UnlinkCategoryFromProduct
- Core Entity Framework
- Core API
- Core Services
- MVC & ViewModels
- Simple Authentication
- Image/File Upload
- Role Based Authorization
- Conditional Access
- Conditional Rendering
- Client Integration
- Workers and Server to Server Communication
- Implement data access methods in Services/CustomerService.cs (defined in ICustomerService.cs)
- Associate the CustomerService implementation with the ICustomerService interface in Program.cs
- Create an API CustomerController.cs
- Use dependency injection in the CustomerController.cs API to receive the ICustomerService interface
- Use API endpoints + ICustomerService definitions to Create, Read, Update, Delete customers on each request
- Create an interface Interfaces/IOrderService.cs
- Create data access methods in Services/OrderService.cs
- Use dependency injection to receive the database context in OrderService.cs
- Repeat the same steps you did for customers!
- IOrderService.cs will need an additional definition: ListOrdersForCustomer