CreateServiceInstance()
        {
            var builder = new StatefulServiceHostBuilder();

            builder.UseRuntimeRegistrant(() => new MockStatefulServiceRuntimeRegistrant());

            return(builder);
        }
        public static IHostBuilder DefineStatefulService(
            this IHostBuilder @this,
            Action <IStatefulServiceHostBuilder> externalConfigAction)
        {
            if (@this is null)
            {
                throw new ArgumentNullException(nameof(@this));
            }

            if (externalConfigAction is null)
            {
                throw new ArgumentNullException(nameof(externalConfigAction));
            }

            @this.InjectReliableService <IStatefulServiceHostBuilder>(
                internalConfigAction =>
            {
                var builder = new StatefulServiceHostBuilder();

                externalConfigAction(builder);
                internalConfigAction(builder);

                builder.ConfigureObject(
                    configurator =>
                {
                    switch (HostingEnvironment.GetRuntime())
                    {
                    case HostingRuntime.Default:
                        configurator.ConfigureDependencies(
                            dependencies =>
                        {
                            dependencies.AddSingleton <IServiceHostRuntime, ServiceHostRuntime>();
                        });
                        break;

                    case HostingRuntime.Local:
                        throw new NotSupportedException("Stateful Services can't be executed using Local Runtime");

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                });

                return(builder.Build());
            });

            return(@this);
        }