Skip to content

Instantly share code, notes, and snippets.

View michaeldimoudis's full-sized avatar

Michael Dimoudis michaeldimoudis

View GitHub Profile
@davidfowl
davidfowl / FromSqlInterpolatedStringHandler.cs
Last active July 3, 2023 12:55
Implementation of parameterized sql queries using string interpolation handlers
using System.Data.Common;
using System.Runtime.CompilerServices;
using System.Text;
using Npgsql;
GetCatalogItemsSql(null, null, null, 10);
void GetCatalogItemsSql(int? catalogBrandId, int? before, int? after, int pageSize)
{
// This looks like it would be susceptible to SQL injection, but it's not.
@davepcallan
davepcallan / GlobalExceptionHandlerProblemDetails.cs
Last active March 3, 2024 04:55
Example of using .NET 8 IExceptionHandler to return 7807 ProblemDetails compliant response to client
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using System.Net;
namespace Samples;
public class GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger) : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(
HttpContext httpContext,