Sharing Top Content from the Angular-sphere.

.NET Core 2.0, Angular 4 and MySQL. Part 4

  • Data access logic is in a separate class, or sets of classes called a repository, with the responsibility of persisting the application’s business model.
  • NET Core) project named Entities and inside it create a folder with a name Models, which will contain all of your model classes.
  • As a result, all the methods can be called upon any repository class in your project.
  • NET Core) project with the name Repository (add the reference from Contracts to this project), and inside the Repository project create abstract class RepositoryBase which will implement the interface IRepositoryBase.
  • Add a new class to the Repository project: – – And in the Startup class inside the ConfigureServices method, above the services.AddMvc() line, add this code: – – All you need to do is to test this code the same way you did with your custom logger in part3 of this series.

What is Repository pattern and why should you use it?; Author: Code Maze; Updated: 5 Feb 2018; Section: ASP.NET; Chapter: Web Development; Updated: 5 Feb 2018

What is Repository pattern and why should you use it?

With Repository pattern, we create an abstraction layer between the data access and the business logic layer of an application. By using it, we are promoting a more loosely coupled approach to access our data from the database. Also, the code is cleaner and easier to maintain and reuse. Data access logic is in a separate class, or sets of classes called a repository, with the responsibility of persisting the application’s business model.

Implementing the  repository pattern is our topic for this post.

So let’s start.

If you want to see all the basic instructions and complete navigation for this series, please follow the following link: Introduction page for this tutorial.

For the previous part check out: Part 3 – Creating .NET Core WebApi project – Custom logging in .NET Core

The source code is available for download at: .NET Core, Angular 4 and MySQL. Part 4 – Source Code

This post is divided into several sections:

Let’s begin by creating a new Class Library (.NET Core) project named Entities and inside it create a folder with a name Models, which will contain all of your model classes. Model classes will represent the tables inside the database and will serve you to map the data from the database to the .NET Core. After that , reference this project to the main project.

In the Models folder create…

.NET Core 2.0, Angular 4 and MySQL. Part 4