Ejemplo n.º 1
0
        /// <summary>
        /// Adds Clash of Clans services to the service collection. The registered services are the main
        /// interface <see cref="IClashOfClans"/> and the individual interfaces <see cref="IClans"/>,
        /// <see cref="ILocations"/>, <see cref="ILeagues"/>, <see cref="IPlayers"/>, <see cref="ILabels"/>
        /// and <see cref="IGoldPass"/>.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> to add services to.</param>
        /// <param name="configureOptions">An <see cref="Action"/> to configure the provided <see cref="ClashOfClansOptionsV2"/></param>
        /// <returns></returns>
        public static IServiceCollection AddClashOfClans(this IServiceCollection services,
                                                         Action <ClashOfClansOptionsV2> configureOptions)
        {
            services.AddOptions();
            services.Configure(configureOptions);

            // Services
            services.AddScoped(services =>
            {
                var options = new ClashOfClansOptionsV2();
                configureOptions(options);
                TokenValidator.Validate(options.Tokens);

                return(new ClashOfClansOptionsInternal(options.Tokens)
                {
                    MaxRequestsPerSecond = options.MaxRequestsPerSecond
                });
            });

            services.AddScoped <IGameData, GameData>();

            // Fine grained public interfaces
            services.AddScoped <IClans, Clans>();
            services.AddScoped <ILocations, Locations>();
            services.AddScoped <ILeagues, Leagues>();
            services.AddScoped <IPlayers, Players>();
            services.AddScoped <ILabels, Labels>();
            services.AddScoped <IGoldPass, GoldPass>();

            // "the" API that depends on fine grained interfaces
            services.AddScoped <IClashOfClans, ClashOfClansDIClient>();

            return(services);
        }
Ejemplo n.º 2
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.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddClashOfClans(options =>
            {
                var clashOptions = new ClashOfClansOptionsV2();
                Configuration.GetSection(ClashOfClansOptions.ClashOfClans).Bind(clashOptions);

                options.Tokens.AddRange(clashOptions.Tokens);
                options.MaxRequestsPerSecond = clashOptions.MaxRequestsPerSecond;
            });
        }