Exposing CRUD operations in API controllers
The client side of our Blazor WebAssembly application will communicate with the server side using the HTTP client for API calls. We need to expose the endpoints for the client. Since we have a generic service class
, we should create a generic controller.
We can start with the definition of the controller as follows:
Controllers\BaseController.cs
using Microsoft.AspNetCore.Mvc; namespace MediaLibrary.Server.Controllers; [ApiController] [Route("rest/[controller]")] public class BaseController<TModel, TEntity, TService> : ControllerBase where TModel : Shared.Model.IModel, new() where TEntity : Data.BaseEntity where TService : Services.BaseService<TEntity, TModel> { private readonly TService _service; private readonly string _createPath; public BaseController...