Skip to content

Instantly share code, notes, and snippets.

### 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 August 29, 2015 13:56
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
// 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;
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 October 11, 2024 08:02
Better enums in C# for DDD ... based on Jimmy Bogards Enumeration class
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 05:48
A nice small wrapper around DateTime. Makes it possible to override the returned DateTime, which is very handy in unit tests
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;
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 December 16, 2015 21:50
A way to send notifications through Redis, that I build. Requires these NuGet packages: *ServiceStack.Redis *Protobuf-net
public interface IMessageSerializer<T> where T : class
{
string Serialize(T message);
byte[] SerializeBytes(T message);
T Deserialize(string message);
T Deserialize(byte[] message);
}
public abstract class Entity
{
public int Id { get; set; }
}