I am using StructureMap.WebApi2 nuget package for Web API 2 project for managing the depedency injection. In the DefaultRegistry.cs class I have mentioned all the dependencies required. This uses Nested container approach only which is recommended.
For<IScoreRepository>().Use<ScoreRepository>();
For<IExternalUsersAuditRepository>().Use<ExternalUsersAuditRepository>();
For<ITestScanService>().Use<TestScanService>();
// hook up specific questionnaire datacontext
For<SportsDataContext>()
.Use(c => new SportsDataContext(
ConfigurationManager.ConnectionStrings["Database"].ConnectionString));
// hook up datacontext for data and services
For<QuestionDataContext>()
.Use(c => new QuestionDataContext(
ConfigurationManager.ConnectionStrings["Database"].ConnectionString));Linq to Sql Datacontext objects are getting disposed and I get the below error:
Cannot access a disposed object.\r\nObject name: 'DataContext accessed after Dispose'
If I use Singleton or ThreadLocalStorageLifecycle scope for the Datacontext objects it's working fine. But I want to scope the DataContext objects to Per Http Request.
Can you please suggest? Our project got stuck due to this showstopper.
Thanks in advance.