Guest User

Untitled

a guest
Jul 15th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. public class PageTemplateManager : IPageTemplateManager
  2. {
  3. readonly IReadModelRepository readModelRepository;
  4. readonly object mutex;
  5. readonly IDictionary<Guid, IList<PageTemplate>> templates;
  6.  
  7. public PageTemplateManager(IReadModelRepository readModelRepository)
  8. {
  9. this.readModelRepository = readModelRepository;
  10. this.templates = new Dictionary<Guid, IList<PageTemplate>>();
  11. this.mutex = new object();
  12. }
  13.  
  14. public IEnumerable<PageTemplate> All(Guid siteId)
  15. {
  16. this.EnsureTemplatesAreLoaded(siteId);
  17.  
  18. lock (this.mutex)
  19. return this.templates[siteId];
  20. }
  21.  
  22. void EnsureTemplatesAreLoaded(Guid siteId)
  23. {
  24. lock(this.mutex)
  25. {
  26. if(!this.templates.ContainsKey(siteId))
  27. this.templates.Add(siteId, readModelRepository.Query<PageTemplate>(new { SiteId = siteId}).ToList());
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment