public SmsServiceSmsRu(IOptions <SmsServiceSettings> smsServiceSettings, ILogger <SmsServiceSmsRu> logger) { _smsServiceSettings = smsServiceSettings.Value; _logger = logger; if (!_smsServiceSettings.ValidateSettingsSmsRu()) { throw new ServiceException($"Sms Service [SmsRu] is not properly set up"); } }
public static IServiceCollection ConfigDiServices(this IServiceCollection services, IConfiguration configuration) { services.AddScoped(typeof(IRepositoryNonDeletable <>), typeof(RepositoryNonDeletable <>)); services.AddScoped(typeof(IRepository <>), typeof(Repository <>)); services.AddScoped <IBookingService, BookingService>(); services.AddScoped <ICheckService, CheckService>(); services.AddScoped <IPayService, PayService>(); services.AddScoped <IUserService, UserService>(); services.AddScoped <IAccountService, AccountService>(); services.AddScoped <INotificationService, NotificationService>(); services.AddScoped <IDateService, DateService>(); services.AddScoped <ICostEvaluationService, CostEvaluationService>(); services.AddScoped <ITokenService, TokenService>(); services.AddScoped <IExternalService, ExternalService>(); services.AddScoped <IHourCostManagerService, HourCostManagerService>(); services.AddScoped <IPromoCodeManagerService, PromoCodeManagerService>(); services.AddScoped <IBookingManagerService, BookingManagerService>(); services.AddScoped <IUserManagerService, UserManagerService>(); services.AddScoped <IAdminConfiguration, AdminConfiguration>(); services.AddSingleton(configuration); #region SmsService SmsServiceSettings smsSettings = configuration.GetSection("SmsServiceSettings")?.Get <SmsServiceSettings>(); if (smsSettings == null) { services.AddScoped <ISmsService, SmsServiceMock>(); } else { switch (smsSettings.Provider) { case "mock": services.AddScoped <ISmsService, SmsServiceMock>(); break; case "twilio": services.AddScoped <ISmsService, SmsServiceTwilio>(); break; case "smsru": services.AddScoped <ISmsService, SmsServiceSmsRu>(); break; default: throw new ArgumentException("Argument value must be in ('mock', 'twilio', 'smsru')", nameof(smsSettings.Provider)); } } #endregion return(services); }
/// <summary> /// Constructs the <see cref="YubotoOmniServiceBase"/> using the <seealso cref="SmsServiceSettings"/>. /// </summary> /// <param name="settings">The settings required to configure the service.</param> /// <param name="httpClient">Injected <see cref="System.Net.Http.HttpClient"/> managed by the DI.</param> /// <param name="logger">Represents a type used to perform logging.</param> public YubotoOmniServiceBase(HttpClient httpClient, SmsServiceSettings settings, ILogger <YubotoOmniServiceBase> logger) { HttpClient = httpClient ?? new HttpClient(); Settings = settings ?? throw new ArgumentNullException(nameof(settings)); Logger = logger ?? throw new ArgumentNullException(nameof(logger)); if (HttpClient.BaseAddress == null) { HttpClient.BaseAddress = new Uri("https://services.yuboto.com/omni/v1/"); } if (!HttpClient.DefaultRequestHeaders.Contains("Authorization")) { HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.UTF8.GetBytes(Settings.ApiKey))); } }
/// <summary> /// Creates a new instance of <see cref="SmsYubotoOmniService"/>. /// </summary> /// <param name="httpClient">Provides a base class for sending HTTP requests and receiving HTTP responses from a resource identified by a URI.</param> /// <param name="settings">Settings class for configuring SMS service clients.</param> /// <param name="logger">Represents a type used to perform logging.</param> public SmsYubotoOmniService(HttpClient httpClient, SmsServiceSettings settings, ILogger <SmsYubotoOmniService> logger) : base(httpClient, settings, logger) { }