Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use the same DI code in asp.net and a windows service
    primarykey
    data
    text
    <p>I have a question about how to use the same DI code in an ASP.NET mvc app and a windows service as both interact with the same database using NHibernate. The windows service however performs background tasks.</p> <p>Like everyone I have a new controller factory that knows how to instantiate controllers using StructureMap. Thus I can have the required repositories given to my controllers as parameters of their constructors. Since Structuremap controls the ISession life cycle using the HTTPContextScope then I can be sure that all repositories receive the same instance of the ISession for every web request.</p> <p>However in a windows service and using Structuremap (the same DI code) I don't know a nice way to logically isolate different background tasks to own a unique ISession instance and share it with the repositories they use. I want to have multiple tasks executing simultaneously, therefore the ISession can not be a singleton object (as recommended for desktop apps using NHibernate).</p> <p>I want to preserve and introduce the One Session Per Request pattern in my windows service trusting Structuremap to give us the same ISession instance per Task. Can anyone point me towards the right direction?</p> <p>Thanks</p> <hr> <h2>EDIT</h2> <p>This two part post by <a href="http://blog.coreycoogan.com/about/" rel="nofollow">Corey Coogan</a> is very much along the lines I think this problem should be resolved. However I'm not familiar with WCF and tend to get confused by its parts in the article.</p> <p><a href="http://blog.coreycoogan.com/2010/05/26/structuremap-wcf-nhibernate-part-1/" rel="nofollow">http://blog.coreycoogan.com/2010/05/26/structuremap-wcf-nhibernate-part-1/</a> <a href="http://blog.coreycoogan.com/2010/05/27/structuremap-wcf-nhibernate-part-2/" rel="nofollow">http://blog.coreycoogan.com/2010/05/27/structuremap-wcf-nhibernate-part-2/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload