/// <summary> /// Registers <see cref="IEmailJobClient"/> in Autofac container using <see cref="EmailJobRestClientSettings"/>. /// </summary> /// <param name="builder">Autofac container builder.</param> /// <param name="settings">EmailJob client settings.</param> /// <param name="builderConfigure">Optional <see cref="RestClientFactoryBuilder"/> configure handler.</param> public static void RegisterEmailJobClient( [NotNull] this ContainerBuilder builder, [NotNull] EmailJobRestClientSettings settings, [CanBeNull] Func <RestClientFactoryBuilder, RestClientFactoryBuilder> builderConfigure) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (string.IsNullOrWhiteSpace(settings.ServiceUrl)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(EmailJobRestClientSettings.ServiceUrl)); } var clientBuilder = RestClientFactory.BuildForUrl(settings.ServiceUrl) .WithAdditionalCallsWrapper(new ExceptionHandlerCallsWrapper()); clientBuilder = builderConfigure?.Invoke(clientBuilder) ?? clientBuilder.WithoutRetries(); builder.RegisterInstance(new EmailJobClient(clientBuilder.Create())) .As <IEmailJobClient>() .SingleInstance(); }