Skip to content

Instantly share code, notes, and snippets.

View yevhen's full-sized avatar
🇺🇦

Yevhen Bobrov yevhen

🇺🇦
View GitHub Profile
@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)
public class SomeCommandHandler
{
uow? where are you?
public void Handle(SomeCommand command)
{
var agg = uow.GetById(command.AggId);
agg.Foo();
}
}
@yevhen
yevhen / gist:1731790
Created February 3, 2012 19:04 — forked from joliver/gist:1311195
NServiceBusCommitDispatcher
public sealed class NServiceBusCommitDispatcher : IPublishMessages
{
private const string AggregateIdKey = "AggregateId";
private const string CommitVersionKey = "CommitVersion";
private const string EventVersionKey = "EventVersion";
private const string BusPrefixKey = "Bus.";
private readonly IBus bus;
public NServiceBusCommitDispatcher(IBus bus)
{
@yevhen
yevhen / gist:5199613
Created March 19, 2013 20:07
The concept of message handling Component and the example of message handler chaining via functional composition
/* somewhere in your Core.CQRS */
// Base class for all ES-based aggregate command handling components;
//
// NOTE: "Component" is a logical grouping of message handlers by function
// They provide good place to encapsulate chaining of cross-cutting concerns
// into a pipeline, providing simplified helper methods for registration of message handlers
//
// Components are similar to Services, thus they only contain handlers of single type (ie Command Handlers only)
// Components operate on envelope (infrastructure) level
public class Dispatcher
{
readonly Dictionary<Type, Func<object, object>> _dictionary = new Dictionary<Type, Func<object, object>>();
public void Register<TMessage, TResult>(Func<TMessage, TResult> func)
{
_dictionary.Add(typeof(TMessage), x => func((TMessage) x));
}
public void Register<TMessage>(Action<TMessage> act)
@yevhen
yevhen / was_es_ucs.txt
Created November 30, 2013 18:35
Use-cases for event store on top of Windows Azure Table Storage
*****************
*** Use-Cases ***
*****************
Writing
#-----#
- Creating stream with given id and initial events
* Detect if stream with given id already exists
public void Start()
{
ShowHelp();
ShowVersion();
SetQuiet();
SetSilent();
SetTrace();
Initialize();
@yevhen
yevhen / Firewall.cs
Created March 7, 2016 15:25 — forked from ReubenBond/Firewall.cs
Snippet to open firewall ports in Windows.
// NOTE: Add a COM reference to NetFwTypeLib
namespace Site.Setup
{
using System;
using System.Linq;
using NetFwTypeLib;
/// <summary>
@yevhen
yevhen / AsyncBatcher.cs
Created March 18, 2017 14:20
Example of AsyncBatcher pattern for acknowledged processing using Orleankka
[Reentrant("IsReentrant")]
public class SaveMentionBatcher : Actor
{
public static bool IsReentrant(object message) => true;
public static TimeSpan FlushTimeout = TimeSpan.FromSeconds(10);
public static int BatchSize = 512;
readonly List<BufferItem> buffer = new List<BufferItem>();
ActorRef topic;
@yevhen
yevhen / DurableTask.cs
Created August 13, 2017 13:50
Example of hierarchical FSM using Orleankka "behaviors"
/*
This represents simple durable task which do some work in background.
The task is automatically saved after every successful transition.
It is modeled as workflow with the following transitions:
1. Initial -> Start -> Started
Accept user request and start preparation
2. Started -> Prepared -> Running
On activation of Started it schedules a one-off timer to delay actual execution of Prepare
to finish previous user request and return control to the caller (Orleans is RPC, so it's the hack)
3. Running -> Executed -> Running