Skip to content

Instantly share code, notes, and snippets.

View yreynhout's full-sized avatar
👔
ceci n'est pas une cravate

Yves Reynhout yreynhout

👔
ceci n'est pas une cravate
View GitHub Profile
@yreynhout
yreynhout / Projection.cs
Created August 29, 2012 17:07
Sample 1 - before
public class CurrentPortfolioProjection :
IHandle<AddedRealtyToPortfolio>,
IHandle<RemovedRealtyFromPortfolio> {
Func<PortfolioContext> _contextFactory;
public CurrentPortfolioProjection(Func<PortfolioContext> contextFactory) {
_contextFactory = contextFactory;
}
@yreynhout
yreynhout / Projection.cs
Created August 29, 2012 17:15
Sample 1 - after
public class CurrentPortfolioProjection :
IHandle<AddedRealtyToPortfolio>,
IHandle<RemovedRealtyFromPortfolio> {
IProjectionSqlOperations<CurrentPortfolioEntry> _operations;
public CurrentPortfolioProjection(IProjectionSqlOperations<CurrentPortfolioEntry> operations) {
_operations = operations;
}
public class PushBasedProjectionSqlOperations<TProjection> :
IProjectionSqlOperations<TProjection> {
IObserver<ISqlStatement> _observer;
ISqlStatementFactory _factory;
public PushBasedProjectionSqlOperations(
IObserver<ISqlStatement> observer,
ISqlStatementFactory factory) {
_observer = observer;
@yreynhout
yreynhout / SqlStatementCollector.cs
Created August 29, 2012 17:45
Sample 2 - Collector
public class SqlStatementCollector : IObserver<ISqlStatement> {
List<ISqlStatement> _statements;
public SqlStatementCollector() {
_statements = new List<ISqlStatement>();
}
public ISqlStatement[] CollectedStatements {
get {
return _statements.ToArray();
@yreynhout
yreynhout / ThresholdedSqlStatementFlusher.cs
Created August 29, 2012 17:59
Sample 2 - ThresholdedFlusher
public class ThresholdedSqlStatementFlusher : IObserver<ISqlStatement> {
readonly int _threshold;
readonly ISqlConnectionTransactionFactory _connectionTransactionFactory;
readonly ISqlBatchWriterFactory _batchWriterFactory;
readonly List<ISqlStatement> _statements;
public ThresholdedSqlStatementFlusher(
int threshold,
@yreynhout
yreynhout / Video.cs
Created October 12, 2012 19:14
VideoTape - Video
public class Video : VoodooMagic {
public static Video New(VideoId id, Title title, Date releaseDate) {
return new Video(
Events.NewVideo(id, title, releaseDate));
}
Video(object initialEvent) {
ApplyEvent(initialEvent);
}
@yreynhout
yreynhout / VideoSimple.cs
Created October 12, 2012 19:25
VideoTape - Video
// In its simplest form
public class VideoTape {
// as purely constructor injection of a "parent"
public VideoTape(Video video) {
_video = video;
}
}
public class VideoTape : IVideoObjectInheritor {
// as a hidden-from-the-public-eye method based injection
@yreynhout
yreynhout / DeferredDecider.cs
Created October 13, 2012 14:07
Simple stab at deferred decision making
public class RenovationPolicy {
public RenovationRequest FileRequestFor(Building building) {
if(building.WasBetween(10.YearsAgo(), 25.YearsAgo()).WhenConstructed()) {
//...
}
}
}
public class Building {
internal BuildingAgeConstraint WasBetween(Date lower, Date upper) {
@yreynhout
yreynhout / Seeker1.cs
Created October 22, 2012 20:26
Seek simplicity & loose coupling between aggregate root and event builder.
public interface IMessageBuilder {
object Build();
}
public interface IEventBuilder : IMessageBuilder {
IMessageBuilder IdentifiedBy(Guid id, int version);
}
public abstract class AggregateRootEntity {
//...
@yreynhout
yreynhout / gist:4716699
Last active December 12, 2015 04:48 — forked from JefClaes/gist:4716622
using System;
using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Subjects;
namespace NaiveEventSourcing {
class Program {
static void Main(string[] args) {
var travelerRepository = new AlwaysNewTravelerRepository();
var travelerService = new TravelerService(travelerRepository);