Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().AddNewtonsoftJson();
            services.AddResponseCompression(opts =>
            {
                opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
                    new[] { "application/octet-stream" });
            });

            var serviceCollection = services;

            // Bot core
            services.AddHostedService <BotService>();

            // Configuration
            serviceCollection.AddSingleton(serviceProvider =>
            {
                var configurationBuilder = new ConfigurationBuilder()
                                           .AddJsonFile("abyss.json", false, true);
                return(configurationBuilder.Build());
            });
            serviceCollection.AddSingleton(serviceProvider =>
            {
                var configurationModel = new AbyssConfig();
                serviceProvider.GetRequiredService <IConfigurationRoot>().Bind(configurationModel);

                return(configurationModel);
            });

            // Discord
            var(discordClient, discordConfig) = ConfigureDiscord();
            serviceCollection.AddSingleton(discordClient);
            serviceCollection.AddSingleton(discordConfig);

            // Commands
            var(commandService, commandServiceConfiguration) = ConfigureCommands();
            serviceCollection.AddSingleton(commandService);
            serviceCollection.AddSingleton(commandServiceConfiguration);

            // Other services
            serviceCollection.AddSingleton <HelpService>();
            serviceCollection.AddSingleton <MessageReceiver>();
            serviceCollection.AddSingleton <ScriptingService>();
            serviceCollection.AddSingleton(provider =>
            {
                var configurationModel = provider.GetRequiredService <AbyssConfig>();
                return(SpotifyClient.FromClientCredentials(configurationModel.Connections.Spotify.ClientId, configurationModel.Connections.Spotify.ClientSecret));
            });
            serviceCollection.AddTransient <Random>();
            serviceCollection.AddSingleton <HttpClient>();
            serviceCollection.AddSingleton <ResponseCacheService>();
            serviceCollection.AddSingleton <AddonService>();
            serviceCollection.AddSingleton <NotificationsService>();
            serviceCollection.AddSingleton <DataService>();
            serviceCollection.AddSingleton <MarketingService>();
        }
Beispiel #2
0
        private static void ConfigureServices(HostBuilderContext context, IServiceCollection serviceCollection)
        {
            serviceCollection.AddHostedService <BotService>();

            // Configuration
            var abyssConfig = new AbyssConfig();

            context.Configuration.Bind(abyssConfig);
            serviceCollection.AddSingleton(abyssConfig);

            context.HostingEnvironment.ApplicationName = abyssConfig.Name;

            // Discord
            var(discordClient, discordConfig) = ConfigureDiscord();
            serviceCollection.AddSingleton(discordClient);
            serviceCollection.AddSingleton(discordConfig);

            // Commands
            var(commandService, commandServiceConfiguration) = ConfigureCommands();
            serviceCollection.AddSingleton(commandService);
            serviceCollection.AddSingleton(commandServiceConfiguration);

            // Other services
            serviceCollection.AddSingleton <HelpService>();
            serviceCollection.AddSingleton <MessageReceiver>();
            serviceCollection.AddSingleton <ScriptingService>();
            serviceCollection.AddSingleton(provider =>
            {
                var configurationModel = provider.GetRequiredService <AbyssConfig>();
                return(SpotifyClient.FromClientCredentials(configurationModel.Connections.Spotify.ClientId, configurationModel.Connections.Spotify.ClientSecret));
            });
            serviceCollection.AddTransient <Random>();
            serviceCollection.AddSingleton <HttpClient>();
            serviceCollection.AddSingleton <ResponseCacheService>();
            serviceCollection.AddSingleton <AddonService>();
            serviceCollection.AddSingleton <NotificationsService>();
            serviceCollection.AddSingleton <DataService>();
            serviceCollection.AddSingleton <MarketingService>();
        }
Beispiel #3
0
 public static void Initialize(TestContext context)
 {
     _client = SpotifyClient.FromClientCredentials(Environment.GetEnvironmentVariable("SpotifyCredentials", EnvironmentVariableTarget.Machine));
 }