Member-only story
Generic Repository Pattern for ASP.NET Core
Part 2: Separate database concern & avoid repetitive code
Hope y’all are familiar with ASP.NET Core and how it can be integrated with database through EF Core. Feel free to follow up on previous article on this:
Why Repository Pattern?
Previously database context were configured and used to interact with database. Repositories are used to create abstraction between database access and business logic. Thereby usage of data, and access of data is separated where repository will manage interaction with database. This can be clearly seen in N-Tier architecture that is designed for separation of concern, and ASP.NET Core Web API can be also be modeled as N-Tier.
From above diagram it is clear repositories separate database from rest of the application. (Note services wouldn’t be used to make application more simple for demonstration purpose.)
In an application there would be domain models such as Author
, Book
and there will be methods associated to CRUD…