SlideShare a Scribd company logo
Enterprise Design Patterns Intro
Designing your app the correct way – SSW Module 1725
Module Overview
1. Intro to Dependency Injection
2. Intro to the Onion Architecture
3. Intro to Enterprise Data Access
a) Repository Pattern
b) Unit of Work Pattern
4. View Models
Are you using Dependency Injection?
 Tried it?
 Like it?
 Used it in a project?
Dependencies
An Introduction to Enterprise Design Patterns
An Introduction to Enterprise Design Patterns
The answer:
Dependency Injection
Loosely coupled classes
Increased code reuse
Maintainable code
Testable methods
All dependencies are specified in one
place
Class dependencies are clearly
visible in the constructor
 Lets look at the OrderProcessor.
 Spot the Code Smell ?
Look Mum. No Dependencies !
Are you using Dependency Injection?
 Tried it?
 Like it?
 Used for new project?
 Refactored existing code?
 Implemented everywhere?
Onion Architecture
Enterprise Data Access Patterns
The Provided Solution Structure
Our Solution Structure
Repository
Directly Accessing Data
Duplicated code / No code re-use
Hard to centralize data-related policies (i.e. caching)
Hard to write unit tests
IIS
Controller
EF
DBContext
Database
No Repository
Direct access to the database
from the controller
IIS
Controller
EF
Repository:
IRepository
Database
With Repository
Abstraction layer between controller and database
context. Unit tests can use a custom persistence
later to facilitate testing
Test Project
Controller
Mock
Repository :
IRepository
Mock
Persistence
Use the Repository Pattern
Isolates the data layer
better unit testing support
Centralised, consistent access rules, logic and caching
Maintainability
improved code re-use
Readability
e.g. GetTopSellingItemsByCategory – Simple method name, complex SQL Query
http://blog.damianbrady.com.au/2012/03/07/a-generic-crud-repository-for-entity-framework/
http://rules.ssw.com.au/SoftwareDevelopment/RulestobetterArchitectureandCodeReview/Pages/RepositoryPattern.aspx
IIS
Controller
LEGACY
DATABASE:
IRepository
Database
Use Repositories to abstract
legacy data access
Test Project
Controller
Mock
Repository :
IRepository
Mock
Persistence
IIS
Controller
EF
Repository:
IRepository
Database
New Functionality
Repositories – Migrating to modern data access
Implementing the Repository
Pattern with Code First
Repository Interfaces
Generic Repository - Overview
Generic Repository – Db Context
Generic Repository - Implementation
The Repositories
Repositories in the store controller
Unit of Work
 Coordinates multiple
repositories with a single
db context
 UOW.SaveChanges()
commits the changes
made to all of the
repositories
IIS
Controller
Unit of Work
Database
Unit of Work
Ensures that multiple repositories share a
single database context
Test Project
Controller
Mock Unit Of Work
Mock
Persistence
Repository
Mock
Repository
Repository
Mock
Repository
DbContext
Implementing the
Unit Of Work Pattern
An Introduction to Enterprise Design Patterns
Where Is My Context?
Where the Magic Happens…..
Our Dependency Injection Container !
Implementing the Repository
Pattern with EDMX
I Need Some Context
Code First Context vs Edmx Generated Context
Generating Entities In My Domain Project
From the EDMX
Update the T4 template to point to the EDMX
DB First - Repository + Unit of Work
 Entity Framework 4 instructions:
http://blogs.msdn.com/b/adonet/archive/2009/05/21/poco-in-the-entity-
framework-part-1-the-experience.aspx
View Models
 models that describe a view
 pass data from a controller to a view.
 provides a convenient way of representing
complex view data
Benefits of View Models
 Remove logic from your views – viewmodels are easily
unit tested
 Security – remove properties from models you don’t
want in the view
 Loose coupling –views are not coupled to the domain
 DataAnnotations describe the model
An Introduction to Enterprise Design Patterns
Summary
1. Intro to Dependency Injection
2. Intro to the Onion Architecture
3. Intro to Enterprise Data Access
a) Repository Pattern
b) Unit of Work Pattern
4. View Models

More Related Content

PPTX
Agile & DevOps - It's all about project success
PDF
An introduction to unit testing
PDF
An Introduction to Dependency Injection
PPTX
2019 04 Containers - The secret to shipping cloud workloads
PDF
Azure DevOps for .NET - Fall into the Pit of Success, .NET Conf 2019
PPTX
Azure dev ops
PPTX
Intro to Azure DevOps
PPTX
Devops interview questions 1 www.bigclasses.com
Agile & DevOps - It's all about project success
An introduction to unit testing
An Introduction to Dependency Injection
2019 04 Containers - The secret to shipping cloud workloads
Azure DevOps for .NET - Fall into the Pit of Success, .NET Conf 2019
Azure dev ops
Intro to Azure DevOps
Devops interview questions 1 www.bigclasses.com

What's hot (18)

PPTX
Introduction to Azure DevOps
PPTX
Microsoft Tech Series 2019 - Azure DevOps
PDF
Devops interview-questions-PDF
PPTX
Using Azure DevOps to continuously build, test, and deploy containerized appl...
PPTX
The Power of Azure DevOps
PPTX
Exposing services with Azure API Management
PPTX
The Power of Azure DevOps
PPTX
Infrastructure automation with .NET
PPTX
Mobile UI Testing using Appium and Docker
PPTX
Azure function DevOps pipeline, ALM / DevOps Rangers feedbacks
PPTX
Leveraging Azure DevOps across the Enterprise
PDF
Mastering Best Azure DevOps Online Training and Certification - Dot Net Tricks
PDF
How To Be a Java Automated Testing Superstar
PDF
DevOps Interview Questions and Answers 2019 | DevOps Tutorial | Edureka
PDF
PPTX
Automate you Appium test like a pro!
PDF
Build embedded and IoT solutions with Microsoft Windows IoT Core (BRK30077)
PDF
[JAZUG Tohoku Azure DevOps] Azure DevOps
Introduction to Azure DevOps
Microsoft Tech Series 2019 - Azure DevOps
Devops interview-questions-PDF
Using Azure DevOps to continuously build, test, and deploy containerized appl...
The Power of Azure DevOps
Exposing services with Azure API Management
The Power of Azure DevOps
Infrastructure automation with .NET
Mobile UI Testing using Appium and Docker
Azure function DevOps pipeline, ALM / DevOps Rangers feedbacks
Leveraging Azure DevOps across the Enterprise
Mastering Best Azure DevOps Online Training and Certification - Dot Net Tricks
How To Be a Java Automated Testing Superstar
DevOps Interview Questions and Answers 2019 | DevOps Tutorial | Edureka
Automate you Appium test like a pro!
Build embedded and IoT solutions with Microsoft Windows IoT Core (BRK30077)
[JAZUG Tohoku Azure DevOps] Azure DevOps
Ad

Similar to An Introduction to Enterprise Design Patterns (20)

PDF
Repository and Unit Of Work Design Patterns
PPTX
Design patterns fast track
DOCX
Generic Repository Pattern in MVC3 Application with Entity Framework
DOCX
Repository Pattern in MVC3 Application with Entity Framework
PPTX
Repository Pattern with c# and Entity Framework
PPTX
Entity Framework Today (May 2012)
PPTX
Applied patterns in the project
PPTX
Entity Framework: To the Unit of Work Design Pattern and Beyond
PPTX
Most Useful Design Patterns
PPTX
Entity Framework 4
PPT
A clean repository pattern in ef
PDF
dependencyinjectionwithunity.pdf
PPTX
PPTX
Entity Framework Database and Code First
PPT
Entity framework 4.0
PPT
A clean repository pattern in ef
PDF
Programming Entity Framework Building Data Centric Apps with the ADO NET Enti...
PPTX
Building nTier Applications with Entity Framework Services (Part 1)
PDF
Generic repository pattern with ASP.NET MVC and Entity Framework
PPTX
Generic Repository Pattern with ASP.NET MVC and EF
Repository and Unit Of Work Design Patterns
Design patterns fast track
Generic Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern in MVC3 Application with Entity Framework
Repository Pattern with c# and Entity Framework
Entity Framework Today (May 2012)
Applied patterns in the project
Entity Framework: To the Unit of Work Design Pattern and Beyond
Most Useful Design Patterns
Entity Framework 4
A clean repository pattern in ef
dependencyinjectionwithunity.pdf
Entity Framework Database and Code First
Entity framework 4.0
A clean repository pattern in ef
Programming Entity Framework Building Data Centric Apps with the ADO NET Enti...
Building nTier Applications with Entity Framework Services (Part 1)
Generic repository pattern with ASP.NET MVC and Entity Framework
Generic Repository Pattern with ASP.NET MVC and EF
Ad

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
Electronic commerce courselecture one. Pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Modernizing your data center with Dell and AMD
PDF
Sensors and Actuators in IoT Systems using pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
cuic standard and advanced reporting.pdf
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Per capita expenditure prediction using model stacking based on satellite ima...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
Electronic commerce courselecture one. Pdf
Review of recent advances in non-invasive hemoglobin estimation
Transforming Manufacturing operations through Intelligent Integrations
Modernizing your data center with Dell and AMD
Sensors and Actuators in IoT Systems using pdf
Empathic Computing: Creating Shared Understanding
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
“AI and Expert System Decision Support & Business Intelligence Systems”
cuic standard and advanced reporting.pdf
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Chapter 2 Digital Image Fundamentals.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
Diabetes mellitus diagnosis method based random forest with bat algorithm

An Introduction to Enterprise Design Patterns