lfaldanam / sharp-architecture

Automatically exported from code.google.com/p/sharp-architecture
Other
0 stars 0 forks source link

Multiple Session Factories #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I downloaded the source tonight and I think its very nicely done, however
from my understanding its not currently suitable to have multiple session
factories for two different databases. I trying to think of way to extend
the NHibernateSession to support this without violating the nice work. I'm
thinking of having NHibernateSession contain a static method with the
signature GetCurrent(Type aggregateRoot) and the generic DAO would call
GetCurrent(T) instead of .Current. Also for NHibernateSession to contain a
static ISessionResolver instance. I could then plug in whatever behaviour I
want - I'd implement ISessionResolver in my application solution to use
either programmatic dictionary, some config values about which
sessionfactory to use by resourceName.  

What do you think? 

Original issue reported on code.google.com by matt8...@gmail.com on 11 Sep 2008 at 5:38

GoogleCodeExporter commented 9 years ago
Sorry damn, wasn't meant to record this as a defect! Apologises

Original comment by matt8...@gmail.com on 11 Sep 2008 at 5:38

GoogleCodeExporter commented 9 years ago
Here is a modified version of S#arp that has support for multiple session 
factories.
It's not the most elegant code or solution, but I was in a bit of a pinch and 
seems
to work fine. This branch is no longer associated with the svn repos, so I 
couldn't
just send a patch (instead i sent the entire solution). For that matter, it's
actually based on the previous version of Sharp; so I'm only providing this for 
the
rest of the group and Billy to get some ideas. 

Essentially, I have extended the NHibernateSession with a couple of 
Dictionaries for
storing multiple SessionFactories and SessionStores. I also included a class
attribute called SessionFactoryAttribute that is used to decorate your DAOs 
with the
appropriate datastore key (In my case this is Oracle and SQLServer). The 
GenericDao
was then updated to read this attribute. If it is not found, it defaults to the
original NHibernate.Session.Current singleton. 

Your nhib config needs to change a bit too. You need to use an external config 
file
for each db. In the config you must specifically list the hbms that are mapped 
to
that particular config as opposed to mapping an entire assembly.

I hope this helps anyone out there that needs multiple DB support before it 
makes it
into the architecture officially.

Original comment by russell....@gmail.com on 10 Oct 2008 at 6:38

Attachments:

GoogleCodeExporter commented 9 years ago
IS there any progress in this aspect?
Accessing multiple databases is very important (and common) in real projects..

Original comment by manuelfe...@gmail.com on 4 Mar 2009 at 6:29

GoogleCodeExporter commented 9 years ago
This will be in the 1.0 final release, but will not make it into the RC 2 
release, 
due for this weekend.  (Another reference I found concerning this was at 
http://tiredblogger.wordpress.com/2009/03/06/using-multiple-nhibernate-session-
factories/ )

Original comment by wmccaffe...@gmail.com on 12 Mar 2009 at 7:29

GoogleCodeExporter commented 9 years ago
Hi,

I'm currently evaluating Sharp Archicture (it's awesome btw) but have also hit 
the
single db connection wall very quickly - is there any update on when this 
feature is
going to be available (in the main trunk or as a patch to the RC2)?

Many thanks,

Howard

Original comment by howard.v...@gmail.com on 1 Apr 2009 at 8:57

GoogleCodeExporter commented 9 years ago
Hi Howard, current priorities are as follows:

* Add WCF support and example of using it; the WCF support is ready but not 
committed
- finishing up the example.
* Add example of using a service.
* Provide support for multiple DBs.

I should be able to get to multiple DB support by mid April or sooner.

Original comment by wmccaffe...@gmail.com on 2 Apr 2009 at 4:45

GoogleCodeExporter commented 9 years ago

Original comment by wmccaffe...@gmail.com on 8 Apr 2009 at 10:35

GoogleCodeExporter commented 9 years ago
Fixed on trunk...see /docs for details within the Q&A section.  Also see
/VersionHistory.txt for a detailed listing of related changes.

Original comment by wmccaffe...@gmail.com on 2 May 2009 at 7:35

GoogleCodeExporter commented 9 years ago
What makes WCF not support multiple databases in the current release, btw?

Original comment by alen.siljak on 25 Nov 2010 at 1:01