mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
Refactor console client to new Govor.ConsoleClient project
Removed Govor.Console implementation and introduced a new Govor.ConsoleClient project with a modular command-based architecture. Added dependency injection, command dispatcher, middleware pipeline, logging, and interactive command support. Updated solution and project files to reflect the new structure.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using Govor.ConsoleClient.Services.Middleware;
|
||||
|
||||
namespace Govor.ConsoleClient.Services;
|
||||
|
||||
public delegate Task CommandMiddleware(CommandContext context, Func<Task> next);
|
||||
|
||||
public class MiddlewarePipeline
|
||||
{
|
||||
private readonly IList<ICommandMiddleware> _middlewares;
|
||||
|
||||
public MiddlewarePipeline(IEnumerable<ICommandMiddleware> middlewares)
|
||||
{
|
||||
_middlewares = middlewares.ToList();
|
||||
}
|
||||
|
||||
public Task ExecuteAsync(CommandContext context)
|
||||
{
|
||||
return InvokeNext(0, context);
|
||||
}
|
||||
|
||||
private Task InvokeNext(int index, CommandContext context)
|
||||
{
|
||||
if (index < _middlewares.Count)
|
||||
{
|
||||
return _middlewares[index].InvokeAsync(context, () => InvokeNext(index + 1, context));
|
||||
}
|
||||
return context.Command.ExecuteAsync(context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user