This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO.Pipelines; | |
using System.Net; | |
using System.Net.Security; | |
using Microsoft.AspNetCore.Connections; | |
using Microsoft.AspNetCore.Connections.Features; | |
using Microsoft.AspNetCore.Http.Features; | |
using Microsoft.AspNetCore.Server.Kestrel.Core; | |
var builder = WebApplication.CreateBuilder(args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.DataAnnotations; | |
using Microsoft.EntityFrameworkCore; | |
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
app.MapPost("/todos", async (CreateTodo createTodo, TodoDb db) => | |
{ | |
// This is where the implicit conversion comes in | |
db.Todos.Add(createTodo); |
This document now exists on the official ASP.NET core docs page.
- Application
- Request Handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Buffers; | |
using System.Net.WebSockets; | |
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
app.MapGet("/ws", async (HttpContext context) => | |
{ | |
const int MaxMessageSize = 1024 * 1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env dotnet run | |
var builder = WebApplication.CreateBuilder(args); | |
var config = builder.Configuration; | |
var connString = config["connectionString"] ?? "Data Source=todos.db"; | |
builder.AddDbContext<TodoDb>(options => options.UseSqlite(connString)); | |
builder.AddSqlite<Todo>(connString) // Higher level API perhaps? | |
var app = builder.Build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Reflection; | |
using System.Runtime.Loader; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Mvc.ApplicationParts; | |
using Microsoft.AspNetCore.Mvc.Infrastructure; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var t1 = DoFooAsync(obj); | |
var t2 = DoBarAsync(obj); | |
var t = await WhenAnySuccessOrAllFail(t1, t2); | |
async Task WhenAnySuccessOrAllFail(params Task[] tasks) | |
{ | |
var remaining = new List<Task>(tasks); | |
while (remaining.Count > 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Question: Implement a route matching enging | |
// Given a list of routes as a list of strings and a matching route, build a route matching engine | |
// that returns true if a path matches. | |
const routes = ['/foo/blah/bar', '/foo', '/products'] | |
function buildTrie(routes) { | |
var root = { path: {} }; | |
for (var route of routes) { | |
var node = root; |