Skip to content

Instantly share code, notes, and snippets.

Avatar

Søren Pedersen spewu

View GitHub Profile
View gist:f0f337684515d1b6c5c6d76d0c715b2f
### Keybase proof
I hereby claim:
* I am spewu on github.
* I am spewu (https://keybase.io/spewu) on keybase.
* I have a public key ASAeu6D8FdngkLl6N6_Xxv8kAqCaX6oIWFKBD6Ien2_8Ewo
To claim this, I am signing this object:
@spewu
spewu / Ninject.Mvc.cs
Last active Aug 29, 2015
Example Ninject configuration for an ASP.NET MVC application. I use a custom ControllerFactory only to get better exception messages if a Ninject binding is not configured properly
View Ninject.Mvc.cs
// In Global.asax, in Application_Start make a call to NinjectContainer.Register(...); providing the NinjectModules to configure
namespace Test
{
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using Ninject.Modules;
View Ninject.WebApi.cs
using Ninject.Modules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Http.Dependencies;
// A small Library to configure Ninject (A Dependency Injection Library) with a WebAPI Application.
// To configure, take the following steps.
@spewu
spewu / Enumeration.cs
Last active Dec 21, 2016
Better enums in C# for DDD ... based on Jimmy Bogards Enumeration class
View Enumeration.cs
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
[Serializable]
[DebuggerDisplay("{DisplayName} - {Value}")]
public abstract class Enumeration<TEnumeration, TValue> : IComparable<TEnumeration>, IEquatable<TEnumeration>
where TEnumeration : Enumeration<TEnumeration, TValue>
where TValue : IComparable
@spewu
spewu / SystemTime.cs
Created May 19, 2013
A nice small wrapper around DateTime. Makes it possible to override the returned DateTime, which is very handy in unit tests
View SystemTime.cs
using System;
using System.Diagnostics.CodeAnalysis;
public class SystemTime
{
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Reviewed. Suppression is OK here.")]
public static Func<DateTime> Now = () => DateTime.Now;
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:FieldsMustBePrivate", Justification = "Reviewed. Suppression is OK here.")]
public static Func<DateTime> UtcNow = () => DateTime.UtcNow;
View TimeSpanExtensions.cs
using System;
using System.Text;
public static class TimeSpanExtensions
{
/// <summary>
/// Returns a string containing the human readable version of this time span, i.e 4 days, 3 hours, 26 minutes and 13.4 seconds.
/// </summary>
/// <param name="timeSpan"></param>
/// <returns></returns>
@spewu
spewu / IMessageSerializer.cs
Last active Dec 16, 2015
A way to send notifications through Redis, that I build. Requires these NuGet packages: *ServiceStack.Redis *Protobuf-net
View IMessageSerializer.cs
public interface IMessageSerializer<T> where T : class
{
string Serialize(T message);
byte[] SerializeBytes(T message);
T Deserialize(string message);
T Deserialize(byte[] message);
}
View Entity.cs
public abstract class Entity
{
public int Id { get; set; }
}
You can’t perform that action at this time.