Who is Ali Özgür?

RecentComments

Comment RSS

I've already developed some projects with NHibernate and I can say that NHibernate is a real time saver. But I must admit that it takes some time to get used to NHibernate. As an ORM NHibernate has fantastic features but if you want to develop successfull projects with NHibernate you must know that NHibernate is only one part (ORM) of a successfull layered architecture. In the attached solution I tried to give you the basic idea of a layered architecture and how NHibernate can be used within such an architecture

Attached solution includes the following projects

  • Core: Our domain objects (entities) reside in this layer. Also DAO (Data Access Objects) interfaces are defined in this layer.
  • DAL (Data Access Layer): Default implementation of DAO interfaces reside in this layer.
  • BLL (Business Logic Layer): Business logic code resides in this layer.
  • Common: Some utility calsses reside in this project
  • Tests.Disconnected: Includes unit tests for domain objects and business logic. Notice that unit tests in this project do not require domain objects to be persisted (NHibernate behaviour will not be tested), so the need for a database connection is eliminated which in turn makes our unit tests fast. Notice how we replaced our default DAL with mocked one.
  • Tests.Connected: This project includes unit tests too, but this time we want to test how our domain objects and bussiness logic perform NHibernate. NHibernate provides very cool features like native sql, lazy loading and cascading and we will likely want to test how our domain objects behave when armored with these cool features of NHibernate. It is also very likely that we will have some mapping errors (typos likely) in our Core, these tests will help us catch these errors. Performance bottlenecks possibly caused by our NHibernate mappings (for example we may discover that we need to make a child collection to be lazy loaded) can also be identified with help of these tests.

In the sample solution you can also find a simple usage of Castle Windsor Inversion of Control (IoC) container. We use IoC to be able to load different implementations of our DAL (DAO implementations). 

Another very important point you need to understand really well is session management of NHibernate when used in web applications. Thanks to Burrow contribution project this task is made very simple, you do not even need to write single line of NHibernate session management code. You only need to inherit your DAO implementation classes from GenericDao<T> class and you are ready to go. 

Additional Notes

  • Database script is included in Tests.Connected project under DBScript folder. 
  • Sample project uses NHibernate  2.0 Aplha1 and NHibernate.Burrow is also Alpha1.
  • ASP .NET MVC Preview 3 to run Sales.MVC sample
  • TestDriven .NET to run NUnt tests

Suggested Readings

Downloads

Update History

  • 09 June 2008
    • Castle files under Libs folder updated to Castle RC3
    • SQLite references removed
    • TestFixtureTearDown override of CustomTestBase class in Sales.Tests.Connected assembly commented out

Posted in: NHibernate  Tags:

Comments


 Scott
June 8. 2008 00:56
Scott
Thank you so much for this - I've been a little nervous this last about the correct way of managing the NHibernate session in ASP.NET MVC - and your example has pointed me in the right direction.

   no site


June 9. 2008 08:51
Ali Özgür
You are welcome Scott.
Latest NHibernate (1.2) includes some built-in support for session management too. I recommend you to check out the "2.3. Contextual Sessions" section found in documentation from NHibernate site.

   http://www.pragmasql.com/


People's Republic of China Leo Xue
August 22. 2008 03:32
Leo Xue
Thank you for your sample.
I open the solution in VSTS 2008. All the projects are loaded successfully except Sales.Mvc. I am not sure what's the problem.

How could I do to correct it?

Thanks again.

   no site


August 22. 2008 09:13
aliozgur
Leo you must download and install ASP.NET MVC Preview. You can find the link in ths post.

   http://blog.pragmasql.com/


People's Republic of China Leo Xue
August 22. 2008 13:50
Leo Xue
thank you for response so quickly.

I have downloaded the preview 4 and compiled the solution. Everything is OK.

Great job!

   no site


People's Republic of China Leo Xue
August 22. 2008 16:02
Leo Xue
One more question. What's the version of your visual studio? I use VS 2008 to run your sample and get an error as : Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

   no site


August 22. 2008 16:37
aliozgur
I use VS 2008.
NHibernate.Burrow.WebUtil.dll depends on this assembly. Possible solutions are

1- Download and install ASP.NET 2.0 AJAX Extensions suit which is freely provided by Microsoft

2- Download NHibernate.Burrow source code and open with VS 2008. Remove System.Web.Extensions ( version 1.0.61025.0) reference from NHibernate.Burrow.WebUtil project and add reference to the latest System.Web.Extensions.dll (Version 3.5.0.0, this comes ready with .NET 3.5 while 1.0.61025.0 version was installed as a seperate extension) and build it with VS 2008. Then copy paste all assemblies to Nh.Burrow folder which is under Libs folder.

   http://blog.pragmasql.com/


People's Republic of China Leo Xue
August 23. 2008 08:57
Leo Xue
Done.
Thank you again!

   no site


United States Joao Araujo
September 20. 2008 02:08
Joao Araujo
DId anyone tried VS 2008 and IIS7?  

I tried many options and versions, still my connections do not happen.
It is interesting but the only problem with connections is when I use burrow.
Any sample that I have using burrow can not connect to the database.
does anyone know what the reason?

Any hint ?


BTW, even when I use debug I still can not connect . I get the following error after pressing the button on the first page.
"A network-related or instance-specific error occurred while establishing a connection to SQL Server ...."
"\DesenvTools\NHibernate\NHibernate 2.0\NHibernate.Burrow-1.0.0.CR1-src\src\NHibernate.Burrow\Impl\TransactionImpl.cs    Line:  25
......



Thanks for helping,

Joao,


   no site


September 20. 2008 21:43
aliozgur

   http://blog.pragmasql.com/


November 4. 2008 12:55
Starting Business Blog
Nice business proj with NHibernate 2.0 Sample Project using NHibernate.Burrow contribution

   http://www.starting-business.org.uk/index.php?q=starting-business-blog/


December 16. 2008 02:26
busby seo test
the sample solution so great, thanks for the project.


   http://intersindo.com/seo-contest/


December 30. 2008 02:09
Speed Dating
I am pretty new to web development. I have heard some good things about NHibernate. I think your project looks pretty awesome - I hope to be able to get to the level you are at now.

   http://www.nyminutedating.com/


United States Nima
January 4. 2009 07:43
Nima
Can use burrow long conversation in MVC ?
Thanks

   no site


January 6. 2009 11:53
aliozgur
Thanks for your comment.
I'm not sure. You can check if long conversations work by modifying the sample project.

   http://blog.pragmasql.com/


January 15. 2009 09:49
Inventory Management Software
i love this blog.. i can get many info here.. thank's blog owner..

   http://free-inventory-management-software.blogspot.com/


January 22. 2009 23:47
jammer
great post
and great thinking also

   http://www.phantom.co.il/


January 22. 2009 23:48
gmat
thanks Ali
I have developed some similar projects
hope to use each other in futre

   http://www.gmaxonline.com/




February 23. 2009 03:36
Auto Insurance
Hello Ali,
I just wanted to say how i love your hair first off =) and keep up the great work/projects that your working on NHibernate. I've bookmarked your site to learn about your new developments ali.

XOXO,
Linda

   http://www.uniforceinsurance.com/


March 29. 2009 13:01
Inventory Management Software
Wow..
great projects..
Thanks for the sample..

   http://inventory-management-software-link.blogspot.com/


April 16. 2009 21:43
Strategic Leadership
Thanks for making this brilliant blog. We could do with a few more 'pragmatic developers'!

   http://www.leadership-expert.co.uk/


April 29. 2009 15:34
Melayu Boleh
nice share and tips..
thank for the hard work to give us the details tips.. Smile

   http://melayubolehinfo.blogspot.com/


May 8. 2009 23:30
sulumits retsambew
what a nice discussion, i really like this.

   http://phreakaholic.com/sulumits-retsambew/


May 11. 2009 12:30
Leadership Books
Nice blog, I always wanted to recreate this nice blog engine theme on my leadership books wordpress blog... but i can't because its so hard to adapt the code, from C# to anything is tricky.

   http://www.leadership-expert.co.uk/leadership-books/


May 14. 2009 21:03
Melayu Boleh
I have download the sample.. thanks..

   http://www.melayuboleh1.co.cc/


May 15. 2009 09:22
Simulation pret immobilier
Thanks a lot for this information. It is really useful.

   http://simulationpretimmobilier.net/


May 22. 2009 01:04
tukang nggame
very nice info, thanks.

   http://agung.iblogger.org/tukang-nggame.html




June 2. 2009 06:38
Melayu Boleh
Good info! its help me a lot to finish my reasearch..keep it up!

   http://cabaran-melayu-boleh.blogspot.com/


June 6. 2009 09:53
99.9% Uptime Guarantee Hosting
Very Informative article thanks to sharing this information with us.

   http://www.marblehost.com/uptime-guarantee.php


June 12. 2009 14:36
Internet Marketing Company
I was just thinking about NHibernate 2.0 Sample Project using NHibernate.Burrow contribution and you’ve really helped out. Thanks!

   http://www.search-value.com/


June 18. 2009 15:09
tukang nggame
thanks for the great article, this really nice blog

   http://newreil.com/tukang-nggame/


June 24. 2009 16:07
Melayu Boleh Online
Great article. it really help me a lot. Thanks for sharing it with us all.

   http://melayubolehonline.blogspot.com/


June 29. 2009 06:25
alantanblog
keep it up...

Hope to get more update soon


   http://www.alantanblog.com/


July 11. 2009 22:21
Billy D
Cool blog, just bookmarked it for later reference

   http://insurance-junction.com/


July 14. 2009 02:54
Maurice Lacroix
Please let me know if you are interested to work as article writer for me? I can offer $10/article.

   http://thewatchshop.biz/


Indonesia ars
July 16. 2009 09:19
ars
thank you for sharing it

   http://www.ars.cybermq.com/


July 16. 2009 09:20
cakep
that a nice article. thank you sir. i love it

   http://cakep.byethost31.com/perkembangan/si-cakep-sudah-bisa-duduk-dan-ngadal.php


July 19. 2009 19:44
запознанства
Thank you, for this code Smile Cheers!

   http://vipdating.bg/


July 20. 2009 01:19
запознанства
10x for the code Smile Cheers!

   http://vipdating.bg/


July 20. 2009 01:19
запознанства
10x for the code Smile Cheers!

   http://vipdating.bg/


July 26. 2009 17:27
grow taller
Cool blog, just bookmarked it for later reference
I was just thinking about NHibernate 2.0 Sample Project using NHibernate.Burrow contribution and you’ve really helped out. Thanks!

David from  <a href="http://deepervoice101.com/">Deeper Voice</a> and <a href="http://howtogrowtaller101.com/">Grow Taller</a>

   http://howtogrowtaller101.com/


August 8. 2009 06:20
Medicare Advantage Plans
Me and my friend were arguing about this the other day! Now I know that I was right. lol!

   http://www.medicareplanssite.com/


August 20. 2009 02:54
Låne Penge Online
Great write up - Thank you for sharing..

   http://www.laan-penge.net/


August 20. 2009 03:13
Buying Selling Home
Thanks, you cleared up some things for me.

   http://www.sandiegofasthomeselling.com/


August 24. 2009 13:54
Joint Tenancy
We are a group of volunteers and starting a new initiative in a community. Your blog provided us valuable information to work on. You have done a marvellous job!

   http://www.easylawyers.co.uk/severance-Joint-tenancy-tenants.php


April 23. 2010 01:52
trackback
Immobilier Brest

Merci pour votre article. 6 guides pour bien acheter ou vendre à télécharger sur notre site.

   http://www.britimmo.com/

Comments are closed