private async void ConsoleOnCancelKeyPress(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; IsRunning = false; await DependencyInjectionManager.StopProgramLoopAsync().ConfigureAwait(false); Environment.Exit(0); }
public void ConfigureServices(IServiceCollection services) { IApplicationConfiguration applicationConfiguration = ApplicationConfigurationHelper.GetApplicationConfiguration(Configuration); services.AddSingleton(applicationConfiguration); DependencyInjectionManager.RegisterServices(services); services.AddControllers(); services.AddApiVersioning(); }
private async Task MainAsync() { Console.Title = "The Dialga Team Discord Bot (.Net Core)"; var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(this); serviceCollection.BindInterfacesAndSelfAsSingleton <FilePathService>(); serviceCollection.BindInterfacesAndSelfAsSingleton <LoggerService>(); serviceCollection.BindInterfacesAndSelfAsSingleton <SqliteDatabaseService>(); serviceCollection.BindInterfacesAndSelfAsSingleton <DiscordAppService>(); serviceCollection.BindInterfacesAndSelfAsSingleton <RestWebService>(); ServiceProvider = serviceCollection.BuildServiceProvider(); CommandService = new CommandService(new CommandServiceConfig { CaseSensitiveCommands = false }); CommandService.AddTypeReader <IEmote>(new EmoteTypeReader()); await CommandService.AddModulesAsync(Assembly.GetExecutingAssembly(), ServiceProvider).ConfigureAwait(false); ConsoleCommandService = new Commands.CommandService(new Commands.CommandServiceConfig { CaseSensitiveCommands = false }); await ConsoleCommandService.AddModulesAsync(Assembly.GetExecutingAssembly(), ServiceProvider).ConfigureAwait(false); DependencyInjectionManager = new DependencyInjectionManager(ServiceProvider); await DependencyInjectionManager.StartProgramLoopAsync().ConfigureAwait(false); LoggerService = ServiceProvider.GetService <LoggerService>(); Console.CancelKeyPress += ConsoleOnCancelKeyPress; do { var commandInput = await Console.In.ReadLineAsync().ConfigureAwait(false); commandInput = commandInput?.Trim(); if (commandInput == null) { break; } var result = await ConsoleCommandService.ExecuteAsync(commandInput, 0, ServiceProvider).ConfigureAwait(false); if (!result.IsSuccess) { await LoggerService.LogMessageAsync("Unknown command. Please try again.", ConsoleColor.Red).ConfigureAwait(false); } } while (IsRunning); await DependencyInjectionManager.StopProgramLoopAsync().ConfigureAwait(false); }
public App() { InitializeComponent(); DependencyInjectionManager.Init(); MainPage = new AppShell(); }