SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
Elements of DDD with
      ASP .NET MVC &
Entity Framework Code First
                          Gabriel ENEA, Technical Director
                                                Maxcode
          Co-founder Joobs.ro – primul portal de joburi IT
            gabriel.enea@maxcode.ro / gabrielenea.blogspot.com / @dotnet18




 Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
IT Camp 2011
• Thanks for coming!
• ITCamp is made possible by our sponsors:




      Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Session agenda
# Unit Testing
# Enterprise Application Architecture
# Domain-Driven-Design
# Dependency Injection
# ASP.NET MVC 3 DI
# Entity Framework 4.1 Code First
# Design Patterns

• Q&A
• Feedback & prizes

       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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?

        Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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?


        Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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!



     Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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?


       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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



       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Layers

                         Presentation


                              Business


                          Data Access

Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Layers – any problems?
                                                                       Presentation


                                                                         Business


Layers Coupling!                                                       Data Access


A strong coupling conducts to a hard way to do:
   – unit testing
   – refactoring
   – agile development
   – or be opened for changes


       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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!? 


      Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
And...what's inappropriate here?
// 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;
        }
      }
...

                Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Let's start with a new approach...
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!

        Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
A new default architecture




 Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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

      Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Building blocks of DDD




Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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, ...




       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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



        Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Dependency Injection


                                                         Log4netLogger


PatientService



                                                        PatientRepositoy




  Premium conference on Microsoft’s Dev and ITPro technologies     @itcampro / #itcampro
Dependency Injection
                                       1) creates
           Builder                                                PatientService




                                     Log4netLogger
2) inject dependencies                                                               3) uses




                                          ILogger



             Premium conference on Microsoft’s Dev and ITPro technologies     @itcampro / #itcampro
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




        Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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>() { … }


        Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
DDD architecture and solution

DEMO


       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Conclusions
Focus on
  –   Analyze application dependencies
  –   Business rules
  –   Do refactoring!
  –   Design your Domain
  –   Don’t forget to do Unit testing




        Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Elements of DDD with ASP.NET MVC & Entity Framework Code First

Q&A


       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
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/domai
  n-driven-design-quickly

       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Don’t forget!
Get your free Azure pass!                            We want your feedback!

• 30+15 days, no CC req’d                        • Win a WP7 smartphone
   – http://bit.ly/ITCAMP11                             – Fill in your feedback forms
   – Promo code: ITCAMP11                               – Raffle: end of the day




        Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro

Weitere ähnliche Inhalte

Andere mochten auch

«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NETAlessandro Giorgetti
 
SignalR With ASP.Net part1
SignalR With ASP.Net part1SignalR With ASP.Net part1
SignalR With ASP.Net part1Esraa Ammar
 
Gettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSGettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSArmin Vieweg
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCKhaled Musaied
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tipsNir Kaufman
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)Gary Arora
 
Introduction to AngularJS Framework
Introduction to AngularJS FrameworkIntroduction to AngularJS Framework
Introduction to AngularJS FrameworkRaveendra R
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015Matt Raible
 

Andere mochten auch (15)

«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET«Real Time» Web Applications with SignalR in ASP.NET
«Real Time» Web Applications with SignalR in ASP.NET
 
SignalR With ASP.Net part1
SignalR With ASP.Net part1SignalR With ASP.Net part1
SignalR With ASP.Net part1
 
Benefits of developing a Single Page Web Applications using AngularJS
Benefits of developing a Single Page Web Applications using AngularJSBenefits of developing a Single Page Web Applications using AngularJS
Benefits of developing a Single Page Web Applications using AngularJS
 
Gettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSGettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJS
 
SignalR
SignalRSignalR
SignalR
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
SignalR
SignalRSignalR
SignalR
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
AngularJS performance & production tips
AngularJS performance & production tipsAngularJS performance & production tips
AngularJS performance & production tips
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Introduction to AngularJS Framework
Introduction to AngularJS FrameworkIntroduction to AngularJS Framework
Introduction to AngularJS Framework
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
The Art of AngularJS in 2015
The Art of AngularJS in 2015The Art of AngularJS in 2015
The Art of AngularJS in 2015
 

Mehr von ITCamp

ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...ITCamp
 
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...ITCamp
 
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Peter Leeson - Managing SkillsITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Peter Leeson - Managing SkillsITCamp
 
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Mihai Tataran - Governing your Cloud ResourcesITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Mihai Tataran - Governing your Cloud ResourcesITCamp
 
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UXITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UXITCamp
 
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Coros - Implementing Clean ArchitectureITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Coros - Implementing Clean ArchitectureITCamp
 
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...ITCamp
 
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp 2019 - Florin Flestea -  How 3rd Level support experience influenced m...ITCamp 2019 - Florin Flestea -  How 3rd Level support experience influenced m...
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...ITCamp
 
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...ITCamp
 
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The EnterpriseITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The EnterpriseITCamp
 
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal TrendsITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal TrendsITCamp
 
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data LakeITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data LakeITCamp
 
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andy Cross - Business Outcomes from AIITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andy Cross - Business Outcomes from AIITCamp
 
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud StoryITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud StoryITCamp
 
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...ITCamp
 
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...ITCamp
 
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go NowITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go NowITCamp
 
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2019 - Peter Leeson - Vitruvian QualityITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2019 - Peter Leeson - Vitruvian QualityITCamp
 
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World ApplicationITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World ApplicationITCamp
 
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...ITCamp
 

Mehr von ITCamp (20)

ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
ITCamp 2019 - Stacey M. Jenkins - Protecting your company's data - By psychol...
 
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
ITCamp 2019 - Silviu Niculita - Supercharge your AI efforts with the use of A...
 
ITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Peter Leeson - Managing SkillsITCamp 2019 - Peter Leeson - Managing Skills
ITCamp 2019 - Peter Leeson - Managing Skills
 
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Mihai Tataran - Governing your Cloud ResourcesITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
ITCamp 2019 - Mihai Tataran - Governing your Cloud Resources
 
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UXITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
ITCamp 2019 - Ivana Milicic - Color - The Shadow Ruler of UX
 
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Coros - Implementing Clean ArchitectureITCamp 2019 - Florin Coros - Implementing Clean Architecture
ITCamp 2019 - Florin Coros - Implementing Clean Architecture
 
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...ITCamp 2019 - Florin Loghiade -  Azure Kubernetes in Production - Field notes...
ITCamp 2019 - Florin Loghiade - Azure Kubernetes in Production - Field notes...
 
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
ITCamp 2019 - Florin Flestea -  How 3rd Level support experience influenced m...ITCamp 2019 - Florin Flestea -  How 3rd Level support experience influenced m...
ITCamp 2019 - Florin Flestea - How 3rd Level support experience influenced m...
 
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
ITCamp 2019 - Emil Craciun - RoboRestaurant of the future powered by serverle...
 
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The EnterpriseITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
ITCamp 2019 - Eldert Grootenboer - Cloud Architecture Recipes for The Enterprise
 
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal TrendsITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
ITCamp 2019 - Cristiana Fernbach - Blockchain Legal Trends
 
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data LakeITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
 
ITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andy Cross - Business Outcomes from AIITCamp 2019 - Andy Cross - Business Outcomes from AI
ITCamp 2019 - Andy Cross - Business Outcomes from AI
 
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud StoryITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
ITCamp 2019 - Andrea Saltarello - Modernise your app. The Cloud Story
 
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
ITCamp 2019 - Andrea Saltarello - Implementing bots and Alexa skills using Az...
 
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
ITCamp 2019 - Alex Mang - I'm Confused Should I Orchestrate my Containers on ...
 
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go NowITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
ITCamp 2019 - Alex Mang - How Far Can Serverless Actually Go Now
 
ITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2019 - Peter Leeson - Vitruvian QualityITCamp 2019 - Peter Leeson - Vitruvian Quality
ITCamp 2019 - Peter Leeson - Vitruvian Quality
 
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World ApplicationITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
ITCamp 2018 - Ciprian Sorlea - Million Dollars Hello World Application
 
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
ITCamp 2018 - Ciprian Sorlea - Enterprise Architectures with TypeScript And F...
 

Kürzlich hochgeladen

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMKumar Satyam
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
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 SavingEdi Saputra
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
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 educationjfdjdjcjdnsjd
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
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 ...apidays
 
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 WoodJuan lago vázquez
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
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 businesspanagenda
 
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 2024Victor Rentea
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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.pptxRemote DBA Services
 

Kürzlich hochgeladen (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
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 ...
 
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
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 

ITCamp 2011 - Gabriel Enea - Elements of DDD with ASPNet MVC and Entity Framework

  • 1. Elements of DDD with ASP .NET MVC & Entity Framework Code First Gabriel ENEA, Technical Director Maxcode Co-founder Joobs.ro – primul portal de joburi IT gabriel.enea@maxcode.ro / gabrielenea.blogspot.com / @dotnet18 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 2. IT Camp 2011 • Thanks for coming! • ITCamp is made possible by our sponsors: Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 3. Session agenda # Unit Testing # Enterprise Application Architecture # Domain-Driven-Design # Dependency Injection # ASP.NET MVC 3 DI # Entity Framework 4.1 Code First # Design Patterns • Q&A • Feedback & prizes Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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? Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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? Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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! Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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? Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 9. Layers Presentation Business Data Access Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 10. Layers – any problems? Presentation Business Layers Coupling! Data Access A strong coupling conducts to a hard way to do: – unit testing – refactoring – agile development – or be opened for changes Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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!?  Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 12. And...what's inappropriate here? // 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; } } ... Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 13. Let's start with a new approach... 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! Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 14. A new default architecture Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 16. Building blocks of DDD Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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, ... Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 19. Dependency Injection Log4netLogger PatientService PatientRepositoy Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 20. Dependency Injection 1) creates Builder PatientService Log4netLogger 2) inject dependencies 3) uses ILogger Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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>() { … } Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 23. DDD architecture and solution DEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 24. Conclusions Focus on – Analyze application dependencies – Business rules – Do refactoring! – Design your Domain – Don’t forget to do Unit testing Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 25. Elements of DDD with ASP.NET MVC & Entity Framework Code First Q&A Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 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/domai n-driven-design-quickly Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  • 27. Don’t forget! Get your free Azure pass! We want your feedback! • 30+15 days, no CC req’d • Win a WP7 smartphone – http://bit.ly/ITCAMP11 – Fill in your feedback forms – Promo code: ITCAMP11 – Raffle: end of the day Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro