Skip to content

Commit

Permalink
Shift tenant to streamId part of stream name
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Oct 14, 2021
1 parent 285a717 commit fabcf77
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions CQRS_Flow/.NET/Core/Core/Events/StreamNameMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ public static string ToStreamPrefix(Type streamType) => Instance.typeNameMap.Get
public static string ToStreamId<TStream>(object aggregateId, object? tenantId = null) =>
ToStreamId(typeof(TStream), aggregateId);

// Generates a stream id in the canonical `{category}-{aggregateId}` format
public static string ToStreamId(Type streamType, object aggregateId, object? tenantId = null)
{
var tenantPrefix = tenantId != null ? $"{tenantId}_" : "";
var tenantPrefix = tenantId == null ? $"{tenantId}_" : "";
var category = ToStreamPrefix(streamType);

return $"{tenantPrefix}{ToStreamPrefix(streamType)}-{aggregateId}";
// (Out-of-the box, the category projection treats the category as the left bit, based on the `-` separator)
// For this reason, we place the "{tenantId}_" bit on the right hand side of the '-' if present
return $"{category}-{tenantPrefix}{aggregateId}";
}

}
}

0 comments on commit fabcf77

Please sign in to comment.