Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Professional ASP.NET Design Patterns
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET Design Patterns
This is the forum to discuss the Wrox book Professional ASP.NET Design Patterns by Scott Millett; ISBN: 978-0-470-29278-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 17th, 2010, 12:18 PM
Registered User
 
Join Date: Nov 2010
Location: Dublin, Ireland
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default NHibernate and the Unit of Work

First of all fantastic book but I'm a bit confused about the use of the Unit of Work pattern and the implementation for nHibernate.

Page 254 shows the implementation of the NHUnitOfWork which seems fine. On the next page there is an NHibernate base repository created which is passed an IUnitOfWork. This is then used in the Add, Remove and Save methods. Committ does not seem to be called despite the description of the NHUnitOfWork saying nothing will be saved/removed until Committ is called.

Later on page 463 when doing the same thing the injection of the Unit of Work in the constructor remains but is not used at any point in the Repository. Errors? Or am I just missing something?
Reply With Quote
The Following User Says Thank You to BrianOConnell For This Useful Post:
elbandit (November 17th, 2010)
  #2 (permalink)  
Old November 17th, 2010, 02:58 PM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 11
Thanked 17 Times in 15 Posts
Default

Hi Brian,

First off thanks for buying the book and taking time to post this question.

The reason I inject the unit of work in via the repository is because an atomic action may span more than one repository. If you take a look on page 245 you can see that there is a call to the unit of works commit method within the AddMember method. The business transaction commits when the service says so.. consider the following senario...

Code:
 
var customer = customerRepository.FindBy(cusomerId);
 
var order = new Order();
 
// populate the order...
 
order.Customer = customer;
 
customer.YearlyOrderSpendAdd(order.Total);
 
// The customer has now been modified and the order needs to be added..
customerRepository.Save(customer);
orderRepository.Add(order);
 
// we only want to call commit now because we don't want an error to occur
// and the customer be saved but not the order added.
// The commit ensures that what has been addded/changed/removed it committed
// in a transaction as an atomic event i.e. all or nothing
uow.Commit();
I hope that make sense? If not please let me know and I can expand.

Cheers
Scott

p.s. would be great if you could adda review to Amazon and give me some feedback when you have finished the book :0) cheers!
Reply With Quote
  #3 (permalink)  
Old November 17th, 2010, 03:32 PM
Registered User
 
Join Date: Nov 2010
Location: Dublin, Ireland
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thanks for the quick reply Scott. Makes sense all right but you might take a look at the Repository implentation later on for the store (463-4 I think) where the unit of work is injected but not used as fas as I can see. I'll get a review up on amazon soon. Just on the last chapter :) My only complaint is the lack of unobtrusive javascript. A book with such an excellent run down of all the ellegant patterns out there should include the most elegant approach to javascript too imo.
Reply With Quote
  #4 (permalink)  
Old November 17th, 2010, 04:04 PM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 11
Thanked 17 Times in 15 Posts
Default

Ah yes, blimey good spot. On page 463-4 i took a short cut and bypassed the unitofwork for the adding/removing/updating this was because I could use the same code straight from within the base repository class - basically I was lazy! Take a look in the NhUnitofWork class and you will see the same code. However all works in the same way and the unitofwork instance is still called to commit the business transaction. But your right it does make it confusing when there is no need to be!

Yes hands up on the JavaScript, I don't do a lot of JavaScript work so thats the reason why it's not as polished as the rest of the code examples.

Glad you enjoyed the rest of the book. I am in the process of adding support for entity framework and db4o in the case study as well as replacing the query object pattern with linq expression trees as most of the orms have a linq provider now.

Cheers
Scott
Reply With Quote
  #5 (permalink)  
Old November 20th, 2010, 09:23 PM
Registered User
 
Join Date: Nov 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Scott,

I am looking forward to the replacement of Query Object pattern with linq expression trees. I hope the code will be available at aspnetdesignpatterns.codeplex.com
Reply With Quote
  #6 (permalink)  
Old November 21st, 2010, 08:04 AM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 11
Thanked 17 Times in 15 Posts
Default

Hi devnetfx,

Yes should be up by the end of next week.

Scott
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 7: Unit Testing with the Unit Testing Framework antwarpes BOOK: Professional Application Lifecycle Management with Visual Studio 2010 3 September 25th, 2011 08:47 AM
beerhouse and nhibernate rocco50 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 16 January 30th, 2008 03:33 AM
Unit Test josericardo_jr BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 0 August 9th, 2007 08:19 AM
Where are all the unit tests? Extrakun BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 1 July 17th, 2007 05:39 PM
Unit Testing jeffmorris BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 7 May 14th, 2007 06:51 AM



All times are GMT -4. The time now is 11:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.