Skip to content

Instantly share code, notes, and snippets.

View stormwild's full-sized avatar
🏠
Working from home

Alexander R Torrijos stormwild

🏠
Working from home
View GitHub Profile

Read Part 1: MediatR vs MassTransit Mediator - Differences

The MassTransit Mediator implementation is more powerful than MediatR implementation, but also more complicate to use. Unit Testing a MassTransit Consumer is not a nice experience.

In this article I will propose some techniques to simplify the MassTransit Consumer and to make them look as straight forward as a MediatR handler.

Case study

We will study a very common use case (the most common use case which I can think of):

Why mediator?

In a ASP.NET Web application. You don't need mediator

  • If you prefers to make controlers depends directly to the Application Codes instead of indirectly via the Mediator.
  • If you prefers to make a normal ASP.NET Web Application instead of a Mediator Application

Frankly it is not a Bad choice, no need to use a Mediator framework or make a Mediator Application just because everyone did.. Though, There are benefits in making a Mediator Application:

  • Event sourcing (Messages broadcast), CQS pattern..
  • Decouple the Controler (presentation) from Application codes, so that you could swap the presentation technology. For eg, if you make a "MassTransit" application, then you can swap the presentation layer to Mediator or RabbitMQ, or Grpc.. => you are not to be sticked with or limited by ASP.NET presentation => but rather sticked with and limited by your mediator framework!
@stormwild
stormwild / test.md
Created July 29, 2023 16:06 — forked from ityonemo/test.md
Zig in 30 minutes

A half-hour to learn Zig

This is inspired by https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/

Basics

the command zig run my_code.zig will compile and immediately run your Zig program. Each of these cells contains a zig program that you can try to run (some of them contain compile-time errors that you can comment out to play with)

@stormwild
stormwild / git bash ssh agent.md
Created May 19, 2023 11:01 — forked from Peregrinox/git bash ssh agent.md
configure your git bash to run agent on start
@stormwild
stormwild / 0 - ServiceHost.cs
Created July 2, 2021 08:35 — forked from andriybuday/0 - ServiceHost.cs
Microsoft.Extensions.DependencyInjection with OWIN Self-Hosted WebAPI
// ...
using Microsoft.Owin.Hosting;
// ...
public class ServiceHost
{
private IDisposable server = null;
const string baseAddress = "https://*:443";
public void Start()
@stormwild
stormwild / curl.md
Created May 15, 2020 15:22 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@stormwild
stormwild / new empty git branch.md
Created May 12, 2020 06:54 — forked from ozh/new empty git branch.md
Create a new empty branch in Git
$ git checkout --orphan NEWBRANCH
$ git rm -rf .

--orphan creates a new branch, but it starts without any commit. After running the above command you are on a new branch "NEWBRANCH", and the first commit you create from this state will start a new history without any ancestry.

You can then start adding files and commit them and they will live in their own branch. If you take a look at the log, you will see that it is isolated from the original log.

@stormwild
stormwild / useUserReducer.ts
Created April 12, 2020 11:27 — forked from schettino/useUserReducer.ts
Better Reducers with React and Typescript 3.4
import { useReducer } from 'react'
export function updateName(name: string) {
return <const>{
type: 'UPDATE_NAME',
name
}
}
export function addPoints(points: number) {