Skip to content

Instantly share code, notes, and snippets.

View emrekizildas's full-sized avatar
🎯
Focusing

Emre Kızıldaş emrekizildas

🎯
Focusing
View GitHub Profile
public class User
{
public Guid ID { get; set; }
[AlwaysUpper]
public string Firstname { get; set; }
[AlwaysUpper]
public string Lastname { get; set; }
public string EmailAddress { get; set; }
public string IdentityNumber { get; set; }
}
using ConverterExample.Converter;
using ConverterExample.Attribute;
using System.Linq;
using System.Reflection;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using System;
namespace ConverterExample.Extension
{
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace ConverterExample.Converter
{
internal sealed class UpperConverter : ValueConverter<string, string>
{
public EncryptionConverter() : base (x => x.ToUpper(), x => x, null)
{
}
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public sealed class AlwaysUpperAttribute : System.Attribute
{
}
CREATE TABLE IF NOT EXISTS "encryptexample"."__EFMigrationsHistory" (
"MigrationId" varchar(150) NOT NULL,
"ProductVersion" varchar(32) NOT NULL,
CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId")
);
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 November 21, 2020 21:36
Ocelot & Redis Caching on .NET 5.0 API Project
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddOcelot().AddCacheManager(x =>
{
x.WithRedisConfiguration("redis",
config =>
{
config.WithAllowAdmin()
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((host, config) =>
{
config.AddJsonFile("ocelot.json");
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
await ResilientTransaction.New(_catalogContext).ExecuteAsync(async () =>
{
await _catalogContext.SaveChangesAsync();
await _eventLogService.SaveEventAsync(evt, _catalogContext.Database.CurrentTransaction);
});
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)