Esempio n. 1
0
        public static IHttpClientBuilder AddScryfallApiClient(this IServiceCollection services, Action <ScryfallApiClientConfig> configure)
        {
            var clientConfig = ScryfallApiClientConfig.GetDefault();

            configure(clientConfig);
            return(AddScryfallApiClient(services, clientConfig));
        }
Esempio n. 2
0
        /// <summary>
        /// Instantiate a new Scryfall API client.
        /// </summary>
        /// <param name="httpClient"></param>
        /// <param name="clientConfig"></param>
        /// <param name="cache"></param>
        public ScryfallApiClient(HttpClient httpClient, ScryfallApiClientConfig clientConfig = null, IMemoryCache cache = null)
        {
            if (clientConfig is null)
            {
                clientConfig = ScryfallApiClientConfig.GetDefault();
                clientConfig.EnableCaching = cache is not null;
            }

            var restService = new BaseRestService(httpClient, clientConfig, cache);

            _cards     = new Lazy <ICards>(() => new Cards(restService));
            _catalogs  = new Lazy <ICatalogs>(() => new Catalogs(restService));
            _sets      = new Lazy <ISets>(() => new Sets(restService));
            _symbology = new Lazy <ISymbology>(() => new Symbology(restService));
        }
Esempio n. 3
0
 public static IHttpClientBuilder AddScryfallApiClient(this IServiceCollection services) =>
 AddScryfallApiClient(services, ScryfallApiClientConfig.GetDefault());
Esempio n. 4
0
        public static IHttpClientBuilder AddScryfallApiClient(this IServiceCollection services, ScryfallApiClientConfig clientConfig)
        {
            services.AddScoped(services => clientConfig.Clone());
            var clientBuilder = services.AddHttpClient <ScryfallApiClient>(client =>
            {
                client.BaseAddress = clientConfig.ScryfallApiBaseAddress;
            });

            return(clientBuilder);
        }