SlideShare a Scribd company logo
Generic Repository Pattern
with ASP.NET MVC and EF
Md. Mahedee Hasan
Microsoft MVP | Trainer | Speaker
Software Architect
LeadSoft Bangladesh Limited
Linkedin: http://www.linkedin.com/in/mahedee
Blog: http://mahedee.net/
1
• MVC Stands for Model – View – Controller
• It is Software Architectural pattern
MAHEDEE.NET 2
What is MVC?
• Is an open source web application framework
• It implements the model-view-controller pattern
• MVC design pattern aims to “Separation Of concern”
MAHEDEE.NET 3
What is ASP.NET MVC?
• Entity Framework is an ORM.
• Work with relational data using domain-specific
objects
• Eliminates the need for most of the data-access code
MAHEDEE.NET 4
What is ASP.NET EF?
DRY?
Don’t repeat yourself
-Means don't write duplicate code
Use generic repository pattern to
implement DRY
MAHEDEE.NET 5
• What is Design Pattern?
• Design pattern is a solution of known problems
• What is Software Design Pattern?
• Is a solution of known problems in Software.
• Strategies of solving commonly occurring problems.
• A design pattern is not a finish design.
• It is like a template to solve a problem.
MAHEDEE.NET 6
Software Design Pattern
Repository Pattern
• Mediator between BLL and DAL(Data Source)
• It’s a separation layer between Data and Domain
Layer
– Separates data and domain Layer
MAHEDEE.NET 7
Benefits of Repository Pattern
• Centralizes data logic or service logic.
• Provides a substitution point for the unit tests
– Both BLL and DAL
• Provides a flexible architecture
– Can adopt new change easily
• Domain driven development is easier
MAHEDEE.NET 8
What is Generic Repository Pattern?
• Generally - one repository for one model to access
data.
– Write similar code again and again
• What if Single Repository for all?
• Single repository for data access of all models.
MAHEDEE.NET 9
Benefits of Generic Repository Pattern
• Reduce redundancy of code
• Faster development
• Force developer to work same pattern
– Possibility of less error or no error
• Easy to maintain
– Centralize data access logic
MAHEDEE.NET 10
Implementation
• Tools and Technology used
– Visual Studio 2013
– Visual C#
– ASP.NET MVC 5
– Entity Framework 6
– Razor view engine
MAHEDEE.NET 11
Step 1: Create an ASP.NET MVC 5 application using
Visual Studio 2013
MAHEDEE.NET 12
Implementation…
Step 2: Configure connection string in web.config
MAHEDEE.NET 13
Implementation …
Step 3: Create Models
MAHEDEE.NET 14
Implementation …
Step 4: Create a DbContext in Repository folder.
MAHEDEE.NET 15
Implementation …
Step 5: Create IGenericRepository and
GenericRepository in Repository folder
MAHEDEE.NET 16
Implementation …
• Step 6:
– Create controllers of each models
– Select template “MVC5 Controller with views, using Entity
Framework”
– Modify Controllers and use Generic Repository in
Controller
MAHEDEE.NET 17
Implementation …
• Step 7: Add links to _Layout
MAHEDEE.NET 18
Implementation …
• Step 8: Write following command in package manager
console
– PM> Enable-Migrations -ContextTypeName
GenericRepoContext
– PM> Add-Migration initialcreate
– PM> Update-Database -Verbose -Force
MAHEDEE.NET 19
Implementation …
Step 9: Run Project
MAHEDEE.NET 20
Implementation …
21

More Related Content

What's hot

Clean architecture
Clean architectureClean architecture
Clean architecture
Lieven Doclo
 
Webhook
WebhookWebhook
Webhook
Mohit Bishnoi
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-design
Arnaud Bouchez
 
Domain Driven Design for Angular
Domain Driven Design for AngularDomain Driven Design for Angular
Domain Driven Design for Angular
Jennifer Estrada
 
소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안
소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안
소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안
Jeongsang Baek
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
Dmytro Turskyi
 
WEB DEVELOPMENT USING REACT JS
 WEB DEVELOPMENT USING REACT JS WEB DEVELOPMENT USING REACT JS
WEB DEVELOPMENT USING REACT JS
MuthuKumaran Singaravelu
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete Guide
Sam Dias
 
Sonarqube
SonarqubeSonarqube
All about Context API
All about Context APIAll about Context API
All about Context API
Souvik Basu
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Nader Albert
 
React hooks
React hooksReact hooks
React hooks
Ramy ElBasyouni
 
Windows IOCP vs Linux EPOLL Performance Comparison
Windows IOCP vs Linux EPOLL Performance ComparisonWindows IOCP vs Linux EPOLL Performance Comparison
Windows IOCP vs Linux EPOLL Performance Comparison
Seungmo Koo
 
Angular material
Angular materialAngular material
Angular material
Kalpesh Satasiya
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8
AppDynamics
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
Matteo Moretti
 
Single page application
Single page applicationSingle page application
Single page application
Arthur Fung
 
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptxGetting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Ilesh Mistry
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
NSCoder Mexico
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
Thibaud Desodt
 

What's hot (20)

Clean architecture
Clean architectureClean architecture
Clean architecture
 
Webhook
WebhookWebhook
Webhook
 
D2 domain driven-design
D2 domain driven-designD2 domain driven-design
D2 domain driven-design
 
Domain Driven Design for Angular
Domain Driven Design for AngularDomain Driven Design for Angular
Domain Driven Design for Angular
 
소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안
소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안
소셜게임 서버 개발 관점에서 본 Node.js의 장단점과 대안
 
The Clean Architecture
The Clean ArchitectureThe Clean Architecture
The Clean Architecture
 
WEB DEVELOPMENT USING REACT JS
 WEB DEVELOPMENT USING REACT JS WEB DEVELOPMENT USING REACT JS
WEB DEVELOPMENT USING REACT JS
 
Angular 6 - The Complete Guide
Angular 6 - The Complete GuideAngular 6 - The Complete Guide
Angular 6 - The Complete Guide
 
Sonarqube
SonarqubeSonarqube
Sonarqube
 
All about Context API
All about Context APIAll about Context API
All about Context API
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
React hooks
React hooksReact hooks
React hooks
 
Windows IOCP vs Linux EPOLL Performance Comparison
Windows IOCP vs Linux EPOLL Performance ComparisonWindows IOCP vs Linux EPOLL Performance Comparison
Windows IOCP vs Linux EPOLL Performance Comparison
 
Angular material
Angular materialAngular material
Angular material
 
Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8Memory Management: What You Need to Know When Moving to Java 8
Memory Management: What You Need to Know When Moving to Java 8
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
Single page application
Single page applicationSingle page application
Single page application
 
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptxGetting started with Next.js - IM Tech Meetup - Oct 2022.pptx
Getting started with Next.js - IM Tech Meetup - Oct 2022.pptx
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 

Viewers also liked

The world of enterprise solution development with asp.net and C#
The world of enterprise solution development with asp.net and C#The world of enterprise solution development with asp.net and C#
The world of enterprise solution development with asp.net and C#
Md. Mahedee Hasan
 
Generic Unit Of Work Service & Repository
Generic Unit Of Work Service & RepositoryGeneric Unit Of Work Service & Repository
Generic Unit Of Work Service & RepositoryAbdulah Al Bahhar
 
Building High Quality Solutions with Design Patterns & Application Foundation...
Building High Quality Solutions with Design Patterns & Application Foundation...Building High Quality Solutions with Design Patterns & Application Foundation...
Building High Quality Solutions with Design Patterns & Application Foundation...Christoffer Sabsay
 
Repository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelRepository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir Poudel
Sameer Poudel
 
Tutorial on how to use Mailertite (Part1)- How to Setup Mailerlite and Make ...
Tutorial on how to use Mailertite (Part1)- How to Setup  Mailerlite and Make ...Tutorial on how to use Mailertite (Part1)- How to Setup  Mailerlite and Make ...
Tutorial on how to use Mailertite (Part1)- How to Setup Mailerlite and Make ...
Richelle Malapit
 
Site map
Site mapSite map
Site map
hanhenmag
 
Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1
Naji El Kotob
 
Mailerlite. Удобный email-маркетинг
Mailerlite. Удобный email-маркетингMailerlite. Удобный email-маркетинг
Mailerlite. Удобный email-маркетингMailer
 
MailerLite Tutorial
MailerLite TutorialMailerLite Tutorial
MailerLite Tutorial
Natasha Rivera
 
Introduction the Repository Pattern
Introduction the Repository PatternIntroduction the Repository Pattern
Introduction the Repository Pattern
Bill Lin
 
A View about ASP .NET and their objectives
A View about ASP .NET and their objectivesA View about ASP .NET and their objectives
Grudinkina EmailConf 2016
Grudinkina EmailConf 2016Grudinkina EmailConf 2016
Grudinkina EmailConf 2016Mailer
 
Introduction to OMNeT++
Introduction to OMNeT++Introduction to OMNeT++
Introduction to OMNeT++
Md. Mahedee Hasan
 
Elizabeth verar how to use mailerlite as email marketing tool
Elizabeth verar how to use mailerlite as email marketing toolElizabeth verar how to use mailerlite as email marketing tool
Elizabeth verar how to use mailerlite as email marketing tool
epverar
 
Intro To Asp Net And Web Forms
Intro To Asp Net And Web FormsIntro To Asp Net And Web Forms
Intro To Asp Net And Web Forms
SAMIR BHOGAYTA
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
Chitrank Dixit
 

Viewers also liked (20)

The world of enterprise solution development with asp.net and C#
The world of enterprise solution development with asp.net and C#The world of enterprise solution development with asp.net and C#
The world of enterprise solution development with asp.net and C#
 
Generic Unit Of Work Service & Repository
Generic Unit Of Work Service & RepositoryGeneric Unit Of Work Service & Repository
Generic Unit Of Work Service & Repository
 
Building High Quality Solutions with Design Patterns & Application Foundation...
Building High Quality Solutions with Design Patterns & Application Foundation...Building High Quality Solutions with Design Patterns & Application Foundation...
Building High Quality Solutions with Design Patterns & Application Foundation...
 
Oop principles
Oop principlesOop principles
Oop principles
 
Repository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir PoudelRepository design pattern in laravel - Samir Poudel
Repository design pattern in laravel - Samir Poudel
 
Tutorial on how to use Mailertite (Part1)- How to Setup Mailerlite and Make ...
Tutorial on how to use Mailertite (Part1)- How to Setup  Mailerlite and Make ...Tutorial on how to use Mailertite (Part1)- How to Setup  Mailerlite and Make ...
Tutorial on how to use Mailertite (Part1)- How to Setup Mailerlite and Make ...
 
Site map
Site mapSite map
Site map
 
2310 b 05
2310 b 052310 b 05
2310 b 05
 
Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1Robots and-sitemap - Version 1.0.1
Robots and-sitemap - Version 1.0.1
 
Mailerlite. Удобный email-маркетинг
Mailerlite. Удобный email-маркетингMailerlite. Удобный email-маркетинг
Mailerlite. Удобный email-маркетинг
 
MailerLite Tutorial
MailerLite TutorialMailerLite Tutorial
MailerLite Tutorial
 
Introduction the Repository Pattern
Introduction the Repository PatternIntroduction the Repository Pattern
Introduction the Repository Pattern
 
A View about ASP .NET and their objectives
A View about ASP .NET and their objectivesA View about ASP .NET and their objectives
A View about ASP .NET and their objectives
 
Grudinkina EmailConf 2016
Grudinkina EmailConf 2016Grudinkina EmailConf 2016
Grudinkina EmailConf 2016
 
Introduction to OMNeT++
Introduction to OMNeT++Introduction to OMNeT++
Introduction to OMNeT++
 
Elizabeth verar how to use mailerlite as email marketing tool
Elizabeth verar how to use mailerlite as email marketing toolElizabeth verar how to use mailerlite as email marketing tool
Elizabeth verar how to use mailerlite as email marketing tool
 
ASP.NET Web form
ASP.NET Web formASP.NET Web form
ASP.NET Web form
 
Intro To Asp Net And Web Forms
Intro To Asp Net And Web FormsIntro To Asp Net And Web Forms
Intro To Asp Net And Web Forms
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Jsp (java server page)
Jsp (java server page)Jsp (java server page)
Jsp (java server page)
 

Similar to Generic Repository Pattern with ASP.NET MVC and EF

Ps02 cint24 mvc in php
Ps02 cint24 mvc in phpPs02 cint24 mvc in php
Ps02 cint24 mvc in php
Conestoga Collage
 
Asp 1a-aspnetmvc
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvc
Fajar Baskoro
 
Aspnetmvc 1
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
Fajar Baskoro
 
Php Framework
Php FrameworkPhp Framework
Php Framework
cncwebworld
 
Php framework
Php frameworkPhp framework
Php framework
cncwebworld
 
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and SwaggerIntroduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Agusto Sipahutar
 
Asp.net Overview and Controllers
Asp.net Overview and ControllersAsp.net Overview and Controllers
Asp.net Overview and Controllers
Mustafa Saeed
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
Malisa Ncube
 
Prism library and MVVM
Prism library and MVVMPrism library and MVVM
Prism library and MVVM
Jiri Danihelka
 
Php and-mvc
Php and-mvcPhp and-mvc
Php and-mvc
Manoj Sahoo
 
Code igniter overview
Code igniter overviewCode igniter overview
Code igniter overview
umesh patil
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
Sam Nasr, MCSA, MVP
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterPongsakorn U-chupala
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
Ulrich Krause
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
Sirwan Afifi
 
ASP.NET MVC Zero to Hero
ASP.NET MVC Zero to HeroASP.NET MVC Zero to Hero
ASP.NET MVC Zero to Hero
Md. Mahedee Hasan
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
Ulrich Krause
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
Thomas Robbins
 

Similar to Generic Repository Pattern with ASP.NET MVC and EF (20)

Ps02 cint24 mvc in php
Ps02 cint24 mvc in phpPs02 cint24 mvc in php
Ps02 cint24 mvc in php
 
MVC 3.0 KU Day 1 v 1.1
MVC 3.0 KU Day 1 v 1.1MVC 3.0 KU Day 1 v 1.1
MVC 3.0 KU Day 1 v 1.1
 
Asp 1a-aspnetmvc
Asp 1a-aspnetmvcAsp 1a-aspnetmvc
Asp 1a-aspnetmvc
 
Aspnetmvc 1
Aspnetmvc 1Aspnetmvc 1
Aspnetmvc 1
 
Php Framework
Php FrameworkPhp Framework
Php Framework
 
Php framework
Php frameworkPhp framework
Php framework
 
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and SwaggerIntroduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
Introduction Asp.Net Core, MVC, Docker (Linux), Postman and Swagger
 
Asp.net Overview and Controllers
Asp.net Overview and ControllersAsp.net Overview and Controllers
Asp.net Overview and Controllers
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
Prism library and MVVM
Prism library and MVVMPrism library and MVVM
Prism library and MVVM
 
green
greengreen
green
 
Php and-mvc
Php and-mvcPhp and-mvc
Php and-mvc
 
Code igniter overview
Code igniter overviewCode igniter overview
Code igniter overview
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
 
An Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPagesAn Introduction To Model  View  Controller In XPages
An Introduction To Model  View  Controller In XPages
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
ASP.NET MVC Zero to Hero
ASP.NET MVC Zero to HeroASP.NET MVC Zero to Hero
ASP.NET MVC Zero to Hero
 
MWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVCMWLUG 2015 - An Introduction to MVC
MWLUG 2015 - An Introduction to MVC
 
Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013Getting started with MVC 5 and Visual Studio 2013
Getting started with MVC 5 and Visual Studio 2013
 

More from Md. Mahedee Hasan

Azure Machine Learning
Azure Machine LearningAzure Machine Learning
Azure Machine Learning
Md. Mahedee Hasan
 
Chatbot development with Microsoft Bot Framework and LUIS
Chatbot development with Microsoft Bot Framework and LUISChatbot development with Microsoft Bot Framework and LUIS
Chatbot development with Microsoft Bot Framework and LUIS
Md. Mahedee Hasan
 
Chatbot development with Microsoft Bot Framework
Chatbot development with Microsoft Bot FrameworkChatbot development with Microsoft Bot Framework
Chatbot development with Microsoft Bot Framework
Md. Mahedee Hasan
 
Introduction to Windows 10 IoT Core
Introduction to Windows 10 IoT CoreIntroduction to Windows 10 IoT Core
Introduction to Windows 10 IoT Core
Md. Mahedee Hasan
 
Whats new in visual studio 2017
Whats new in visual studio 2017Whats new in visual studio 2017
Whats new in visual studio 2017
Md. Mahedee Hasan
 
Increasing productivity using visual studio 2017
Increasing productivity using visual studio 2017Increasing productivity using visual studio 2017
Increasing productivity using visual studio 2017
Md. Mahedee Hasan
 
Exciting features in visual studio 2017
Exciting features in visual studio 2017Exciting features in visual studio 2017
Exciting features in visual studio 2017
Md. Mahedee Hasan
 
Introduction to TFS 2013
Introduction to TFS 2013Introduction to TFS 2013
Introduction to TFS 2013
Md. Mahedee Hasan
 
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkGeneric repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity Framework
Md. Mahedee Hasan
 
Feature and Future of ASP.NET
Feature and Future of ASP.NETFeature and Future of ASP.NET
Feature and Future of ASP.NET
Md. Mahedee Hasan
 
C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3Md. Mahedee Hasan
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Md. Mahedee Hasan
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
Md. Mahedee Hasan
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
Md. Mahedee Hasan
 

More from Md. Mahedee Hasan (14)

Azure Machine Learning
Azure Machine LearningAzure Machine Learning
Azure Machine Learning
 
Chatbot development with Microsoft Bot Framework and LUIS
Chatbot development with Microsoft Bot Framework and LUISChatbot development with Microsoft Bot Framework and LUIS
Chatbot development with Microsoft Bot Framework and LUIS
 
Chatbot development with Microsoft Bot Framework
Chatbot development with Microsoft Bot FrameworkChatbot development with Microsoft Bot Framework
Chatbot development with Microsoft Bot Framework
 
Introduction to Windows 10 IoT Core
Introduction to Windows 10 IoT CoreIntroduction to Windows 10 IoT Core
Introduction to Windows 10 IoT Core
 
Whats new in visual studio 2017
Whats new in visual studio 2017Whats new in visual studio 2017
Whats new in visual studio 2017
 
Increasing productivity using visual studio 2017
Increasing productivity using visual studio 2017Increasing productivity using visual studio 2017
Increasing productivity using visual studio 2017
 
Exciting features in visual studio 2017
Exciting features in visual studio 2017Exciting features in visual studio 2017
Exciting features in visual studio 2017
 
Introduction to TFS 2013
Introduction to TFS 2013Introduction to TFS 2013
Introduction to TFS 2013
 
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity FrameworkGeneric repository pattern with ASP.NET MVC and Entity Framework
Generic repository pattern with ASP.NET MVC and Entity Framework
 
Feature and Future of ASP.NET
Feature and Future of ASP.NETFeature and Future of ASP.NET
Feature and Future of ASP.NET
 
C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3C#.net applied OOP - Batch 3
C#.net applied OOP - Batch 3
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
C# - Part 1
C# - Part 1C# - Part 1
C# - Part 1
 

Recently uploaded

Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 

Recently uploaded (20)

Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 

Generic Repository Pattern with ASP.NET MVC and EF

  • 1. Generic Repository Pattern with ASP.NET MVC and EF Md. Mahedee Hasan Microsoft MVP | Trainer | Speaker Software Architect LeadSoft Bangladesh Limited Linkedin: http://www.linkedin.com/in/mahedee Blog: http://mahedee.net/ 1
  • 2. • MVC Stands for Model – View – Controller • It is Software Architectural pattern MAHEDEE.NET 2 What is MVC?
  • 3. • Is an open source web application framework • It implements the model-view-controller pattern • MVC design pattern aims to “Separation Of concern” MAHEDEE.NET 3 What is ASP.NET MVC?
  • 4. • Entity Framework is an ORM. • Work with relational data using domain-specific objects • Eliminates the need for most of the data-access code MAHEDEE.NET 4 What is ASP.NET EF?
  • 5. DRY? Don’t repeat yourself -Means don't write duplicate code Use generic repository pattern to implement DRY MAHEDEE.NET 5
  • 6. • What is Design Pattern? • Design pattern is a solution of known problems • What is Software Design Pattern? • Is a solution of known problems in Software. • Strategies of solving commonly occurring problems. • A design pattern is not a finish design. • It is like a template to solve a problem. MAHEDEE.NET 6 Software Design Pattern
  • 7. Repository Pattern • Mediator between BLL and DAL(Data Source) • It’s a separation layer between Data and Domain Layer – Separates data and domain Layer MAHEDEE.NET 7
  • 8. Benefits of Repository Pattern • Centralizes data logic or service logic. • Provides a substitution point for the unit tests – Both BLL and DAL • Provides a flexible architecture – Can adopt new change easily • Domain driven development is easier MAHEDEE.NET 8
  • 9. What is Generic Repository Pattern? • Generally - one repository for one model to access data. – Write similar code again and again • What if Single Repository for all? • Single repository for data access of all models. MAHEDEE.NET 9
  • 10. Benefits of Generic Repository Pattern • Reduce redundancy of code • Faster development • Force developer to work same pattern – Possibility of less error or no error • Easy to maintain – Centralize data access logic MAHEDEE.NET 10
  • 11. Implementation • Tools and Technology used – Visual Studio 2013 – Visual C# – ASP.NET MVC 5 – Entity Framework 6 – Razor view engine MAHEDEE.NET 11
  • 12. Step 1: Create an ASP.NET MVC 5 application using Visual Studio 2013 MAHEDEE.NET 12 Implementation…
  • 13. Step 2: Configure connection string in web.config MAHEDEE.NET 13 Implementation …
  • 14. Step 3: Create Models MAHEDEE.NET 14 Implementation …
  • 15. Step 4: Create a DbContext in Repository folder. MAHEDEE.NET 15 Implementation …
  • 16. Step 5: Create IGenericRepository and GenericRepository in Repository folder MAHEDEE.NET 16 Implementation …
  • 17. • Step 6: – Create controllers of each models – Select template “MVC5 Controller with views, using Entity Framework” – Modify Controllers and use Generic Repository in Controller MAHEDEE.NET 17 Implementation …
  • 18. • Step 7: Add links to _Layout MAHEDEE.NET 18 Implementation …
  • 19. • Step 8: Write following command in package manager console – PM> Enable-Migrations -ContextTypeName GenericRepoContext – PM> Add-Migration initialcreate – PM> Update-Database -Verbose -Force MAHEDEE.NET 19 Implementation …
  • 20. Step 9: Run Project MAHEDEE.NET 20 Implementation …
  • 21. 21

Editor's Notes

  1. DRY – Object Oriented design Principle. Ex. Dept Info in several code
  2. DRY – Object Oriented design Principle. Ex. Dept Info in several code
  3. DRY – Object Oriented design Principle. Ex. Dept Info in several code
  4. Create Designation and Employee Model in model folder Describe model and annotation
  5. DbContext: Simplified alternative to ObjectContext and is the primary object for interacting with a database using a specified model. DbSet: Simplified alternative to ObjectSet and is used to perform CRUD operations against a specific type from the model
  6. It's a type constraint on T , specifying that it must be a class.
  7. Create Designation Controller and Employee Controller. First Add designation and then Employee. Look corresponding view