Hi Gabriel,
in your UOW implementation, I see a static variable ISession _currentSession. In web environment when multiple concurrent requests/threads start (can be took many time to execute...) can dispose current static Session in use, and of course we have a common error: "You are not in a unit of work.".
Why not store _currentSession in Local.Data storage ?
thx Luca
a very very good article
Excellent article!!!
I have a question...Why in your design you tie the UoW factory interface to the Hibernate ISession (IUnitOfWorkFactory.CurrentSession)?, at the beginning of the article you claim that the idea of your design is to abstract the data manipulation from a specific infrastructure (ex. NHibernate, EF, Memory, etc) otherwise you can use ISession in a simple way, so, unless I miss something, it seems the original design goal is broken.
Thanks, JC
Hi Gabriel, nice and useful implementation. I am using it. But gianfragolo is right. ISession _currentSession must be saved in a LocalData storage. Otherwise serious troubles do occur at least in Web environment. It just takes hitting Refresh fast enough a small number of time to have very bad problems.
Anyway when moving to LocalData storage this serious problem disappear.
Section: Implementation For Smart Clients
[ThreadStatic]
private static Hashtable _localData = new Hashtable();
Initialization has to be encapsulated on a property, because initialization just occur in main thread, that's why in the background thread _localData is always null, example:
private static Hashtable _localData;
private static Hashtable LocalHashTable
{
get
if (_localData == null)
_localData = new Hashtable();
return _localData;
}