How to properly configure Spring.NET in a web context
I'm having a bit of a problem keeping values from appearing in scope for all users. I'm not sure what exactly I may be doing wrong, but I'm at wits end. I'm thinking either I have my container objects scoped wrong or I'm passing the values along the WebContext. First, here's what I'm doing in code. This works, but it's showing details for the first user who logs into the site (note: my PageStore is just a property of type IDictionary that stores values to share to all user controls on the page):
using (BasePage page = (BasePage)(Spring.Web.UI.Page)this.Context.Handler) {
if ((page.PageStore("LoginId") != null)) {
this.Model.LoginId = Convert.ToString(page.PageStore("LoginId"));
}
}
Second, I've tried different scopes for my objects but I'm coming up empty. Here is how my objects are currently configured in the container:
Snippet of my business tier configuration
<!-- Transaction Management Strategy - local database transactions -->
<object id="transactionManager"
type="Spring.Data.Core.AdoPlatformTransactionManager, Spring.Data" scope="request">
<property name="DbProvider" ref="MyProvid开发者_如何学JAVAer"/>
</object>
<tx:attribute-driven transaction-manager="transactionManager" />
<!-- Data Access Objects -->
<object id="DataAccess" type="MyApp.Business.DataAccess.DataAccess, MyApp.Business.DataAccess" abstract="true" scope="request">
<property name="AdoTemplate" ref="MyTemplate" />
</object>
<object id="ManagerDAO" type="MyApp.Business.DataAccess.ManagerDAO, MyApp.Business.DataAccess" parent="DataAccess" scope="request">
<property name="TableName" value="vw_managers" />
<property name="IsAllowedDeletion" value="False" />
<property name="IsAllowedUniqueIdRetrieval" value="False" />
</object>
<!-- Services -->
<object id="SearchService" type="MyApp.Business.Services.SearchService, MyApp.Business.Services" scope="request">
<property name="ManagerDAO" ref="UserDAO" />
</object>
Snippet of my presentation layer:
<object id="BasePageModel" type="MyApp.Presentation.Models.BasePageModel, MyApp.Presentation" abstract="true" scope="session"/>
<object id="ManagerModel" type="MyApp.Presentation.Models.ManagerModel, MyApp.Presentation" parent="BasePageModel" scope="session"/>
<!-- Presenters-->
<object name="ManagerPresenter" type="MyApp.Presentation.Presenters.ManagePresenter, MyApp.Presentation" singleton="false" scope="session">
<property name="SearchSvc" ref="SearchService"/>
</object>
Snippet of my UI layer objects:
<!-- Pages -->
<object id="BasePage" type="MyApp.UI.BasePage, MyApp.UI" abstract="true" singleton="false" scope="session" />
<object id="StandardPage" parent="BasePage" abstract="true" singleton="false" scope="session">
<property name="MasterPageFile" value="~/Layouts/Site.master"/>
</object>
<object type="~/Pages/Manager.aspx" parent="StandardPage" singleton="false" scope="session"/>
I know there are 100 ways to skin this cat, but the fastest solution is to just get this configured properly and drive on. Is my configuration flaky or am I going about this all wrong?
Edit: Common sense is starting to kick in....IDictionary isn't thread safe.
Fixed my problem. Switched my Dictionary objects to thread safe ConcurrentDictionary objects and fixed my scoping issues. For the scopes, my business tier objects are singletons, my model objects are in the session scope, and my views(user controls) and pages are now set to the request scope, non-singletons.
精彩评论