In memory example configuration
See original GitHub issueHey, a while ago I was playing around with CosmoStore and I used the in-memory approach.
#load ".paket/load/main.group.fsx"
open System
open System.Collections.Concurrent
open CosmoStore
open CosmoStore.InMemory
open Thoth.Json.Net
open Microsoft.FSharp.Reflection
let config : Configuration =
{ InMemoryStreams = ConcurrentDictionary<string,Stream>()
InMemoryEvents = ConcurrentDictionary<Guid, EventRead>() }
let store = EventStore.getEventStore config
type Event =
| Increase of int
| Decrease of int
let encodeEvent = Encode.Auto.generateEncoder<Event>()
let decodeEvent = Decode.Auto.generateDecoder<Event>()
let getUnionCaseName (x:'a) =
match FSharpValue.GetUnionFields(x, typeof<'a>) with
| case, _ -> case.Name
let createEvent event =
{ Id = (Guid.NewGuid())
CorrelationId = None
CausationId = None
Name = getUnionCaseName event
Data = encodeEvent event
Metadata = None }
let appendEvent event =
store.AppendEvent "CounterStream" ExpectedPosition.Any event
|> Async.AwaitTask
|> Async.RunSynchronously
let increase amount =
Increase(amount)
|> createEvent
|> appendEvent
let decrease amount =
Decrease(amount)
|> createEvent
|> appendEvent
increase 5
decrease 3
increase 198
decrease 203
increase 4
store.GetEvents "CounterStream" EventsReadRange.AllEvents
|> Async.AwaitTask
|> Async.RunSynchronously
|> List.fold (fun acc e ->
match Decode.fromValue "$" decodeEvent e.Data with
| Ok(Increase i) -> acc + i
| Ok(Decrease d) -> acc - d
| Error e ->
failwithf "invalid event from store, %s" e
) 0
|> printfn "Projected state is %d"
When upgrading to v3 I noticed that my configuration isn’t correct anymore. Could a sample perhaps be added to the README for InMemory configuration?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Keeping Configuration Settings in Memory
This lets me organize my configuration settings into sections. My example defined a section called toDoService with two settings: url and ...
Read more >How to create a hierarchical in-memory configuration ...
I would like to create a hierarchical in-memory configuration along the lines of using a nested dictionary to populate the IConfiguration . My ......
Read more >In-Memory Authentication
In the following sample, we use User.withDefaultPasswordEncoder to ensure that the password stored in memory is protected.
Read more >Configuration in ASP.NET Core
Learn how to use the Configuration API to configure AppSettings in an ASP.NET Core app.
Read more >MemoryConfigurationSource Class
Builds the MemoryConfigurationProvider for this source. Equals(Object). Determines whether the specified object is equal to the current object.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My fault, I didn’t publish new in memory version yet - will do now.
@Dzoukr this can be closed as well. I guess we are having updated version now.