Skip to content

Instantly share code, notes, and snippets.

View ContextFactory.cs
public static class ContextFactory
public static ICommandQueryContext CreateContext()
// this environment variable determines if we are running inside TeamCity
if (Environment.GetEnvironmentVariable("TEAMCITY_PROJECT_NAME") == null)
return new InMemoryContext();
// we are inside TeamCity, use a database with unique name
// that includes test method and test class
dlidstrom / serialize.cs
Created Feb 20, 2014
Serialize into xml
View serialize.cs
var serializer = new XmlSerializer(command.GetType());
MemoryStream stream = null;
stream = new MemoryStream();
var streamRef = stream;
using (var writer = new XmlTextWriter(stream, Encoding.Unicode))
// stream is owned by writer and will be disposed automatically
stream = null;
View gist:7dd9ed85135a11e3022e
View RunStyleCop.ps1
param([switch]$verbose, [switch]$v)
# read list of files to ignore
$ignoredFiles = @{}
$filesWithoutIssues = @{}
Get-Content .\StyleCop.IgnoredFiles.txt | % {
if (Test-Path($_))
$item = Get-ChildItem $_
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="StyleCop" xmlns="">
<Import Project="tools\MSBuild Extension Pack\bin\MSBuild.ExtensionPack.tasks"/>
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\tools\StyleCop-4.7\StyleCop.dll" TaskName="StyleCopTask"/>
<Target Name="StyleCop">
View exceptionHandlerDecorator.js
(function () {
//'use strict'; allow default mode here, to be able to capture more detail
function ExceptionHandlerDecorator($provide) {
$provide.decorator('$exceptionHandler', ['$delegate', '$injector', function ($delegate, $injector) {
var apiUrl = '/api/logerror';
return function (exception, cause) {
View httpRequestInterceptor.js
(function () {
'use strict';
.factory('httpRequestInterceptor', HttpRequestInterceptor);
function HttpRequestInterceptor($q, toaster) {
return {
responseError: function (response) {
if (response.status === 500) {
View toaster.js
(function () {
'use strict';
.factory('Toaster', ToasterProvider);
function ToasterProvider(toaster) {
return {
success: function (title, body) {
toaster.pop('success', title, body);
dlidstrom / ExtractIssues.ps1
Created Nov 7, 2014
Can be used to get a record of which files were associated with which Jira issues.
View ExtractIssues.ps1
#foreach line in the input, until empty line
# [DateTime]::Parse('2014-05-28 12:43:43 +0200', [System.Globalization.CultureInfo]::InvariantCulture)
# try some (known) variations
$regex = New-Object System.Text.RegularExpressions.Regex('(?i)(HMO-|HMO -|HMO |HMO - )(\d+)')
$issueNumbers = @{}
$input | % { $regex.Matches($_) } | % {
$issueNumber = "HMO-$($_.Groups[2])"
if (-not $issueNumbers.ContainsKey($issueNumber))
dlidstrom /
Last active Aug 29, 2015
Domain Driven Design Guidelines
  • Aggregate roots should not refer to any other aggregate roots, even in the constructor. Only the id of related aggregate roots is allowed.
  • Constructors can only accept ids and value types.
  • No setter properties are allowed. Use only methods for mutating state.
  • All business rules should be coded in the aggregate roots. Querying is the only type of "business rules" that are allowed outside of aggregate roots.
  • Use domain events to signal events in the domain. This is how related aggregate roots can get notified of what happens in other aggregate roots.
  • Log all non-standard exits from aggregate root methods. For example, return statements in the middle must have a logging statement that explains the decision to exit.