{"action":"created","issue":{"url":"https://api.github.com/repos/devtrends/Unity.Mvc5/issues/1","labels_url":"https://api.github.com/repos/devtrends/Unity.Mvc5/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/devtrends/Unity.Mvc5/issues/1/comments","events_url":"https://api.github.com/repos/devtrends/Unity.Mvc5/issues/1/events","html_url":"https://github.com/devtrends/Unity.Mvc5/issues/1","id":78164146,"number":1,"title":"HttpApplication.EndProcessRequest vs. execution of results","user":{"login":"jorupp","id":3874909,"avatar_url":"https://avatars.githubusercontent.com/u/3874909?v=3","gravatar_id":"","url":"https://api.github.com/users/jorupp","html_url":"https://github.com/jorupp","followers_url":"https://api.github.com/users/jorupp/followers","following_url":"https://api.github.com/users/jorupp/following{/other_user}","gists_url":"https://api.github.com/users/jorupp/gists{/gist_id}","starred_url":"https://api.github.com/users/jorupp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorupp/subscriptions","organizations_url":"https://api.github.com/users/jorupp/orgs","repos_url":"https://api.github.com/users/jorupp/repos","events_url":"https://api.github.com/users/jorupp/events{/privacy}","received_events_url":"https://api.github.com/users/jorupp/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-19T16:43:53Z","updated_at":"2015-05-19T16:45:35Z","closed_at":"2015-05-19T16:45:35Z","body":"I'm seeing an issue in my application where sometimes result objects returned from my controller are executed *after* the container is disposed in the HttpApplication.EndProcessRequest event handler.\r\n\r\nLooking at http://i2.asp.net/media/4773381/lifecycle-of-an-aspnet-mvc-5-application.pdf?cdn_id=2015-04-01-001, it seems that (in MVC 5 at least) with async processing, results are executed during HttpApplication.EndProcessRequest, leading to the possibility of a race condition between the container cleanup and result execution.\r\n\r\nI don't have any async or otherwise Task-returning controller actions, but I occasionally will get error messages during rendering of views about a on of my services being disposed when it tries to use it.\r\n\r\nIs HttpApplication.EndProcessRequest still the right place for these hooks in MVC 5?  Here's a comparison of the call stacks where one of my services is getting `.Dispose()` called by the container, and a trace of the error:\r\n\r\n```\r\n...\r\n   at Unity.Mvc3.UnityDependencyResolver.DisposeOfChildContainer()\r\n   at Unity.Mvc3.RequestLifetimeHttpModule.<Init>b__0(Object sender, EventArgs e)\r\n   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n```\r\n\r\n```\r\n...\r\n   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +294\r\n...\r\n   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62\r\n   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +47\r\n   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9\r\n   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651188\r\n   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155\r\n```"},"comment":{"url":"https://api.github.com/repos/devtrends/Unity.Mvc5/issues/comments/103586326","html_url":"https://github.com/devtrends/Unity.Mvc5/issues/1#issuecomment-103586326","issue_url":"https://api.github.com/repos/devtrends/Unity.Mvc5/issues/1","id":103586326,"user":{"login":"jorupp","id":3874909,"avatar_url":"https://avatars.githubusercontent.com/u/3874909?v=3","gravatar_id":"","url":"https://api.github.com/users/jorupp","html_url":"https://github.com/jorupp","followers_url":"https://api.github.com/users/jorupp/followers","following_url":"https://api.github.com/users/jorupp/following{/other_user}","gists_url":"https://api.github.com/users/jorupp/gists{/gist_id}","starred_url":"https://api.github.com/users/jorupp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jorupp/subscriptions","organizations_url":"https://api.github.com/users/jorupp/orgs","repos_url":"https://api.github.com/users/jorupp/repos","events_url":"https://api.github.com/users/jorupp/events{/privacy}","received_events_url":"https://api.github.com/users/jorupp/received_events","type":"User","site_admin":false},"created_at":"2015-05-19T16:45:35Z","updated_at":"2015-05-19T16:45:35Z","body":"Just thought to look at my references... This project wasn't actually upgraded to MVC 5 like I thought - it's a MVC 4 app and not even using this version of the library :("}}