Skip to content

Instantly share code, notes, and snippets.

View randomcodenz's full-sized avatar

Neal Blomfield randomcodenz

View GitHub Profile
@randomcodenz
randomcodenz / AutofacAppBuilder.cs
Created November 3, 2014 19:30
Autofac aware OWIN middleware - trying to inject the equivalent of IDependencyResolver into any middleware that needs it
public class AutofacAppBuilder : IAppBuilder
{
private readonly IAppBuilder _inner;
private readonly IContainer _container;
public AutofacAppBuilder( IAppBuilder inner, IContainer container )
{
_inner = inner;
_container = container;
}
@randomcodenz
randomcodenz / Snip1.cs
Created May 30, 2014 03:44
FuturePublishing and Message Versioning
// Current ScheduleMe message creation ...
var typeName = typeNameSerializer.Serialize( typeof( T ) );
var messageBody = serializer.MessageToBytes( message );
var scheduleMe = new ScheduleMe
{
WakeTime = futurePublishDate,
BindingKey = typeName,
CancellationKey = cancellationKey,
InnerMessage = messageBody
};
// Explicit opt-in message versioning via a marker interface and exchange to exchange bindings to
// route messages from publishing exchange to previous message version exchanges.
// Message serialisation adds all message versions into the message headers and deserialisation
// keeps trying the listed types until it finds one it can create (or runs out and throws an exception)
public interface ISupersede<T> where T : class { }
@randomcodenz
randomcodenz / Commands.cs
Created February 10, 2014 21:29
Lightweight CQS / DomainEvents Infrastructure
namespace Domain.Commands
{
public interface ICommandInvoker
{
// Extreme CQS - probably should have a version of execute that can return an Id<T>
void Execute<T>( T command );
}
// If you alter the void Execute<T> in ICommandInvoker you will need to alter this as well
public interface ICommandHandler<T>
<#
.Synopsis
Provides a PowerShell wrapper over MSDeploy.
.Description
Allows MSDeploy to be invoked via powershell without shelling out to Start-Process or cmd.exe. Abuses reflection and internal knowledge of the msdeploy exe - may fail on other versions
.Parameter Verb
Action to perform.
@randomcodenz
randomcodenz / OuterJoinExtensions.cs
Created July 16, 2012 05:03
Outer join extension
public static class OuterJoinExtensions
{
public static IEnumerable<TResult> LeftOuterJoin( this IEnumerable<TLeft> left, IEnumerable<TRight> right, Func<TLeft, TLefTKey> leftKey, Func<TRight,TRightKey> rightKey, Func<TLeft,TRight,TResult> resultSelector )
{
return left.GroupJoin( right, leftKey, rightKey, (key,matches) => { Key = key, Matches = matches })
.SelectMany( x => x.Matches.DefaultIfEmpty(), resultSelector);
}
}
using System.Collections.Generic;
namespace GoFetchV2.Web.ViewHelpers
{
public class RadioButtonList : List<RadioButtonListItem>
{
public RadioButtonListItem this[ string value ]
{
get
{
using System;
using System.Web.Mvc;
using System.Web.Routing;
using GoFetchV2.Infrastructure;
namespace GoFetchV2.Web.Mvc
{
/// <summary>
/// Conventions are as follows:
/// 1. All controllers must be registered in the container
// Implementation of this basically looks up the appropriate command handler from a container
// and calls Handle passing the command
public interface ICommandExecutor
{
Guid ExecuteCreate<T>( T createCommand );
void Execute<T>( T command );
}
public interface ICommandHandler<T>
{
using System;
using ExtensionMethods;
namespace Events
{
public static class DomainEvents
{
private static IEventHandlerResolver _handlerResolver;
public static bool IsInitialised()