I have a single .NET application that serves several host sites, so
mydomain1.com, mydomain2.com, mydomain3.com, etc are all sharing the
same .NET application. I'd like to create a mapper instance for each
host site and store it in the application cache. This will save me from
creating a static class per site, which would get out of hand when the
number of sites grow. This way I can just store a mapper instance per
site using the site host name as the application cache name. I've tried
my code below and it runs fine for all my sites, which each have their
own iBatis config file. Does anybody see anything wrong with using the
application cache to store the mapper instances or anything I should be
concerned about in my code?
Usage:
SiteUser user = new SiteUser();
user = DataMapper.Membership.QueryForObject("GetUser", null) as SiteUser;
Code:
public static class DataMapper
{
public static ISqlMapper Membership
{
get
{
if (HttpContext.Current.Cache[GetHostName() +
":DataMapper:Membership"] == null)
{
DomSqlMapBuilder builder = new DomSqlMapBuilder();
ConfigureHandler handler = new ConfigureHandler(
delegate
{
DataMapper.Membership = null;
});
HttpContext.Current.Cache[GetHostName() +
":DataMapper:Membership"] =
builder.ConfigureAndWatch(Globals.Site.Config.Membership.DataMapFile, handler);
}
return HttpContext.Current.Cache[GetHostName() +
":DataMapper:Membership"] as ISqlMapper;
}
set
{
if (HttpContext.Current.Cache[GetHostName() +
":DataMapper:Membership"] != null &&
value == null)
HttpContext.Current.Cache.Remove(GetHostName() +
":DataMapper:Membership");
}
}
}
_________________________________________________________________
Don't get caught with egg on your face. Play chicktionary!
http://club.live.com/chicktionary.aspx?icid=chick_wlhmtextlink1_feb