Skip to content

Commit

Permalink
Added README for versioning samples
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz committed Dec 8, 2021
1 parent a790eb7 commit bcdbeaa
Show file tree
Hide file tree
Showing 11 changed files with 627 additions and 39 deletions.
31 changes: 23 additions & 8 deletions README.md
Expand Up @@ -25,10 +25,11 @@ Tutorial, practical samples and other resources about Event Sourcing in .NET Cor
- [6.2 Simple EventSourcing with EventStoreDB](#62-simple-eventsourcing-with-eventstoredb)
- [6.3 ECommerce with EventStoreDB](#63-ecommerce-with-eventstoredb)
- [6.5 Warehouse](#65-warehouse)
- [6.6 Event Pipelines](#66-event-pipelines)
- [6.7 Meetings Management with Marten](#67-meetings-management-with-marten)
- [6.8 Cinema Tickets Reservations with Marten](#68-cinema-tickets-reservations-with-marten)
- [6.9 SmartHome IoT with Marten](#69-smarthome-iot-with-marten)
- [6.6 Event Versioning](#66-event-versioning)
- [6.7 Event Pipelines](#67-event-pipelines)
- [6.8 Meetings Management with Marten](#68-meetings-management-with-marten)
- [6.9 Cinema Tickets Reservations with Marten](#69-cinema-tickets-reservations-with-marten)
- [6.10 SmartHome IoT with Marten](#610-smarthome-iot-with-marten)
- [7. Self-paced training Kit](#7-self-paced-training-kit)
- [8. Articles](#8-articles)
- [9. Event Store - Marten](#9-event-store---marten)
Expand Down Expand Up @@ -453,7 +454,21 @@ Samples are using CQRS architecture. They're sliced based on the business module
- No Event Sourcing! Using Entity Framework to show that CQRS is not bounded to Event Sourcing or any type of storage,
- No Aggregates! CQRS do not need DDD. Business logic can be handled in handlers.

### 6.6 [Event Pipelines](./Sample/EventPipelines)
### 6.6 [Event Versioning](./Sample/EventVersioning)
Shows how to handle basic event schema versioning scenarios using event and stream transformations (e.g. upcasting):
- [Simple mapping](./Sample/EventsVersioning/#simple-mapping)
- [New not required property](./Sample/EventsVersioning/#new-not-required-property)
- [New required property](./Sample/EventsVersioning/#new-required-property)
- [Renamed property](./Sample/EventsVersioning/#renamed-property)
- [Upcasting](./Sample/EventsVersioning/#upcasting)
- [Changed Structure](./Sample/EventsVersioning/#changed-structure)
- [New required property](./Sample/EventsVersioning/#new-required-property-1)
- [Downcasters](./Sample/EventsVersioning/#downcasters)
- [Events Transformations](./Sample/EventsVersioning/#events-transformations)
- [Stream Transformation](./Sample/EventsVersioning/#stream-transformation)
- [Summary](./Sample/EventsVersioning/#summary)

### 6.7 [Event Pipelines](./Sample/EventPipelines)
Shows how to compose event handlers in the processing pipelines to:
- filter events,
- transform them,
Expand All @@ -464,20 +479,20 @@ Shows how to compose event handlers in the processing pipelines to:
- can be used with Dependency Injection, but also without through builder,
- integrates with MediatR if you want to.

### 6.7 [Meetings Management with Marten](./Sample/MeetingsManagement/)
### 6.8 [Meetings Management with Marten](./Sample/MeetingsManagement/)
- typical Event Sourcing and CQRS flow,
- DDD using Aggregates,
- microservices example,
- stores events to Marten,
- Kafka as a messaging platform to integrate microservices,
- read models handled in separate microservice and stored to other database (ElasticSearch)

### 6.8 [Cinema Tickets Reservations with Marten](./Sample/Tickets/)
### 6.9 [Cinema Tickets Reservations with Marten](./Sample/Tickets/)
- typical Event Sourcing and CQRS flow,
- DDD using Aggregates,
- stores events to Marten.

### 6.9 [SmartHome IoT with Marten](./Sample/AsyncProjections/)
### 6.10 [SmartHome IoT with Marten](./Sample/AsyncProjections/)
- typical Event Sourcing and CQRS flow,
- DDD using Aggregates,
- stores events to Marten,
Expand Down
2 changes: 1 addition & 1 deletion Sample/EventPipelines/README.md
@@ -1,4 +1,4 @@
# [Event Pipelines](./EventPipelines)
# Event Pipelines

Shows how to compose event handlers in the processing pipelines to:
- filter events,
Expand Down
2 changes: 1 addition & 1 deletion Sample/EventStoreDB/Simple/README.md
@@ -1,6 +1,6 @@
# Simple, practical EventSourcing with EventStoreDB and EntityFramework

The PR is adding a new sample that contains the simple Event Sourcing setup with EventStoreDB. For the Read Model, Postgres and Entity Framework are used.
The is the simple Event Sourcing setup with EventStoreDB. For the Read Model, Postgres and Entity Framework are used.

You can watch the webinar on YouTube where I'm explaining the details of the implementation:

Expand Down
Expand Up @@ -18,27 +18,27 @@ public record ShoppingCartInitialized(
Client Client
);

public static V1.ShoppingCartInitialized Downcast(
ShoppingCartInitialized newEvent
)
{
return new V1.ShoppingCartInitialized(
newEvent.ShoppingCartId,
newEvent.Client.Id
);
}
public static V1.ShoppingCartInitialized Downcast(
ShoppingCartInitialized newEvent
)
{
return new V1.ShoppingCartInitialized(
newEvent.ShoppingCartId,
newEvent.Client.Id
);
}

public static V1.ShoppingCartInitialized Downcast(
string newEventJson
)
{
var newEvent = JsonDocument.Parse(newEventJson).RootElement;
public static V1.ShoppingCartInitialized Downcast(
string newEventJson
)
{
var newEvent = JsonDocument.Parse(newEventJson).RootElement;

return new V1.ShoppingCartInitialized(
newEvent.GetProperty("ShoppingCartId").GetGuid(),
newEvent.GetProperty("Client").GetProperty("Id").GetGuid()
);
}
return new V1.ShoppingCartInitialized(
newEvent.GetProperty("ShoppingCartId").GetGuid(),
newEvent.GetProperty("Client").GetProperty("Id").GetGuid()
);
}

[Fact]
public void UpcastObjects_Should_BeForwardCompatible()
Expand Down Expand Up @@ -74,4 +74,4 @@ public void UpcastJson_Should_BeForwardCompatible()
@event.ShoppingCartId.Should().Be(newEvent.ShoppingCartId);
@event.ClientId.Should().Be(newEvent.Client.Id);
}
}
}
Expand Up @@ -86,7 +86,8 @@ public EventTransformations Register<TEvent>(string eventTypeName, Func<JsonDocu
return this;
}

public EventTransformations Register<TOldEvent, TEvent>(string eventTypeName, Func<TOldEvent, TEvent> transformEvent)
public EventTransformations Register<TOldEvent, TEvent>(string eventTypeName,
Func<TOldEvent, TEvent> transformEvent)
where TOldEvent : notnull
where TEvent : notnull
{
Expand All @@ -100,7 +101,7 @@ public EventTransformations Register<TEvent>(string eventTypeName, Func<JsonDocu

public class EventTypeMapping
{
private readonly Dictionary<string, Type> mappings = new ();
private readonly Dictionary<string, Type> mappings = new();

public EventTypeMapping Register<TEvent>(params string[] typeNames)
{
Expand Down Expand Up @@ -130,7 +131,8 @@ public EventSerializer(EventTypeMapping mapping, EventTransformations transforma

public object? Deserialize(string eventTypeName, string json) =>
transformations.TryTransform(eventTypeName, json, out var transformed)
? transformed : JsonSerializer.Deserialize(json, mapping.Map(eventTypeName));
? transformed
: JsonSerializer.Deserialize(json, mapping.Map(eventTypeName));
}

[Fact]
Expand Down Expand Up @@ -160,15 +162,15 @@ public void UpcastObjects_Should_BeForwardCompatible()
);
var eventV2 = new ShoppingCartInitialized(
Guid.NewGuid(),
new Client(Guid.NewGuid(), "Oscar the Grouch" )
new Client(Guid.NewGuid(), "Oscar the Grouch")
);
var eventV3 = new ShoppingCartInitializedWithStatus(
Guid.NewGuid(),
new Client(Guid.NewGuid(), "Big Bird"),
ShoppingCartStatus.Pending
);

var events = new []
var events = new[]
{
new { EventType = eventTypeV1Name, EventData = JsonSerializer.Serialize(eventV1) },
new { EventType = eventTypeV2Name, EventData = JsonSerializer.Serialize(eventV2) },
Expand Down Expand Up @@ -198,4 +200,4 @@ public void UpcastObjects_Should_BeForwardCompatible()
deserializedEvents[2].Client.Should().Be(eventV3.Client);
deserializedEvents[2].Status.Should().Be(eventV3.Status);
}
}
}
Expand Up @@ -289,4 +289,4 @@ public void UpcastObjects_Should_BeForwardCompatible()
deserializedEvents[2].As<V1.ShoppingCartConfirmed>()
.ShoppingCartId.Should().Be(shoppingCardId);
}
}
}
Expand Up @@ -73,4 +73,4 @@ public void UpcastJson_Should_BeForwardCompatible()
@event.Client.Id.Should().Be(oldEvent.ClientId);
@event.Client.Name.Should().Be("Unknown");
}
}
}
Expand Up @@ -79,4 +79,4 @@ public void UpcastJson_Should_BeForwardCompatible()
@event.ClientId.Should().Be(oldEvent.ClientId);
@event.InitializedBy.Should().Be(eventMetadata.UserId);
}
}
}

0 comments on commit bcdbeaa

Please sign in to comment.