private static IHost BuildServiceFabricService()

in src/Hosting.Services/HostBuilderExtensions.cs [66:115]


		private static IHost BuildServiceFabricService<TRunner, TService, TContext>(
			this IHostBuilder builder,
			string serviceName,
			Action<ServiceFabricHostBuilder<TService, TContext>> builderAction)
				where TRunner : OmexServiceRegistrator<TService, TContext>
				where TService : IServiceFabricService<TContext>
				where TContext : ServiceContext
		{
			string serviceNameForLogging = serviceName;

			try
			{
				if (string.IsNullOrWhiteSpace(serviceName))
				{
					// use executing assembly name for logging since application name not available
					serviceNameForLogging = Assembly.GetExecutingAssembly().GetName().FullName;
					throw new ArgumentException("Service type name is null of whitespace", nameof(serviceName));
				}

				builderAction(new ServiceFabricHostBuilder<TService, TContext>(builder));

				IHost host = builder
					.ConfigureServices((context, collection) =>
					{
						collection
							.Configure<ServiceRegistratorOptions>(options =>
							{
								options.ServiceTypeName = serviceName;
							})
							.AddOmexServiceFabricDependencies<TContext>()
							.AddSingleton<IOmexServiceRegistrator, TRunner>()
							.AddHostedService<OmexHostedService>();
					})
					.UseDefaultServiceProvider(options =>
					{
						options.ValidateOnBuild = true;
						options.ValidateScopes = true;
					})
					.Build();

				InitializationLogger.LogInitializationSucceed(serviceNameForLogging);

				return host;
			}
			catch (Exception e)
			{
				InitializationLogger.LogInitializationFail(serviceNameForLogging, e);
				throw;
			}
		}