Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- {
- this.EnsureTemplatesAreLoaded(siteId);
- lock (this.mutex)
- 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());
- }
- }
- }
Add Comment
Please, Sign In to add comment