public async Task MainAsync() { var configClient = InternalConfigurationApiClientFactory.Create(GetConfiguration().GetValue <string>("System:InternalConfiguration:Host"), TimeSpan.FromSeconds(5), 5); var systemConfig = await configClient.GetConfigurationAsync(); // TODO : ideally queue name should be read from InternalConfigurationApi IMessageChannel messageChannel = new RabbitMqChannel(systemConfig.MessageQueue.Host, systemConfig.MessageQueue.User, systemConfig.MessageQueue.Password, new JsonSerializer(), RabbitMqConsts.WorkerQueueName); IMessageBus messageBus = new RabbitMqBus(systemConfig.MessageQueue.Host, systemConfig.MessageQueue.User, systemConfig.MessageQueue.Password, new JsonSerializer()); var worker = new WorkerService(messageChannel, messageBus, new ChannelPersistence(new MongoDbOptions(systemConfig.ChannelsDb.DbHost, systemConfig.ChannelsDb.DbName, systemConfig.ChannelsDb.CollectionName, systemConfig.ChannelsDb.User, systemConfig.ChannelsDb.Password))); worker.Start(); await Task.Delay(-1); }
public void ConfigureServices(IServiceCollection services) { var sysClient = InternalConfigurationApiClientFactory.Create(Configuration.GetValue <string>("System:InternalConfiguration:Host"), TimeSpan.FromSeconds(5), 5); var sysConfig = sysClient.GetConfigurationAsync().GetAwaiter().GetResult(); services.AddHealthChecks(context => context.AddUrlCheck("https://google.com")); services .RegisterApiService(sysConfig.UsersDb.DbHost, sysConfig.UsersDb.DbName, sysConfig.UsersDb.CollectionName, sysConfig.UsersDb.User, sysConfig.UsersDb.Password) .AddScoped <DiscordApiClient>(builder => { return(new DiscordApiClient(new SimpleHttpClient(), sysConfig.DiscordOAuth.ClientId, sysConfig.DiscordOAuth.ClientSecret)); }) .AddSingleton <DiscordOAuth>(b => Mapper.Map <DiscordOAuthConfiguration, DiscordOAuth>(sysConfig.DiscordOAuth)); services.AddMvc(); }
public async Task MainAsync() { var configClient = InternalConfigurationApiClientFactory.Create(GetConfiguration().GetValue <string>("System:InternalConfiguration:Host"), TimeSpan.FromSeconds(5), 5); var systemConfig = await configClient.GetConfigurationAsync(); // TODO : ideally queue name should be read from InternalConfigurationApi IMessageChannel messageChannel = new RabbitMqChannel(systemConfig.MessageQueue.Host, systemConfig.MessageQueue.User, systemConfig.MessageQueue.Password, new JsonSerializer(), RabbitMqConsts.DiscordBotQueueName); IMessageBus messageBus = new RabbitMqBus(systemConfig.MessageQueue.Host, systemConfig.MessageQueue.User, systemConfig.MessageQueue.Password, new JsonSerializer()); var svc = new DiscordService(systemConfig.DiscordBot.ApiKey, messageChannel, messageBus); messageChannel.Start(); await svc.ConnectAsync(); await Task.Delay(-1); }
public void ConfigureServices(IServiceCollection services) { var sysClient = InternalConfigurationApiClientFactory.Create(Configuration.GetValue <string>("System:InternalConfiguration:Host"), TimeSpan.FromSeconds(5), 5); var sysConfig = sysClient.GetConfigurationAsync().GetAwaiter().GetResult(); // https://stackoverflow.com/a/45955658/8030072 services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.Events.OnRedirectToLogin = context => { context.Response.Headers["Location"] = context.RedirectUri; context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return(Task.CompletedTask); }; }); services.AddAuthorization(opt => { opt.AddPolicy(nameof(ApiKeyRequirement), policy => policy.Requirements.Add(new ApiKeyRequirement())); }); services .RegisterApiService(sysConfig.UsersDb.DbHost, sysConfig.UsersDb.DbName, sysConfig.UsersDb.CollectionName, sysConfig.UsersDb.User, sysConfig.UsersDb.Password) .AddScoped <IGameService, GameService>() .AddScoped <IHashService>(s => new HashService(sysConfig.ChannelHashEntropy)) .AddScoped <IChannelPersistence>(s => new ChannelPersistence(new MongoDbOptions(sysConfig.ChannelsDb.DbHost, sysConfig.ChannelsDb.DbName, sysConfig.ChannelsDb.CollectionName, sysConfig.ChannelsDb.User, sysConfig.ChannelsDb.Password))) .AddSingleton <IMessageBus>(s => new RabbitMqBus(sysConfig.MessageQueue.Host, sysConfig.MessageQueue.User, sysConfig.MessageQueue.Password, new JsonSerializer())) .AddScoped <IAuthorizationHandler, ApiKeyHandler>(); services.AddHealthChecks(context => context.AddUrlCheck("https://google.com")); services.AddMvc(opt => { opt.Filters.Add <ModelStateValidationFilter>(); }); }