I would like to use DifferentDatabaseScope on a per request basis. In this web application it will be possible for a user to switch from a preview to a staging view. The preview and staging databases have identical schemas, and only differ by the data they contain. I have read similar threads, and it seems that using DifferentDatabaseScope is the way to go. This is my first experience with Castle ActiveRecord and I was hoping you kind folks could either validate or suggest improvements to the following approach.
SessionScope is being initialized and disposed in a custom HttpApplication class, the implementation closely follows this article which explains how to create a session per request in a web application. http://www.castleproject.org/activerecord/documentation/trunk/usersguide/web.html I have used DifferentDatabaseScope in the OnBeginRequest and OnEndRequest methods. public void OnBeginRequest(object sender, EventArgs e) { HttpContext.Current.Items.Add(sessionScopekey, new SessionScope ()); SqlConnection conn = MyContext.GetCurrentSQLConnection(); sqlConnection.Open(); HttpContext.Current.Items.Add(differentDatabaseScopeKey, new DifferentDatabaseScope(sqlConnection)); } public void OnEndRequest(object sender, EventArgs e) { try { SessionScope sessionScope = HttpContext.Current.Items [sessionScopekey] as SessionScope; if (sessionScope != null) { sessionScope.Dispose(); } DifferentDatabaseScope ddScope = HttpContext.Current.Items [ddScopeKey] as DifferentDatabaseScope; if (ddScope != null) { ddScope.Dispose(); } } catch(Exception ex) { HttpContext.Current.Trace.Warn("Error", "EndRequest: " + ex.Message, ex); } } My questions are: 1) Is DifferentDatabaseScope being used in a correct manner? I was not sure if I still need to declare SessionScope, and if so, if I am doing this in the correct order. 2) Should I be worried that DifferentDatabaseScope is using a single database connection? From my understanding, the Session will generally open and close connections from a connection pool as needed. In this case it looks like only a single connection will be used by DifferentDatabaseScope, which I am afraid my lead to performance issues if many queries are being generated in this session scope. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
