using Microsoft.Extensions.Options; using MP.Core.Conf; namespace MP.RIOC.Services { public sealed class LuaScriptProvider { private readonly Dictionary _scripts; public IReadOnlyDictionary Scripts => _scripts; public LuaScriptProvider( IOptions cfg, IWebHostEnvironment env) { _scripts = new Dictionary(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; } } }