props/Props/Services/Content/CachedContentManager.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 CachedContentManager<TPage> : IContentManager<TPage>
{
private dynamic data;
2021-07-24 07:33:43 +00:00
private readonly ContentOptions options;
private readonly string fileName;
dynamic IContentManager<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;
}
}
2021-07-24 07:33:43 +00:00
public CachedContentManager(IConfiguration configuration)
{
2021-07-24 07:33:43 +00:00
this.options = configuration.GetSection(ContentOptions.Content).Get<ContentOptions>();
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
}
}
}