Skip to content

Instantly share code, notes, and snippets.

@bradwilson
bradwilson / Cacheability.cs
Created January 23, 2014 20:53
Using chaining to create cached results in ASP.NET Web API v2
public enum Cacheability
{
NoCache,
Private,
Public,
}
@darrelmiller
darrelmiller / gist:8548166
Created January 21, 2014 20:54
How to tell Web API 2.1 to allow errors to propagate up the MessageHandler pipeline so all exceptions can be converted to HttpResponseMessages in one place.
class Program
{
static void Main(string[] args)
{
var server = WebApp.Start("http://localhost:1002/", (app) =>
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Services.Replace(typeof(IExceptionHandler), new RethrowExceptionHandler());
public class Result<T>
{
public bool IsSuccess { get; private set; }
public string ErrorMessage { get; private set; }
public IEnumerable<T> Results { get; private set; }
private Result()
{ }
public static Result<T> Success(IEnumerable<T> results)
@gregoryyoung
gregoryyoung / gist:7690486
Created November 28, 2013 11:31
updated to support actions to funcs
namespace crap
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public class PartialAppPlayground
namespace Fabrik.Common.Net
{
/// <summary>
/// RFC5988 Link relation types <see cref="http://www.iana.org/assignments/link-relations/link-relations.xml"/>.
/// </summary>
public static class LinkRelations
{
/// <summary>
/// Refers to a resource that is the subject of the link's context.
@jen20
jen20 / GetEventStoreRepository.cs
Last active August 13, 2018 18:36
Event Store implementation of the CommonDomain IRepository interface and integration tests
public class GetEventStoreRepository : IRepository
{
private const string EventClrTypeHeader = "EventClrTypeName";
private const string AggregateClrTypeHeader = "AggregateClrTypeName";
private const string CommitIdHeader = "CommitId";
private const int WritePageSize = 500;
private const int ReadPageSize = 500;
private readonly Func<Type, Guid, string> _aggregateIdToStreamName;
@benfoster
benfoster / gist:4577974
Created January 20, 2013 11:16
Hypermedia links that meet the JSON HAL specification. http://tools.ietf.org/html/draft-kelly-json-hal-03
{
"_links": {
"self": [
{
"href": "/orders/10"
}
],
"warehouse": [
{
"href": "/warehouse/10"
@benfoster
benfoster / gist:4488755
Created January 8, 2013 22:48
Patching in ASP.NET Web API
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
@benfoster
benfoster / gist:4416655
Last active June 19, 2021 18:32
A lightweight message bus using TPL DataFlow
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace TDFDemo
{
class Program
{
@benfoster
benfoster / gist:3636956
Created September 5, 2012 13:57
Api Key authentication handler
public class ApiKeyAuthHandler : DelegatingHandler
{
private const string ApiKeySchemeName = "ApiKey";
private const string AuthResponseHeader = "WWW-Authenticate";
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var authHeader = request.Headers.Authorization;
if (authHeader != null && authHeader.Scheme == ApiKeySchemeName)