21 lines
539 B
C#
21 lines
539 B
C#
namespace backend.Tools;
|
|
|
|
public class ToolRegistry
|
|
{
|
|
private readonly Dictionary<string, ITool> _byName;
|
|
private readonly List<ITool> _all;
|
|
|
|
public ToolRegistry(IEnumerable<ITool> tools)
|
|
{
|
|
_all = tools.ToList();
|
|
_byName = _all.ToDictionary(t => t.Name);
|
|
}
|
|
|
|
public IReadOnlyList<ITool> All => _all;
|
|
|
|
public ITool? Get(string name) => _byName.GetValueOrDefault(name);
|
|
|
|
public IEnumerable<ITool> EnabledFor(IReadOnlySet<string> enabled)
|
|
=> _all.Where(t => enabled.Contains(t.Name));
|
|
}
|