Last active
August 11, 2023 13:29
-
-
Save SibeeshVenu/21bc246fddc07aad9b04ded1f02b4900 to your computer and use it in GitHub Desktop.
IpHostedService that implements IHostedService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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