props/Props/Services/Content/CachedContentManager.cs

29 lines
861 B
C#

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