コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MerriamWebsterClient"/> class.
 /// </summary>
 /// <param name="client">The HttpClient that is used to make the requests</param>
 /// <param name="config">MerriamWebsterConfig should contain a valid API key</param>
 /// <param name="logger">An <see cref="ILogger"/> instance</param>
 /// <remarks>It's most convenient to register this class as implementation of the <see cref="IMerriamWebsterClient"/> interface and inject the interface where it's needed.
 /// This constructor should therefore not be called directly, new instances should be created by the current IoC framework.</remarks>
 public MerriamWebsterClient(HttpClient client, MerriamWebsterConfig config, ILogger <MerriamWebsterClient> logger)
 {
     _client = client;
     _logger = logger;
     _apiKey = config.ApiKey;
 }
コード例 #2
0
        /// <summary>
        /// Registers the classes that are required to make calls to the Merriam-Webster API.
        /// </summary>
        /// <param name="services">The IServiceCollection.</param>
        /// <param name="config">The configuration. A valid API key should be present.</param>
        /// <returns>The IServiceCollection</returns>
        public static IServiceCollection RegisterMerriamWebster(this IServiceCollection services, MerriamWebsterConfig config)
        {
            services.AddSingleton(config);
            services.AddHttpClient <IMerriamWebsterClient, MerriamWebsterClient>(client =>
            {
                client.BaseAddress = Configuration.ApiBaseAddress;
            })
            .AddTransientHttpErrorPolicy(builder => builder.RetryAsync(2));


            services.AddTransient <IEntryParser, EntryParser>();

            return(services);
        }