Skip to content

Commit c9f626f

Browse files
committed
minor refactoring
1 parent 0f41bd7 commit c9f626f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/SolidifyProject.Engine.Services/TemplateService/MustacheTemplateService.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public sealed class MustacheTemplateService : ITemplateService
2020
public MustacheTemplateService(IContentReaderService<TextContentModel> partialsLocator = null)
2121
{
2222
_partialsLocator = partialsLocator;
23-
_cache = new LazyCache<Template>(loadTemplate);
23+
_cache = new LazyCache<Template>(loadTemplateAsync);
2424
}
2525

2626
public Task<string> RenderTemplateAsync(string template, PageModel pageModel, ExpandoObject dataModel)
@@ -41,19 +41,24 @@ public Task<string> RenderTemplateAsync(string template, PageModel pageModel, Ex
4141
return Task.FromResult(result);
4242
}
4343

44-
private Task<Template> loadTemplate(string name)
44+
private async Task<Template> loadTemplateAsync(string name)
4545
{
4646
if (_partialsLocator == null)
4747
{
4848
return null;
4949
}
5050

51-
var content = _partialsLocator.LoadContentByIdAsync(name).Result.ContentRaw;
51+
var content = await _partialsLocator.LoadContentByIdAsync(name);
52+
53+
if (content == null)
54+
{
55+
throw new FileNotFoundException(name);
56+
}
5257

5358
var template = new Template();
54-
template.Load(new StringReader(content));
59+
template.Load(new StringReader(content.ContentRaw));
5560

56-
return Task.FromResult(template);
61+
return template;
5762
}
5863

5964
private Template getTemplate(string key)

0 commit comments

Comments
 (0)