Skip to content

Instantly share code, notes, and snippets.

@gshutler
Created November 25, 2010 14:15
Show Gist options
  • Save gshutler/715441 to your computer and use it in GitHub Desktop.
Save gshutler/715441 to your computer and use it in GitHub Desktop.
public class PageTemplateManager : IPageTemplateManager
{
readonly IReadModelRepository readModelRepository;
readonly object mutex;
readonly IDictionary<Guid, IList<PageTemplate>> templates;
public PageTemplateManager(IReadModelRepository readModelRepository)
{
this.readModelRepository = readModelRepository;
this.templates = new Dictionary<Guid, IList<PageTemplate>>();
this.mutex = new object();
}
public IEnumerable<PageTemplate> All(Guid siteId)
{
if(!this.templates.ContainsKey(siteId))
this.EnsureTemplatesAreLoaded(siteId);
return this.templates[siteId];
}
void EnsureTemplatesAreLoaded(Guid siteId)
{
lock(this.mutex)
{
if(!this.templates.ContainsKey(siteId))
this.templates.Add(siteId, readModelRepository.Query<PageTemplate>(new { SiteId = siteId}).ToList());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment