Skip to content

Instantly share code, notes, and snippets.

View rmaziarka's full-sized avatar

Radek Maziarka rmaziarka

View GitHub Profile

This is an obvious reference to the There Is No Antimemetics Division book, but I couldn't resist it ;) (btw it is very good if you like semi-sf stories)

I want to highlight that in a usual bigger system (just bigger, not a really big one) there are no strict CRUD subdomains / components. There are obviously simpler ones which require less thinking, and complex ones. But there is no CRUD as simple Create / Read / Update / Delete. You will always need to apply some analysis and work around it.

Let's go through typical E-commerce domain to get the idea. For each CRUD word I will ask several question to show that answers are not that simple. Then you can adjust this mindset to your own domain.

Create

You could think that this case is a simple one - shouldn't you always be able to create something? You are almost right, but sometimes reality is tricky.

let queryRUChargeData = AzureDiagnostics
| where Category == "DataPlaneRequests"
| where OperationName == "Query"
| project requestCharge_s, operationType_s, activityId_g, databaseName_s, collectionName_s, requestResourceType_s, requestResourceId_s, OperationName, TimeGenerated, callerId_s, clientIpAddress_s, userAgent_s;
AzureDiagnostics
| where Category == "QueryRuntimeStatistics"
| join queryRUChargeData on $left.activityId_g == $right.activityId_g
| summarize SumRU = sum(todouble(requestCharge_s1)), Count = count(requestCharge_s1) by collectionname_s
// it was easier to describe this file on my blog that here:
// https://radekmaziarka.pl/2020/04/12/markdown-generation
'use strict';
const fs = require('fs');
const path = require('path');
const xml2js = require('xml2js');
const TurndownService = require('turndown');
var moment = require('moment');
public class ProductReadModel
{
public ProductReadModel(ProductAddedEvent @event)
{
Id = @event.Id;
Name = @event.Name;
CategoryId = @event.CategoryId;
OrderAmount = 0;
Review = new ReviewReadModel();
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
try
{
await CreateTableAsync("tags");
@rmaziarka
rmaziarka / Category.cs
Last active April 8, 2018 12:26
Product Entities
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
public List<Field> Fields { get; set; }
}
INSERT INTO ProductReadModel
SELECT
P.[Id],
P.[Name],
P.[CategoryId],
(
SELECT
COUNT(O.Id)
FROM
OrderItems AS O
public class ProductAddedEventHandler: INotificationHandler<ProductAddedEvent>
{
private readonly IProductReadModelRepository _repo;
public ProductAddedEventHandler(IProductReadModelRepository repo)
{
_repo = repo;
}
public void Handle(ProductAddedEvent @event)
public class ProductAddedEvent : INotification
{
public ProductAddedEvent(int id, string name, int categoryId)
{
Id = id;
Name = name;
CategoryId = categoryId;
}
public int Id { get; }
public class AddProductCommandHandler : IRequestHandler<AddProductCommand>
{
private readonly ProductDatabase _database;
private readonly IMediator _mediator;
public AddProductCommandHandler(ProductDatabase database, IMediator mediator)
{
_database = database;
_mediator = mediator;
}