This file contains hidden or 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 ObjectIntitializer; | |
| public class Program | |
| { | |
| public static void Main() | |
| { | |
| // Initialize objects by using an object initializer. | |
| var currency = new Currency { Id = 128, Code = "ZAR", Name = "Rand", Country = "South Africa" }; | |
| // Id = 128, Code = ZAR, Name = South Africa, Country = South Africa |
This file contains hidden or 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 DataMask; | |
| public class Program | |
| { | |
| public static void Main() | |
| { | |
| var creditCard = new CreditCard() | |
| { | |
| NameOnCard = "Muhammad Ahmod", | |
| Pan = "1234 5678 6787 2332", |
This file contains hidden or 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 TupleDeconstruction; | |
| public class Program | |
| { | |
| public static void Main() | |
| { | |
| // When deconstructing you can use _ to discard unwanted variables. | |
| var (Status, _, Reason) = WorkflowProgress.GetPaymentProgress("PMT_01J17CQ41K2Y0D5C3D8VG8"); | |
| // Status: ProvisionallyAccepted |
This file contains hidden or 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 System.Globalization; | |
| var _cache = new Dictionary<string, CacheItem<Transfer>>() { | |
| { "1", new CacheItem<Transfer> { Item = new Transfer { Id = 100, Status = TransferStatus.Completed, LastModified = DateTime.ParseExact("2024-07-16 11:00", "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture) } } }, | |
| { "2", new CacheItem<Transfer> { Item = new Transfer { Id = 200, Status = TransferStatus.Incomplete, LastModified = DateTime.ParseExact("2024-07-16 11:00", "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture) } } }, | |
| { "3", new CacheItem<Transfer> { Item = new Transfer { Id = 300, Status = TransferStatus.Canceled, LastModified = DateTime.ParseExact("2024-07-16 11:00", "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture) } } }, | |
| }; | |
| // Global method to access and clean up cache. | |
| void CleanUpCache<T>(KeyValuePair<string, CacheItem<T>> entry) => |
This file contains hidden or 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
| public class CardConfiguration : IEntityTypeConfiguration<Card> | |
| { | |
| public void Configure(EntityTypeBuilder<Card> builder) => | |
| builder.Property(c => c.EntityId) | |
| .HasValueGenerator<CardIdGenerator>() | |
| .HasColumnType("nvarchar") | |
| .HasColumnOrder(1) | |
| .HasMaxLength(30) | |
| .IsRequired(); | |
This file contains hidden or 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
| public enum CardStatus : int | |
| { | |
| Active = 1, | |
| Expired = 2, | |
| PendingVerification = 3 | |
| } | |
| public record CardEntity(CardStatus Status); | |
| public class CardConfiguration : IEntityTypeConfiguration<Card> |
This file contains hidden or 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 Garnet; | |
| using Garnet.client; | |
| // Server.Program.cs | |
| using var server = new GarnetServer(args); | |
| server.Start(); | |
| // Client.Program.cs | |
| using var db = new GarnetClient("localhost", 6379, null); | |
| db.Connect(); |
This file contains hidden or 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
| public static class RouteHandlerBuilderExtensions | |
| { | |
| public static RouteHandlerBuilder ValidateRequest<TRequest>(this RouteHandlerBuilder builder) => | |
| builder.AddEndpointFilter<ValidationFilter<TRequest>>(); | |
| } | |
| public class ValidationFilter<TRequest>(ILogger<RequestValidationFilter<TRequest>> logger, IValidator<TRequest>? validator = null) : IEndpointFilter | |
| { | |
| public async ValueTask<object?> InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next) | |
| { return await next(context); } | |
| } |
This file contains hidden or 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
| var builder = WebApplication.CreateBuilder(args); | |
| builder.Services.AddOutputCache(options => | |
| { | |
| options.AddPolicy("ManualExpire", builder => | |
| { | |
| builder.Expire(TimeSpan.FromDays(14)); | |
| builder.Tag("StaticCollections"); | |
| }); | |
This file contains hidden or 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
| version: "3" | |
| services: | |
| shorturl.gateway: | |
| container_name: shorturl.gateway | |
| image: haproxytech/haproxy-ubuntu | |
| build: | |
| context: ./shorturl/gateway | |
| env_file: | |
| - ./shorturl/gateway/.env | |
| ports: |
OlderNewer