Skip to content

Nguyen-Son-Tung/RepositoryPattern.Simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smallop -- (Simple RepositoryPattern Implemetation)

Repository Pattern Simple
This package was written in .NET 5.0
There are 2 base classes and 2 interface

  • GenericRepo
  • UnitOfWork
  • IGenericRepo
  • IUnitOfWork

Example

This a ASP NET CORE WEB API project

Repositories

I organized the file like the image below

Organized

I conntected with my database and generated 3 classes in Models directory based on my databse

Models Directory

  • Course
  • Enrollment
  • AppContext

We'll create a directory with name is Repositories
We'll create a classes named CoursesRepo implemented from GenericRepo based class
The EnrollmentsRepo class is same for the CoursesRepo class

Implemented GenericRepo

Default GenericRepo includes methods:

  • Get
  • GetAsync
  • GetAll
  • GetAllAsync
  • Add
  • AddAsync
  • Update
  • UpdateAsync
  • Remove
  • RemoveAsync

If you want to add or modify the above methods, you can override them.

UnitOfWork

We create a interface ICourseUnitOfWork inherit from IUnitOfWork interface

Implemented Unit Of Work

We also create a class CourseUnitOfWork implemented UnitOfWork base class and ICourseUnitOfWork interface

Implemented Unit Of Work

If you want to add or modify the above methods, you can override them.

Remember to declare the services in the startup.cs file

Implemented GenericRepo

Usage

Usage

About

Repository Pattern Simple

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages