Exemple #1
0
        public SupportApiHostedService(IConfiguration configuration, ILoggerProvider loggerProvider, IClusterClient client, INetworkPortFinder portFinder)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (loggerProvider == null)
            {
                throw new ArgumentNullException(nameof(loggerProvider));
            }
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (portFinder == null)
            {
                throw new ArgumentNullException(nameof(portFinder));
            }

            Port = portFinder.GetAvailablePortFrom(
                configuration.GetValue <int>("Api:Port:Start"),
                configuration.GetValue <int>("Api:Port:End"));

            _host = new WebHostBuilder()
                    .UseKestrel(op =>
            {
                op.ListenAnyIP(Port);
            })
                    .ConfigureLogging(configure =>
            {
                configure.AddProvider(loggerProvider);
            })
                    .ConfigureServices(configure =>
            {
                configure.AddMvc()
                .SetCompatibilityVersion(CompatibilityVersion.Latest)
                .AddApplicationPart(typeof(DummyController).Assembly)
                .AddControllersAsServices();

                configure.AddApiVersioning(op =>
                {
                    op.ReportApiVersions = true;
                    op.DefaultApiVersion = new ApiVersion(1, 0);
                });

                configure.AddVersionedApiExplorer(op =>
                {
                    op.GroupNameFormat = "'v'VVV";
                });

                configure.AddSupportApiInfo(configuration["Api:Title"]);
                configure.AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerOptions>();
                configure.AddSwaggerGen();
                configure.AddSingleton(client);
            })
                    .Configure(app =>
            {
                var provider = app.ApplicationServices.GetService <IApiVersionDescriptionProvider>();

                app.UseMvc();
                app.UseSwagger();
                app.UseSwaggerUI(op =>
                {
                    foreach (var description in provider.ApiVersionDescriptions)
                    {
                        op.SwaggerEndpoint(
                            $"/swagger/{description.GroupName}/swagger.json",
                            description.GroupName.ToLowerInvariant());
                    }
                });
            })
                    .Build();
        }
Exemple #2
0
        public SiloHostedService(IConfiguration configuration, ILoggerProvider loggerProvider, INetworkPortFinder portFinder, IHostingEnvironment environment)
        {
            // validate
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            if (loggerProvider == null)
            {
                throw new ArgumentNullException(nameof(loggerProvider));
            }
            if (portFinder == null)
            {
                throw new ArgumentNullException(nameof(portFinder));
            }
            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            // get desired port configuration
            SiloPort = portFinder.GetAvailablePortFrom(
                configuration.GetValue <int>("Orleans:Ports:Silo:Start"),
                configuration.GetValue <int>("Orleans:Ports:Silo:End"));

            GatewayPort = portFinder.GetAvailablePortFrom(
                configuration.GetValue <int>("Orleans:Ports:Gateway:Start"),
                configuration.GetValue <int>("Orleans:Ports:Gateway:End"));

            DashboardPort = portFinder.GetAvailablePortFrom(
                configuration.GetValue <int>("Orleans:Ports:Dashboard:Start"),
                configuration.GetValue <int>("Orleans:Ports:Dashboard:End"));

            // configure the silo host
            _host = new SiloHostBuilder()

                    .ConfigureApplicationParts(_ =>
            {
                _.AddApplicationPart(typeof(TestGrain).Assembly).WithReferences();
            })

                    .ConfigureLogging(_ =>
            {
                _.AddProvider(loggerProvider);
            })

                    .Configure <ClusterMembershipOptions>(_ =>
            {
                if (environment.IsDevelopment())
                {
                    _.ValidateInitialConnectivity = false;
                    _.NumVotesForDeathDeclaration = 1;
                }
            })

                    .Configure <UserOptions>(_ =>
            {
                _.MaxCachedMessages = 100;
            })

                    .Configure <ProcessExitHandlingOptions>(_ =>
            {
                _.FastKillOnProcessExit = false;
            })

                    .AddSimpleMessageStreamProvider(SimpleMessageStreamProviderName)

                    .UseDashboard(_ =>
            {
                _.HostSelf = true;
                _.Port     = DashboardPort;
            })

                    // configure the clustering provider
                    .TryUseLocalhostClustering(configuration, SiloPort, GatewayPort)
                    .TryUseAdoNetClustering(configuration, SiloPort, GatewayPort)

                    // configure the reminder service
                    .TryUseInMemoryReminderService(configuration)
                    .TryUseAdoNetReminderService(configuration)

                    // configure the default storage provider
                    .TryAddMemoryGrainStorageAsDefault(configuration)
                    .TryAddAdoNetGrainStorageAsDefault(configuration)

                    // configure the storage provider for pubsub
                    .TryAddMemoryGrainStorageForPubSub(configuration)
                    .TryAddAdoNetGrainStorageForPubSub(configuration)

                    // configure the registry provider
                    .TryAddInMemoryRegistry(configuration)
                    .TryAddSqlServerRegistry(configuration)

                    // done
                    .Build();
        }