This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I want to use the "PerRequestUnitOfWorkScope" in my DotNetNuke Module (essentially, an ASP.NET WebForms application) but I'm not sure how to manage the lifetime and access of the UoW along with the "Context". I see the code in the FilmFestival MVC Sample, but since this is WebForms, I don't have the "MvcApplication" class, nor the "BaseController" concept to stash these objects. What is the recommended way to implement the LS Context and PerRequestUnitOfWorkScope objects and manage their lifetime, to make sure I initialize and dispose of them properly with the start and end of each web request? Thanks. |
|
|
I should also mention that I'm using LINQ, so I'd be using the strongly-typed classes generated by the LS designer |
|
|
Also, I've looked at the "Store" sample, which is WebForms, but I've seen you guys mention that the Store sample is an older example, and FilmFestival is the one to look at, so I just want to make sure I'm using the most up-to-date technique on the WebForms side. |
|
|
Looking at this older thread, it looks like you ran into this issue before and solved it by using an IHttpModule. Can you reuse that solution? Or have you hit a specific detail which is causing you problems? |
|
|
I guess I'm just confused because the "Store" sample (WebForms) only uses a few lines of code in Global.asax.cs and UnitOfWorkHolder.cs to fire up the LS Context and UoW and stash it in the HttpContext. In contrast, the FilmFestival MVC sample uses a bit more code and a different style to do what I think is essentially the same thing? It looks like I just need to figure out a way to get expose the UoW and Context so that any of my code-behinds can access it? Looks like the Store sample does this via a public static class. |
|
|
The Store sample is from LightSpeed 1 prior to us including the PerRequestUnitOfWorkScope class (which essentially does the same thing as the UnitOfWorkHolder in that sample) but the use of BeginRequest/EndRequest as your hooks for initialization are still the right place. Your current approach should be to create a new PerRequestUnitOfWorkScope<TModel> using a static context as required (e.g. you may be using dependancy injection so it would be sensible to do this in BeginRequest, alternatively you could consolidate this into a base page object) To dispose it at the end of each request call PerRequestUnitOfWorkScope<TModel>.Current.Dispose() in EndRequest if PerRequestUnitOfWorkScope<TModel>.HasCurrent. The UnitOfWork can be accessed via PerRequestUnitOfWorkScope<TModel>.Current. Note that the class is not static, so you would be dealing with an instance of PerRequestUnitOfWorkScope<TModel> in each case mentioned above.
Jeremy |
|