2019-10-10 01:48:48 +03:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2023-01-12 01:01:36 +02:00
|
|
|
|
namespace Netmash.Hosting.WindowsService
|
2019-10-10 01:48:48 +03:00
|
|
|
|
{
|
|
|
|
|
public static class ServiceBaseLifetimeHostExtensions
|
|
|
|
|
{
|
|
|
|
|
public static IHostBuilder UseServiceBaseLifetime(this IHostBuilder hostBuilder)
|
|
|
|
|
{
|
|
|
|
|
return hostBuilder.ConfigureServices((hostContext, services) => services.AddSingleton<IHostLifetime, ServiceBaseLifetime>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Task RunAsServiceAsync(this IHostBuilder hostBuilder, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
return hostBuilder.UseServiceBaseLifetime().Build().RunAsync(cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|