public static IHost BuildStatelessWebService()

in src/Hosting.Services.Web/HostBuilderExtensions.cs [65:130]


		public static IHost BuildStatelessWebService<TStartup>(
			this IHostBuilder hostBuilder,
			string serviceName,
			WebEndpointInfo[] endpoints,
			ServiceFabricIntegrationOptions integrationOptions = DefaultServiceFabricIntegrationOptions,
			Action<WebHostBuilderContext, KestrelServerOptions>? kestrelOptions = null,
			Action<ServiceFabricHostBuilder<OmexStatelessService, StatelessServiceContext>>? serviceBuilder = null)
				where TStartup : class
		{
			if (integrationOptions.HasFlag(ServiceFabricIntegrationOptions.UseUniqueServiceUrl))
			{
				// Supporting this options would require some hacks:
				// * Creating UrlSuffix like PartitionId/InstanceId where PartitionId could be taken from Env variable 'Fabric_PartitionId', for InstanceId we might thy to use new guid instead
				// * Adding this path to address returned by OmexKestrelListener
				// * In OmexServiceFabricSetupFilter initially add app.UseServiceFabricMiddleware(UrlSuffix) or create new similar middleware that with work with list of suffixes
				throw new ArgumentException("ServiceFabricIntegrationOptions.UseUniqueServiceUrl currently not supported");
			}

			return hostBuilder
				.ConfigureServices(collection =>
				{
					collection
						.AddHttpContextAccessor()
						.AddOmexMiddleware()
						.AddSingleton<IStartupFilter>(new OmexServiceFabricSetupFilter(integrationOptions));
				})
				.ConfigureWebHost(webBuilder =>
				{
					webBuilder
						.UseKestrel((WebHostBuilderContext context, KestrelServerOptions options) =>
						{
							foreach (WebEndpointInfo endpoint in endpoints)
							{
								options.Listen(IPAddress.IPv6Any, endpoint.Port, listenOptions =>
								{
									if (endpoint.UseHttps)
									{
										string certificateSubject = context.Configuration.GetValue<string>(endpoint.SettingForCertificateCommonName);
										listenOptions.UseHttps(StoreName.My, certificateSubject, true, StoreLocation.LocalMachine);
									}
								});
							}

							kestrelOptions?.Invoke(context, options);
						})
						.UseContentRoot(Directory.GetCurrentDirectory())
						.UseStartup<TStartup>()
						.UseUrls(endpoints.Select(e => e.GetListenerUrl()).ToArray());
				})
				.BuildStatelessService(
					serviceName,
					builder =>
					{
						string publisherAddress = SfConfigurationProvider.GetPublishAddress();
						foreach (WebEndpointInfo endpoint in endpoints)
						{
							builder.AddServiceListener(endpoint.Name, (p, s) =>
								new OmexKestrelListener(
									p.GetRequiredService<IServer>(),
									publisherAddress,
									endpoint.Port));
						}

						serviceBuilder?.Invoke(builder);
					});
		}