It works like a charm.

After integrating the class into the project, the only hibernate 
configuration line I used to switch to this approach is the following:

<property 
name="current_session_context_class">Full.Namespace.HybridWebSessionContext, 
AssemblyName</property>

Thank you.
Marcello.

Il giorno lunedì 3 dicembre 2012 18:11:26 UTC+1, Marcello Esposito ha 
scritto:
>
> Hi Jason.
>
> Thank you for your helpful link.
> I will try to follow this approach.
>
> Marcello.
>
> Il giorno mercoledì 28 novembre 2012 14:22:55 UTC+1, Jason Meckley ha 
> scritto:
>>
>> something like this may help.
>>
>> http://stackoverflow.com/questions/5854238/nhibernate-session-management-strategy-for-web-application-with-background-worke
>>
>> On Wednesday, November 28, 2012 6:53:50 AM UTC-5, Marcello Esposito wrote:
>>>
>>> The action method is:
>>>
>>> [NeedsPersistence]
>>> public void ExecuteScheduledTasks()
>>> {
>>>     scheduler.Execute();
>>> }
>>>
>>> Scheduler.Execute() is more or less:
>>>
>>>                 var tasksToBeExecuted = getTask.GetTasks();
>>>                 
>>>                 foreach (var task in tasksToBeExecuted)
>>>                 {
>>>                     var t = threadFactory.Create(task);
>>>                     t.Start();
>>>                 }
>>>
>>> threadFactory.Create(task) creates (by using (with Ninject.
>>> Extensions.Factory) a system thread and injects in it sessionFactory 
>>> and needed repositories and EQO (all using 
>>> sessionFactory.GetCurrentSession() to access the session).
>>> t.Start() triggers thread execution.
>>>
>>> Thread's code is that in my original question.
>>>
>>> Thanks.
>>> Marcello.
>>>
>>> Il giorno mercoledì 28 novembre 2012 12:02:26 UTC+1, Øyvind ha scritto:
>>>>
>>>> Can you show us the code of the controller in question?
>>>>
>>>>
>>>> On 28 November 2012 10:57, Marcello Esposito <[email protected]>wrote:
>>>>
>>>>> Hi all.
>>>>>
>>>>> I have a ASP.NET MVC3 application using the Transaction ASP.NET MVC 
>>>>> action filter from NH 3 Cookbook, so current_session_context_class="web".
>>>>> Everything works fine except in a controller action method which uses 
>>>>> multi-threading.
>>>>> I cannot figure out how to initialize current session context used by 
>>>>> injected repositories (used within the threads).
>>>>>
>>>>> Each thread has the SessionFactory singleton injected and executes:
>>>>>
>>>>> using (var session = sessionFactory.OpenSession())
>>>>> {
>>>>>     CurrentSessionContext.Bind(session); <--- this throws 
>>>>> NullReferenceException
>>>>>
>>>>> Any help?
>>>>>
>>>>> Thanks in advance,
>>>>> Marcello.
>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "nhusers" group.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msg/nhusers/-/kbuTKPELosMJ.
>>>>> To post to this group, send email to [email protected].
>>>>> To unsubscribe from this group, send email to 
>>>>> [email protected].
>>>>> For more options, visit this group at 
>>>>> http://groups.google.com/group/nhusers?hl=en.
>>>>>
>>>>
>>>>
>>>>
>>>> -- 
>>>> Visit my blog at http://www.babel-lutefisk.net
>>>>  
>>>

-- 
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