Skip to content

Instantly share code, notes, and snippets.

View slashdotdash's full-sized avatar

Ben Smith slashdotdash

View GitHub Profile
public class EventDispatcher : IDispatchEvents
{
private readonly IDictionary<Type, Action<IDomainEvent>> handlers = new Dictionary<Type, Action<IDomainEvent>>();
public virtual void Register<TEvent>(Action<TEvent> handler)
where TEvent : class, IDomainEvent
{
// re-wrap delegate
this.handlers[typeof(TEvent)] = @event => handler(@event as TEvent);
}
@joliver
joliver / gist:875528
Created March 18, 2011 02:35
EventStore Fluent Builder API
return EventStore.Wireup.Init()
.UsingSqlPersistence("EventStore")
.InitializeDatabaseSchema()
.UsingCustomSerializer(new JsonSerializer())
.Compress()
.EncryptWith(EncryptionKey)
.UsingAsynchronousDispatcher()
.PublishTo(new DelegateMessagePublisher(DispatchCommit))
.HandleExceptionsWith(DispatchErrorHandler)
.Build();
@kof
kof / inherits.js
Created March 24, 2011 13:10
nodejs like utility method for inheritance
/**
* Inherit prototype properties
* @param {Function} ctor
* @param {Function} superCtor
*/
_.mixin({
inherits: (function(){
function noop(){}
function ecma3(ctor, superCtor) {
@gregoryyoung
gregoryyoung / Example.cs
Created July 6, 2011 19:27
Simple.Testing.Documentation.Example
public class AccountSpecifications
{
public Specification when_constructing_an_account = new
ConstructorSpecification<Account>()
{
When = () => new Account("Jane Smith", 17),
Expect =
{
account => account.AccountHolderName == "Jane Smith",
account => account.UniqueIdentifier == 17,
@yevhen
yevhen / SpecificationFixture.cs
Created July 27, 2011 15:26
NUnit support for Greg Young's Simple.Testing "framework"
[TestFixture]
public class SpecificationFixture
{
[Test, TestCaseSource("GetSpecificationTestCases")]
public void Verify(SpecificationToRun spec)
{
var runner = new SpecificationRunner();
RunResult result = runner.RunSpecifciation(spec);
if (result.Passed)
@rdkhatch
rdkhatch / RestoreNugetPackages.bat
Created February 20, 2012 23:59
Easily Restores Nuget Packages for a Solution - So you can exclude 'packages' folder from Source Control. (Much better than having Build Targets everywhere.)
@ECHO OFF
:: Installs all Nuget packages for all Projects, Recursively.
:: Ignores Resharper folders
:: DOS Help - http://www.dostips.com/forum/viewtopic.php?f=3&t=431
SET NUGET="Nuget.exe"
SET SOLUTIONDIR=..\src
ECHO.
ECHO Finding Projects in Solution... (saving to ProjectsUsingNuget.log.txt)
ECHO ------------------------------
@jmibanez
jmibanez / gist:2140974
Created March 20, 2012 20:29
Using restify with connect
// Restify server config here
var server = restify.createServer({
name: 'restify-test',
version: '1.0.0',
});
// ...
// Connect config here
var connectApp = connect()
@model EditUserModel
@using (Html.BeginForm())
{
<div>
@Html.HiddenFor(m => m.Id)
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
@Html.DropDownListFor(m => m.CountryId, Model.Countries)
@model UserViewModel
@using (Html.BeginForm())
{
<div>
@Html.HiddenFor(m => m.Id)
@Html.TextBoxFor(m => m.FirstName)
@Html.TextBoxFor(m => m.LastName)
@Html.DropDownListFor(m => m.CountryId, Model.Countries)
@koblas
koblas / backbone-filtered-collection.js
Created June 26, 2012 14:03
Filtered Collection Wrapper For Backbone
(function(_, Backbone) {
var defaultFilter = function() {return true;};
/**
* This represents a filtered collection. You can either pass a filter or
* invoke setFilter(filter) to give a filter. The filter is identical to
* that which is used for _.select(array, filter)
*
* false filter indicates no filtering.
*