Skip to content

Instantly share code, notes, and snippets.

View pjvds's full-sized avatar
:octocat:
‏‏‎

Pieter Joost van de Sande pjvds

:octocat:
‏‏‎
View GitHub Profile
public class SalesOrderService
{
// A command should map to this method.
public void AddProducToSalesOrder(Guid salesOrderId, Guid productId, int quantity)
{
using(var work = GetUnitOfWork())
{
var order = work.GetById<SalesOrder>(salesOrderId);
var product = work.GetById<Product>(productId);
using System;
using System.Collections.Generic;
using Scrumr.Events.Project;
namespace Scrumr.Domain
{
public class Project : ScrumrAggregateRoot
{
private string _name;
private List<Guid> _members = new List<Guid>();

Adding Entity Support to Ncqrs

Goal

Add entity support to Ncqrs.

Why we need it

An aggregate root covers all state changes by events. These events are stored and aggregate roots can rebuild themself from these events by re-applying them.

using System;
using System.Linq;
using FluentAssertions;
using Ncqrs.Commanding.CommandExecution;
using Ncqrs.Commanding.CommandExecution.Mapping.Fluent;
using Ncqrs.Spec;
using Scrumr.Commands;
using Scrumr.Events.Project;
namespace Scrumr.Domain.Tests.Scenarios.Creating_a_new_project
@pjvds
pjvds / gist:733118
Created December 8, 2010 10:27 — forked from larsw/gist:733114
C:\github\larsw\ncqrs-master>tools\nant\nant.exe /f:"MAIN.build"
NAnt 0.91 (Build 0.91.3881.0; alpha2; 17.08.2010)
Copyright (C) 2001-2010 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///C:/github/larsw/ncqrs-master/MAIN.build
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: build
@pjvds
pjvds / gist:745087
Created December 17, 2010 15:12
Poco Aggregate Root braindump

Intro

This is just an braindrump and rolling gist that reflect the thought about POCO support for Ncqrs.

The Poco object

  1. Contain typed event handling methods like OnCustomerNameChanged(NameChanged e) that update internal state.
  2. Contains a Guid ID property. This will hold the event source id.
  3. Contains one ctor for 'new' instances that only accepts an Func callback.
  4. Contains one ctor to support loading from history. This ctor has two parameters. On Func callback and an Guid value with the existing id.

So minimal code is:

{"Could not load file or assembly 'nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"}
Could not load file or assembly 'nunit.framework, Version=2.5.5.10112, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at FluentAssertions.Verification.Fail(String format, Object expected, Object actual, String reason, Object[] reasonParameters, Object[] args)
at FluentAssertions.Verification.Verify(Boolean condition, String failureMessage, Object expected, Object actual, String reason, Object[] reasonParameters)
at FluentAssertions.Verification.Verify(Func`1 condition, String failureMessage, Objec
@pjvds
pjvds / LinqExpression
Created January 21, 2011 14:59
Possible solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using LinqKit;
using System.Text.RegularExpressions;
namespace DynamicQueryProblem
private static long? GetKnownVersion(ICommand cmd)
{
const BindingFlags allInstance = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
var knownVersionAttributeType = typeof (KnownVersionAttribute);
var commandType = cmd.GetType();
var knownVersionProperties =
commandType.GetProperties(allInstance).Where(p => p.IsDefined(knownVersionAttributeType, false));
if (knownVersionProperties.IsEmpty())