Last active
August 12, 2023 07:11
-
-
Save SibeeshVenu/9412bd9798bf78fc3d1ae62abdc61e50 to your computer and use it in GitHub Desktop.
WeatherForecastController.cs with IpActionFilter ServiceFilter
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; | |
using Microsoft.AspNetCore.Mvc; | |
namespace DotNetIpFilter.Controllers | |
{ | |
[ApiController] | |
[Route("[controller]")] | |
[ServiceFilter(typeof(IpActionFilter))] | |
public class WeatherForecastController : ControllerBase | |
{ | |
private static readonly string[] Summaries = new[] | |
{ | |
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | |
}; | |
private readonly ILogger<WeatherForecastController> logger; | |
public WeatherForecastController(ILogger<WeatherForecastController> logger) | |
{ | |
this.logger = logger; | |
} | |
[HttpGet(Name = "GetWeatherForecast")] | |
public IEnumerable<WeatherForecast> Get() | |
{ | |
this.logger.LogInformation($"{nameof(WeatherForecastController)}.{nameof(Get)} start"); | |
return Enumerable.Range(1, 5).Select(index => new WeatherForecast | |
{ | |
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | |
TemperatureC = Random.Shared.Next(-20, 55), | |
Summary = Summaries[Random.Shared.Next(Summaries.Length)] | |
}) | |
.ToArray(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment