Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Emre Kızıldaş emrekizildas

🎯
Focusing
View GitHub Profile
View WeatherForecastController.cs
private static readonly string[] Cities = new[]
{
"İstanbul", "Bursa", "Çankırı", "Konya", "Ardahan", "Ordu", "Giresun", "Adana", "Sivas", "İzmir"
};
[HttpGet("getforecast/{id}")]
public IEnumerable<WeatherForecast> GetForecast(int id)
{
List<WeatherForecast> weatherForecasts = new List<WeatherForecast>();
var rng = new Random();
@emrekizildas
emrekizildas / Startup.cs
Created Nov 21, 2020
Ocelot & Redis Caching on .NET 5.0 API Project
View Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddOcelot().AddCacheManager(x =>
{
x.WithRedisConfiguration("redis",
config =>
{
config.WithAllowAdmin()
View Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((host, config) =>
{
config.AddJsonFile("ocelot.json");
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
View resilientExample.cs
await ResilientTransaction.New(_catalogContext).ExecuteAsync(async () =>
{
await _catalogContext.SaveChangesAsync();
await _eventLogService.SaveEventAsync(evt, _catalogContext.Database.CurrentTransaction);
});
View resilientTransaction.cs
public class ResilientTransaction
{
private DbContext _context;
private ResilientTransaction(DbContext context) =>
_context = context ?? throw new ArgumentNullException(nameof(context));
public static ResilientTransaction New (DbContext context) =>
new ResilientTransaction(context);
public async Task ExecuteAsync(Func<Task> action)
View typedclientmodel.cs
public class TypedClientModel : PageModel
{
private readonly ExampleService _exampleService;
public IEnumerable<User> Users { get; private set; }
public bool HasUser => Users.Any();
public bool GetUsersError { get; private set; }
View exampleservice.cs
public class ExampleService
{
public HttpClient Client { get; }
public ExampleService(HttpClient client)
{
client.BaseAddress = new Uri("https://api.example.com/");
client.DefaultRequestHeaders.Add("Accept","application/json");
client.DefaultRequestHeaders.Add("User-Agent","HttpClientFactory-Sample");
Client = client;
View namedclientmodel.cs
public class NamedClientModel : PageModel
{
private readonly IHttpClientFactory _clientFactory;
public IEnumerable<Employee> Employees { get; private set; }
public bool GetEmployeesError { get; private set; }
public bool HasEmployees => Employees.Any();
View namedclientstartup.cs
services.AddHttpClient("example", c =>
{
c.BaseAddress = new Uri("https://api.example.com/");
c.DefaultRequestHeaders.Add("Accept", "application/json");
c.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory-Sample");
});
You can’t perform that action at this time.