Created
August 11, 2023 13:14
-
-
Save SibeeshVenu/a857e6b16005eb36b8161bfc000fdaf8 to your computer and use it in GitHub Desktop.
Program file with AddHostedService<IpHostedService>()
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
using DotNetIpFilter.Services; | |
var builder = WebApplication.CreateBuilder(args); | |
// Add services to the container. | |
builder.Services.AddControllers(); | |
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | |
builder.Services.AddEndpointsApiExplorer(); | |
builder.Services.AddSwaggerGen(); | |
builder.Services.AddScoped<IIpFilterService, IpFilterService>(); | |
// To add the IP addresses to filter | |
builder.Services.AddHostedService<IpHostedService>(); | |
// Enable the Ip Action Filter with Admin Safe IP List | |
builder.Services.AddScoped(container => | |
{ | |
var loggerFactory = container.GetRequiredService<ILoggerFactory>(); | |
var logger = loggerFactory.CreateLogger<IpActionFilter>(); | |
return new IpActionFilter(builder.Configuration["AdminSafeIpList"], logger); | |
}); | |
var app = builder.Build(); | |
// Configure the HTTP request pipeline. | |
if (app.Environment.IsDevelopment()) | |
{ | |
app.UseSwagger(); | |
app.UseSwaggerUI(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseAuthorization(); | |
app.MapControllers(); | |
app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment