For the update on beers, I’m back the land of the IPAs! Cider was just not a thing for me anymore. I tried to like it, but without any success I’ve now fallen back to IPAs :)
Code for this post is in branch: learning-unbeered-13.
- Brought in RavenDB as a data store! I’m using RavenDB(v3.5) in production at work and I’ve to say I’m extremely happy! Take a look at the feature list and you’d definitely want to give it a try. The community edition is now free for commercial usage.
- The only place that I am still using LiteDB is to store data about “Consecutive Beering”, every other data is now in RavenDB. This is the beauty of de-coupling logic. We can use separate storage for separate concerns. Use relational, nosql, graph storage where it makes sense!
- I’ve separated out handlers according to what it does. i.e CalculatedDataHandler.cs deals with anything to do with CalculatedData. Similarly, ConsecutiveBeering and TooManyBeers handles logic related to their concerns!
- Installing RavenDB is extremely easy! Follow the getting started instruction here. Once installed, use the Management Studio(web) to create a database “unbeering-db”. When initializing the DocumentStore later in the Program.cs, we provide the db name and connection to the server which is localhost:8080 or any other port you used during setup!
- Program.cs now also initializes RavenDB DocumentStore which basically acts as a connection manager to RavenDB server. by providing api to perform various operations. An instance of the DocumentStore is registered as a singleton to ServiceCollection since it is costly to initialize and dispose it.
- In order to perform various operations like querying, loading, saving data to RavenDB, we need to use DocumentSession which can be obtained from DocumentStore.
- A new instance of DocumentSession should be obtained for a life cycle of a single session.
- When we are ready to commit the changes to a document in a session we call SaveChanges() method on a session. The API implements Unit Of Work pattern and therefore changes in the data in a particular session is sent to the server as an unit!
Whats next?
I hope this was pretty straight forward! I think the next step would be to make a few minor changes to the console UI!
Cheers until then!