WaYdotNET Web Blogs

Il blog di Carlo Bertini e qualcosa di .NET
posts - 57, comments - 2796, trackbacks - 925

My Links

News

Tag Cloud

Article Categories

Archives

Post Categories

Image Galleries

ASP.NET

Caxxate

Simple NHibernate Architecture

By Cassio Alves.

Introduction

I started using NHibernate at the end of last year and I am having a wonderful experience with it. The simple fact that I don't have to maintain hundreds of procedures and data access abstraction classes to do basic CRUD operations is enough to justify the use of NHibernate (even though I used a custom code generation tool). Besides that, my code is amazingly clearer and simpler. I only need to worry about business and user interface logic now. All that pluming code has gone for good.

I had zero experience with ORM frameworks, so on the first couple of weeks using NHibernate I had a hard time with some issues, like using it with ASP.NET disconnected objects and abstracting NHibernate sessions from the domain layer. After putting in some effort I came out with a nice architecture that abstracts the NHibernate layer and allows me to work with an ASP.NET session.

Background

I am assuming you already have some familiarity with NHibernate. If you are new to NHibernate I encourage you to go to the website and download the reference documentation. I am using NHibernate 1.2 CR1 in this article.

The Architecture

The idea here is to keep my business objects unaware of an NHibernate session. So I created a different project for NHibernate stuff, called Shared.NHibernateDAL. It includes the session and transaction manager classes. I also created a common business object that serves as a base class for all my business entities. This class (BusinessObject) encapsulates the common methods and properties all entities that need to be persisted have, like Save(), Delete(), ID, etc.

Here's a class diagram just to give an idea:

Screenshot - nh_classdiagram.jpg

The Implementation

The main classes on the NHibernateDAL project are the following:

  • NHibernateSessionManager – This is the class responsible for managing the NHibernate session. I've got this class from another NHibernate article on Code Project.
  • TransactionBlock – This is a class I created to manage transactions and abstract it from NHibernate. I will show an example of its use further on this article.
  • BusinessObject<T> - This is the base class for all the business entities I need to persist. It implements the basic CRUD methods.

 

LINK: http://www.codeproject.com/aspnet/NHibernateArchitecture.asp

Print | posted on venerdì 27 aprile 2007 20:14 |

Feedback

Gravatar

# re: Simple NHibernate Architecture

The concept here is to keep my business things unacquainted with an NHibernate period. So I designed a different venture for NHibernate things, known as Distributed.NHibernateDAL. It contains the period and deal administrator sessions.I am supposing you already have some information about NHibernate. If you are new to NHibernate I motivate you to go to the web page and obtain the referrals certification.
14/01/2014 09:35 | dissertation-writing-help.org
Gravatar

# Himanshu

Hey guys here on our website you will learn how to sync setting in windows 10 operating system step by step with snapshot. windows 10 is an advanced version microsoft windows series.
Gravatar

# re: Simple NHibernate Architecture

I have a keen interest in NHibernate. Can you please provide more details about it? I appreciate it in advance.
13/08/2017 17:44 | essay writing service
Gravatar

# re: Simple NHibernate Architecture

You realize that steam codes and steam blessings cards are similar things with the distinctive name. You can get many free steam wallet codes free of cost from various perspectives. You can get these codes from internet business sites. You can likewise get these codes from the market yet these codes are not accessible in all business sectors of the city.
07/12/2017 08:33 | steam codes list
Gravatar

# re: Simple NHibernate Architecture

good article
10/07/2018 12:14 | good
Gravatar

# re: Simple NHibernate Architecture

This article is much useful for me to understand about NHibernate.It doesn't have to maintain hundreds of procedures and data access abstraction classes to do basic CRUD operations is enough to justify the use of NHibernate.This is comparatively easy to do. cheap cable and internet near me
10/07/2018 17:23 | Harry
Gravatar

# re: Simple NHibernate Architecture

This article is much valuable for me to comprehend about NHibernate.It doesn't need to keep up several systems and information get to reflection classes to do essential CRUD activities is sufficient to legitimize the utilization of NHibernate.This is similarly simple to do.
24/07/2018 16:53 | BellaHenderson
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET