Created
November 25, 2010 14:15
-
-
Save gshutler/715441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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