{"id":13571835,"url":"https://github.com/farhan1386/GenericRepositoryAndUnitOfWorkMVC5_Demo","last_synced_at":"2025-04-04T09:30:29.082Z","repository":{"id":139596802,"uuid":"296230205","full_name":"farhan1386/GenericRepositoryAndUnitOfWorkMVC5_Demo","owner":"farhan1386","description":"The Repository mediates between the domain and data mapping layers, acting like an in-memory collection of domain objects.The Repository pattern and Unit of Work pattern are used together most of the time.","archived":false,"fork":false,"pushed_at":"2020-09-17T06:47:35.000Z","size":578,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-05T04:34:19.635Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/farhan1386.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-09-17T05:41:10.000Z","updated_at":"2021-01-13T10:55:29.000Z","dependencies_parsed_at":"2024-01-14T03:49:12.205Z","dependency_job_id":"eaf16808-d280-4f07-9ff3-0a167acbc43d","html_url":"https://github.com/farhan1386/GenericRepositoryAndUnitOfWorkMVC5_Demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhan1386%2FGenericRepositoryAndUnitOfWorkMVC5_Demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhan1386%2FGenericRepositoryAndUnitOfWorkMVC5_Demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhan1386%2FGenericRepositoryAndUnitOfWorkMVC5_Demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/farhan1386%2FGenericRepositoryAndUnitOfWorkMVC5_Demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/farhan1386","download_url":"https://codeload.github.com/farhan1386/GenericRepositoryAndUnitOfWorkMVC5_Demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247152740,"owners_count":20892546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T14:01:07.012Z","updated_at":"2025-04-04T09:30:28.057Z","avatar_url":"https://github.com/farhan1386.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Generic Repository And UnitOfWork MVC5\n\n## What is the Repository Design Pattern in C#?\nThe Repository mediates between the domain and data mapping layers, acting like an in-memory collection of domain objects.\n\n## Repository Pattern Goals\n* Decouple Business code from data Access. As a result, the persistence Framework can be changed without a great effort\n* Separation of Concerns\n* Minimize duplicate query logic\n* Testability\n\n## Why we need the Repository Pattern in C#?\nNowadays, most of the data-driven applications need to access the data residing in one or more other data sources. Most of the time data sources will be a database. Again, these data-driven applications need to have a good and secure strategy for data access to perform the CRUD operations against the underlying database. One of the most important aspects of this strategy is the separation between the actual database, queries and other data access logic from the rest of the application. In our example, we need to separate the data access logic from the Employee Controller. The Repository Design Pattern is one of the most popular design patterns to achieve such separation between the actual database, queries and other data access logic from the rest of the application.\n\n## Why the UnitOfWork and Repository pattern?\nThe UnitOfWork and repository patterns are intended to act like a abstraction layer between business logic and data access layer.\nThis can help insulate your application from changes in the data store and can facilitate automated unit testing / test driven development.\n\n## What is Unit of Work\nMaintains a list of objects affected by a business transaction and coordinates the writing out of changes.\n\n## Consequences of the Unit of Work Pattern\n* Increases the level of abstraction and keep business logic free of data access code\n* Increased maintainability, flexibility and testability\n* More classes and interfaces but less duplicated code\n* The business logic is further away from the data because the repository abstracts the infrastructure. This has the effect that it might be harder to optimize certain operations which are performed against the data source.\n\n## Implementing Generic Repository\n\n    public interface IRepository\u003cTEntity\u003e where TEntity : class\n    {\n        IEnumerable\u003cTEntity\u003e GetAll();\n        TEntity GetById(int? id);\n        void Add(TEntity entity);\n        void Remove(TEntity entity);\n    }\n\n## Implementing Unit of Work\n\n    public interface IUnitOfWork : IDisposable\n    {\n        IRepository\u003cStudent\u003e StudentRepository { get; }\n        IRepository\u003cCourse\u003e CourseRepositroy { get; }\n        IRepository\u003cInstructor\u003e InstructorRepository { get; }\n        IStudentRepository Students { get; }\n        int Complete();\n    }\n    \n    \n    public class UnitOfWork : IUnitOfWork\n    {\n        private readonly ApplicationDbContext db;\n        public UnitOfWork(ApplicationDbContext context)\n        {\n            db = context;\n        }\n        public IRepository\u003cStudent\u003e StudentRepository =\u003e new Repository\u003cStudent\u003e(db);\n\n        public IRepository\u003cCourse\u003e CourseRepositroy =\u003e new Repository\u003cCourse\u003e(db);\n\n        public IRepository\u003cInstructor\u003e InstructorRepository =\u003e new Repository\u003cInstructor\u003e(db);\n\n        public IStudentRepository Students =\u003e new StudentRepository(db);\n\n        public int Complete()\n        {\n            return db.SaveChanges();\n        }\n\n        public void Dispose()\n        {\n            db.Dispose();\n        }\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarhan1386%2FGenericRepositoryAndUnitOfWorkMVC5_Demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffarhan1386%2FGenericRepositoryAndUnitOfWorkMVC5_Demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffarhan1386%2FGenericRepositoryAndUnitOfWorkMVC5_Demo/lists"}