Currently, my preference is to inject a 'unit of work' class into my BL classes 
- the UoW contains an injected ISession with trivial transaction handling code 
as below.  So basically, I treat ISession as the boundary for the DAL with the 
BLL consuming it directly.  Previously, I tried using repositories & facades 
but (for me) it just introduced a lot of complexity & maintenance burden 
without bringing any benefits - we found were fighting the façade & 
'repository' design instead of working with it

 

Simplified example:

 

class UnitOfWork {

       ISession NhSession { get; set; }                // Injected via IoC, 
Castle Windsor in my case

 

       T DoWork<T>(Func<ISession, T> work) {

              T retVal;

              using(var tran = this.NhSession.BeginTransaction()) {

                     retVal = work(this.NhSession);

                     tran.Commit();

              }

       }                    

}

 

class MyBusinessLogic {

       UnitOfWork UoW { get; set; }                    // Injected via IoC

 

       SomeDTO DoSomething(SomeDTO request) {

              try {

                     return UoW.DoWork(session -> {

                     });

              catch { .... }

       }

}

 

I emphasise that this is just something I've come up with and am happy with, 
I'm sure that there are many other approaches with equal or better merit!  

 

/Pete

 

From: [email protected] [mailto:[email protected]] On Behalf Of 
Sean Farrow
Sent: 25 April 2013 23:37
To: [email protected]
Subject: [nhusers] NHibernate architecture in a clas library

 

Hi Fokes:

I'm currently working on an application which is using NHibernate for some of 
it's data access.

I have a bunch of clases that write to a database.

I've currently set up a façade class to hide all details of data 
access-saving/loading etc.

Is this the best design for multiple classes, I don't really want to go down 
the repository route, as only 3 database tables are being hit-the table being 
hit depends on the entity passed in to the save method as this is saved as xml 
and I'd ideally like to hold the session factory somewhere, the library is used 
in both sharepoint webparts and a console application.

Any ideas greatfully accepted, as it seems my design is convoluted, I carn't 
see where though

Cheers

Sean.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to