Skip to content

Commit

Permalink
Merge pull request #5 from erikshafer/fixes_during_youtube_video_reco…
Browse files Browse the repository at this point in the history
…rding

Updates for YouTube video release
  • Loading branch information
erikshafer authored Jun 12, 2024
2 parents f6d80f3 + 2ee5646 commit e4c6540
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 21 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

An application showing the absolute basics of event sourcing with [EventStoreDB (ESDB)](https://www.eventstore.com/).

The accompanying [YouTube video can be found here](https://www.youtube.com/watch?v=SB55-lgK_8I).

## 💡 Inspiration

Inspired by Nick Chapsas' video about [getting started with Event Sourcing in .NET](https://www.youtube.com/watch?v=n_o-xuuVtmw). This take however uses EventStoreDB as its, well, store of events!
This effort was inspired by Nick Chapsas' excellent video about [getting started with Event Sourcing in .NET](https://www.youtube.com/watch?v=n_o-xuuVtmw). This version however uses EventStoreDB as its database.

Be sure to check out [Nick's YouTube channel](https://www.youtube.com/@nickchapsas) if you are somehow unfamiliar with his content, as well as his education platform [Dometrain](https://dometrain.com/) where you can level up your software development skills!

### 📄 Mini-Log / 🤔 Thoughts / 🧠 Brain Dump

Expand Down
19 changes: 5 additions & 14 deletions StudentEnrollment03.Esdb/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
await client.AppendToStreamAsync(
streamId,
StreamState.Any,
new[] { created, enrolled, enrolled2, enrolled3, emailChanged },
new[] { created, enrolled, enrolled2, enrolled3, emailChanged, withdrawn },
cancellationToken: default
);

Expand All @@ -112,23 +112,14 @@ await client.AppendToStreamAsync(

// Okay, taking that StreamResult we're going to make it a List of ResolvedEvents.
var eventStream = await streamResult.ToListAsync();
// Get the last event's event number.
var lastEventNumFromStream = eventStream.Last().Event.EventNumber.ToUInt64();

// Append another event. This time let's make sure no one has appended to (AKA updated) the stream.
await client.AppendToStreamAsync(
streamId,
new StreamRevision(lastEventNumFromStream), // checking against expected revision number
new[] { withdrawn },
cancellationToken: default
);
Console.WriteLine($"Events (total: {eventStream.Count}) from selected stream: ");

// Instantiate our model and then apply state changes from the deserialized events.
var student = new Student();

Console.WriteLine($"Events (total: {eventStream.Count}) from selected stream: ");
foreach (var @event in eventStream)
{
switch (DeserializeEvent(@event.Event))
var deserializeEvent = DeserializeEvent(@event.Event);
switch (deserializeEvent)
{
case StudentCreated studentCreated:
student.Apply(studentCreated);
Expand Down
6 changes: 3 additions & 3 deletions StudentEnrollment03.Esdb/Student.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public void Apply(Event @event)
case StudentCreated created:
Apply(created);
break;
case StudentEmailChanged emailChanged:
Apply(emailChanged);
break;
case StudentEnrolled enrolled:
Apply(enrolled);
break;
case StudentEmailChanged emailChanged:
Apply(emailChanged);
break;
case StudentWithdrew withdrawn:
Apply(withdrawn);
break;
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
version: "3.4"

services:
services:
app01-inmemory:
build:
dockerfile: StudentEnrollment01.InMemory/Dockerfile
Expand Down

0 comments on commit e4c6540

Please sign in to comment.