props/Props/Services/Textual/CachedTextualManager.cs

29 lines
861 B
C#
Raw Normal View History

using System.IO;
2021-07-24 07:33:43 +00:00
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
2021-07-24 07:33:43 +00:00
using Props.Options;
namespace Props.Services.Content
{
public class CachedTextualManager<TPage> : ITextualManager<TPage>
{
private dynamic data;
private readonly TextualOptions options;
private readonly string fileName;
dynamic ITextualManager<TPage>.Json
{
get
{
2021-07-24 07:33:43 +00:00
if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(options.Dir, fileName)));
return data;
}
}
public CachedTextualManager(IConfiguration configuration)
{
this.options = configuration.GetSection(TextualOptions.Textual).Get<TextualOptions>();
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
}
}
}