/// <summary>
 /// Set the centralized Lucene engine as the search engine and
 /// sets the <see cref="GrpcServiceClient"/> as the client for
 /// search service communication.
 /// </summary>
 /// <param name="repositoryBuilder">The <see cref="IRepositoryBuilder"/> instance.</param>
 /// <param name="serviceAddress">Url of the gRPC search service.</param>
 /// <param name="configure">Optional configure method.</param>
 public static IRepositoryBuilder UseLucene29CentralizedSearchEngineWithGrpc(
     this IRepositoryBuilder repositoryBuilder,
     string serviceAddress,
     Action <GrpcChannelOptions> configure = null)
 {
     return(repositoryBuilder
            .UseLucene29CentralizedSearchEngine()
            .UseLucene29CentralizedGrpcServiceClient(serviceAddress, configure));
 }
        /// <summary>
        /// Set the centralized Lucene engine as the search engine and initialize it
        /// using the provided WCF endpoint binding.
        /// </summary>
        public static IRepositoryBuilder UseLucene29CentralizedSearchEngineWithWcf(this IRepositoryBuilder repositoryBuilder,
                                                                                   Binding binding, EndpointAddress address)
        {
            if (binding == null)
            {
                throw new ArgumentNullException(nameof(binding));
            }
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            WcfServiceClient.InitializeServiceEndpoint(binding, address);

            return(repositoryBuilder.UseLucene29CentralizedSearchEngine());
        }
        /// <summary>
        /// Set the centralized Lucene engine as the search engine and
        /// sets the <see cref="GrpcServiceClient"/> as the client for
        /// search service communication.
        /// </summary>
        /// <param name="repositoryBuilder">The <see cref="IRepositoryBuilder"/> instance.</param>
        /// <param name="options">Grpc client options</param>
        public static IRepositoryBuilder UseLucene29CentralizedSearchEngineWithGrpc(this IRepositoryBuilder repositoryBuilder, GrpcClientOptions options)
        {
            //TODO: refactor the Grpc client to be able to work as a hosted service and use dependency injection correctly

            // shortcut for bypassing certificate validation using a single configurable flag
            if (!options.ValidateServerCertificate)
            {
                options.ChannelOptions.HttpClient = new HttpClient(new HttpClientHandler
                {
                    ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true
                });
                options.ChannelOptions.DisposeHttpClient = true;
            }

            repositoryBuilder
            .UseLucene29CentralizedSearchEngine()
            .UseLucene29CentralizedServiceClient(CreateGrpcServiceClient(options.ServiceAddress, options.ChannelOptions));

            SnLog.WriteInformation("GrpcServiceClient set as Lucene29 Centralized Service Client.");

            return(repositoryBuilder);
        }