{"action":"created","issue":{"url":"https://api.github.com/repos/seesharper/LightInject/issues/184","labels_url":"https://api.github.com/repos/seesharper/LightInject/issues/184/labels{/name}","comments_url":"https://api.github.com/repos/seesharper/LightInject/issues/184/comments","events_url":"https://api.github.com/repos/seesharper/LightInject/issues/184/events","html_url":"https://github.com/seesharper/LightInject/issues/184","id":68886553,"number":184,"title":"Manually begin/end scope (without touching ScopeManager[Provider])","user":{"login":"justdmitry","id":3540597,"avatar_url":"https://avatars.githubusercontent.com/u/3540597?v=3","gravatar_id":"","url":"https://api.github.com/users/justdmitry","html_url":"https://github.com/justdmitry","followers_url":"https://api.github.com/users/justdmitry/followers","following_url":"https://api.github.com/users/justdmitry/following{/other_user}","gists_url":"https://api.github.com/users/justdmitry/gists{/gist_id}","starred_url":"https://api.github.com/users/justdmitry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justdmitry/subscriptions","organizations_url":"https://api.github.com/users/justdmitry/orgs","repos_url":"https://api.github.com/users/justdmitry/repos","events_url":"https://api.github.com/users/justdmitry/events{/privacy}","received_events_url":"https://api.github.com/users/justdmitry/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-16T09:44:23Z","updated_at":"2015-04-16T11:04:25Z","closed_at":null,"body":"I'm using LightInject.Mvc for NET 4.5 Razor application, but my website also need to run some background tasks, where no current HttpRequest is available.\r\n\r\nMy services are registered in Global.asa as follows:\r\n\r\n    Container = new ServiceContainer();\r\n    Container.ScopeManagerProvider = new PerLogicalCallContextScopeManagerProvider();\r\n    Container.RegisterControllers();\r\n    Container.Register<SomeService>(new PerScopeLifetime());\r\n    Container.EnableMvc();\r\n\r\nAnd in background task I'm trying to start scope manually:\r\n\r\n    using (MvcApplication.Container.BeginScope()) { ... }\r\n\r\nAnd this code fails with `Object reference not set to an instance of an object` in `LightInject.Web.PerWebRequestScopeManagerProvider.GetScopeManager()`, because there is not HttpRequest which can store Scope for request.\r\n\r\nIs there any option to manually \"begin scope\" without touching \"current\" ScopeManagerProvider?\r\n\r\nI made a sample demo app to play with: https://github.com/justdmitry/LightInjectBackgroundTasks"},"comment":{"url":"https://api.github.com/repos/seesharper/LightInject/issues/comments/93708961","html_url":"https://github.com/seesharper/LightInject/issues/184#issuecomment-93708961","issue_url":"https://api.github.com/repos/seesharper/LightInject/issues/184","id":93708961,"user":{"login":"seesharper","id":1034073,"avatar_url":"https://avatars.githubusercontent.com/u/1034073?v=3","gravatar_id":"","url":"https://api.github.com/users/seesharper","html_url":"https://github.com/seesharper","followers_url":"https://api.github.com/users/seesharper/followers","following_url":"https://api.github.com/users/seesharper/following{/other_user}","gists_url":"https://api.github.com/users/seesharper/gists{/gist_id}","starred_url":"https://api.github.com/users/seesharper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seesharper/subscriptions","organizations_url":"https://api.github.com/users/seesharper/orgs","repos_url":"https://api.github.com/users/seesharper/repos","events_url":"https://api.github.com/users/seesharper/events{/privacy}","received_events_url":"https://api.github.com/users/seesharper/received_events","type":"User","site_admin":false},"created_at":"2015-04-16T11:04:25Z","updated_at":"2015-04-16T11:04:25Z","body":"Assign the PerLogicalCallContextScopeManagerProvider  after the EnableMvc call.\r\nThen you can do\r\n\r\n```\r\nusing (container.BeginScope())\r\n{\r\n    container.GetInstance<IFoo>();\r\n}\r\n````\r\n\r\n"}}