Skip to content

Instantly share code, notes, and snippets.

View aradalvand's full-sized avatar

Arad Alvand (AmirHossein Ahmadi) aradalvand

View GitHub Profile
namespace Sqids;
public class SqidsOptions
{
public string Alphabet { get; set; } = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public HashSet<string> BlockList { get; set; } = new() { /* TODO */ };
public int MinLength { get; set; } = 10;
}
public class SqidsGenerator
namespace Sqids;
public class SqidsOptions
{
public string Alphabet { get; set; } = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public HashSet<string> BlockList { get; set; } = new() { /* TODO */ };
public int MinLength { get; set; } = 10;
}
public class SqidsGenerator
@aradalvand
aradalvand / AddValidationFilterExtension.cs
Last active May 12, 2023 06:04
FluentValidation filter for ASP.NET Core Minimal APIs
public static class AddValidationFilterExtension
{
public static TBuilder AddValidationFilter<TBuilder>(
this TBuilder builder
) where TBuilder : IEndpointConventionBuilder
{
return builder.AddEndpointFilterFactory((factoryCtx, next) =>
{
var sp = factoryCtx.ApplicationServices.GetRequiredService<IServiceProviderIsService>();
var validatableParameters = factoryCtx.MethodInfo.GetParameters()
@aradalvand
aradalvand / QueryableExtensions.cs
Last active July 31, 2023 19:42
Solves the Hot Chocolate + EF Core + DTO overfetching problem for related entities
namespace Translator;
public static class QueryableExtensions
{
public static IQueryable<T> AsTranslatable<T>(this IQueryable<T> source)
{
if (source is TranslatableQuery<T> query)
return query;
return new TranslatableQueryProvider(source.Provider).CreateQuery<T>(source.Expression);
@aradalvand
aradalvand / DockerfileForDotNetCore.md
Last active April 11, 2022 02:11
Dockerfile for multi-project ASP.NET Core applications

Tailored to multi-project solutions:

TL;DR:

Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS builder
WORKDIR /app
COPY <other-proj-dir>/*.csproj <other-proj-dir>/
COPY <web-proj-dir>/*.csproj <web-proj-dir>/
RUN dotnet restore 
@aradalvand
aradalvand / DockerfileForSvelteKit.md
Last active April 24, 2024 20:31
Dockerfile and .dockerignore for SvelteKit:

*This Dockerfile is intended for SvelteKit applications that use adapter-node. So, the Dockerfile below assumes that you have already installed and configured the adapter.

Dockerfile:

FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json .
RUN npm ci
COPY . .
RUN npm run build