private ISiloHostBuilder InitBuilder()
        {
            var hostBuilder = new SiloHostBuilder();

            hostBuilder.Configure <SerializationProviderOptions>(options =>
            {
                options.SerializationProviders.Add(typeof(OrleansCustomSerialization));

                // A workaround for an Orleans issue
                // to ensure the stack trace properly de/serialized
                // Gigya.Microdot.UnitTests.Serialization.ExceptionSerializationTests
                options.SerializationProviders.Add(typeof(NonSerializedExceptionsSerializer));

                options.FallbackSerializationProvider = typeof(OrleansCustomSerialization);
            })
            .UsePerfCounterEnvironmentStatistics()
            // We paid attention that AddFromApplicationBaseDirectory making issues of non-discovering grain types.
            .ConfigureApplicationParts(parts => parts.AddFromAppDomain())
            .Configure <SiloOptions>(options => options.SiloName = _appInfo.Name);

            if (_orleansConfig.Dashboard.Enable)
            {
                hostBuilder.UseDashboard(o =>
                {
                    o.Port = _endPointDefinition.SiloDashboardPort;
                    o.CounterUpdateIntervalMs = (int)TimeSpan.Parse(_orleansConfig.Dashboard.WriteInterval).TotalMilliseconds;
                    o.HideTrace = _orleansConfig.Dashboard.HideTrace;
                });
            }

            SetGrainCollectionOptions(hostBuilder);

            hostBuilder.Configure <PerformanceTuningOptions>(options =>
            {
                options.DefaultConnectionLimit = ServicePointManager.DefaultConnectionLimit;
            });
            hostBuilder.AddMemoryGrainStorage(ProviderConstants.DEFAULT_STORAGE_PROVIDER_NAME, options => options.NumStorageGrains = 10);
            hostBuilder.Configure <TelemetryOptions>(o => o.AddConsumer <MetricsStatisticsConsumer>());
            hostBuilder.Configure <SchedulingOptions>(options =>
            {
                options.PerformDeadlockDetection = true;
                options.AllowCallChainReentrancy = true;
                options.MaxActiveThreads         = Process.GetCurrentProcess().ProcessorAffinityList().Count();
            });

            hostBuilder.Configure <ClusterMembershipOptions>(options =>
            {
            });

            if (_orleansConfig.EnableTls)
            {
                var localCertificate = _certificateLocator.GetCertificate("Service");
                hostBuilder.UseTls(localCertificate, tlsOptions =>
                {
                    tlsOptions.LocalCertificate      = localCertificate;
                    tlsOptions.ClientCertificateMode = RemoteCertificateMode.AllowCertificate;
                    tlsOptions.RemoteCertificateMode = RemoteCertificateMode.AllowCertificate;

                    tlsOptions.SslProtocols = SslProtocols.Tls12;

                    tlsOptions.OnAuthenticateAsClient = OnAuthenticateAsClient;
                });
            }

            SetReminder(hostBuilder);
            SetSiloSource(hostBuilder);

            hostBuilder.Configure <StatisticsOptions>(o =>
            {
                o.LogWriteInterval          = TimeSpan.FromDays(1);
                o.PerfCountersWriteInterval = TimeSpan.Parse(_orleansConfig.MetricsTableWriteInterval);
            });

            return(hostBuilder);
        }