aimenux / RepositoryPatternDemo

Using repository pattern with entity framework in web api projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.NET

RepositoryPatternDemo

Using repository pattern with entity framework in web api projects

In this repo, i m exploring various ways of using repository pattern in web api projects

Example01 use controller api with directly the db context

Example02 use minimal api with directly the db context

Example03 use controller api with specific repository

Example04 use minimal api with specific repository

Example05 use controller api with generic repository

Example06 use minimal api with generic repository

Example07 use controller api with generic repository & specific unit of work

Example08 use minimal api with generic repository & specific unit of work

Example09 use controller api with generic repository & generic unit of work

Example10 use minimal api with generic repository & generic unit of work

In order to setup the database, follow these steps for some example :

  • Run this docker command : docker run -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=Pa55w0rd’ -p 1433:1433 -d mcr.microsoft.com/mssql/server
  • Use this connection string : "Data Source=localhost;Initial Catalog=BooksDB;User Id=sa;Password=Pa55w0rd;TrustServerCertificate=True;"
  • Run database migrations : dotnet-ef database update

Tools : net 8.0, ef-core, xunit, fluent-assertions

About

Using repository pattern with entity framework in web api projects

License:MIT License


Languages

Language:C# 100.0%