Elements of DDD with      ASP .NET MVC &Entity Framework Code First                        Gabriel ENEA, Technical Directo...
IT Camp 2011• Thanks for coming!• ITCamp is made possible by our sponsors:      Premium conference on Microsoft’s Dev and ...
Agenda# Unit Testing challenges# Today Architectural Design# New approach: Domain-Driven-Design# Today’s Tools (@web)# Dem...
Application requirementsDEMO       Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
UNIT TESTING CHALLENGES   Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
How do you test it?Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Testing on componentsPremium 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 abo...
Is unit testing achievable? 100%?Yes or No? Who knows?Maybe not! Possible answers:• The customer doesnt understand this ne...
TODAY ARCHITECTURAL DESIGN   Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Lets start thinking to architecture                design What? Right, now!? Hey, we have only 1 hour to finish this prese...
What stops 100% unit testing?1. Layers  – How do we design them?2. Business rules  – Where and how do we implement?3. Pers...
1 - Layers                         Presentation                              Business                          Data Access...
1 - Layers – any problems?                                                                       Presentation             ...
2 - Business rulesWhere should these be located?  – Database  – Business layer  – User Interface (aka code behind!)How do ...
And...whats inappropriate here?// somewhere in the business layerpublic class Patient {   public DateTime Birthdate { get;...
3 - PersistenceRequirements• Persistence Ignorance / POCO• Help Domain Model stay out of  infrastructure stuff• Decide whe...
NEW APPROACH: DDD  Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Lets start with a new approach...Domain-Driven-Design• What is Domain?A new default architecture where:• the database is n...
A new default architecture - DDD   Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Building blocks of DDDPremium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
TODAYS TOOLS   Premium conference on Microsoft’s Dev and ITPro technologies   @itcampro / #itcampro
Todays tools(from a web developer perspective)Dependency Injection frameworks  – Manage dependencies  – Castle Windsor, St...
What is Dependency Injection?• = DI.Equals(IoC); // true or false?• IoC = Inversion of Control• DI = Dependency Injection•...
Dependency Injection                                                         Log4netLoggerPatientService                  ...
Dependency Injection                                       1) creates           Builder                                   ...
ASP.NET MVC 3 and DI support• Based on MVC pattern• Provides better support for IoC   – Views/Controllers• Model Validatio...
Persistance with EF 4.1 CodeFirst1st version benefits:• CodeFirst development• Better POCO support• Mapping based on prede...
DDD architecture with ASP.NET MVC 3, Unity, Entity FrameworkCodeFirst 4.1DEMO       Premium conference on Microsoft’s Dev ...
ConclusionsFocus on  –   Analyze application dependencies  –   Business rules  –   Do refactoring!  –   Design your Domain...
ResourcesBooks• Domain-Driven Design, Tackling Complexity in the  Heart of Software, by Eric Evans• Applying Domain-Driven...
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstQ&A       Premium conference on Microsoft’s Dev and ITPro te...
Don’t forget!Get your free Azure pass!                            We want your feedback!• 30+15 days, no CC req’d         ...
Upcoming SlideShare
Loading in...5
×

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

8,285

Published on

This is a presentation about the new Domain Driven Design architecture in combination with ASP.NET MVC 3 and Entity Framework 4.1 CodeFirst tools.

The session was part of the IT Camp 2011 event (http://www.itcamp.ro).

Published in: Technology
3 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total Views
8,285
On Slideshare
0
From Embeds
0
Number of Embeds
26
Actions
Shares
0
Downloads
120
Comments
3
Likes
1
Embeds 0
No embeds

No notes for slide

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

  1. 1. Elements of DDD with ASP .NET MVC &Entity Framework Code First Gabriel ENEA, Technical Director MAXCODE.nlCo-founder Joobs.ro – the first IT job portal in Romania CodeCamp member / Iași gabriel.enea@maxcode.ro / gabrielenea.blogspot.com / @dotnet18 Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  2. 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. 3. Agenda# Unit Testing challenges# Today Architectural Design# New approach: Domain-Driven-Design# Today’s Tools (@web)# Demo• Q&A Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  4. 4. Application requirementsDEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  5. 5. UNIT TESTING CHALLENGES Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  6. 6. How do you test it?Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  7. 7. Testing on componentsPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  8. 8. 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• reusing existing code?• but, in the end, do you achieve 99,99% test code coverage? Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  9. 9. Is unit testing achievable? 100%?Yes or No? Who knows?Maybe not! Possible answers:• The customer doesnt 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 dont know how to achieve it? Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  10. 10. TODAY ARCHITECTURAL DESIGN Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  11. 11. Lets start thinking to architecture design What? Right, now!? Hey, we have only 1 hour to finish this presentation!  Indeed, but lets try to do something! Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  12. 12. What stops 100% unit testing?1. Layers – How do we design them?2. Business rules – Where and how do we implement?3. Persistence – Should we use an ORM? … Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  13. 13. 1 - Layers Presentation Business Data AccessPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  14. 14. 1 - Layers – any problems? Presentation BusinessLayers Coupling! Data AccessA 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
  15. 15. 2 - Business rulesWhere 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
  16. 16. And...whats inappropriate here?// somewhere in the business layerpublic 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
  17. 17. 3 - PersistenceRequirements• Persistence Ignorance / POCO• Help Domain Model stay out of infrastructure stuff• Decide where to store data (NoSQL?)• 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
  18. 18. NEW APPROACH: DDD Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  19. 19. Lets 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
  20. 20. A new default architecture - DDD Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  21. 21. Building blocks of DDDPremium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  22. 22. TODAYS TOOLS Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  23. 23. Todays tools(from a web developer perspective)Dependency Injection frameworks – Manage dependencies – Castle Windsor, StructureMap, Spring.NET, Unity, ...ASP.NET MVC 3 – a mature web development platform based on MVC patternEntity Framework 4.1 Code First / NHibernate – helps you focus on your domain Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  24. 24. What is Dependency Injection?• = 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 – Layers Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  25. 25. Dependency Injection Log4netLoggerPatientService PatientRepositoy Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  26. 26. Dependency Injection 1) creates Builder PatientService Log4netLogger2) inject dependencies 3) uses ILogger Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  27. 27. ASP.NET MVC 3 and DI support• Based on MVC pattern• Provides better support for IoC – Views/Controllers• Model Validation support• Check IDependencyResolver interface – simplify service location and dependency resolutionTService GetService<TService>() { … }IEnumerable<TService> GetServices<TService>() { … } Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  28. 28. Persistance with EF 4.1 CodeFirst1st version benefits:• CodeFirst development• Better POCO support• Mapping based on predefined conventions (Convention over configuration)• Fluent API for manual mapping entities to tables, no more .edmx files• Built-in Model-Level Validation• Dynamic database creation and dropping Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  29. 29. DDD architecture with ASP.NET MVC 3, Unity, Entity FrameworkCodeFirst 4.1DEMO Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  30. 30. ConclusionsFocus 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
  31. 31. ResourcesBooks• 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 NilssonOnline 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
  32. 32. Elements of DDD with ASP.NET MVC & Entity Framework Code FirstQ&A Premium conference on Microsoft’s Dev and ITPro technologies @itcampro / #itcampro
  33. 33. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×