Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for YouTube video release #5

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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