Skip to content

Instantly share code, notes, and snippets.

@SibeeshVenu
Last active August 11, 2023 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SibeeshVenu/21bc246fddc07aad9b04ded1f02b4900 to your computer and use it in GitHub Desktop.
Save SibeeshVenu/21bc246fddc07aad9b04ded1f02b4900 to your computer and use it in GitHub Desktop.
IpHostedService that implements IHostedService
namespace DotNetIpFilter.Services
{
/// <summary>
/// IpHostedService
/// </summary>
public class IpHostedService: IHostedService
{
/// <summary>
/// The service provider
/// </summary>
private readonly IServiceProvider serviceProvider;
/// <summary>
/// The configuration
/// </summary>
private readonly IConfiguration configuration;
/// <summary>
/// Initializes a new instance of the <see cref="IpHostedService"/> class.
/// </summary>
public IpHostedService(IServiceProvider serviceProvider, IConfiguration configuration)
{
this.serviceProvider = serviceProvider;
this.configuration = configuration;
}
/// <summary>
/// IpHostedService StartAsync
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task StartAsync(CancellationToken cancellationToken)
{
using var scope = this.serviceProvider.CreateScope();
var ipService = scope.ServiceProvider.GetRequiredService<IIpFilterService>();
var ipAddresses = await ipService.GetAdminSafeIpList();
this.configuration["AdminSafeIpList"] = ipAddresses;
}
/// <summary>
/// IpHostedService StopAsync
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public Task StopAsync(CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment