public static IHttpClientBuilder AddScryfallApiClient(this IServiceCollection services, Action <ScryfallApiClientConfig> configure) { var clientConfig = ScryfallApiClientConfig.GetDefault(); configure(clientConfig); return(AddScryfallApiClient(services, clientConfig)); }
/// <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)); }
public static IHttpClientBuilder AddScryfallApiClient(this IServiceCollection services) => AddScryfallApiClient(services, ScryfallApiClientConfig.GetDefault());
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); }