Skip to content

Instantly share code, notes, and snippets.

View PBeckerr's full-sized avatar

PBeckerr

View GitHub Profile
@PBeckerr
PBeckerr / Program.cs
Created September 11, 2024 09:58
Develappers Status Page
var builder = WebApplication.CreateBuilder(args);
using var app = builder.Build();
app.MapGet("/", () => Results.File(Path.Combine(builder.Environment.WebRootPath, "index.html"), "text/html"));
// See https://aka.ms/new-console-template for more information
using System.Diagnostics;
using System.Net;
using System.Threading.RateLimiting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Polly;
using Polly.RateLimit;
using Polly.RateLimiting;
public static class TaskHelper
{
/// <summary>
/// Say you have 1000 URLs, and you only want to have 50 requests open at a time; but as soon as one request completes, you open up a connection to the next URL in the list. That
/// way, there are always exactly 50 connections open at a time, until the URL list is exhausted.
/// </summary>
/// <param name="items"></param>
/// <param name="awaitableFunc"></param>
/// <param name="maxDegreeOfParallism"></param>
/// <typeparam name="TResult"></typeparam>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Dsoc.Api.Infrastructure.Extensions
{
public static class TaskHelper
{
@PBeckerr
PBeckerr / Arch.md
Created March 20, 2020 19:42
Arch.md

Minimal template for clean web api with vertical sliced architecture based on AutoMapper, MediatR and FluentValidation

Points of interest

  • 1:1 Mapping is setup over a IMapFrom<,> interface, for more complex cased implement a public void Mapping(Profile profile) method to override to default implementation of the interface
  • Implement a AbstractValidator<,> to setup validation
  • Controllers should only contain a reference to IMediator and nothing else
  • MediatR handles all request, commands and notifications
    • Commands = creates and updates
    • Queries = queries
    • RequestValidationBehavior applies validations from FluentValidation to data that is passed in based on their respective AbstractValidator<,>
  • CustomExceptionHandlerMiddleware is a middleware that captures exceptions and display them in a better unified format
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic;
using System.Linq.Expressions;
using System.Reflection;
namespace ConsoleApp2
{
internal static class Program
@PBeckerr
PBeckerr / Filter.cs
Created January 17, 2020 22:42
Well this got out of hand by i like it
public static class WhereFilterBuilderExpression
{
public static IEnumerable<T> FilterByExpr<T>(this IEnumerable<T> source, object filterObject)
{
return source.Where(FilterByCore());
Func<T, bool> FilterByCore()
{
var type = typeof(T);
var param = Expression.Parameter(type);
@PBeckerr
PBeckerr / DefaultInterfaces.cs
Last active January 17, 2020 12:04
Hier scheiden sich die Geister :D
public interface IMapFrom<T>
{
void Mapping(Profile profile)
{
profile.CreateMap(typeof(T), this.GetType());
profile.CreateMap(this.GetType(), typeof(T));
}
}
//Ich mapp einfach 1:1
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading;
using System.Threading.Tasks;
@PBeckerr
PBeckerr / WebHostExtensions.cs
Created November 14, 2019 10:59
WebHostExtensions.cs
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureKeyVault;
namespace Dso.Api.Service.Core.Extensions
{
public static class KeyVaultWebHostExtension