views:

1078

answers:

2

Hi,

I have a web application based on the sharp-architecture framework. It actually use NHibernate for the dal, and i've added a service layer between the (VIEW-CONTROLLER) and the DAL.

I actually need to implement a scheduler to run my jobs frequently. I will use Quartz.net to do that task. Actually i'm facing a problem. Because I will have lot's of jobs that will run at different schedule, like every 30 sec, every days, every weeks.

I want to know if there is a way to run NHibernate with service injection inside Quartz, and if it will support job concurrence, I mean if two jobs runs simultaniously, if there will be no problems with NHibernate. I know there is some issue with NHibernate and multithreading.

I found an implementation of Quartz.Net for Spring (http://www.zorched.net/2009/03/07/using-quartznet-springnet-and-nhibernate-to-run-scheduled-tasks-in-aspnet/) and an implementation for Castle-Windsor (http://bugsquash.blogspot.com/2009/03/windsor-facility-for-quartznet.html).

The problem is, I think this examples don't take care of the case that jobs can be ran simultaniously, that's an Nhibernate problem. And i want to use CommonServiceLocator to be more high level and not limit myself to one IoC framework.

What can be the best approach to solve this problem ?

Thanks for your help

+2  A: 

Use the NHibernate facility, then inject ISessionManager in your IJobs. That should give you one ISession per thread and you should have no problems.

Mauricio Scheffer
In my Jobs i use Workflow Foundation to handle in a more readable way the logic. In each Activities I need to access particular services and i use CommonServiceLocator because in one line I get the services : var orderService = (IOrderService)ServiceLocator.Current.GetService(typeof(IOrderService));
alexl
inject the IOrderService (push) instead of asking for it (pull). Remember the Hollywood principle...
Mauricio Scheffer
See the workflow facility (http://using.castleproject.org/display/Contrib/Castle.Facilities.WorkflowIntegration) if you need to inject services to your workflow stuff
Mauricio Scheffer
K i got it! But i need to inject the repository and a manager to get my Service working. Can i do that by code of i have to make a configuration file. By code I mean a Castle automatic generic injection, so i dun need to specify each repository by hand.
alexl
I'm using the scheme of the Sharp Arch if you need a sample i can provide one
alexl
to register generic components without defining type parameter: http://devlicio.us/blogs/casey/archive/2008/04/13/windsor-container-registration-of-generic-component-via-c-code.aspx
Mauricio Scheffer
A: 

I am also have same problem. Where do you call NHibernateInitialization method for Session initialization and do you use SimpleSessionStorage?

serser12