Wrox Programmer Forums
|
BOOK: Professional ASP.NET Design Patterns
This is the forum to discuss the Wrox book Professional ASP.NET Design Patterns by Scott Millett; ISBN: 978-0-470-29278-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 6th, 2012, 02:20 PM
Registered User
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default DataContext Lifetime : Structure Map + EF

First of all this is a great book! I can't wait to read what you write next.
I have been looking for a book like this.

I am following along with the examples in your book.

I have a question about the DataContext lifetime.
I am following your code and looking at HttpDataContextStorageContainer
and how it uses HttpContext.Current.Items. I understand this is a "Per Http Request" usage.

My question is the DataContext getting properly disposed of and thus database connections getting closed?

In Sql Profiler I am showing some open connections after the Http Request has processed

I have read that the following may need to be used to dispose of the DataContext that stored in the HttpContext

Code:
        
protected void Application_EndRequest(object sender, EventArgs e)
        {
            ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
        }
If the above is needed how does DataContext get setup in the BootStrapper?


Code:
For<IUnitOfWork>().HttpContextScoped().Use<EFUnitOfWork>();
        OR 
For<MyConcreteDataContext().HybridHttpOrThreadLocalScoped();
Does IDispose need to get implemented anywhere?

FYI: I am using EF 4.1, MS Sql, MVC3, Structure Map

Thanks in advance for any help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic DataContext? softwarea BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 8 June 1st, 2009 01:04 PM
Creating a DataContext Schildb BOOK: Professional ADO.NET 3.5 with LINQ and the Entity Framework ISBN: 978-0-470-22988-0 1 April 14th, 2009 02:11 PM
Hashtable and lifetime of objects inside luca C# 3 February 19th, 2007 07:33 AM
CCommand Lifetime comdev2001 Oracle 0 November 29th, 2005 12:13 PM
Threads and an objects lifetime Kep C# 3 May 18th, 2004 01:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.