mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-20 18:42:50 +08:00
enable disposing ITypeResolver
This commit is contained in:
parent
1ed7e65fcb
commit
6bceac8a5e
@ -4,7 +4,7 @@ using Spectre.Console.Cli;
|
|||||||
|
|
||||||
namespace Injection
|
namespace Injection
|
||||||
{
|
{
|
||||||
public sealed class TypeResolver : ITypeResolver
|
public sealed class TypeResolver : ITypeResolver, IDisposable
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _provider;
|
private readonly IServiceProvider _provider;
|
||||||
|
|
||||||
@ -17,5 +17,13 @@ namespace Injection
|
|||||||
{
|
{
|
||||||
return _provider.GetRequiredService(type);
|
return _provider.GetRequiredService(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_provider is IDisposable disposable)
|
||||||
|
{
|
||||||
|
disposable.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ namespace Spectre.Console.Cli
|
|||||||
_registrar.RegisterInstance(typeof(IRemainingArguments), parsedResult.Remaining);
|
_registrar.RegisterInstance(typeof(IRemainingArguments), parsedResult.Remaining);
|
||||||
|
|
||||||
// Create the resolver and the context.
|
// Create the resolver and the context.
|
||||||
var resolver = new TypeResolverAdapter(_registrar.Build());
|
using var resolver = new TypeResolverAdapter(_registrar.Build());
|
||||||
var context = new CommandContext(parsedResult.Remaining, leaf.Command.Name, leaf.Command.Data);
|
var context = new CommandContext(parsedResult.Remaining, leaf.Command.Name, leaf.Command.Data);
|
||||||
|
|
||||||
// Execute the command tree.
|
// Execute the command tree.
|
||||||
|
@ -2,7 +2,7 @@ using System;
|
|||||||
|
|
||||||
namespace Spectre.Console.Cli
|
namespace Spectre.Console.Cli
|
||||||
{
|
{
|
||||||
internal sealed class TypeResolverAdapter : ITypeResolver
|
internal sealed class TypeResolverAdapter : ITypeResolver, IDisposable
|
||||||
{
|
{
|
||||||
private readonly ITypeResolver? _resolver;
|
private readonly ITypeResolver? _resolver;
|
||||||
|
|
||||||
@ -43,5 +43,13 @@ namespace Spectre.Console.Cli
|
|||||||
throw CommandRuntimeException.CouldNotResolveType(type, ex);
|
throw CommandRuntimeException.CouldNotResolveType(type, ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_resolver is IDisposable disposable)
|
||||||
|
{
|
||||||
|
disposable.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user