Skip to content

Instantly share code, notes, and snippets.

View davidfowl's full-sized avatar

David Fowler davidfowl

View GitHub Profile
@davidfowl
davidfowl / dotnetlayout.md
Last active April 18, 2024 23:31
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
 tests/
@davidfowl
davidfowl / .NET6Migration.md
Last active April 11, 2024 02:02
.NET 6 ASP.NET Core Migration
@davidfowl
davidfowl / MinimalAPIs.md
Last active April 10, 2024 04:24
Minimal APIs at a glance
@davidfowl
davidfowl / TimeHttpEvents.cs
Last active April 6, 2024 20:17
Using Yarp.Telemetry.Consumption to track outbound network events (this package isn't tied to YARP)
using System.Diagnostics;
using System.Net.Sockets;
using System.Security.Authentication;
using Yarp.Telemetry.Consumption;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTelemetryConsumer<TelemetryConsumer>();
var app = builder.Build();
@davidfowl
davidfowl / UsingCopilot.md
Created March 30, 2024 22:51
Github copilot

Me using copilot

Copilot_Aspire.mp4
@davidfowl
davidfowl / Example1.cs
Last active March 28, 2024 20:36
How .NET Standard relates to .NET Platforms
namespace Analogy
{
/// <summary>
/// This example shows that a library that needs access to target .NET Standard 1.3
/// can only access APIs available in that .NET Standard. Even though similar the APIs exist on .NET
/// Framework 4.5, it implements a version of .NET Standard that isn't compatible with the library.
/// </summary>INetCoreApp10
class Example1
{
public void Net45Application(INetFramework45 platform)
@davidfowl
davidfowl / PeekJsonToken.cs
Last active February 29, 2024 17:47
Peeking at a JSON token using a PipeReader in the ASP.NET Core request pipeline
using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO.Pipelines;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using System;
using System.Threading.Tasks;
namespace System.Collections.Concurrent
{
public static class ConcurrentDictionaryExtensions
{
/// <summary>
/// Provides an alternative to <see cref="ConcurrentDictionary{TKey, TValue}.GetOrAdd(TKey, Func{TKey, TValue})"/> that disposes values that implement <see cref="IDisposable"/>.
/// </summary>
@davidfowl
davidfowl / gist:3173128
Created July 24, 2012 22:36 — forked from jmangelo/gist:3173109
MethodInfo.Invoke is slow... open instance delegate to the rescue
using System;
using System.Linq;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
using System.Collections.Generic;
namespace ConsoleApplication3
{
class Program
@davidfowl
davidfowl / DynamicController.cs
Last active October 9, 2023 12:30
Dynamically loading a controller
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Infrastructure;