Skip to content

Instantly share code, notes, and snippets.

View joliver's full-sized avatar
💭
It's complicated

Jonathan Oliver joliver

💭
It's complicated
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 / Example.cs
Created November 2, 2009 20:04
CQRS Sample Routing Table
private static void Main()
{
IContainer container = null; // build container here
RegisterRoutes(container); // routes don't change
using (threadSpecificContainer = container.CreateInnerContainer())
{
var handler = new UnitOfWorkMessageHandler<IContainer>(
threadSpecificContainer,
new TransactionScope(),
namespace Cqrs.Domain
{
using System;
using Messages;
public abstract class BaseAggregateRoot<TAggregate> : IAggregateRoot
where TAggregate : class, IAggregateRoot
{
private static readonly IDispatchMessages<TAggregate> Dispatcher = new MessageDispatcher<TAggregate>();
namespace Cqrs.Persistence
{
using System;
using System.Collections.Generic;
using Domain;
public class DomainUnitOfWork : IUnitOfWork
{
private readonly ICollection<IAggregate> inserted = new HashSet<IAggregate>();
private readonly ICollection<IAggregate> updated = new HashSet<IAggregate>();
lib/jspec.timers.js | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/jspec.timers.js b/lib/jspec.timers.js
index c88d10b..82df7ad 100644
--- a/lib/jspec.timers.js
+++ b/lib/jspec.timers.js
@@ -24,7 +24,7 @@
* @api public
*/
lib/jspec.xhr.js | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/lib/jspec.xhr.js b/lib/jspec.xhr.js
index 482a3c4..f0a618a 100644
--- a/lib/jspec.xhr.js
+++ b/lib/jspec.xhr.js
@@ -34,7 +34,14 @@
*/
namespace ConsoleApplication1
{
using System;
using System.Transactions;
using Raven.Client.Document;
public static class MainProgram
{
private const string RavenUrl = "http://localhost:8080";
private const string CustomDatabaseName = "MyDatabase";
@joliver
joliver / gist:784370
Created January 18, 2011 12:27
Bug in Json.NET 4.0r1?
public void Test()
{
var serializer = new Newtonsoft.Json.JsonSerializer();
using (var memoryStream = new MemoryStream())
{
using (var bsonWriter = new BsonWriter(memoryStream))
serializer.Serialize(bsonWriter, 12345);
Console.Write("Stream length is: " + memoryStream.Length); // shouldn't be *0*!
@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();
@joliver
joliver / DDL.sql
Created April 5, 2011 04:11
Blog--CQRS: Out of Sequence Messages and Read Models
CREATE TABLE [dbo].[Messages]
(
[AggregateId] [uniqueidentifier] NOT NULL,
[Version] [int] NOT NULL CHECK ([Version] > 0),
[Inserted] [datetime] NOT NULL DEFAULT (GETUTCDATE()),
[Headers] [varbinary](max) NOT NULL,
[Payload] [varbinary](max) NOT NULL,
CONSTRAINT [PK_Messages] PRIMARY KEY CLUSTERED ([AggregateId], [Version])
);