static async Task Main(string[] args) { var cancellationSource = new CancellationTokenSource(); Console.CancelKeyPress += (s, a) => { a.Cancel = true; cancellationSource.Cancel(); }; var config = SetProgramConfig(args); var logger = new Logger(); var calculator = new Calculator( new StringParser(logger), new TermParser(new VariableParser(logger), logger), new TermConverter(logger), logger); var appRunner = new AppRunner( config, calculator, cfg => { switch (cfg.ProgramMode) { case ProgramMode.Interactive: return(new ConsoleEquationsHandler()); case ProgramMode.FromFile: return(new FileEquationsHandler(cfg.InputFilepath, cfg.OutputFilepath)); default: throw new NotSupportedException($"{cfg.ProgramMode} is not supported"); } }, logger); using (appRunner) { await appRunner.RunAppAsync(cancellationSource.Token); } }