Skip to content

Instantly share code, notes, and snippets.

View khellang's full-sized avatar

Kristian Hellang khellang

View GitHub Profile
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
[DebuggerTypeProxy(typeof(CircularBuffer<>.DebugView))]
[DebuggerDisplay("Count = {Count}, Type = {Collection}")]
public class CircularBuffer<T> : IReadOnlyCollection<T>, ICollection
{
@khellang
khellang / Program.cs
Last active September 30, 2016 13:55
Less allocatey DateTimeOffset RFC1123 formatting
using System;
using static System.Text.Encoding;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnostics.Windows;
using BenchmarkDotNet.Running;
using Xunit;
public static class Program
{
[Route("customers")]
public class CustomerController
{
public CustomerController(DbContext context)
{
Context = context;
}
private DbContext Context { get; }
@khellang
khellang / Application.cs
Last active August 10, 2016 09:23
The nightmares of virtual methods.
public class MyAwesomeStartup : Startup<IContainer>
{
public MyAwesomeStartup(IServiceProviderFactory factory) : base(factory)
{
}
protected override void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
@khellang
khellang / Program.cs
Last active July 28, 2016 10:58
Assign to a getter-only auto property
using System;
using System.Reflection;
public static class Program
{
public static void Main()
{
var test = new T();
var testType = test.GetType();

Current Adapters

  • StructureMap.Dnx
  • Autofac.Extensions.DependencyInjection
  • DryIoc.AspNetCore.DependencyInjection
  • Grace.DependencyInjection.Extensions
  • LightInject.Microsoft.DependencyInjection

Proposed StructureMap Alternatives

using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
public class Program
{
public static void Main(string[] args)
{
var services = new ServiceCollection();
public class Startup : IStartup
{
private static readonly Assembly[] ControllerAssemblies = { typeof(Startup).GetTypeInfo().Assembly };
public Startup(IHostingEnvironment environment, ILoggerFactory logging)
{
Environment = environment;
ConfigureLogging(logging);
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
public delegate Task AppFunc(IDictionary<string, object> env);
public delegate AppFunc MidFunc(AppFunc next);
public delegate MidFunc MidFactoryFunc(IDictionary<string, object> props);
@khellang
khellang / Program.cs
Last active February 4, 2016 15:02
Assembly loading and scanning
public static class Program
{
private static readonly AssemblyName CurrentAssemblyName = typeof(Program).Assembly.GetName();
public static void Main()
{
var mainDomain = AppDomain.CurrentDomain;
var assemblyFolders = mainDomain.GetAssemblyFolders();