I am registering some components related to Linq2Sql using the PerWebRequest style. I see that they are created, but they are destroyed before calling the global Application_EndRequest method. Is it for design? Does anyone know a job? I want to call commit on my UnitOfWork object for subscriptions () at the end of each request. In addition to using the Global.asax Application_EndResult application, I also tried IHttpModule with the same results.
I am using Castle 2.0.
This is how I register my material with PerWebRequest. I am creating a DataCOntextProvider object that is stored in the L2S DataContext. This object is entered in UoW.
Now I'm just trying to pull the UoW out of the container via the CommonServiceLocator (both CSL and Windsor Adapter 1.0) from EndRequest as follows:
protected void Application_EndRequest(object sender, EventArgs e) { //ignore unless this is a page (.aspx) or handler (.ashx) if (!RequestCanHaveContext()) return; //get the IUnitOfWork manager var uow = ServiceLocator.Current.GetInstance<IUnitOfWorkManager>(); //if we have one, commit changes at the end of the request if (uow != null) { //don't explicitly dispose of uow or we'll get Disposed exceptions on the context uow.Commit(); } }
Thanks Corey
Corey coogan
source share