madslundt / NetCoreMicroservicesSample

Sample using micro services in .NET Core 3.1 Focusing on clean code
MIT License
695 stars 169 forks source link

[QUESTION] projections and snapshot #11

Closed 3dotsDev closed 3 years ago

3dotsDev commented 3 years ago

when i go step by step trought the code i see the lines in EventStore.cs where you touch the projections and snapshot... But i have no idea what this code does at the end... Maybe you can explain this two things ???? i really like the solution and i want better understanding it image

jbonnett92 commented 3 years ago

They are just calling the handle functions e.g. https://github.com/madslundt/NetCoreMicroservicesSample/blob/1a8e7618343da0a3381abfc6319ccd9ff8adfef2/Src/MoviesService/Commands/CreateMovieCommand.cs#L34-L55

So the process is this, you create a service that uses the event store: https://github.com/madslundt/NetCoreMicroservicesSample/blob/1a8e7618343da0a3381abfc6319ccd9ff8adfef2/Src/MoviesService/Startup.cs#L45

Notice how it uses the movie aggregate class: https://github.com/madslundt/NetCoreMicroservicesSample/blob/1a8e7618343da0a3381abfc6319ccd9ff8adfef2/Src/MoviesService/MovieAggregate.cs

And notice how this is used in the event store class?

Essentially the controllers in each service will send a event to the broker / mediator and does a full circle: https://github.com/madslundt/NetCoreMicroservicesSample/blob/1a8e7618343da0a3381abfc6319ccd9ff8adfef2/Src/MoviesService/Controllers/MovieController.cs#L54-L62 https://github.com/madslundt/NetCoreMicroservicesSample/blob/1a8e7618343da0a3381abfc6319ccd9ff8adfef2/Infrastructure/Core/Commands/CommandBus.cs#L24-L27

Hint, anything that is pushed to the broker / mediator becomes an event and starts using everything in here: https://github.com/madslundt/NetCoreMicroservicesSample/tree/master/Infrastructure/Core/Events

Sorry if it still doesn't make sense! It's a long process but you can follow it in code providing you know the basic concepts of each technology used.

3dotsDev commented 3 years ago

Okay... i see the point... But... when i step trought the code with the debugger and i come to the point above... _snapshot and _projections are always empty...

I start the Docker's for the infrastucture thinks like broker and so on... then i start the 3 services User,Movie and Review from rider ( Jetbrains ) ... and then i try to figure out where this things get filled... ( for the eventstore purpose i debugging reviews -> created calls over postman ).

Maybe you can get me a hint where this Lists where filled and what they called if they filled...

jbonnett92 commented 3 years ago

Have you tried triggering an event that isn't internal? E.g. Deleting a user?

3dotsDev commented 3 years ago

sorry for the long break.... i have tried to check what you mentioned... the lists are always empty.... at this point i wondering where this list get filled...

maybe it would help when you can explain why and how _projections and _snapshots get filled....

In the meantime i did deeper researching on the outbox , cqrs , eventsourcing pattern... and now i can use MediatR too...