Using generic services for data manipulation
Each time we need to CRUD some record from the database, we will need to use our MediaLibraryDbContext
class and write a LINQ query to retrieve the required data. To prevent typing the same lines of code, we will create a service class that will retrieve the data for us.
For reasons including concerns around security, we also should never expose database entities to the client. We can avoid this behavior by creating models that will be shared between the client and server part of the application. The client will only know about the public models, and not about database entities. The service class will CRUD the entities created in the previous section, but the caller of this method will only see the model as method parameters or result values. This can prevent unrequired modifications of the entities and create a more secure and extensible application.
Creating models
In this section, we will create two classes in the MediaLibrary...