Skip to content

Instantly share code, notes, and snippets.

View davidfowl's full-sized avatar

David Fowler davidfowl

View GitHub Profile
@davidfowl
davidfowl / ResourceModel.md
Last active April 27, 2025 15:51
Aspire Resource Model: Concepts, Design, and Authoring Guidance

Aspire Resource Model: Concepts, Design, and Authoring Guidance

Audience – Aspire integrators, advanced users, and contributors who are defining custom resource types, implementing publishers, or working across both runtime and publish workflows.
Just getting started? Jump straight to Quick Start and come back later for the deep‑dive.


Quick Start

A two‑minute "hello‑world" that shows the happy path.

@davidfowl
davidfowl / git.cs
Last active December 12, 2024 09:11
Sample schema for git add, clone, commit, clean
using System;
using System.Collections.Generic;
using CliWrap;
namespace GitCLIWrapper;
public static class Git
{
public static Command Clone(
string repository,
@davidfowl
davidfowl / WaitToStart.cs
Last active December 19, 2024 16:38
Wait to start command
using Microsoft.Extensions.DependencyInjection;
var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("redis", "redis").WithExplicitStart();
builder.Build().Run();
public static class ExplicitStartupExtensions
{
@davidfowl
davidfowl / UsingCopilot.md
Created March 30, 2024 22:51
Github copilot

Me using copilot

Copilot_Aspire.mp4
using System.Text.Json;
using System.Text.Json.Serialization;
var data = new[]
{
"Hello"u8.ToArray(),
"Twitter"u8.ToArray(),
"Optimize"u8.ToArray()
}
.Select(m => new Message(m)).ToArray();
@davidfowl
davidfowl / TimeHttpEvents.cs
Last active August 7, 2024 01:57
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();
public static class ConfigurationBinderExtensions
{
public static ValidateOptionsResult BindAndValidate<TOptions>(this IConfiguration configuration, TOptions instance) where TOptions : class, new()
{
configuration.Bind(instance);
var validateOptions = new DataAnnotationValidateOptions<TOptions>(Options.DefaultName);
return validateOptions.Validate(Options.DefaultName, instance);
}
}
@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.
@davidfowl
davidfowl / SingleThreadedScheduler.cs
Created October 11, 2022 02:53
A sample showing how to schedule work on a single thread
using System.Collections.Concurrent;
using System.Threading.Channels;
var channel = Channel.CreateUnbounded<int>();
var syncContext = new SingleThreadedSyncContext();
syncContext.Post(async _ =>
{
await foreach (var item in channel.Reader.ReadAllAsync())
@davidfowl
davidfowl / DefaultConfigProvider.cs
Last active April 11, 2025 11:04
Allows specifying default configuration values in code while still allowing other sources to override
using Microsoft.Extensions.Configuration.Memory;
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddConfigurationDefaults(new()
{
{ "request:timeout", "60" }
});
var app = builder.Build();