public static void AddMastercardApi(this IServiceCollection services, MastercardApiConfig rateApiConfig) { services.AddSingleton <IDateTimeProvider, DateTimeProvider>(); var signingKey = AuthenticationUtils.LoadSigningKey( rateApiConfig.CertPath, rateApiConfig.KeyAlias, rateApiConfig.KeyPassword); services.AddSingleton(new SigningKey { Key = signingKey }); services.AddSingleton(rateApiConfig); services.AddScoped <RequestSignerHandler>(); services.AddRefitClient <ICurrencyRateService>() .ConfigureHttpClient(c => { c.BaseAddress = new Uri(rateApiConfig.Url); c.Timeout = TimeSpan.FromSeconds(rateApiConfig.CurrencyRateServiceTimeoutInSeconds); }).AddHttpMessageHandler <RequestSignerHandler>(); services.AddRefitClient <ISettlementCurrenciesService>() .ConfigureHttpClient(c => { c.BaseAddress = new Uri(rateApiConfig.Url); c.Timeout = TimeSpan.FromSeconds(rateApiConfig.SettlementCurrenciesServiceTimeoutInSeconds); }).AddHttpMessageHandler <RequestSignerHandler>(); }
public RequestSignerHandler(MastercardApiConfig rateApiConfig, SigningKey signingKey) { _signer = new NetHttpClientSigner(rateApiConfig.ConsumerKey, signingKey.Key); }