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

12,455 views

Published on

Download demo: http://bit.ly/CodeCampIasi07mai2011-DDDDemo

Published in: Technology
11 Comments
5 Likes
Statistics
Notes
  • You need Visual Studio 2010 Professional or Ultimate to open those projects. I recommend you to have a look at Domain.Tests project (source files) and then you can try to rewrite the tests using NUnit or other test framework (in case you only have the VS Express edition).

    Thank you!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Gabriel,
    Some of the projects won't open when solution is opened in Visual Web Developer 2010 Express. Domain.Tests, ModelingProject, WebSite.Tests.
    Is there anything special need to be done to compile and run this demo? I have SqlExpress 2008 as well.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Thanks Gabriel. Wonderful presentation.
    The latest link worked.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Very strange...I've uploaded the archive to another location: http://bit.ly/lISaNq
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Great presentation! For some reason, the new download link does not appear to be working. I've tried in Chrome and a couple other browsers.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
12,455
On SlideShare
0
From Embeds
0
Number of Embeds
48
Actions
Shares
0
Downloads
222
Comments
11
Likes
5
Embeds 0
No embeds

No notes for slide

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

  1. 1. Elements of DDD withASP.NET MVC &Entity Framework Code FirstGabriel ENEASoftware developer / Maxcode.roCo-founder Joobs.ro – primul portal de joburi IT07 may 2011
  2. 2. Updated:Elements of software design07 may 2011
  3. 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. 4. How do you start building anapplication 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. 5. Is unit testing realizable? 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?
  6. 6. Lets start thinking to architecturedesign?What? Right, now!?Hey, we have only 1 hour to finish thispresentation! Indeed, but lets try to do something!
  7. 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. 8. Modeling approach - Pros/ConsDatabase First Design  doesnt 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. 9. Layers Presentation Business Data Access
  10. 10. PresentationLayers – any problems? Business Data AccessLayers Coupling!A strong coupling conducts to a hard way to do:  unit testing  refactoring  agile development  or be opened for changes
  11. 11. 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!? 
  12. 12. And...whats inappropriate in thiscode?// 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. 13. Lets start with a new approach...DDDDomain-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. 14. A new default architecture
  15. 15. PersistenceRequirements 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. 16. Building blocks of Domain-DrivenDesign
  17. 17. Todays tools(from a web developer perspective)ASP.NET MVC 3  a mature web development platform based on MVC patternEntity Framework 4.1 Code First / NHibernate  helps you focus on your domainDI frameworks  Manage dependencies  Castle Windsor, StructureMap, Spring.NET, Unity, ...
  18. 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. 19. Dependency Injection Log4netLogger PatientService PatientRepositoy
  20. 20. Dependency Injection 1) creates Builder PatientService Log4netLogger2) inject dependencies 3) uses ILogger
  21. 21. Persistance with EF 4.1 CodeFirstBenefits 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. 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 resolutionTService GetService<TService>() { … }IEnumerable<TService> GetServices<TService>() { … }
  23. 23. DemoWhat? We have a demo? Finally!
  24. 24. ConclusionsFocus on  Analyze application dependencies  Business rules  Do refactoring!  Design your Domain  Don’t forget to do Unit testing
  25. 25. Questions?
  26. 26. 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/domain-driven-design-quickly
  27. 27. The end…Thank you!Elements of DDD withASP.NET MVC &Entity Framework Code FirstGabriel ENEASoftware developer / Maxcode.roCo-founder Joobs.ro – primul portal de joburi IT07 may 2011

×