1 / 32

Domain Driven Design with NHibernate

Domain Driven Design with NHibernate. Ben Scheirman Principal Consultant Sogeti www.flux88.com. Start with the Database?. Ok, start with the Model. Domain Driven Design. Focus on Core Domain first Work closely with Domain Experts Learn & Use the “Ubiquitous Language”.

gavin
Télécharger la présentation

Domain Driven Design with NHibernate

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Domain Driven Design with NHibernate Ben Scheirman Principal Consultant Sogeti www.flux88.com

  2. Start with the Database?

  3. Ok, start with the Model

  4. Domain Driven Design • Focus on Core Domain first • Work closely with Domain Experts • Learn & Use the “Ubiquitous Language” Ignore Persistence for Now

  5. Unit Tests • We’re POCO, baby! I love NUnit!

  6. Now… what about persistence? • Pure POCO Model • Ultimate Flexibility

  7. Barriers? • Granularity • Inheritance • Associations

  8. The problem of Granularity User ? Address

  9. The problem of Inheritance BillingAccount ? CreditCard CheckingAccount

  10. NHibernate in a Nutshell • ISessionFactory • ISession • ITransaction

  11. Demo time Hello World with NHibernate

  12. Key concepts • ISessionFactory per application • ISession per Unit of Work

  13. NHibernate Architecture Domain Model Persistent Classes IInterceptor ILifecycle IUserType IValidatable NHibernate ISessionFactory ISession ITransaction IQuery Configuration ADO.NET

  14. How do you GLUE the objects and the database? Foo.cs .NET Object Foo.hbm.xml Mapping XML

  15. Did I just say XML?

  16. Mapping concepts • <id> • <property> • Associations…

  17. Unidirectional One to many “A Blog has many Posts” Blog IList<Post> Posts; Post 1 * Blog.hbm.xml <bag name="Posts"> <key column="BlogId" /> <one-to-many class="Post" /> </bag>

  18. Bidirectional Many-to-Many A category has items, an item has categories Item ISet Categories Category ISet Items * * Item.hbm.xml <set name="Categories" table="Item_Categories"> <key column="ItemId" /> <many-to-many class="Category" /> </set> Category.hbm.xml <set name=“Items" table="Item_Categories“ inverse=“true”> <key column=“CategoryId" /> <many-to-many class=“Item" /> </set> What is INVERSE?

  19. Understanding INVERSE Post p = new Post(); Category cat = new Category(); p.Categories.Add(cat); cat.Posts.Add(p); INSERT Post_Categories(PostId, CategoryId) VALUES(3, 15) INSERT Post_Categories(PostId, CategoryId) VALUES(3, 15) NHibernate needs to “ignore” one of the collections

  20. A Domain Driven Design Experience • A restaurant owner wants us to build him some point-of-sale software for his chain of restaurants.

  21. Can you tell me about how the process works? Sure, a waiter takes an order for a table. Then he rings it up at the computer system… You Domain Expert

  22. Can you tell me about how the process works? Sure, a waiter takes an order for a table. Then he rings it up at the computer system. You Domain Expert

  23. Can you elaborate on “rings it up? “ What exactly would he do? Well, he enters the table number and a ticket opens. Actually, if the there was already a ticket for that table open, then it would be displayed. Otherwise a new ticket is created. We need to record how many guests are at the table when the ticket is created. You Domain Expert

  24. What goes on the ticket? Oh yeah, the waiter punches in the order for the table. Like what drinks everyone had, what meal selection. Any menu item really. Along with the item the price is shown and a running total is displayed at the bottom. You Domain Expert

  25. So the Ticket is like the printed ticket you would receive when you’re ready to pay the bill? Yeah, pretty much. You Domain Expert

  26. So what happens then? The waiter will review what he rung up and then send the order. You Domain Expert

  27. What happens when the order gets “sent?” It prints up at the station that prepares the item. On these “chitters” it has the time the item was ordered, the waiter’s name, and the table number. You Domain Expert

  28. So, each item needs to specify what printers it prints at, correct? Yes, we should be able to pick from any number of printers, for example: Bar Printer, Line Printer, Grill Printer, and Dessert Printer. You Domain Expert

  29. Say the waiter opens up an existing ticket. If they ring up additional items and click send, you only want the new items to get sent, right? Yeah, that’s correct. I’m thinking that the items that were already sent would be in a lighter grey font so that it would be easy to see. You Domain Expert

  30. So what happens when the guests are ready to pay? The waiter can take cash or credit payments. The recorded payments need to satisfy the total before the ticket can be closed. You Domain Expert

  31. Ticket Payment * * CashPayment MenuItem TicketLine * * CreditPayment * PrinterStation

  32. Resources • Domain Driven Design (Eric Evans) • ayende.com/blog • Hibernate in Action • NHibernate in Action (pre-release PDFs) • NHibernate Forums • nhusers@googlegroups.com • Castle Project (Active Record)

More Related