Made content directory configurable.
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
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 string directory;
|
||||
private readonly ContentOptions options;
|
||||
private readonly string fileName;
|
||||
|
||||
dynamic IContentManager<TPage>.Json
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(directory, fileName)));
|
||||
if (data == null) data = JValue.Parse(File.ReadAllText(Path.Combine(options.Dir, fileName)));
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public CachedContentManager(string directory = "content")
|
||||
public CachedContentManager(IConfiguration configuration)
|
||||
{
|
||||
this.directory = directory;
|
||||
this.options = configuration.GetSection(ContentOptions.Content).Get<ContentOptions>();
|
||||
this.fileName = typeof(TPage).Name.Replace("Model", "") + ".json";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user