Update gestione script LUA:

- cartella con script
- conf x scelta
- gestione script letti 1 sola volta all'avvio
This commit is contained in:
Samuele Locatelli
2026-04-20 10:51:38 +02:00
parent 2d77838a01
commit 91f433e41c
12 changed files with 196 additions and 8 deletions
+43
View File
@@ -0,0 +1,43 @@
using Microsoft.Extensions.Options;
using MP.Core.Conf;
namespace MP.IOC.Services
{
public sealed class LuaScriptProvider
{
private readonly Dictionary<string, string> _scripts;
public IReadOnlyDictionary<string, string> Scripts => _scripts;
public LuaScriptProvider(
IOptions<RedisScriptsConfig> cfg,
IWebHostEnvironment env)
{
_scripts = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var kv in cfg.Value.Scripts)
{
var name = kv.Key;
var relativePath = kv.Value;
var fullPath = Path.Combine(env.ContentRootPath, relativePath);
if (!File.Exists(fullPath))
throw new FileNotFoundException($"Script Lua non trovato: {fullPath}");
var content = File.ReadAllText(fullPath);
_scripts[name] = content;
}
}
public string Get(string name)
{
if (!_scripts.TryGetValue(name, out var script))
throw new KeyNotFoundException($"Script Lua '{name}' non trovato.");
return script;
}
}
}