Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. using Microsoft.Extensions.DependencyInjection;
  2. using Microsoft.Extensions.Hosting;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5.  
  6. namespace Backup.Service.Extensions
  7. {
  8. public static class ServiceBaseLifetimeExtension
  9. {
  10. public static IHostBuilder UseServiceLifetime(this IHostBuilder hostBuilder)
  11. {
  12. return hostBuilder.ConfigureServices((hostContext, services) => services.AddSingleton<IHostLifetime, ServiceLifeTime>());
  13. }
  14.  
  15. public static Task RunTheServiceAsync(this IHostBuilder hostBuilder, CancellationToken cancellationToken = default)
  16. {
  17. return hostBuilder.UseServiceLifetime().Build().RunAsync(cancellationToken);
  18. }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement