Register the console lazily in CLI type registrar

This should fix a strange bug we're seeing in Cake on macOS.
This commit is contained in:
Patrik Svensson
2021-02-12 00:02:59 +01:00
committed by Patrik Svensson
parent fd217ffc83
commit 28e9c14de4
5 changed files with 47 additions and 1 deletions

View File

@ -37,6 +37,19 @@ namespace Spectre.Console.Testing
}
}
public void RegisterLazy(Type service, Func<object> factory)
{
if (factory is null)
{
throw new ArgumentNullException(nameof(factory));
}
if (!Instances.ContainsKey(service))
{
Instances.Add(service, new List<object> { factory() });
}
}
public ITypeResolver Build()
{
return _resolver;