SlideShare a Scribd company logo
1 of 27
Download to read offline
Elements of DDD with
ASP.NET MVC &
Entity Framework Code First
Gabriel ENEA
Software developer / Maxcode.ro
Co-founder Joobs.ro – primul portal de joburi IT

07 may 2011
Updated:
Elements of software design


07 may 2011
Agenda Tags
# Unit Testing
# Enterprise Application Architecture
# Dependency Injection
# ASP.NET MVC 3
# Entity Framework 4.1 Code First
# Domain-Driven-Design
# Design Patterns
How do you start building an
application architecture?
Focus on?
 building an architecture from scratch
 thinking about how to achieve unit testing
 start with modeling the database schema and data relations
 using drag & drop programming
 modeling the domain entities, relations, business rules



 but, in the end, do you achieve 99,99% of unit testing?
Is unit testing realizable? 100%?
Yes or No? Who knows?

Maybe not! Possible answers:
 The customer doesn't understand this need
 Neither the management staff
 Instead, everyone expects you to write the perfect code

 As developers, every time we say: we need time to do it
  right!

 But, do we need time or we don't know how to achieve it?
Let's start thinking to architecture
design?
What? Right, now!?

Hey, we have only 1 hour to finish this
presentation! 



Indeed, but let's try to do something!
Some directions
Modeling approaches
  Database First Design
  Model First Design
Layers
  How do we design them?
Business rules
  Where and how do we implement?
Persistence
  Should we use an ORM?
Modeling approach - Pros/Cons
Database First Design
  doesn't focus on business rules, only on the way the
   data is represented


Model First Design
  Conceptual Design
   defines a conceptual model of the entities and relations
    (UML vs. Domain-Specific Languages)
  Code First Design
   starts writing code: classes, properties, associations,
    businesss rules
Layers

         Presentation


          Business


         Data Access
Presentation


Layers – any problems?                       Business


                                            Data Access



Layers Coupling!

A strong coupling conducts to a hard way to do:
   unit testing
   refactoring
   agile development
   or be opened for changes
Business rules
Where should these be located?
  Database
  Business layer
  User Interface (aka code behind!)


How do we test them?
  Running the application
  Automatically, maybe using unit tests
  Or we should let the customer test them!? 
And...what's inappropriate in this
code?
// somewhere in the business layer
...
public class Patient {
    public DateTime Birthdate { get; set; }

      public int Age { // computed value
        get {
           return DateTime.Now.Year - this.Birthdate.Year;
        }
      }                  Strong coupling!

      public bool IsAdult { // business rule
        get {
           return this.Age >= 18;
        }
      }
...
Let's start with a new approach...DDD
Domain-Driven-Design
 What is Domain?

A new default architecture where:
 the database is not the first focus
 the layers are loosely coupled
 the business rules are within the application Domain
 it is easier to achieve unit testing

 Why? Today we have the tools!
A new default architecture
Persistence
Requirements
 Persistence Ignorance (PI) / POCO
 Help Domain Model stay out of infrastructure stuff
 Decide where to store data
 Use code generation or an Object Relation (O/R) Mapper
   Metadata mapping
 Support for the Unit of Work pattern
Building blocks of Domain-Driven
Design
Today's tools
(from a web developer perspective)
ASP.NET MVC 3
  a mature web development platform based on
   MVC pattern
Entity Framework 4.1 Code First / NHibernate
  helps you focus on your domain
DI frameworks
  Manage dependencies
  Castle Windsor, StructureMap, Spring.NET, Unity, ...
Stop, What is DI?
 = DI.Equals(IoC); // true or false?

 IoC = Inversion of Control
 DI = Dependency Injection

 Helps you to decouple the application dependencies
   Logging mechanisms (log4net, Enterprise Library Logging
    Application Block, ...)
   Persistence mechanism (direct access to database, ORM)
   User Interface dependencies on Domain services
Dependency Injection

                   Log4netLogger


 PatientService



                   PatientRepositoy
Dependency Injection
                           1) creates
         Builder                         PatientService




                         Log4netLogger
2) inject dependencies                                    3) uses




                            ILogger
Persistance with EF 4.1 CodeFirst
Benefits
 Mapping based on predefined conventions
 Support for Query Object pattern (LINQ - IQuerable
  interface)
 Fluent API for manual mapping entities to tables, no
  more .edmx files
 Entity Validation
ASP.NET MVC 3 and DI support
 Based on MVC pattern
 Provides better support for IoC
   Views/Controllers


 Check IDependencyResolver interface
   simplify service location and dependency resolution


TService GetService<TService>() { … }

IEnumerable<TService> GetServices<TService>() { … }
Demo



What? We have a demo? Finally!
Conclusions
Focus on
  Analyze application dependencies
  Business rules
  Do refactoring!
  Design your Domain
  Don’t forget to do Unit testing
Questions?
Resources
Books
 Domain-Driven Design, Tackling Complexity in the
  Heart of Software, by Eric Evans
 Applying Domain-Driven Design and Patterns, With
  Examples in C# and .NET, by Jimmy Nilsson

Online resources
 http://domaindrivendesign.org/
 http://www.infoq.com/minibooks/domain-driven-design-quickly
The end…Thank you!


Elements of DDD with
ASP.NET MVC &
Entity Framework Code First
Gabriel ENEA
Software developer / Maxcode.ro
Co-founder Joobs.ro – primul portal de joburi IT

07 may 2011

More Related Content

What's hot

Hexagonal
HexagonalHexagonal
Hexagonal
jglobal
 

What's hot (20)

Introduction to-ddd
Introduction to-dddIntroduction to-ddd
Introduction to-ddd
 
Implementing DDD Concepts in PHP
Implementing DDD Concepts in PHPImplementing DDD Concepts in PHP
Implementing DDD Concepts in PHP
 
Decoupling with Domain Events
Decoupling with Domain EventsDecoupling with Domain Events
Decoupling with Domain Events
 
How to Implement Domain Driven Design in Real Life SDLC
How to Implement Domain Driven Design  in Real Life SDLCHow to Implement Domain Driven Design  in Real Life SDLC
How to Implement Domain Driven Design in Real Life SDLC
 
Domain driven design and model driven development
Domain driven design and model driven developmentDomain driven design and model driven development
Domain driven design and model driven development
 
Hexagonal architecture - message-oriented software design
Hexagonal architecture  - message-oriented software designHexagonal architecture  - message-oriented software design
Hexagonal architecture - message-oriented software design
 
ZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven DesignZendCon 2011 UnCon Domain-Driven Design
ZendCon 2011 UnCon Domain-Driven Design
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
EF6 and DDD
EF6 and DDDEF6 and DDD
EF6 and DDD
 
Domain Driven Design Quickly
Domain Driven Design QuicklyDomain Driven Design Quickly
Domain Driven Design Quickly
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
Refactoring for Domain Driven Design
Refactoring for Domain Driven DesignRefactoring for Domain Driven Design
Refactoring for Domain Driven Design
 
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
Hexagonal architecture - message-oriented software design (PHP Barcelona 2015)
 
Real-world Entity Framework
Real-world Entity FrameworkReal-world Entity Framework
Real-world Entity Framework
 
Hexagonal
HexagonalHexagonal
Hexagonal
 
Introduction To Domain Driven Design
Introduction To Domain Driven DesignIntroduction To Domain Driven Design
Introduction To Domain Driven Design
 
Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"Domain-Driven Design: The "What" and the "Why"
Domain-Driven Design: The "What" and the "Why"
 
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
Hexagonal architecture - message-oriented software design (PHP Benelux 2016)
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Hexagonal architecture in PHP
Hexagonal architecture in PHPHexagonal architecture in PHP
Hexagonal architecture in PHP
 

Similar to Elements of DDD with ASP.NET MVC & Entity Framework Code First

Similar to Elements of DDD with ASP.NET MVC & Entity Framework Code First (20)

Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Entity framework
Entity frameworkEntity framework
Entity framework
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs Public
 
Actively looking for an opportunity to work as a challenging Dot Net Developer
Actively looking for an opportunity to work as a challenging Dot Net DeveloperActively looking for an opportunity to work as a challenging Dot Net Developer
Actively looking for an opportunity to work as a challenging Dot Net Developer
 
Actively looking for an opportunity to work as a challenging Dot Net Developer
Actively looking for an opportunity to work as a challenging Dot Net DeveloperActively looking for an opportunity to work as a challenging Dot Net Developer
Actively looking for an opportunity to work as a challenging Dot Net Developer
 
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
Java TechTalk "Spring boot made life easier with Kubernetes and Microservices"
 
Best practices for creating modular Web applications
Best practices for creating modular Web applicationsBest practices for creating modular Web applications
Best practices for creating modular Web applications
 
Azure presentation nnug dec 2010
Azure presentation nnug  dec 2010Azure presentation nnug  dec 2010
Azure presentation nnug dec 2010
 
Latest trends in information technology
Latest trends in information technologyLatest trends in information technology
Latest trends in information technology
 
Pragmatic Architecture in .NET
Pragmatic Architecture in .NETPragmatic Architecture in .NET
Pragmatic Architecture in .NET
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
Spring tutorials
Spring tutorialsSpring tutorials
Spring tutorials
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Isset Presentation @ EECI2009
Isset Presentation @ EECI2009Isset Presentation @ EECI2009
Isset Presentation @ EECI2009
 
Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)Building nTier Applications with Entity Framework Services (Part 1)
Building nTier Applications with Entity Framework Services (Part 1)
 
Microsoft Entity Framework
Microsoft Entity FrameworkMicrosoft Entity Framework
Microsoft Entity Framework
 
Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010Building N Tier Applications With Entity Framework Services 2010
Building N Tier Applications With Entity Framework Services 2010
 
How .NET Framework Supports Cost-Effective Application Development
How .NET Framework Supports Cost-Effective Application DevelopmentHow .NET Framework Supports Cost-Effective Application Development
How .NET Framework Supports Cost-Effective Application Development
 
.net Framework
.net Framework.net Framework
.net Framework
 

More from Enea Gabriel

Introducere în ASP.NET MVC prin exemple
Introducere în ASP.NET MVC prin exempleIntroducere în ASP.NET MVC prin exemple
Introducere în ASP.NET MVC prin exemple
Enea Gabriel
 
Magia testelor automate cu ASP.NET MVC
Magia testelor automate cu ASP.NET MVCMagia testelor automate cu ASP.NET MVC
Magia testelor automate cu ASP.NET MVC
Enea Gabriel
 
Rute cu ASP.NET MVC
Rute cu ASP.NET MVCRute cu ASP.NET MVC
Rute cu ASP.NET MVC
Enea Gabriel
 
Model View Controller și ASP.NET MVC + AJAX
Model View Controller și ASP.NET MVC + AJAXModel View Controller și ASP.NET MVC + AJAX
Model View Controller și ASP.NET MVC + AJAX
Enea Gabriel
 

More from Enea Gabriel (10)

Moving forward with ASP.NET Core
Moving forward with ASP.NET CoreMoving forward with ASP.NET Core
Moving forward with ASP.NET Core
 
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
 
Improving the availability of your website
Improving the availability of your websiteImproving the availability of your website
Improving the availability of your website
 
Applying EF Code First at Your Job
Applying EF Code First at Your JobApplying EF Code First at Your Job
Applying EF Code First at Your Job
 
Noutăţi în ASP.NET MVC 2
Noutăţi în ASP.NET MVC 2Noutăţi în ASP.NET MVC 2
Noutăţi în ASP.NET MVC 2
 
FII absolvent!
FII absolvent!FII absolvent!
FII absolvent!
 
Introducere în ASP.NET MVC prin exemple
Introducere în ASP.NET MVC prin exempleIntroducere în ASP.NET MVC prin exemple
Introducere în ASP.NET MVC prin exemple
 
Magia testelor automate cu ASP.NET MVC
Magia testelor automate cu ASP.NET MVCMagia testelor automate cu ASP.NET MVC
Magia testelor automate cu ASP.NET MVC
 
Rute cu ASP.NET MVC
Rute cu ASP.NET MVCRute cu ASP.NET MVC
Rute cu ASP.NET MVC
 
Model View Controller și ASP.NET MVC + AJAX
Model View Controller și ASP.NET MVC + AJAXModel View Controller și ASP.NET MVC + AJAX
Model View Controller și ASP.NET MVC + AJAX
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Elements of DDD with ASP.NET MVC & Entity Framework Code First

  • 1. Elements of DDD with ASP.NET MVC & Entity Framework Code First Gabriel ENEA Software developer / Maxcode.ro Co-founder Joobs.ro – primul portal de joburi IT 07 may 2011
  • 2. Updated: Elements of software design 07 may 2011
  • 3. Agenda Tags # Unit Testing # Enterprise Application Architecture # Dependency Injection # ASP.NET MVC 3 # Entity Framework 4.1 Code First # Domain-Driven-Design # Design Patterns
  • 4. How do you start building an application architecture? Focus on?  building an architecture from scratch  thinking about how to achieve unit testing  start with modeling the database schema and data relations  using drag & drop programming  modeling the domain entities, relations, business rules  but, in the end, do you achieve 99,99% of unit testing?
  • 5. Is unit testing realizable? 100%? Yes or No? Who knows? Maybe not! Possible answers:  The customer doesn't understand this need  Neither the management staff  Instead, everyone expects you to write the perfect code  As developers, every time we say: we need time to do it right!  But, do we need time or we don't know how to achieve it?
  • 6. Let's start thinking to architecture design? What? Right, now!? Hey, we have only 1 hour to finish this presentation!  Indeed, but let's try to do something!
  • 7. Some directions Modeling approaches  Database First Design  Model First Design Layers  How do we design them? Business rules  Where and how do we implement? Persistence  Should we use an ORM?
  • 8. Modeling approach - Pros/Cons Database First Design  doesn't focus on business rules, only on the way the data is represented Model First Design  Conceptual Design  defines a conceptual model of the entities and relations (UML vs. Domain-Specific Languages)  Code First Design  starts writing code: classes, properties, associations, businesss rules
  • 9. Layers Presentation Business Data Access
  • 10. Presentation Layers – any problems? Business Data Access Layers Coupling! A strong coupling conducts to a hard way to do:  unit testing  refactoring  agile development  or be opened for changes
  • 11. Business rules Where should these be located?  Database  Business layer  User Interface (aka code behind!) How do we test them?  Running the application  Automatically, maybe using unit tests  Or we should let the customer test them!? 
  • 12. And...what's inappropriate in this code? // somewhere in the business layer ... public class Patient { public DateTime Birthdate { get; set; } public int Age { // computed value get { return DateTime.Now.Year - this.Birthdate.Year; } } Strong coupling! public bool IsAdult { // business rule get { return this.Age >= 18; } } ...
  • 13. Let's start with a new approach...DDD Domain-Driven-Design  What is Domain? A new default architecture where:  the database is not the first focus  the layers are loosely coupled  the business rules are within the application Domain  it is easier to achieve unit testing  Why? Today we have the tools!
  • 14. A new default architecture
  • 15. Persistence Requirements  Persistence Ignorance (PI) / POCO  Help Domain Model stay out of infrastructure stuff  Decide where to store data  Use code generation or an Object Relation (O/R) Mapper  Metadata mapping  Support for the Unit of Work pattern
  • 16. Building blocks of Domain-Driven Design
  • 17. Today's tools (from a web developer perspective) ASP.NET MVC 3  a mature web development platform based on MVC pattern Entity Framework 4.1 Code First / NHibernate  helps you focus on your domain DI frameworks  Manage dependencies  Castle Windsor, StructureMap, Spring.NET, Unity, ...
  • 18. Stop, What is DI?  = DI.Equals(IoC); // true or false?  IoC = Inversion of Control  DI = Dependency Injection  Helps you to decouple the application dependencies  Logging mechanisms (log4net, Enterprise Library Logging Application Block, ...)  Persistence mechanism (direct access to database, ORM)  User Interface dependencies on Domain services
  • 19. Dependency Injection Log4netLogger PatientService PatientRepositoy
  • 20. Dependency Injection 1) creates Builder PatientService Log4netLogger 2) inject dependencies 3) uses ILogger
  • 21. Persistance with EF 4.1 CodeFirst Benefits  Mapping based on predefined conventions  Support for Query Object pattern (LINQ - IQuerable interface)  Fluent API for manual mapping entities to tables, no more .edmx files  Entity Validation
  • 22. ASP.NET MVC 3 and DI support  Based on MVC pattern  Provides better support for IoC  Views/Controllers  Check IDependencyResolver interface  simplify service location and dependency resolution TService GetService<TService>() { … } IEnumerable<TService> GetServices<TService>() { … }
  • 23. Demo What? We have a demo? Finally!
  • 24. Conclusions Focus on  Analyze application dependencies  Business rules  Do refactoring!  Design your Domain  Don’t forget to do Unit testing
  • 26. Resources Books  Domain-Driven Design, Tackling Complexity in the Heart of Software, by Eric Evans  Applying Domain-Driven Design and Patterns, With Examples in C# and .NET, by Jimmy Nilsson Online resources  http://domaindrivendesign.org/  http://www.infoq.com/minibooks/domain-driven-design-quickly
  • 27. The end…Thank you! Elements of DDD with ASP.NET MVC & Entity Framework Code First Gabriel ENEA Software developer / Maxcode.ro Co-founder Joobs.ro – primul portal de joburi IT 07 may 2011